diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-28 10:02:12 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-28 10:02:12 +0300 |
| commit | 3d6a882cf14f36297d8b379e0fdf65376064edf7 (patch) | |
| tree | 91728997624076d0eb0d6b38df011851e559a838 /Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs | |
| parent | 888d3037722f80b00c12e140ba101f58661ec4b6 (diff) | |
| download | Tango-3d6a882cf14f36297d8b379e0fdf65376064edf7.tar.gz Tango-3d6a882cf14f36297d8b379e0fdf65376064edf7.zip | |
Many changes and improvements.
Diffstat (limited to 'Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs index 46ca080a2..c08304ca8 100644 --- a/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs +++ b/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs @@ -7,6 +7,7 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using Tango.Core.Helpers; using Tango.FileSystem.Network; +using Tango.Logging; namespace Tango.FileSystem { @@ -22,7 +23,7 @@ namespace Tango.FileSystem { Path = x.RootDirectory.FullName, DriveType = x.DriveType, - DriveLabel = x.Name, + DriveLabel = $"{x.VolumeLabel} ({x.Name.Replace("\\", "")})", Type = FileSystemItemType.Drive, }).Cast<FileSystemItemDTO>().ToList(); @@ -198,5 +199,61 @@ namespace Tango.FileSystem Path = fullPath }); } + + public long PerformDiskSpaceOptimization() + { + var tempDir = Path.GetTempPath(); + var logsFolder = FileLogger.DefaultLogsFolder; + + long sizeBefore = GetDirectorySize(new DirectoryInfo(tempDir)) + GetDirectorySize(new DirectoryInfo(logsFolder)); + + foreach (var file in Directory.GetFiles(tempDir, "*.*", SearchOption.AllDirectories)) + { + try + { + FileInfo fileInfo = new FileInfo(file); + if (fileInfo.LastWriteTime < DateTime.Now.AddDays(-1)) + { + File.Delete(file); + } + } + catch { } + } + + foreach (var file in Directory.GetFiles(logsFolder, "*.*", SearchOption.AllDirectories)) + { + try + { + FileInfo fileInfo = new FileInfo(file); + if (fileInfo.LastWriteTime < DateTime.Now.AddDays(-2)) + { + File.Delete(file); + } + } + catch { } + } + + long sizeAfter = GetDirectorySize(new DirectoryInfo(tempDir)) + GetDirectorySize(new DirectoryInfo(logsFolder)); + + return Math.Max(sizeBefore - sizeAfter, 0); + } + + public static long GetDirectorySize(DirectoryInfo d) + { + long size = 0; + // Add file sizes. + FileInfo[] fis = d.GetFiles(); + foreach (FileInfo fi in fis) + { + size += fi.Length; + } + // Add subdirectory sizes. + DirectoryInfo[] dis = d.GetDirectories(); + foreach (DirectoryInfo di in dis) + { + size += GetDirectorySize(di); + } + return size; + } } } |
