/// <summary> /// Generate a dictionary from a collection of file paths and a base directory /// Progress can be fetched from the OnGetFilesDictionaryProgress event /// </summary> /// <param name="files"></param> /// <param name="directory"></param> /// <returns></returns> public static void GetFilesDictionary(out Dictionary <string, string> result, string path = "") { GetFilesDictionaryProgressEventArgs args = new GetFilesDictionaryProgressEventArgs(); result = null; path = RootedPathCheck(path); try { string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Where(name => !(name.Contains("Version.json"))).ToArray(); args.FilesFound = files.Length; args.ChecksumsGenerated = 0; OnGetFilesDictionaryProgress(args); Dictionary <string, string> validFilesDictionary = new Dictionary <string, string>(); for (int i = 0; i < files.Length; i++) { string relPath = GetRelativePath(files[i], path); validFilesDictionary.Add(relPath, GetChecksum(files[i], relPath)); args.ChecksumsGenerated++; OnGetFilesDictionaryProgress(args); } result = validFilesDictionary; } catch (Exception e) { Console.WriteLine(ConsoleExtension.AddTimestamp("Not a valid path OR path not found")); Console.WriteLine(ConsoleExtension.AddTimestamp("Path was: \n" + path)); Console.WriteLine(ConsoleExtension.AddTimestamp(e.Message)); } }
private static void OnGetFilesDictionaryProgress(GetFilesDictionaryProgressEventArgs e) { var handler = GetFilesDictionaryProgress; handler(null, e); }