Update progress bar more fluidly.

This commit is contained in:
2017-08-22 16:31:31 +01:00
parent 052fd5145f
commit a874eb48a3

View File

@@ -172,7 +172,6 @@ namespace osrepodbmgr.Core
else else
filesPath = Context.path; filesPath = Context.path;
int counter = 0;
string extension = null; string extension = null;
switch(Settings.Current.CompressionAlgorithm) switch(Settings.Current.CompressionAlgorithm)
@@ -191,13 +190,17 @@ namespace osrepodbmgr.Core
break; break;
} }
long totalSize = 0, currentSize = 0;
foreach (KeyValuePair<string, DBOSFile> file in Context.hashes)
totalSize += file.Value.Length;
#if DEBUG #if DEBUG
stopwatch.Restart(); stopwatch.Restart();
#endif #endif
foreach(KeyValuePair<string, DBOSFile> file in Context.hashes) foreach(KeyValuePair<string, DBOSFile> file in Context.hashes)
{ {
if(UpdateProgress != null) if(UpdateProgress != null)
UpdateProgress("Compressing...", file.Value.Path, counter, Context.hashes.Count); UpdateProgress("Compressing...", file.Value.Path, currentSize, totalSize);
destinationFolder = Path.Combine(Settings.Current.RepositoryPath, file.Value.Sha256[0].ToString(), file.Value.Sha256[1].ToString(), file.Value.Sha256[2].ToString(), file.Value.Sha256[3].ToString(), file.Value.Sha256[4].ToString()); destinationFolder = Path.Combine(Settings.Current.RepositoryPath, file.Value.Sha256[0].ToString(), file.Value.Sha256[1].ToString(), file.Value.Sha256[2].ToString(), file.Value.Sha256[3].ToString(), file.Value.Sha256[4].ToString());
Directory.CreateDirectory(destinationFolder); Directory.CreateDirectory(destinationFolder);
@@ -236,9 +239,12 @@ namespace osrepodbmgr.Core
UpdateProgress2(string.Format("{0:P}", inFs.Position / (double)inFs.Length), UpdateProgress2(string.Format("{0:P}", inFs.Position / (double)inFs.Length),
string.Format("{0} / {1} bytes", inFs.Position, inFs.Length), string.Format("{0} / {1} bytes", inFs.Position, inFs.Length),
inFs.Position, inFs.Length); inFs.Position, inFs.Length);
if (UpdateProgress != null)
UpdateProgress("Compressing...", file.Value.Path, currentSize, totalSize);
inFs.Read(buffer, 0, buffer.Length); inFs.Read(buffer, 0, buffer.Length);
zStream.Write(buffer, 0, buffer.Length); zStream.Write(buffer, 0, buffer.Length);
currentSize += buffer.Length;
} }
buffer = new byte[inFs.Length - inFs.Position]; buffer = new byte[inFs.Length - inFs.Position];
@@ -246,9 +252,12 @@ namespace osrepodbmgr.Core
UpdateProgress2(string.Format("{0:P}", inFs.Position / (double)inFs.Length), UpdateProgress2(string.Format("{0:P}", inFs.Position / (double)inFs.Length),
string.Format("{0} / {1} bytes", inFs.Position, inFs.Length), string.Format("{0} / {1} bytes", inFs.Position, inFs.Length),
inFs.Position, inFs.Length); inFs.Position, inFs.Length);
if (UpdateProgress != null)
UpdateProgress("Compressing...", file.Value.Path, currentSize, totalSize);
inFs.Read(buffer, 0, buffer.Length); inFs.Read(buffer, 0, buffer.Length);
zStream.Write(buffer, 0, buffer.Length); zStream.Write(buffer, 0, buffer.Length);
currentSize += buffer.Length;
if (UpdateProgress2 != null) if (UpdateProgress2 != null)
UpdateProgress2(string.Format("{0:P}", inFs.Length / (double)inFs.Length), UpdateProgress2(string.Format("{0:P}", inFs.Length / (double)inFs.Length),
@@ -258,8 +267,8 @@ namespace osrepodbmgr.Core
zStream.Close(); zStream.Close();
outFs.Dispose(); outFs.Dispose();
} }
else
counter++; currentSize += file.Value.Length;
} }
#if DEBUG #if DEBUG
stopwatch.Stop(); stopwatch.Stop();