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