private void UpdateDownloadFormHashing(bool UpdateUIText) { int numfiles = 0; int numnothashed = 0; // iterate files foreach (PatchFile file in files) { // get this once, cause they have a locking PatchFileHashedStatus filestatus = file.HashedStatus; if (filestatus == PatchFileHashedStatus.NotHashed) { numnothashed++; } // filescounter numfiles++; } int numdone = numfiles - numnothashed; // update progress bar double progress = (numfiles == 0) ? 0.0 : (double)numdone / (double)numfiles; int progressint = Convert.ToInt32(((progress * (double)progressOverall.Maximum) * 0.4) + (double)progressOverall.Maximum * 0.1); progressOverall.Value = Math.Max(progressOverall.Minimum, Math.Min(progressOverall.Maximum, progressint)); // update processed files not more than once per second if (UpdateUIText) { progressOverall.Text = String.Format(languageHandler.NumFiles, numdone, numfiles); } }
private void UpdateDownloadFormDownloadingFiles(double MsInterval, bool UpdateUIText, int MaxStages) { int numfiles = 0; int numdone = 0; long todo = 0; long done = 0; // iterate files foreach (PatchFile file in files) { // get these once, cause they have a locking long filedone = file.LengthDone; PatchFileHashedStatus filestatus = file.HashedStatus; if (filestatus == PatchFileHashedStatus.Download) { // byte-counters todo += file.Length; done += filedone; // done files counter if (filedone >= file.Length) { numdone++; } numfiles++; } } // update download speed and processed bytes not more than once per second if (UpdateUIText) { // update speed for last interval double bytes_in_interval = done - lastLengthDone; double interval_in_s = 0.001 * MsInterval; double kbps = (interval_in_s <0.0001 && interval_in_s> -0.0001) ? 0.0 : 0.001 * (bytes_in_interval / interval_in_s); // update processed MB counter double done_mb = (double)done / (1024.0 * 1024.0); double todo_mb = (double)todo / (1024.0 * 1024.0); progressOverall.Text = String.Format("{0:0.00}", done_mb) + " / " + String.Format("{0:0.00} MB", todo_mb) + " @ " + String.Format("{0:0.00} KB/s", kbps); // remember values for next execution lastLengthDone = done; } // update progress bar double progress = (todo == 0) ? 0.0 : (double)done / (double)todo; double maxStageProgress = (MaxStages == 4 ? 0.4 : 0.5); int progressint = Convert.ToInt32(((progress * (double)progressOverall.Maximum) * maxStageProgress) + (double)progressOverall.Maximum * 0.5); progressOverall.Value = Math.Max(progressOverall.Minimum, Math.Min(progressOverall.Maximum, progressint)); }
private void OnDeserialized(StreamingContext ctx) { this.lengthDonelockObject = new Object(); this.hashedStatuslockObject = new Object(); this.ErrorCount = 0; this.lengthDone = 0; this.hashedStatus = PatchFileHashedStatus.NotHashed; this.Basepath = Basepath.Replace("\\\\", "/").Replace("\\", "/"); }