private void AddDirectory(LogBasePathInfo info) { ListViewItem lvi = new ListViewItem(info.LogBasePath); lvi.Tag = info; lvi.SubItems.Add(CommonFormats.DateTimeToShortString(info.UpdatedTime.ToLocalTime())); lvi.SubItems.Add(Tx.DataSize(info.Size)); LogDirsListView.Items.Add(lvi); info.ListViewItem = lvi; }
private void CheckLogBasePath(string basePath, Dictionary <string, LogBasePathInfo> logPaths) { string dir = Path.GetDirectoryName(basePath); string baseName = Path.GetFileName(basePath); try { foreach (string logFile in Directory.GetFiles(dir, baseName + "-?-*.fl")) { FileInfo fi = new FileInfo(logFile); DateTime updatedTime = fi.LastWriteTimeUtc; LogBasePathInfo info; if (logPaths.TryGetValue(basePath, out info)) { if (updatedTime > info.UpdatedTime) { info.UpdatedTime = updatedTime; } info.Size += fi.Length; } else { info = new LogBasePathInfo { LogBasePath = basePath, UpdatedTime = updatedTime, Size = fi.Length }; logPaths.Add(basePath, info); } } } catch { // Ignore this base path, we can't use it } }
private void UpdateDirectory(LogBasePathInfo info) { info.ListViewItem.SubItems[1].Text = CommonFormats.DateTimeToShortString(info.UpdatedTime.ToLocalTime()); info.ListViewItem.SubItems[2].Text = Tx.DataSize(info.Size); }
private bool ScanDirectory(string path) { if (ScanDirectoryWorker.CancellationPending) { return(false); } int level = 0; string parent = path; while ((parent = Path.GetDirectoryName(parent)) != null) { level++; } DirectoryInfo di = new DirectoryInfo(path); if (level >= 1 && (di.Attributes & FileAttributes.Hidden) != 0 && (di.Attributes & FileAttributes.System) != 0) { return(true); } foreach (string dir in ignoredDirectories) { if (IsPath(path, dir)) { return(true); } } if (Path.GetFileName(path) == ".git") { return(true); } if (Path.GetFileName(path) == ".svn") { return(true); } if (level >= 8) { return(true); } try { var interestingFiles = Directory.GetFiles(path, "*-?-*.fl") .Concat(Directory.GetFiles(path, "*-scr-*.png")) .Concat(Directory.GetFiles(path, "*-scr-*.jpg")); foreach (string file in interestingFiles) { if (ScanDirectoryWorker.CancellationPending) { return(false); } string basePath = GetBasePath(file); if (basePath == null) { continue; } FileInfo fi = new FileInfo(file); DateTime updatedTime = fi.LastWriteTimeUtc; LogBasePathInfo info; if (logBasePathData.TryGetValue(basePath, out info)) { if (updatedTime > info.UpdatedTime) { info.UpdatedTime = updatedTime; } info.Size += fi.Length; BeginInvoke(new Action <LogBasePathInfo>(UpdateDirectory), info); } else { info = new LogBasePathInfo { LogBasePath = basePath, UpdatedTime = updatedTime, Size = fi.Length }; logBasePathData.Add(basePath, info); BeginInvoke(new Action <LogBasePathInfo>(AddDirectory), info); } } foreach (string subdir in Directory.GetDirectories(path)) { if (ScanDirectoryWorker.CancellationPending) { return(false); } bool result = ScanDirectory(subdir); if (!result) { return(false); } } } catch (UnauthorizedAccessException) { // Ignore unauthorised access } return(true); }
private void UpdateDirectory(LogBasePathInfo info) { info.ListViewItem.SubItems[1].Text = CommonFormats.DateTimeToShortString(info.UpdatedTime.ToLocalTime()); info.ListViewItem.SubItems[2].Text = Tx.DataSize(info.Size); }
private bool ScanDirectory(string path) { if (ScanDirectoryWorker.CancellationPending) return false; int level = 0; string parent = path; while ((parent = Path.GetDirectoryName(parent)) != null) { level++; } DirectoryInfo di = new DirectoryInfo(path); if (level >= 1 && (di.Attributes & FileAttributes.Hidden) != 0 && (di.Attributes & FileAttributes.System) != 0) return true; foreach (string dir in ignoredDirectories) { if (IsPath(path, dir)) return true; } if (Path.GetFileName(path) == ".git") return true; if (Path.GetFileName(path) == ".svn") return true; if (level >= 8) return true; try { var interestingFiles = Directory.GetFiles(path, "*-?-*.fl") .Concat(Directory.GetFiles(path, "*-scr-*.png")) .Concat(Directory.GetFiles(path, "*-scr-*.jpg")); foreach (string file in interestingFiles) { if (ScanDirectoryWorker.CancellationPending) return false; string basePath = GetBasePath(file); if (basePath == null) continue; FileInfo fi = new FileInfo(file); DateTime updatedTime = fi.LastWriteTimeUtc; LogBasePathInfo info; if (logBasePathData.TryGetValue(basePath, out info)) { if (updatedTime > info.UpdatedTime) { info.UpdatedTime = updatedTime; } info.Size += fi.Length; BeginInvoke(new Action<LogBasePathInfo>(UpdateDirectory), info); } else { info = new LogBasePathInfo { LogBasePath = basePath, UpdatedTime = updatedTime, Size = fi.Length }; logBasePathData.Add(basePath, info); BeginInvoke(new Action<LogBasePathInfo>(AddDirectory), info); } } foreach (string subdir in Directory.GetDirectories(path)) { if (ScanDirectoryWorker.CancellationPending) return false; bool result = ScanDirectory(subdir); if (!result) return false; } } catch (UnauthorizedAccessException) { // Ignore unauthorised access } return true; }
private void CheckLogBasePath(string basePath, Dictionary<string, LogBasePathInfo> logPaths) { string dir = Path.GetDirectoryName(basePath); string baseName = Path.GetFileName(basePath); try { foreach (string logFile in Directory.GetFiles(dir, baseName + "-?-*.fl")) { FileInfo fi = new FileInfo(logFile); DateTime updatedTime = fi.LastWriteTimeUtc; LogBasePathInfo info; if (logPaths.TryGetValue(basePath, out info)) { if (updatedTime > info.UpdatedTime) { info.UpdatedTime = updatedTime; } info.Size += fi.Length; } else { info = new LogBasePathInfo { LogBasePath = basePath, UpdatedTime = updatedTime, Size = fi.Length }; logPaths.Add(basePath, info); } } } catch { // Ignore this base path, we can't use it } }
private void AddDirectory(LogBasePathInfo info) { ListViewItem lvi = new ListViewItem(info.LogBasePath); lvi.Tag = info; lvi.SubItems.Add(CommonFormats.DateTimeToShortString(info.UpdatedTime.ToLocalTime())); lvi.SubItems.Add(Tx.DataSize(info.Size)); LogDirsListView.Items.Add(lvi); info.ListViewItem = lvi; }