diff --git a/SPTInstaller/App.axaml.cs b/SPTInstaller/App.axaml.cs index 18582ce..cf7fc97 100644 --- a/SPTInstaller/App.axaml.cs +++ b/SPTInstaller/App.axaml.cs @@ -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), }; } diff --git a/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs b/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs index 994d353..1a3d4d4 100644 --- a/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs +++ b/SPTInstaller/CustomControls/Dialogs/WhyCacheThoughDialog.axaml.cs @@ -95,6 +95,10 @@ public partial class WhyCacheThoughDialog : UserControl AdditionalInfo = message; AdditionalInfoColor = allDeleted ? "green" : "red"; Log.Information(message); + + var data = ServiceHelper.Get(); + + App.ReLaunch(false, data.TargetInstallPath!); } public void MoveDownloadsPatcherToCache() diff --git a/SPTInstaller/SPTInstaller.csproj b/SPTInstaller/SPTInstaller.csproj index 6358059..df1842f 100644 --- a/SPTInstaller/SPTInstaller.csproj +++ b/SPTInstaller/SPTInstaller.csproj @@ -10,8 +10,8 @@ icon.ico Assets\spt_installer.ico Debug;Release;TEST - 2.85 - 2.85 + 2.86 + 2.86 SPT diff --git a/SPTInstaller/ViewModels/InstallPathSelectionViewModel.cs b/SPTInstaller/ViewModels/InstallPathSelectionViewModel.cs index fcac7c7..332d64c 100644 --- a/SPTInstaller/ViewModels/InstallPathSelectionViewModel.cs +++ b/SPTInstaller/ViewModels/InstallPathSelectionViewModel.cs @@ -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() ?? 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) { diff --git a/SPTInstaller/ViewModels/InstallerUpdateViewModel.cs b/SPTInstaller/ViewModels/InstallerUpdateViewModel.cs index 5bf8fb8..abc8e5b 100644 --- a/SPTInstaller/ViewModels/InstallerUpdateViewModel.cs +++ b/SPTInstaller/ViewModels/InstallerUpdateViewModel.cs @@ -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() ?? 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() diff --git a/SPTInstaller/ViewModels/MainWindowViewModel.cs b/SPTInstaller/ViewModels/MainWindowViewModel.cs index 40fc793..811fd9f 100644 --- a/SPTInstaller/ViewModels/MainWindowViewModel.cs +++ b/SPTInstaller/ViewModels/MainWindowViewModel.cs @@ -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() diff --git a/SPTInstaller/ViewModels/PreChecksViewModel.cs b/SPTInstaller/ViewModels/PreChecksViewModel.cs index 1688404..9b32d52 100644 --- a/SPTInstaller/ViewModels/PreChecksViewModel.cs +++ b/SPTInstaller/ViewModels/PreChecksViewModel.cs @@ -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) {