コード例 #1
0
ファイル: FileChecker.cs プロジェクト: Neebzan/SwaggyNetty
        /// <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;
            string currentDirectory;

            if (!Path.IsPathRooted(path))
            {
                currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                if (path != "")
                {
                    if (currentDirectory[currentDirectory.Length - 1] != '\\')
                    {
                        currentDirectory += "\\";
                    }

                    currentDirectory += path;
                }
            }
            else
            {
                currentDirectory = path;
            }


            string[] files = Directory.GetFiles(currentDirectory, "*.*", SearchOption.AllDirectories);
            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++)
            {
                validFilesDictionary.Add(GetRelativePath(files[i], currentDirectory), GetChecksum(files[i]));
                args.ChecksumsGenerated++;
                OnGetFilesDictionaryProgress(args);
            }
            result = validFilesDictionary;
        }
コード例 #2
0
ファイル: FileChecker.cs プロジェクト: Neebzan/SwaggyNetty
        private static void OnGetFilesDictionaryProgress(GetFilesDictionaryProgressEventArgs e)
        {
            var handler = GetFilesDictionaryProgress;

            handler(null, e);
        }