Exemplo n.º 1
0
        private static void ParseInner(DirectoryInfo directory, DirectoryEntity parent, int prefixLength, HashProvider hashProvider, IgnoreList ignoreList, IProgress <int> progress)
        {
            bool computeHash = hashProvider != null;

            foreach (FileInfo file in directory.EnumerateFiles())
            {
                string relativePath = file.FullName.Substring(prefixLength).TrimStart('\\');

                if (ignoreList.IsIgnored(relativePath))
                {
                    continue;
                }

                if (file.Extension == ".pkg")
                {
                    ParsePackage(file, parent, hashProvider, progress);
                    progress?.Report(1);
                }
                else
                {
                    FileEntity fileEnt = computeHash ? new FileEntity(file.Name, hashProvider.FromStream(new FileStream(file.FullName, FileMode.Open, FileAccess.Read)) + relativePath.GetHashCode(), file.Length) : new FileEntity(file.Name, file.Length);
                    parent.Add(fileEnt);
                    progress?.Report(1);
                }
            }

            foreach (DirectoryInfo dir in directory.EnumerateDirectories())
            {
                if (ignoreList.IsIgnored(Path.Combine(parent.RelativePath, dir.Name) + "\\"))
                {
                    continue;
                }

                DirectoryEntity child = new DirectoryEntity(dir.Name);
                parent.Add(child);
                ParseInner(dir, child, prefixLength, hashProvider, ignoreList, progress);
            }
        }
Exemplo n.º 2
0
        public static void Parse(DirectoryInfo directory, RootDirectoryEntity root, int prefixLength, HashProvider hashProvider, IgnoreList ignoreList, IProgress <int> progress)
        {
            RootDirectoryEntity temp = new RootDirectoryEntity();

            ParseInner(directory, temp, prefixLength, null, ignoreList, null);

            if (hashProvider == null)
            {
                progress?.Report(100);
                return;
            }

            int            totalFiles  = temp.GetAllFileEntities(true).Count;
            int            processed   = 0;
            Progress <int> sumProgress = new Progress <int>(prog =>
            {
                int percent = ++processed * 100 / totalFiles;
                progress?.Report(percent);
            });

            ParseInner(directory, root, prefixLength, hashProvider, ignoreList, sumProgress);
        }