private void SearchListForSelectedIndex(int selectedIndex) { MyFileInfo selectedFile = files[selectedIndex]; for (int i = 0; i < files.Count; ++i) { if (i == selectedIndex) { continue; } MyFileInfo file = files[i]; if (!file.Verified) { continue; } bool notMatch = mD5ToolStripMenuItem.Checked && !selectedFile.MD5.Equals(file.MD5) || sHA1ToolStripMenuItem.Checked && !selectedFile.SHA1.Equals(file.SHA1) || cRC32ToolStripMenuItem.Checked && !selectedFile.CRC32.Equals(file.CRC32); if (!notMatch) { dataGridView.Rows[i].Selected = true; } } }
private void UpdateRowHash(DataRow row, MyFileInfo file) { Invoke((MethodInvoker) delegate { row[1] = "校验成功"; row[2] = file.MD5; row[3] = file.SHA1; row[4] = file.CRC32; }); }
private void RemoveItem(int index) { if (index < 0) { return; } MyFileInfo file = files[index]; fileNames.Remove(file.FullName); if (file.Verified) { --verifiedItems; } files.RemoveAt(index); dataTable.Rows.RemoveAt(index); }
private void ResetItem(int index) { MyFileInfo file = files[index]; DataRow row = dataTable.Rows[index]; row[1] = file.Exists ? "等待校验" : "文件不存在"; if (file.Verified) { --verifiedItems; file.Verified = false; file.MD5 = null; file.SHA1 = null; file.CRC32 = null; row[2] = ""; row[3] = ""; row[4] = ""; } }
private void AddItem(string fileName) { // 检查是否重复添加。 if (fileNames.Contains(fileName)) { return; } else { fileNames.Add(fileName); } MyFileInfo file = new MyFileInfo(); file.FullName = fileName; files.Add(file); DataRow row = dataTable.NewRow(); row[0] = file.FileName; row[1] = file.Exists ? "等待校验" : "文件不存在"; dataTable.Rows.Add(row); }
private void WorkerThreshold() { WorkerEnter(); MyFileInfo file = null; DataRow row = null; FileStream stream = null; try { while (true) { try { int index = DequeueItem(); if (index < 0) { break; } file = files[index]; row = dataTable.Rows[index]; UpdateRowStatus(row, "校验中……"); stream = new FileStream(file.FullName, FileMode.Open, FileAccess.Read); if (mD5ToolStripMenuItem.Checked && file.MD5 == null) { file.MD5 = Hasher.GetMD5Hash(stream); } if (sHA1ToolStripMenuItem.Checked && file.SHA1 == null) { file.SHA1 = Hasher.GetSHA1Hash(stream); } if (cRC32ToolStripMenuItem.Checked && file.CRC32 == null) { file.CRC32 = Hasher.GetCRC32Hash(stream); } file.Verified = true; Interlocked.Increment(ref verifiedItems); UpdateRowHash(row, file); } catch (FileNotFoundException) { UpdateRowStatus(row, "文件不存在"); } catch (IOException) { UpdateRowStatus(row, "读取错误"); } finally { if (stream != null) { stream.Close(); } } } } catch (ThreadAbortException) { Thread.ResetAbort(); file.Verified = false; AddAbortedRows(row); } WorkerLeave(); }