Compare commits

...
3 changed files with 37 additions and 5 deletions
+8 -3
View File
@@ -719,7 +719,8 @@ namespace Duplicati.Library.Main
m_backend.Put(item.RemoteFilename, item.LocalFilename);
var duration = DateTime.Now - begin;
Logging.Log.WriteMessage(string.Format("Uploaded {0} in {1}, {2}/s", Library.Utility.Utility.FormatSizeString(item.Size), duration, Library.Utility.Utility.FormatSizeString((long)(item.Size / duration.TotalSeconds))), Duplicati.Library.Logging.LogMessageType.Profiling);
var speed = duration.TotalMilliseconds < 100 ? string.Empty : string.Format(", {0}/s", Library.Utility.Utility.FormatSizeString(item.Size / duration.TotalSeconds));
Logging.Log.WriteMessage(string.Format("Uploaded {0} in {1}{2}", Library.Utility.Utility.FormatSizeString(item.Size), duration, speed), Duplicati.Library.Logging.LogMessageType.Profiling);
if (!item.NotTrackedInDb)
m_db.LogDbUpdate(item.RemoteFilename, RemoteVolumeState.Uploaded, item.Size, item.Hash);
@@ -995,8 +996,12 @@ namespace Duplicati.Library.Main
tmpfile = coreDoGetPiping(item, useDecrypter, out dataSizeDownloaded, out fileHash);
var duration = DateTime.Now - begin;
Logging.Log.WriteMessage(string.Format("Downloaded {3}{0} in {1}, {2}/s", Library.Utility.Utility.FormatSizeString(dataSizeDownloaded),
duration, Library.Utility.Utility.FormatSizeString((long)(dataSizeDownloaded / duration.TotalSeconds)),
var speed = duration.TotalMilliseconds < 100 ? string.Empty : string.Format(", {0}/s", Library.Utility.Utility.FormatSizeString(item.Size / duration.TotalSeconds));
Logging.Log.WriteMessage(string.Format("Downloaded {3}{0} in {1}{2}",
Library.Utility.Utility.FormatSizeString(dataSizeDownloaded),
duration,
speed,
useDecrypter == null ? "" : "and decrypted "), Duplicati.Library.Logging.LogMessageType.Profiling);
m_db.LogDbOperation("get", item.RemoteFilename, JsonConvert.SerializeObject(new { Size = dataSizeDownloaded, Hash = fileHash }));
+1
View File
@@ -30,6 +30,7 @@ namespace Duplicati.Library.Utility.Strings {
public static string FormatStringKB(double size) { return LC.L(@"{0:N} KB", size); }
public static string FormatStringMB(double size) { return LC.L(@"{0:N} MB", size); }
public static string FormatStringTB(double size) { return LC.L(@"{0:N} TB", size); }
public static string FormatStringPB(double size) { return LC.L(@"{0:N} PB", size); }
public static string InvalidDateError(string data) { return LC.L(@"The string ""{0}"" could not be parsed into a date", data); }
}
internal static class MD5CalculatingStream {
+28 -2
View File
@@ -588,8 +588,11 @@ namespace Duplicati.Library.Utility
/// <returns>A human readable string representing the size</returns>
public static string FormatSizeString(long size)
{
long sizeAbs = Math.Abs(size); // Allow formatting of negative sizes
if (sizeAbs >= 1024 * 1024 * 1024 * 1024L)
// Allow formatting of negative sizes, but guard against the min value
var sizeAbs = Math.Abs(size == long.MinValue ? size + 1 : size);
if (sizeAbs >= 1024 * 1024 * 1024 * 1024L * 1024L)
return Strings.Utility.FormatStringPB((double)size / (1024 * 1024 * 1024 * 1024L * 1024L));
else if (sizeAbs >= 1024 * 1024 * 1024 * 1024L)
return Strings.Utility.FormatStringTB((double)size / (1024 * 1024 * 1024 * 1024L));
else if (sizeAbs >= 1024 * 1024 * 1024)
return Strings.Utility.FormatStringGB((double)size / (1024 * 1024 * 1024));
@@ -601,6 +604,29 @@ namespace Duplicati.Library.Utility
return Strings.Utility.FormatStringB(size);
}
/// <summary>
/// Formats a size into a human readable format, eg. 2048 becomes &quot;2 KB&quot; or -2283 becomes &qout;-2.23 KB%quot.
/// </summary>
/// <param name="size">The size to format</param>
/// <returns>A human readable string representing the size</returns>
public static string FormatSizeString(double size)
{
// Allow formatting of negative sizes, but guard against the min value
var sizeAbs = Math.Abs(size);
if (sizeAbs >= 1024.0 * 1024 * 1024 * 1024 * 1024)
return Strings.Utility.FormatStringPB(size / (1024.0 * 1024 * 1024 * 1024 * 1024));
else if (sizeAbs >= 1024.0 * 1024 * 1024 * 1024)
return Strings.Utility.FormatStringTB(size / (1024.0 * 1024 * 1024 * 1024));
else if (sizeAbs >= 1024.0 * 1024 * 1024)
return Strings.Utility.FormatStringGB(size / (1024.0 * 1024 * 1024));
else if (sizeAbs >= 1024.0 * 1024)
return Strings.Utility.FormatStringMB(size / (1024.0 * 1024));
else if (sizeAbs >= 1024.0)
return Strings.Utility.FormatStringKB(size / 1024.0);
else
return Strings.Utility.FormatStringB((long)Math.Round(size));
}
public static System.Threading.ThreadPriority ParsePriority(string value)
{
if (string.IsNullOrEmpty(value) || value.Trim().Length == 0)