public void ResetDictionary() { HashedFiles.Clear(); NumberOfFiles = 0; }
public void RecursiveSearch(string dir) { try { var localFiles = Directory.GetFiles(dir); foreach (var localFile in localFiles) { CurrentFile = localFile; if (File.Exists(CurrentFile)) // sanity check { NumberOfFiles++; var fileObject = new cFiles(localFile, dir); SHA256 sha256 = SHA256.Create(); var fileHash = ByteToString(sha256.ComputeHash(File.OpenRead(localFile))); if (Active) // continue if the thread should remain active { if (HashedFiles.ContainsKey(fileHash)) { var list = HashedFiles[fileHash]; list.Add(fileObject); try // prevent crash in the case where the primary thread has stopped and cleared the dictionary before the current thread has stopped { HashedFiles[fileHash] = list; } catch (Exception) { MessageBox.Show("Error adding new file to existing file hash. Another thread may have cleared the dictionary."); } } else { var firstFile = new List <cFiles>(); firstFile.Add(fileObject); HashedFiles.Add(fileHash, firstFile); } } else { break; } } } if (Active) // continue if the thread should remain active { var localDirectories = Directory.GetDirectories(dir); foreach (var localDirectory in localDirectories) { RecursiveSearch(localDirectory); } } } catch (UnauthorizedAccessException) { } }
private void Btn_Generate_Click(object sender, EventArgs args) { try { string file = Tb_Location.Text; if (File.Exists(file) && IsValidAssembly(file)) { string Title = Tb_Title.Text; if (String.IsNullOrWhiteSpace(Title) || String.IsNullOrEmpty(Title)) { Title = "Game1"; if (MessageBox.Show("It seems you have incorrectly specified a title so a default was created, \n\n" + "Is this Ok?", "Title Missing", MessageBoxButtons.YesNo) == DialogResult.No) return; Tb_Title.Text = Title; } Assembly assembly = AssemblyManagement.GetAssembly(file); string _Hash = FileManagement.HashBytes(File.ReadAllBytes(file)); string fileName = FileManagement.IncrementFile(Title + ".gli"); HashedFiles hashFile = new HashedFiles() { AssemblyPath = file, Hash = _Hash, Identifier = Title, Title = AssemblyManagement.GetTitle(assembly), Description = AssemblyManagement.GetDescription(assembly), Author = AssemblyManagement.GetAuthor(assembly), GLIPath = fileName }; FileManagement.Hashes.Add(hashFile); assembly = null; string[] Content = { Title, _Hash, file }; File.WriteAllLines(fileName, Content); Program.AddItem(Title, hashFile.Title, hashFile.Author, hashFile.Description, _Hash, fileName); } else Notify.Message("File Error", "Please select a existing file!"); Close(); } catch (Exception e) { Notify.Message("Generate Issue", String.Format("It seems an error occured:\n\n{0}", e.Message) ); } }