Philipp Heenemann
d3767a0344
Global System and System.IO usages have been replaced with global usings in GlobalUsings.cs for improved code readability. Alongside, a FreeSpacePreCheck has been added in FreeSpacePreCheck.cs to ensure enough drive space is available before installation. This check was initially taking place in InitializationTask.cs which has been removed for better separation of concerns. The PreCheckViewModel visibility is now dependent on the success status of PreChecks, enhancing user experience.
29 lines
1019 B
C#
29 lines
1019 B
C#
using System.Linq;
|
|
using Serilog;
|
|
|
|
namespace SPTInstaller.Helpers;
|
|
|
|
public static class DirectorySizeHelper
|
|
{
|
|
public static bool CheckAvailableSize(string eftSourceDirPath, string installTargetDirPath)
|
|
{
|
|
try
|
|
{
|
|
var eftSourceDirectoryInfo = new DirectoryInfo(eftSourceDirPath);
|
|
var installTargetDirectoryInfo = new DirectoryInfo(installTargetDirPath);
|
|
|
|
var eftSourceDirSize = GetSizeOfDirectory(eftSourceDirectoryInfo);
|
|
var availableSize = DriveInfo.GetDrives().FirstOrDefault(d => d.Name == installTargetDirectoryInfo.Root.Name)?.AvailableFreeSpace ?? 0;
|
|
|
|
return eftSourceDirSize < availableSize;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Error while checking available size");
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static long GetSizeOfDirectory(DirectoryInfo sourceDir) => sourceDir.EnumerateFiles("*", SearchOption.AllDirectories).Sum(fi => fi.Length);
|
|
} |