private void UpdateStart(object state) { ThreadFileObj fileObj = (ThreadFileObj)state; fListItems[fileObj.Core].Text = fileObj.FileName; exListView1.Update(); }
private void UpdateHash(object state) { ThreadFileObj fileObj = (ThreadFileObj)state; int core = fileObj.Core; fProgressBars[core].Value = 0; fListItems[core].Text = "?"; exListView1.Update(); lvFiles.Items[fileObj.Index].SubItems[1].Text = FCCore.Hash2Str(fileObj.Hash); lvFiles.Update(); fCompleted += 1; ProgressBar.Value = fCompleted; if (fCompleted == fCurrentDigest.Files.Count) { if (fCheckMode) { CompareDigests(); } else { fCurrentDigest.WriteDigest(txtDigestFile.Text); } ProgressBar.Value = 0; } }
public void ReadDigest(string fileName) { if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) { return; } Clear(); using (var sw = new StreamReader(fileName, Encoding.UTF8)) { string line; while (!string.IsNullOrEmpty(line = sw.ReadLine())) { switch (line[0]) { case ';': // comment break; case '*': // folder fFolders.Add(line.Substring(1)); break; default: // file int pos = line.IndexOf(" *"); string fName, fHash; fName = line.Substring(pos + 2); fHash = line.Substring(0, pos); byte[] hash = FCCore.Str2Hash(fHash); var fileObj = new ThreadFileObj(fName, hash); fFiles.Add(fileObj); break; } } } }
private void CreateFileHashThread(int index, int coreNum, ThreadFileObj fileObj) { ProcessorCore core = FCCore.CORES[coreNum]; ((IUserForm)this).ReportLog(core.ToString() + ", Processing: " + fileObj.FileName); fileObj.Core = coreNum; ((IUserForm)this).ReportStart(fileObj); DistributedThread thread = new DistributedThread(ParameterizedThreadProc); thread.ProcessorAffinity = (int)core; thread.Start(fileObj); }
void IUserForm.ReportHash(ThreadFileObj fileObj) { fSyncContext.Post(UpdateHash, fileObj); lock (fCoreBusy) { int threadCore = fileObj.Core; fCoreBusy[threadCore] = false; } initEvent.Set(); //var core = FCCore.CORES[fileObj.Core]; //fSyncContext.Post(UpdateLog, core.ToString() + ", FileHash (" + fileObj.FileName + "): " + FCCore.Hash2Str(fileObj.Hash)); }
public static void CalculateFileHash(ThreadFileObj fileObj) { string fileName = fileObj.FileName; IUserForm userForm = fileObj.UserForm; byte[] buffer; byte[] oldBuffer; int bytesRead; int oldBytesRead; long size; long totalBytesRead = 0; using (Stream stream = File.OpenRead(fileName)) using (HashAlgorithm hashAlgorithm = GetHashAlgorithm(ChecksumType.MD5)) { size = stream.Length; buffer = new byte[4096]; bytesRead = stream.Read(buffer, 0, buffer.Length); totalBytesRead += bytesRead; do { oldBytesRead = bytesRead; oldBuffer = buffer; buffer = new byte[4096]; bytesRead = stream.Read(buffer, 0, buffer.Length); totalBytesRead += bytesRead; if (bytesRead == 0) { hashAlgorithm.TransformFinalBlock(oldBuffer, 0, oldBytesRead); } else { hashAlgorithm.TransformBlock(oldBuffer, 0, oldBytesRead, oldBuffer, 0); } int progress = (size == 0) ? 0 : (int)((double)totalBytesRead * 100 / size); fileObj.Progress = progress; userForm.ReportProgress(fileObj); } while (bytesRead != 0); fileObj.Hash = hashAlgorithm.Hash; userForm.ReportHash(fileObj); } }
void IUserForm.ReportStart(ThreadFileObj fileObj) { fSyncContext.Post(UpdateStart, fileObj); }
private void UpdateProgress(object state) { ThreadFileObj fileObj = (ThreadFileObj)state; fProgressBars[fileObj.Core].Value = fileObj.Progress; }
void IUserForm.ReportProgress(ThreadFileObj fileObj) { fSyncContext.Post(UpdateProgress, fileObj); }