mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-21 10:49:25 +01:00
Added disk space check loop
This commit is contained in:
@@ -775,5 +775,30 @@ namespace Flowframes.IO
|
||||
Logger.Log($"OverwriteWithText failed for '{path}': {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static long GetDiskSpace(string path, bool mbytes = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
string driveLetter = path.Substring(0, 2); // Make 'C:/some/random/path' => 'C:' etc
|
||||
DriveInfo[] allDrives = DriveInfo.GetDrives();
|
||||
|
||||
foreach (DriveInfo d in allDrives)
|
||||
{
|
||||
if (d.IsReady == true && d.Name.StartsWith(driveLetter))
|
||||
{
|
||||
if (mbytes)
|
||||
return (long)(d.AvailableFreeSpace / 1024f / 1000f);
|
||||
else
|
||||
return d.AvailableFreeSpace;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log("Error trying to get disk space: " + e.Message, true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,34 @@ namespace Flowframes
|
||||
|
||||
Networks.Init();
|
||||
|
||||
Task.Run(() => DiskSpaceCheckLoop());
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
mainForm = new Form1();
|
||||
Application.Run(mainForm);
|
||||
}
|
||||
|
||||
static async Task DiskSpaceCheckLoop ()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (busy)
|
||||
{
|
||||
string drivePath = Interpolate.current.tempFolder.Substring(0, 2);
|
||||
long mb = IOUtils.GetDiskSpace(Interpolate.current.tempFolder);
|
||||
|
||||
Logger.Log($"Disk space check for '{drivePath}/': {mb} MB free.", true);
|
||||
|
||||
if (mb < 4096)
|
||||
{
|
||||
Interpolate.Cancel("Running out of disk space!");
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(15000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user