Esempio n. 1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckTasksCompleted())
            {
                Messages.CalculationOngoing();
                return;
            }
            MessageBoxResult result = Messages.SaveConfirmation();

            if (result == MessageBoxResult.OK)
            {
                try
                {
                    foreach (GUIRow row in rows)
                    {
                        if (row.IsChecked())
                        {
                            HashFile.WriteHashFile(row.Hash, file);
                        }
                    }
                    lblStatus.Content = "Save done";
                }
                catch (Exception error)
                {
                    Messages.SaveException(error);
                    lblStatus.Content = "Save aborted";
                }
            }
            else
            {
                lblStatus.Content = "Save canceled";
            }
        }
Esempio n. 2
0
        public static void WriteHashFile(Hash hash, String filePath)
        {
            String hashFile = HashFile.HashFilePath(hash, filePath);
            // Format: ea912a289186e5120eac3a722fe23c2f *apr-1.5.2-win32-src.zip
            String line = hash.HashString.ToLower() + " *" + filePath + "\n";

            File.WriteAllText(hashFile, line);
        }
        public static Boolean CheckHash(Hash hash, String filePath)
        {
            StreamReader stream = null;

            try
            {
                String fileToCheck = HashFile.HashFilePath(hash, filePath);
                stream = new StreamReader(fileToCheck);
                String line     = stream.ReadLine();
                String hashPart = UserInput.Normalize(line.Split(' ')[0]);
                return(hashPart.Equals(hash.HashString));
            }
            catch (Exception e)
            {
                throw new HashCheckException(e.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }