From 227071258cf2a3de86fd859c0204bb18318c0d1a Mon Sep 17 00:00:00 2001 From: JT Date: Wed, 31 May 2023 00:41:55 -0700 Subject: [PATCH 1/8] setup one-click install foundations --- StabilityMatrix/App.xaml.cs | 2 + StabilityMatrix/Helper/EventManager.cs | 2 + StabilityMatrix/Helper/IPrerequisiteHelper.cs | 9 + StabilityMatrix/Helper/PrerequisiteHelper.cs | 38 ++++ StabilityMatrix/LaunchOptionsDialog.xaml.cs | 2 + StabilityMatrix/MainWindow.xaml | 67 +++++-- .../ViewModels/InstallerViewModel.cs | 2 +- StabilityMatrix/ViewModels/LaunchViewModel.cs | 11 +- .../ViewModels/MainWindowViewModel.cs | 165 ++++++++++++++++-- 9 files changed, 272 insertions(+), 26 deletions(-) create mode 100644 StabilityMatrix/Helper/IPrerequisiteHelper.cs create mode 100644 StabilityMatrix/Helper/PrerequisiteHelper.cs diff --git a/StabilityMatrix/App.xaml.cs b/StabilityMatrix/App.xaml.cs index c59d55a6..8049ba93 100644 --- a/StabilityMatrix/App.xaml.cs +++ b/StabilityMatrix/App.xaml.cs @@ -9,6 +9,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using NLog.Layouts; using Polly; using Polly.Contrib.WaitAndRetry; using Polly.Extensions.Http; @@ -82,6 +83,7 @@ namespace StabilityMatrix serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); + serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddMemoryCache(); serviceCollection.AddSingleton(); diff --git a/StabilityMatrix/Helper/EventManager.cs b/StabilityMatrix/Helper/EventManager.cs index 06ebed05..2a892ae6 100644 --- a/StabilityMatrix/Helper/EventManager.cs +++ b/StabilityMatrix/Helper/EventManager.cs @@ -13,6 +13,8 @@ public class EventManager public event EventHandler? GlobalProgressChanged; public event EventHandler? PageChangeRequested; + public event EventHandler? InstalledPackagesChanged; public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress); public void RequestPageChange(Type pageType) => PageChangeRequested?.Invoke(this, pageType); + public void OnInstalledPackagesChanged() => InstalledPackagesChanged?.Invoke(this, EventArgs.Empty); } diff --git a/StabilityMatrix/Helper/IPrerequisiteHelper.cs b/StabilityMatrix/Helper/IPrerequisiteHelper.cs new file mode 100644 index 00000000..f999a374 --- /dev/null +++ b/StabilityMatrix/Helper/IPrerequisiteHelper.cs @@ -0,0 +1,9 @@ +using System.Diagnostics; +using System.Threading.Tasks; + +namespace StabilityMatrix.Helper; + +public interface IPrerequisiteHelper +{ + Task InstallGitIfNecessary(); +} \ No newline at end of file diff --git a/StabilityMatrix/Helper/PrerequisiteHelper.cs b/StabilityMatrix/Helper/PrerequisiteHelper.cs new file mode 100644 index 00000000..3e6076bf --- /dev/null +++ b/StabilityMatrix/Helper/PrerequisiteHelper.cs @@ -0,0 +1,38 @@ +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + +namespace StabilityMatrix.Helper; + +public class PrerequisiteHelper : IPrerequisiteHelper +{ + private readonly ILogger logger; + + public PrerequisiteHelper(ILogger logger) + { + this.logger = logger; + } + + public async Task InstallGitIfNecessary() + { + try + { + var gitOutput = await ProcessRunner.GetProcessOutputAsync("git", "--version"); + if (gitOutput.Contains("git version 2")) + { + return default; + } + } + catch (Exception e) + { + logger.LogError(e, "Error running git: "); + } + + var installProcess = + ProcessRunner.StartProcess("Assets\\Git-2.40.1-64-bit.exe", "/VERYSILENT /NORESTART"); + installProcess.OutputDataReceived += (sender, args) => { logger.LogDebug(args.Data); }; + + return installProcess; + } +} diff --git a/StabilityMatrix/LaunchOptionsDialog.xaml.cs b/StabilityMatrix/LaunchOptionsDialog.xaml.cs index 63d0a7ba..a9d521d8 100644 --- a/StabilityMatrix/LaunchOptionsDialog.xaml.cs +++ b/StabilityMatrix/LaunchOptionsDialog.xaml.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -19,6 +20,7 @@ public partial class LaunchOptionsDialog : ContentDialog dialogService.GetContentPresenter()) { this.viewModel = viewModel; + var sw = new Stopwatch(); InitializeComponent(); DataContext = viewModel; } diff --git a/StabilityMatrix/MainWindow.xaml b/StabilityMatrix/MainWindow.xaml index 6e450f6b..e5fbb67c 100644 --- a/StabilityMatrix/MainWindow.xaml +++ b/StabilityMatrix/MainWindow.xaml @@ -8,6 +8,8 @@ Title="Stability Matrix" Width="1100" WindowBackdropType="Mica" + d:DesignHeight="500" + d:DesignWidth="700" d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel, IsDesignTimeCreatable=True}" mc:Ignorable="d" @@ -18,7 +20,16 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:viewModels="clr-namespace:StabilityMatrix.ViewModels" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:converters="clr-namespace:StabilityMatrix.Converters"> + + + + + + + + @@ -35,7 +46,10 @@ - + - - -