Merge pull request 'feature/size-check' (#17) from Schrader/SPT-AKI-Installer:feature/size-check into master
Reviewed-on: CWX/SPT-AKI-Installer#17
This commit is contained in:
commit
eabe30c386
@ -6,6 +6,7 @@
|
|||||||
- Checks if .net 4.7.2 (or higher) is installed
|
- Checks if .net 4.7.2 (or higher) is installed
|
||||||
- Checks if .net 6 desktop runtime is installed
|
- Checks if .net 6 desktop runtime is installed
|
||||||
- Checks if EFT is installed,
|
- Checks if EFT is installed,
|
||||||
|
- Checks if there is enough space before install,
|
||||||
- Checks installer is not in OG game directory,
|
- Checks installer is not in OG game directory,
|
||||||
- Checks install folder does not have game files already in it,
|
- Checks install folder does not have game files already in it,
|
||||||
- Checks if gameversion matches aki version, if so skip patcher process,
|
- Checks if gameversion matches aki version, if so skip patcher process,
|
||||||
|
3
SPTInstaller/GlobalUsings.cs
Normal file
3
SPTInstaller/GlobalUsings.cs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Global using directives
|
||||||
|
global using System;
|
||||||
|
global using System.IO;
|
29
SPTInstaller/Helpers/DirectorySizeHelper.cs
Normal file
29
SPTInstaller/Helpers/DirectorySizeHelper.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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);
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
using SPTInstaller.Aki.Helper;
|
using SPTInstaller.Aki.Helper;
|
||||||
using SPTInstaller.Interfaces;
|
using SPTInstaller.Interfaces;
|
||||||
using SPTInstaller.Models;
|
using SPTInstaller.Models;
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SPTInstaller.Installer_Tasks
|
namespace SPTInstaller.Installer_Tasks
|
||||||
|
25
SPTInstaller/Installer Tasks/PreChecks/FreeSpacePreCheck.cs
Normal file
25
SPTInstaller/Installer Tasks/PreChecks/FreeSpacePreCheck.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using System.Threading.Tasks;
|
||||||
|
using SPTInstaller.Helpers;
|
||||||
|
using SPTInstaller.Models;
|
||||||
|
|
||||||
|
namespace SPTInstaller.Installer_Tasks.PreChecks;
|
||||||
|
|
||||||
|
public class FreeSpacePreCheck : PreCheckBase
|
||||||
|
{
|
||||||
|
private readonly InternalData _internalData;
|
||||||
|
|
||||||
|
public FreeSpacePreCheck(InternalData internalData) : base("Free Space", true)
|
||||||
|
{
|
||||||
|
_internalData = internalData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<bool> CheckOperation()
|
||||||
|
{
|
||||||
|
if (_internalData.OriginalGamePath is null || _internalData.TargetInstallPath is null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return DirectorySizeHelper.CheckAvailableSize(_internalData.OriginalGamePath, _internalData.TargetInstallPath);
|
||||||
|
}
|
||||||
|
}
|
@ -8,12 +8,12 @@ namespace SPTInstaller.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The folder to install SPT into
|
/// The folder to install SPT into
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string TargetInstallPath { get; set; }
|
public string? TargetInstallPath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The orginal EFT game path
|
/// The orginal EFT game path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string OriginalGamePath { get; set; }
|
public string? OriginalGamePath { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The original EFT game version
|
/// The original EFT game version
|
||||||
|
@ -9,8 +9,6 @@ using SPTInstaller.Installer_Tasks;
|
|||||||
using SPTInstaller.Installer_Tasks.PreChecks;
|
using SPTInstaller.Installer_Tasks.PreChecks;
|
||||||
using SPTInstaller.Interfaces;
|
using SPTInstaller.Interfaces;
|
||||||
using SPTInstaller.Models;
|
using SPTInstaller.Models;
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
@ -35,8 +33,9 @@ namespace SPTInstaller
|
|||||||
ServiceHelper.Register<InternalData>();
|
ServiceHelper.Register<InternalData>();
|
||||||
ServiceHelper.Register<PreCheckBase, NetFramework472PreCheck>();
|
ServiceHelper.Register<PreCheckBase, NetFramework472PreCheck>();
|
||||||
ServiceHelper.Register<PreCheckBase, NetCore6PreCheck>();
|
ServiceHelper.Register<PreCheckBase, NetCore6PreCheck>();
|
||||||
|
ServiceHelper.Register<PreCheckBase, FreeSpacePreCheck>();
|
||||||
#if !TEST
|
#if !TEST
|
||||||
string logPath = Path.Join(Environment.CurrentDirectory, "spt-aki-installer_.log");
|
var logPath = Path.Join(Environment.CurrentDirectory, "spt-aki-installer_.log");
|
||||||
|
|
||||||
Log.Logger = new LoggerConfiguration()
|
Log.Logger = new LoggerConfiguration()
|
||||||
.MinimumLevel.Debug()
|
.MinimumLevel.Debug()
|
||||||
|
@ -9,8 +9,8 @@
|
|||||||
<PackageIcon>icon.ico</PackageIcon>
|
<PackageIcon>icon.ico</PackageIcon>
|
||||||
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\icon.ico</ApplicationIcon>
|
||||||
<Configurations>Debug;Release;TEST</Configurations>
|
<Configurations>Debug;Release;TEST</Configurations>
|
||||||
<AssemblyVersion>2.2</AssemblyVersion>
|
<AssemblyVersion>2.3</AssemblyVersion>
|
||||||
<FileVersion>2.2</FileVersion>
|
<FileVersion>2.3</FileVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,32 +1,37 @@
|
|||||||
using ReactiveUI;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using ReactiveUI;
|
||||||
|
using SPTInstaller.Aki.Helper;
|
||||||
using SPTInstaller.Controllers;
|
using SPTInstaller.Controllers;
|
||||||
using SPTInstaller.Helpers;
|
using SPTInstaller.Helpers;
|
||||||
using SPTInstaller.Models;
|
using SPTInstaller.Models;
|
||||||
using System;
|
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Input;
|
|
||||||
|
|
||||||
namespace SPTInstaller.ViewModels
|
namespace SPTInstaller.ViewModels;
|
||||||
{
|
|
||||||
public class PreChecksViewModel : ViewModelBase
|
public class PreChecksViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
private string _InstallPath;
|
private string _installPath;
|
||||||
|
private bool _allowInstall;
|
||||||
|
|
||||||
|
public ObservableCollection<PreCheckBase> PreChecks { get; set; } = new(ServiceHelper.GetAll<PreCheckBase>());
|
||||||
|
public ICommand StartInstallCommand { get; set; }
|
||||||
public string InstallPath
|
public string InstallPath
|
||||||
{
|
{
|
||||||
get => _InstallPath;
|
get => _installPath;
|
||||||
set => this.RaiseAndSetIfChanged(ref _InstallPath, value);
|
set => this.RaiseAndSetIfChanged(ref _installPath, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ObservableCollection<PreCheckBase> PreChecks { get; set; }
|
public bool AllowInstall
|
||||||
= new ObservableCollection<PreCheckBase>(ServiceHelper.GetAll<PreCheckBase>());
|
{
|
||||||
|
get => _allowInstall;
|
||||||
ICommand StartInstallCommand { get; set; }
|
set => this.RaiseAndSetIfChanged(ref _allowInstall, value);
|
||||||
|
}
|
||||||
|
|
||||||
public PreChecksViewModel(IScreen host) : base(host)
|
public PreChecksViewModel(IScreen host) : base(host)
|
||||||
{
|
{
|
||||||
var data = ServiceHelper.Get<InternalData>();
|
var data = ServiceHelper.Get<InternalData?>();
|
||||||
var installer = ServiceHelper.Get<InstallController>();
|
var installer = ServiceHelper.Get<InstallController?>();
|
||||||
|
|
||||||
if (data == null || installer == null)
|
if (data == null || installer == null)
|
||||||
{
|
{
|
||||||
@ -34,26 +39,16 @@ namespace SPTInstaller.ViewModels
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.OriginalGamePath = PreCheckHelper.DetectOriginalGamePath();
|
||||||
data.TargetInstallPath = Environment.CurrentDirectory;
|
data.TargetInstallPath = Environment.CurrentDirectory;
|
||||||
|
|
||||||
InstallPath = data.TargetInstallPath;
|
InstallPath = data.TargetInstallPath;
|
||||||
|
|
||||||
StartInstallCommand = ReactiveCommand.Create(() =>
|
StartInstallCommand = ReactiveCommand.Create(() => NavigateTo(new InstallViewModel(HostScreen)));
|
||||||
{
|
|
||||||
NavigateTo(new InstallViewModel(HostScreen));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var result = await installer.RunPreChecks();
|
var result = await installer.RunPreChecks();
|
||||||
|
AllowInstall = result.Succeeded;
|
||||||
if(!result.Succeeded)
|
|
||||||
{
|
|
||||||
//if a required precheck fails, abort to message view
|
|
||||||
NavigateTo(new MessageViewModel(HostScreen ,result));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
Margin="10"
|
Margin="10"
|
||||||
FontSize="15" FontWeight="SemiBold"
|
FontSize="15" FontWeight="SemiBold"
|
||||||
Classes="yellow"
|
Classes="yellow"
|
||||||
|
IsEnabled="{Binding AllowInstall}"
|
||||||
Command="{Binding StartInstallCommand}"
|
Command="{Binding StartInstallCommand}"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user