From f11869bcb872f4c0b482621025205ec003a32d6c Mon Sep 17 00:00:00 2001 From: "waffle.lord" Date: Wed, 1 May 2024 14:17:09 -0400 Subject: [PATCH] update free space check to also check free space on cache drive when not installing on the same drive for the game --- .../PreChecks/FreeSpacePreCheck.cs | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/SPTInstaller/Installer Tasks/PreChecks/FreeSpacePreCheck.cs b/SPTInstaller/Installer Tasks/PreChecks/FreeSpacePreCheck.cs index 1455241..cc2ddde 100644 --- a/SPTInstaller/Installer Tasks/PreChecks/FreeSpacePreCheck.cs +++ b/SPTInstaller/Installer Tasks/PreChecks/FreeSpacePreCheck.cs @@ -27,6 +27,8 @@ public class FreeSpacePreCheck : PreCheckBase var eftSourceDirectoryInfo = new DirectoryInfo(_internalData.OriginalGamePath); var installTargetDirectoryInfo = new DirectoryInfo(_internalData.TargetInstallPath); + var cacheDirectory = new DirectoryInfo(DownloadCacheHelper.CachePath); + var eftSourceDirSize = DirectorySizeHelper.GetSizeOfDirectory(eftSourceDirectoryInfo); if (eftSourceDirSize == -1) @@ -45,14 +47,46 @@ public class FreeSpacePreCheck : PreCheckBase var requiredSpaceMessage = $"Space Required for EFT Client: {DirectorySizeHelper.SizeSuffix(eftSourceDirSize, 2)} including ~10Gb overhead"; + var cacheDriveMessage = ""; + var cacheDriveOK = true; + + // if cache directory is on another drive, check that drive for around 5Gb of required space + if (cacheDirectory.Root.Name.ToLower() != installTargetDirectoryInfo.Root.Name.ToLower()) + { + cacheDriveOK = false; + var availableCacheDriveSize = DriveInfo.GetDrives() + .FirstOrDefault(d => + d.Name.ToLower() == cacheDirectory.Root.Name.ToLower()) + ?.AvailableFreeSpace ?? + 0; + + // check if the drive where the cache is has at least 5Gb of free space. We should only need 2-3Gb + if (availableCacheDriveSize > 5000000000) + { + cacheDriveMessage = $"Drive for cache '{cacheDirectory.Root.Name}' has at least 5Gb of space. Available: {DirectorySizeHelper.SizeSuffix(availableCacheDriveSize, 2)}"; + cacheDriveOK = true; + } + else + { + cacheDriveMessage = $"Drive for cache '{cacheDirectory.Root.Name}' does NOT have at least 5Gb of space. Available: {DirectorySizeHelper.SizeSuffix(availableCacheDriveSize, 2)}"; + } + } + if (eftSourceDirSize > availableSize) { return PreCheckResult.FromError( - $"Not enough free space on {installTargetDirectoryInfo.Root.Name} to install SPT\n\n{availableSpaceMessage}\n{requiredSpaceMessage}"); + $"Not enough free space on {installTargetDirectoryInfo.Root.Name} to install SPT\n\n{availableSpaceMessage}\n{requiredSpaceMessage}\n\n{cacheDriveMessage}"); } - return PreCheckResult.FromSuccess( - $"There is enough space available on {installTargetDirectoryInfo.Root.Name} to install SPT.\n\n{availableSpaceMessage}\n{requiredSpaceMessage}"); + var okGameSpaceMessage = + $"There is enough space available on {installTargetDirectoryInfo.Root.Name} to install SPT.\n\n{availableSpaceMessage}\n{requiredSpaceMessage}\n\n{cacheDriveMessage}"; + + if (!cacheDriveOK) + { + return PreCheckResult.FromError(okGameSpaceMessage); + } + + return PreCheckResult.FromSuccess(okGameSpaceMessage); } catch (Exception ex) {