public ProgressEstimator BeginSubPhase(int phases) { phaseProgress = new ProgressEstimator(); phaseProgress.Reset(phases); return(phaseProgress); }
private void Scan(DirectoryInfo dir, List <Regex> ignores, ProgressEstimator progress = null) { if (cancelScan) { return; } // never allow scanning of our own parity folder if (Utils.PathsAreEqual(dir.FullName, config.ParityDir)) { LogFile.Log("Warning: skipping " + dir.FullName + " because it is the parity folder."); return; } Status = "Scanning " + dir.FullName; if (scanProgress != null) { Progress = scanProgress.Progress; } DirectoryInfo[] subDirs; try { subDirs = dir.GetDirectories(); } catch (Exception e) { if (progress == null) { throw; } LogFile.Log("Warning: Could not enumerate subdirectories of {0}: {1}", dir.FullName, e.Message); return; } FileInfo[] fileInfos; try { fileInfos = dir.GetFiles(); } catch (Exception e) { LogFile.Log("Warning: Could not enumerate files in {0}: {1}", dir.FullName, e.Message); return; } ProgressEstimator folderProgress; if (scanProgress == null) { scanProgress = new ProgressEstimator(); scanProgress.Reset(subDirs.Length); folderProgress = scanProgress; } else { folderProgress = progress.BeginSubPhase(subDirs.Length); } foreach (DirectoryInfo d in subDirs) { if (cancelScan) { return; } if ((config.IgnoreHidden && (d.Attributes & FileAttributes.Hidden) != 0) || ((d.Attributes & FileAttributes.System) != 0)) { folderProgress.EndPhase(); continue; } string subDir = Path.Combine(dir.FullName, d.Name); if (subDir.Length >= MAX_FOLDER) { LogFile.Log("Warning: skipping folder \"" + subDir + "\" because the path is too long."); } else { Scan(d, ignores, folderProgress); } folderProgress.EndPhase(); } Progress = scanProgress.Progress; string relativePath = Utils.StripRoot(root, dir.FullName); foreach (FileInfo f in fileInfos) { if (cancelScan) { return; } // have to use Path.Combine here because accessing the f.FullName property throws // an exception if the path is too long string fullName = Path.Combine(dir.FullName, f.Name); try { if (fullName.Length >= MAX_PATH) { LogFile.Log("Warning: skipping file \"" + fullName + "\" because the path is too long"); continue; } if (f.Attributes == (FileAttributes)(-1)) { continue; } if (config.IgnoreHidden && (f.Attributes & FileAttributes.Hidden) != 0) { continue; } if ((f.Attributes & FileAttributes.System) != 0) { continue; } bool ignore = false; foreach (Regex regex in ignores) { if (regex.IsMatch(f.Name.ToLower())) { ignore = true; break; } } if (ignore) { if (LogFile.Verbose) { LogFile.Log("Skipping \"{0}\" because it matches an ignore", f.FullName); } ignoreCount++; continue; } FileRecord r = new FileRecord(f, relativePath, this); scanFiles.Add(r); seenFileNames[r.Name.ToLower()] = r; } catch (Exception e) { errorFiles.Add(fullName.ToLower()); FireErrorMessage(String.Format("Error scanning \"{0}\": {1}", fullName, e.Message)); } } }
public ProgressEstimator BeginSubPhase(int phases) { phaseProgress = new ProgressEstimator(); phaseProgress.Reset(phases); return phaseProgress; }
private void Scan(DirectoryInfo dir, List<Regex> ignores, ProgressEstimator progress = null) { if (cancelScan) return; // never allow scanning of our own parity folder if (Utils.PathsAreEqual(dir.FullName, config.ParityDir)) { LogFile.Log("Warning: skipping " + dir.FullName + " because it is the parity folder."); return; } Status = "Scanning " + dir.FullName; if (scanProgress != null) Progress = scanProgress.Progress; DirectoryInfo[] subDirs; try { subDirs = dir.GetDirectories(); } catch (Exception e) { if (progress == null) throw; LogFile.Log("Warning: Could not enumerate subdirectories of {0}: {1}", dir.FullName, e.Message); return; } FileInfo[] fileInfos; try { fileInfos = dir.GetFiles(); } catch (Exception e) { LogFile.Log("Warning: Could not enumerate files in {0}: {1}", dir.FullName, e.Message); return; } ProgressEstimator folderProgress; if (scanProgress == null) { scanProgress = new ProgressEstimator(); scanProgress.Reset(subDirs.Length); folderProgress = scanProgress; } else folderProgress = progress.BeginSubPhase(subDirs.Length); foreach (DirectoryInfo d in subDirs) { if (cancelScan) return; if ((config.IgnoreHidden && (d.Attributes & FileAttributes.Hidden) != 0) || ((d.Attributes & FileAttributes.System) != 0)) { folderProgress.EndPhase(); continue; } string subDir = Path.Combine(dir.FullName, d.Name); if (subDir.Length >= MAX_FOLDER) LogFile.Log("Warning: skipping folder \"" + subDir + "\" because the path is too long."); else Scan(d, ignores, folderProgress); folderProgress.EndPhase(); } Progress = scanProgress.Progress; string relativePath = Utils.StripRoot(root, dir.FullName); foreach (FileInfo f in fileInfos) { if (cancelScan) return; // have to use Path.Combine here because accessing the f.FullName property throws // an exception if the path is too long string fullName = Path.Combine(dir.FullName, f.Name); try { if (fullName.Length >= MAX_PATH) { LogFile.Log("Warning: skipping file \"" + fullName + "\" because the path is too long"); continue; } if (f.Attributes == (FileAttributes)(-1)) continue; if (config.IgnoreHidden && (f.Attributes & FileAttributes.Hidden) != 0) continue; if ((f.Attributes & FileAttributes.System) != 0) continue; bool ignore = false; foreach (Regex regex in ignores) if (regex.IsMatch(f.Name.ToLower())) { ignore = true; break; } if (ignore) { if (LogFile.Verbose) LogFile.Log("Skipping \"{0}\" because it matches an ignore", f.FullName); ignoreCount++; continue; } FileRecord r = new FileRecord(f, relativePath, this); scanFiles.Add(r); seenFileNames[r.Name.ToLower()] = r; } catch (Exception e) { errorFiles.Add(fullName.ToLower()); FireErrorMessage(String.Format("Error scanning \"{0}\": {1}", fullName, e.Message)); } } }