aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
diff options
context:
space:
mode:
authorShlomo Hecht <shlomo@twine-s.com>2020-03-30 17:20:46 +0300
committerShlomo Hecht <shlomo@twine-s.com>2020-03-30 17:20:46 +0300
commitbc7604caa4c43ed3c222125708b8bc52eec8c4ae (patch)
tree74d2f3407669497430d75e9249a16aa21f8977c5 /Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs
parentac29139d6908b757930756e928a6126599d5a10f (diff)
parent3e02fe5388e517444d94947738e9e30506857244 (diff)
downloadTango-bc7604caa4c43ed3c222125708b8bc52eec8c4ae.tar.gz
Tango-bc7604caa4c43ed3c222125708b8bc52eec8c4ae.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs')
-rw-r--r--Software/Visual_Studio/Tango.FileSystem/FileSystemManager.cs59
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;
+ }
}
}