Exemplo n.º 1
0
 /// <summary>
 /// Processes command line argument sent to the application.
 /// </summary>
 /// <param name="args">String array of arguments.</param>
 static void ProcessArguments(string[] args)
 {
     foreach (string arg in args)
     {
         if (!String.IsNullOrEmpty(arg))
         {
             FileInfo fi = new FileInfo(arg);
             if (fi.Exists)
             {
                 if (HashFile.IsHashFile(fi))
                 {
                     HashFile sfv = new HashFile(fi.FullName);
                     Program.CoreWorkQueue.Add(sfv.ReadAll());
                 }
                 else
                 {
                     Program.CoreWorkQueue.Add(new QueueItem(fi, StringUtilities.FindCRC(fi.Name), QueueItemAction.TestHash, HashType.CRC));
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        private void ScanHashFilesAndAdd(string[] fileNames)
        {
            if (fileNames.Length == 0)
                return;

            // Pre-sort file list
            Array.Sort(fileNames);

            // Load all hash files in this directory
            List<FileInfo> HashFileList = HashFile.GetHashFiles(new DirectoryInfo(Path.GetDirectoryName(fileNames[0])));
            HashFile[] HashFiles = new HashFile[HashFileList.Count];
            for (int i = 0; i < HashFileList.Count; i++)
            {
                HashFiles[i] = new HashFile(HashFileList[i].FullName);
            }

            // Add the contents of any selected hash files to the work queue
            foreach (string FileName in fileNames)
            {
                if (HashFile.IsHashFile(FileName))
                {
                    HashFile hf = new HashFile(FileName);
                    Program.CoreWorkQueue.Add(hf.ReadAll());
                }
            }

            // Add the selected files to the work queue
            foreach (string FileName in fileNames)
            {
                // Check the SFV files in the directory for information on this file
                bool FoundCRCInSFV = false;
                foreach (HashFile sfv in HashFiles)
                {
                    string FileHash = sfv.GetHash(Path.GetFileName(FileName));
                    if (!String.IsNullOrEmpty(FileHash))
                    {
                        Program.CoreWorkQueue.Add(new QueueItem(new FileInfo(FileName), FileHash, QueueItemAction.TestHash, HashType.CRC));
                        FoundCRCInSFV = true;
                        break;
                    }
                }

                // If there was no information found in the SFVs then try to parse the file name
                if (!FoundCRCInSFV)
                {
                    // Only add hash files if they have an embedded hash... any other file will be added simply because it's not a hash file
                    string EmbeddedCRC = StringUtilities.FindCRC(FileName);
                    if (!String.IsNullOrEmpty(EmbeddedCRC) || !HashFile.IsHashFile(FileName))
                    {
                        Program.CoreWorkQueue.Add(new QueueItem(new FileInfo(FileName), EmbeddedCRC, QueueItemAction.TestHash, HashType.CRC));
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog1.Title = "Select the file you want to process";
            openFileDialog1.Filter = "Hash Files (*.sfv, *.md5)|*.sfv;*.md5|SFV File (*.sfv)|*.sfv|MD5 File (*.md5)|*.md5";

            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
            {
                HashFile TargetFile = new HashFile(openFileDialog1.FileName);

                if (TargetFile.Exists)
                {
                    QueueItem[] HashItems = TargetFile.ReadAll();

                    if (HashItems.Length > 0)
                    {
                        Program.CoreWorkQueue.Reset();
                        Program.CoreWorkQueue.Add(HashItems);
                        CurrentHashFile = TargetFile;
                        ResetInfoAndLaunchWorker();
                    }
                    else
                    {
                        MessageBox.Show("The file does not appear to contain any file/checksum pairs.", "Unable to parse file", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void RecursiveDirectoryGrab(string directory)
        {
            DirectoryInfo RootDirectory = new DirectoryInfo(directory);
            foreach (DirectoryInfo dir in RootDirectory.GetDirectories())
            {
                // Load hash files first
                List<FileInfo> HashFiles = HashFile.GetHashFiles(dir);
                foreach (FileInfo file in HashFiles)
                {
                    HashFile hf = new HashFile(file.FullName);
                    Program.CoreWorkQueue.Add(hf.ReadAll());
                }

                foreach (FileInfo TargetFile in dir.GetFiles())
                {
                    if (!HashFile.IsHashFile(TargetFile))
                    {
                        Program.CoreWorkQueue.Add(new QueueItem(TargetFile, StringUtilities.FindCRC(TargetFile.Name), QueueItemAction.TestHash, HashType.CRC));
                    }
                }

                RecursiveDirectoryGrab(dir.FullName);
            }
        }
Exemplo n.º 5
0
        private void directoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() != DialogResult.Cancel)
            {
                DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog1.SelectedPath);

                if (dir.Exists)
                {
                    FileInfo[] DirectoryFiles = dir.GetFiles();
                    List<FileInfo> HashFiles = HashFile.GetHashFiles(dir);

                    Program.CoreWorkQueue.Reset();

                    // Load hash files first
                    foreach (FileInfo file in HashFiles)
                    {
                        HashFile hf = new HashFile(file.FullName);
                        Program.CoreWorkQueue.Add(hf.ReadAll());
                    }

                    // Add all the files in the base directory
                    foreach (FileInfo TargetFile in DirectoryFiles)
                    {
                        if (!HashFile.IsHashFile(TargetFile))
                        {
                            Program.CoreWorkQueue.Add(new QueueItem(TargetFile, StringUtilities.FindCRC(TargetFile.Name), QueueItemAction.TestHash, HashType.CRC));
                        }
                    }

                    // Recursive grab
                    RecursiveDirectoryGrab(dir.FullName);

                    if (DirectoryFiles.Length == 1 && HashFile.IsHashFile(DirectoryFiles[0]))
                    {
                        CurrentHashFile = new HashFile(DirectoryFiles[0].Name);
                    }
                    else
                    {
                        CurrentHashFile = null;
                    }
                    ResetInfoAndLaunchWorker();
                }
                else
                {
                    MessageBox.Show("Target directory does not exist!", "Directory does not exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }