add installpath param

added relaunch method for ease of restarting the installer
This commit is contained in:
IsWaffle 2024-07-06 17:06:21 -04:00
parent 498eeaa0ef
commit ca2dec269f
7 changed files with 67 additions and 21 deletions

View File

@ -1,4 +1,5 @@
using System.Linq;
using System.Diagnostics;
using System.Linq;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
@ -7,6 +8,8 @@ using Serilog;
using SPTInstaller.ViewModels;
using SPTInstaller.Views;
using System.Reactive;
using System.Text;
using DynamicData;
namespace SPTInstaller;
@ -14,6 +17,24 @@ public partial class App : Application
{
public static string LogPath = Path.Join(Environment.CurrentDirectory, "spt-installer.log");
public static void ReLaunch(bool debug, string installPath = "")
{
var installerPath = Path.Join(Environment.CurrentDirectory, "SPTInstaller.exe");
var args = new StringBuilder()
.Append(debug ? "debug " : "")
.Append(!string.IsNullOrEmpty(installPath) ? $"installPath=\"{installPath}\"" : "")
.ToString();
Process.Start(new ProcessStartInfo()
{
FileName = installerPath,
Arguments = args
});
Environment.Exit(0);
}
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
@ -35,7 +56,19 @@ public partial class App : Application
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var debug = desktop.Args != null && desktop.Args.Any(x => x.ToLower() == "debug");
var debug = false;
var providedPath = "";
if (desktop.Args != null)
{
debug = desktop.Args.Any(x => x.ToLower() == "debug");
var installPath = desktop.Args.FirstOrDefault(x => x.StartsWith("installPath=", StringComparison.CurrentCultureIgnoreCase));
providedPath = installPath != null && installPath.Contains('=') ? installPath?.Split('=')[1] ?? "" : "";
}
if (debug)
{
Log.Logger = new LoggerConfiguration()
@ -52,7 +85,7 @@ public partial class App : Application
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(debug),
DataContext = new MainWindowViewModel(providedPath, debug),
};
}

View File

@ -95,6 +95,10 @@ public partial class WhyCacheThoughDialog : UserControl
AdditionalInfo = message;
AdditionalInfoColor = allDeleted ? "green" : "red";
Log.Information(message);
var data = ServiceHelper.Get<InternalData>();
App.ReLaunch(false, data.TargetInstallPath!);
}
public void MoveDownloadsPatcherToCache()

View File

@ -10,8 +10,8 @@
<PackageIcon>icon.ico</PackageIcon>
<ApplicationIcon>Assets\spt_installer.ico</ApplicationIcon>
<Configurations>Debug;Release;TEST</Configurations>
<AssemblyVersion>2.85</AssemblyVersion>
<FileVersion>2.85</FileVersion>
<AssemblyVersion>2.86</AssemblyVersion>
<FileVersion>2.86</FileVersion>
<Company>SPT</Company>
</PropertyGroup>

View File

@ -5,6 +5,7 @@ using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform.Storage;
using ReactiveUI;
using Serilog;
using SPTInstaller.Helpers;
using SPTInstaller.Models;
@ -38,13 +39,26 @@ public class InstallPathSelectionViewModel : ViewModelBase
set => this.RaiseAndSetIfChanged(ref _errorMessage, value);
}
public InstallPathSelectionViewModel(IScreen host, bool debugging) : base(host)
public InstallPathSelectionViewModel(IScreen host, string installPath, bool debugging) : base(host)
{
_debugging = debugging;
_data = ServiceHelper.Get<InternalData?>() ?? throw new Exception("Failed to get internal data");
SelectedPath = Environment.CurrentDirectory;
ValidPath = false;
if (!string.IsNullOrEmpty(installPath))
{
SelectedPath = installPath;
ValidatePath();
if (ValidPath)
{
Log.Information("Install Path was provided by parameter and seems valid");
Task.Run(NextCommand);
return;
}
}
AdjustInstallPath();
}
@ -131,7 +145,7 @@ public class InstallPathSelectionViewModel : ViewModelBase
}
}
public async Task NextCommand()
public void NextCommand()
{
if (FileHelper.CheckPathForProblemLocations(SelectedPath, out var failedCheck) && failedCheck.CheckAction == PathCheckAction.Deny)
{

View File

@ -13,9 +13,12 @@ public class InstallerUpdateViewModel : ViewModelBase
private InternalData _data;
private bool _debugging;
public InstallerUpdateViewModel(IScreen Host, bool debugging) : base(Host)
private string _installPath;
public InstallerUpdateViewModel(IScreen Host, string installPath, bool debugging) : base(Host)
{
_debugging = debugging;
_installPath = installPath;
_data = ServiceHelper.Get<InternalData>() ?? throw new Exception("Failed to get internal data");
Task.Run(async () =>
@ -24,14 +27,14 @@ public class InstallerUpdateViewModel : ViewModelBase
if (!UpdateInfo.UpdateAvailable)
{
NavigateTo(new InstallPathSelectionViewModel(HostScreen, _debugging));
NavigateTo(new InstallPathSelectionViewModel(HostScreen, _installPath, _debugging));
}
});
}
public void NotNowCommand()
{
NavigateTo(new InstallPathSelectionViewModel(HostScreen, _debugging));
NavigateTo(new InstallPathSelectionViewModel(HostScreen, _installPath, _debugging));
}
public async Task UpdateInstallCommand()

View File

@ -19,7 +19,7 @@ public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScree
set => this.RaiseAndSetIfChanged(ref _title, value);
}
public MainWindowViewModel(bool debugging)
public MainWindowViewModel(string installPath, bool debugging)
{
Title =
$"{(debugging ? "-debug-" : "")} SPT Installer {"v" + Assembly.GetExecutingAssembly().GetName()?.Version?.ToString() ?? "--unknown version--"}";
@ -31,7 +31,7 @@ public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScree
Log.Information("System Language: {iso} - {name}", uiCulture.TwoLetterISOLanguageName, uiCulture.DisplayName);
Router.Navigate.Execute(new InstallerUpdateViewModel(this, debugging));
Router.Navigate.Execute(new InstallerUpdateViewModel(this, installPath, debugging));
}
public void CloseCommand()

View File

@ -214,15 +214,7 @@ public class PreChecksViewModel : ViewModelBase
{
try
{
var installerPath = Path.Join(Environment.CurrentDirectory, "SPTInstaller.exe");
Process.Start(new ProcessStartInfo()
{
FileName = installerPath,
Arguments = "debug"
});
Environment.Exit(0);
App.ReLaunch(true, InstallPath);
}
catch (Exception ex)
{