예제 #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (m_init)
     {
         if (m_mode == 0)
         {
             string m_flnm = textBox2.Text;
             string s      = DialogHelper.DoSaveFileDialog("Text files (*.txt)|*.txt", (string.IsNullOrEmpty(m_flnm)) ? null : (Path.GetFileNameWithoutExtension(m_flnm) + ".txt"));
             if (!string.IsNullOrEmpty(s))
             {
                 Dictionary <string, HashCheckResult> res = fileHashListView1.Result;
                 if ((res != null) && (res.Count > 0))
                 {
                     Cursor = Cursors.WaitCursor;
                     using (StreamWriter sr = new StreamWriter(s))
                     {
                         foreach (KeyValuePair <string, HashCheckResult> ritem in res)
                         {
                             sr.WriteLine(string.Concat(ritem.Key, " ", (ritem.Value.IsOk) ? "OK" : string.Concat("ERROR: ", ritem.Value.ErrorMessage)));
                         }
                         //sr.Close();
                     }
                     Cursor = Cursors.Default;
                 }
             }
         }
         else
         if ((m_mode > 0) && (dic != null))
         {
             bool b = m_exres > 0;
             if (b)
             {
                 b = MessageBox.Show(m_exres.ToString() + " errors.\nDo you want to save the output file anyway?", comboBox1.Text, MessageBoxButtons.YesNo) == DialogResult.No;
             }
             if (!b)
             {
                 Cursor = Cursors.WaitCursor;
                 PlainTextStream pts = getTextFile();
                 int             i   = -1;
                 if (pts != null)
                 {
                     pts.hashes         = dic;
                     pts.AdditionalInfo = addinfo;
                     pts.SetByteStringFormat(((saveMenu.Items[0] as ToolStripMenuItem).Checked) ? ByteStringFormat.Bytes : ByteStringFormat.Base64);
                     i = pts.Write();
                 }
                 Cursor = Cursors.Default;
                 if (i >= 0)
                 {
                     MessageBox.Show(i.ToString() + " checksums written to output file.", comboBox1.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
                 else
                 {
                     MessageBox.Show("Wrong output file specified.", comboBox1.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
     }
 }
예제 #2
0
        private PlainTextStream getTextFile()
        {
            PlainTextStream res = null;
            string          s   = textBox2.Text;

            if (m_mode == 0)
            {
                while (!string.IsNullOrEmpty(s) && !File.Exists(s))
                {
                    s = DialogHelper.DoOpenFileDialog(FILTER_STRING);
                    if (!string.IsNullOrEmpty(s))
                    {
                        textBox2.Text = s;
                    }
                }
            }
            if (!string.IsNullOrEmpty(s))
            {
                res = new PlainTextStream(s);
            }
            return(res);
        }
예제 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     m_exres = -1;
     if (m_init)
     {
         Cursor = Cursors.WaitCursor;
         fileHashListView1.RefreshInProcess = checkBox1.Checked;
         fileHashListView1.ProcessingMode   = (FileVerifierLib.HashHelpers.HashAlgorithmType)m_mode;
         progressBar1.Value = progressBar1.Minimum;
         progressBar1.Show();
         DateTime dt1 = DateTime.Now;
         m_exres = fileHashListView1.Execute();
         TimeSpan tsp1 = DateTime.Now - dt1;
         progressBar1.Hide();
         Cursor = Cursors.Default;
         MessageBox.Show(m_exres.ToString() + " errors.\nElapsed time: " + tsp1.ToString(), comboBox1.Text, MessageBoxButtons.OK, (m_exres > 0) ? MessageBoxIcon.Warning : MessageBoxIcon.Information);
     }
     else
     {
         string rp = textBox1.Text;
         while (!string.IsNullOrEmpty(rp) && !Directory.Exists(rp))
         {
             rp = DialogHelper.DoFolderBrowserDialog(FOLDER_DESCRIPTION);
             if (!string.IsNullOrEmpty(rp))
             {
                 textBox1.Text = rp;
             }
         }
         if (!string.IsNullOrEmpty(rp))
         {
             m_mode = comboBox1.SelectedIndex;
             fileHashListView1.RefreshInProcess = checkBox1.Checked;
             fileHashListView1.ProcessingMode   = (FileVerifierLib.HashHelpers.HashAlgorithmType)m_mode;
             fileHashListView1.Hashes           = null;
             fileHashListView1.RootPath         = rp;
             if (m_mode == 0)
             {
                 PlainTextStream pts = getTextFile();
                 if ((pts != null) && (pts.Read() > 0))
                 {
                     Cursor = Cursors.WaitCursor;
                     fileHashListView1.Hashes = pts.hashes;
                     progressBar1.Value       = progressBar1.Minimum;
                     progressBar1.Maximum     = pts.hashes.Count << 1;
                     progressBar1.Show();
                     DateTime dt1 = DateTime.Now;
                     m_exres = fileHashListView1.Execute();
                     TimeSpan tsp1 = DateTime.Now - dt1;
                     progressBar1.Hide();
                     Cursor = Cursors.Default;
                     MessageBox.Show(m_exres.ToString() + " errors.\nElapsed time: " + tsp1.ToString(), comboBox1.Text, MessageBoxButtons.OK, (m_exres > 0) ? MessageBoxIcon.Warning : MessageBoxIcon.Information);
                     m_init = true;
                 }
             }
             else
             {
                 dic = null;
                 using (Form2 fm2 = new Form2())
                 {
                     fm2.RootFolder = fileHashListView1.RootPath;
                     if (fm2.ShowDialog(this) == DialogResult.OK)
                     {
                         int cc = fm2.listBox2.Items.Count;
                         if (cc > 0)
                         {
                             Cursor = Cursors.WaitCursor;
                             int rl = fm2.RootFolder.Length + 1;
                             dic = new Dictionary <string, ByteStringAuto>(cc);
                             foreach (object fl in fm2.listBox2.Items)
                             {
                                 dic.Add((fl as string).Substring(rl), null);
                             }
                             Cursor = Cursors.Default;
                         }
                     }
                 }
                 if (dic != null)
                 {
                     Cursor = Cursors.WaitCursor;
                     fileHashListView1.Hashes = dic;
                     progressBar1.Value       = progressBar1.Minimum;
                     progressBar1.Maximum     = dic.Count << 1;
                     progressBar1.Show();
                     DateTime dt1 = DateTime.Now;
                     m_exres = fileHashListView1.Execute();
                     TimeSpan tsp1 = DateTime.Now - dt1;
                     progressBar1.Hide();
                     //if (m_exres == 0)
                     //{
                     addinfo = string.Concat(fileHashListView1.ProcessingMode.ToString(), " checksums generated by ", ProductName, string.Concat("\nGenerated ", DateTime.Now.ToString()));
                     m_init  = true;
                     //}
                     Cursor = Cursors.Default;
                     MessageBox.Show(m_exres.ToString() + " errors.\nElapsed time: " + tsp1.ToString(), comboBox1.Text, MessageBoxButtons.OK, (m_exres > 0) ? MessageBoxIcon.Warning : MessageBoxIcon.Information);
                 }
             }
         }
         button2.Enabled = m_init;
     }
 }