udpate prechecks

This commit is contained in:
IsWaffle 2023-07-29 14:26:55 -04:00
parent b2a9e9942e
commit 2eb9197e37
3 changed files with 79 additions and 20 deletions

View File

@ -1,4 +1,5 @@
using System.Threading.Tasks; using System.Linq;
using System.Threading.Tasks;
using SPTInstaller.Helpers; using SPTInstaller.Helpers;
using SPTInstaller.Models; using SPTInstaller.Models;
@ -13,13 +14,35 @@ public class FreeSpacePreCheck : PreCheckBase
_internalData = internalData; _internalData = internalData;
} }
public override async Task<bool> CheckOperation() public override async Task<PreCheckResult> CheckOperation()
{ {
if (_internalData.OriginalGamePath is null || _internalData.TargetInstallPath is null) if (_internalData.OriginalGamePath is null)
return PreCheckResult.FromError("Could not find EFT game path");
if (_internalData.TargetInstallPath is null)
return PreCheckResult.FromError("Could not find install target path");
try
{ {
return false; var eftSourceDirectoryInfo = new DirectoryInfo(_internalData.OriginalGamePath);
var installTargetDirectoryInfo = new DirectoryInfo(_internalData.TargetInstallPath);
var eftSourceDirSize = DirectorySizeHelper.GetSizeOfDirectory(eftSourceDirectoryInfo);
var availableSize = DriveInfo.GetDrives().FirstOrDefault(d => d.Name.ToLower() == installTargetDirectoryInfo.Root.Name.ToLower())?.AvailableFreeSpace ?? 0;
var availableSpaceMessage = $"Available Space: {DirectorySizeHelper.SizeSuffix(availableSize, 2)}";
var requiredSpaceMessage = $"Space Required for EFT Client: {DirectorySizeHelper.SizeSuffix(eftSourceDirSize, 2)}";
if (eftSourceDirSize > availableSize)
{
return PreCheckResult.FromError($"Not enough free space on {installTargetDirectoryInfo.Root.Name} to install SPT\n\n{availableSpaceMessage}\n{requiredSpaceMessage}");
} }
return DirectorySizeHelper.CheckAvailableSize(_internalData.OriginalGamePath, _internalData.TargetInstallPath); return PreCheckResult.FromSuccess($"There is enough space available on {installTargetDirectoryInfo.Root.Name} to install SPT.\n\n{availableSpaceMessage}\n{requiredSpaceMessage}");
}
catch (Exception ex)
{
return PreCheckResult.FromException(ex);
}
} }
} }

View File

@ -10,11 +10,24 @@ public class NetCore6PreCheck : PreCheckBase
{ {
} }
public override async Task<bool> CheckOperation() public override async Task<PreCheckResult> CheckOperation()
{ {
var minRequiredVersion = new Version("6.0.0"); var minRequiredVersion = new Version("6.0.0");
string[] output; string[] output;
var failedButtonText = "Download .Net Core 6 Desktop Runtime";
var failedButtonAction = () =>
{
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
UseShellExecute = true,
WindowStyle = ProcessWindowStyle.Hidden,
ArgumentList = { "/C", "start", "https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-desktop-6.0.4-windows-x64-installer" }
});
};
try try
{ {
var proc = Process.Start(new ProcessStartInfo() var proc = Process.Start(new ProcessStartInfo()
@ -32,9 +45,11 @@ public class NetCore6PreCheck : PreCheckBase
catch (Exception ex) catch (Exception ex)
{ {
// TODO: logging // TODO: logging
return false; return PreCheckResult.FromException(ex);
} }
var highestFoundVersion = new Version("0.0.0");
foreach (var lineVersion in output) foreach (var lineVersion in output)
{ {
if (lineVersion.StartsWith("Microsoft.WindowsDesktop.App") && lineVersion.Split(" ").Length > 1) if (lineVersion.StartsWith("Microsoft.WindowsDesktop.App") && lineVersion.Split(" ").Length > 1)
@ -43,14 +58,16 @@ public class NetCore6PreCheck : PreCheckBase
var foundVersion = new Version(stringVerion); var foundVersion = new Version(stringVerion);
// not fully sure if we should only check for 6.x.x versions or if higher major versions are ok -waffle // waffle: not fully sure if we should only check for 6.x.x versions or if higher major versions are ok
if (foundVersion >= minRequiredVersion) if (foundVersion >= minRequiredVersion)
{ {
return true; return PreCheckResult.FromSuccess($".Net Core {minRequiredVersion} Desktop Runtime or higher is installed.\n\nInstalled Version: {foundVersion}");
} }
highestFoundVersion = foundVersion > highestFoundVersion ? foundVersion : highestFoundVersion;
} }
} }
return false; return PreCheckResult.FromError($".Net Core Desktop Runtime version {minRequiredVersion} or higher is required.\n\nHighest Version Found: {(highestFoundVersion > new Version("0.0.0") ? highestFoundVersion : "Not Found")}\n\nThis is required to play SPT, but you can install it later if and shouldn't affect the SPT install process.", failedButtonText, failedButtonAction);
} }
} }

View File

@ -1,5 +1,6 @@
using Microsoft.Win32; using Microsoft.Win32;
using SPTInstaller.Models; using SPTInstaller.Models;
using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SPTInstaller.Installer_Tasks.PreChecks; namespace SPTInstaller.Installer_Tasks.PreChecks;
@ -10,7 +11,7 @@ public class NetFramework472PreCheck : PreCheckBase
{ {
} }
public override async Task<bool> CheckOperation() public override async Task<PreCheckResult> CheckOperation()
{ {
try try
{ {
@ -18,27 +19,45 @@ public class NetFramework472PreCheck : PreCheckBase
var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full"); var key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full");
var failedButtonText = "Download .Net Framework 4.7.2";
var failedButtonAction = () =>
{
Process.Start(new ProcessStartInfo
{
FileName = "cmd.exe",
UseShellExecute = true,
WindowStyle = ProcessWindowStyle.Hidden,
ArgumentList = { "/C", "start", "https://dotnet.microsoft.com/download/dotnet-framework/thank-you/net472-developer-pack-offline-installer" }
});
};
if (key == null) if (key == null)
{ {
return false; return PreCheckResult.FromError("Could not find .Net Framework on system.\n\nThis is required to play SPT, but you can install it later and shouldn't affect the SPT install process.", failedButtonText, failedButtonAction);
} }
var value = key.GetValue("Version"); var value = key.GetValue("Version");
if (value != null && value is string versionString) if (value == null || value is not string versionString)
{ {
var installedVersion = new Version(versionString); return PreCheckResult.FromError("Something went wrong. This precheck failed for an unknown reason. :(");
return installedVersion > minRequiredVersion;
} }
return false; var installedVersion = new Version(versionString);
if (installedVersion < minRequiredVersion)
{
return PreCheckResult.FromError($".Net Framework {versionString} is installed, but {minRequiredVersion} or higher is required.\n\nYou can install it later and shouldn't affect the SPT install process.", failedButtonText, failedButtonAction);
}
return PreCheckResult.FromSuccess($".Net Framework {minRequiredVersion} or higher is installed.\n\nInstalled Version: {installedVersion}");
} }
catch (Exception ex) catch (Exception ex)
{ {
// TODO: log exceptions // TODO: log exceptions
return false; return PreCheckResult.FromException(ex);
} }
} }
} }