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/DialogErrorHandler.cs b/StabilityMatrix/Helper/DialogErrorHandler.cs index 01aa4194..a79fa047 100644 --- a/StabilityMatrix/Helper/DialogErrorHandler.cs +++ b/StabilityMatrix/Helper/DialogErrorHandler.cs @@ -42,7 +42,7 @@ public class DialogErrorHandler : IDialogErrorHandler } /// - /// Attempt to run the given action, showing a generic error snackbar if it fails. + /// Attempt to run the given task, showing a generic error snackbar if it fails. /// public async Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000) { @@ -62,4 +62,29 @@ public class DialogErrorHandler : IDialogErrorHandler }; } } + + /// + /// Attempt to run the given void task, showing a generic error snackbar if it fails. + /// Return a TaskResult with true if the task succeeded, false if it failed. + /// + public async Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000) + { + try + { + await task; + return new TaskResult + { + Result = true + }; + } + catch (Exception e) + { + ShowSnackbarAsync(message, level, timeoutMilliseconds); + return new TaskResult + { + Result = false, + Exception = e + }; + } + } } diff --git a/StabilityMatrix/Helper/EventManager.cs b/StabilityMatrix/Helper/EventManager.cs index 06ebed05..6ddcf47b 100644 --- a/StabilityMatrix/Helper/EventManager.cs +++ b/StabilityMatrix/Helper/EventManager.cs @@ -13,6 +13,10 @@ public class EventManager public event EventHandler? GlobalProgressChanged; public event EventHandler? PageChangeRequested; + public event EventHandler? InstalledPackagesChanged; + public event EventHandler? OneClickInstallFinished; 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); + public void OnOneClickInstallFinished() => OneClickInstallFinished?.Invoke(this, EventArgs.Empty); } diff --git a/StabilityMatrix/Helper/IDialogErrorHandler.cs b/StabilityMatrix/Helper/IDialogErrorHandler.cs index 6769a35e..9753ec71 100644 --- a/StabilityMatrix/Helper/IDialogErrorHandler.cs +++ b/StabilityMatrix/Helper/IDialogErrorHandler.cs @@ -12,7 +12,13 @@ public interface IDialogErrorHandler void ShowSnackbarAsync(string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000); /// - /// Attempt to run the given action, showing a generic error snackbar if it fails. + /// Attempt to run the given task, showing a generic error snackbar if it fails. /// Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000); + + /// + /// Attempt to run the given void task, showing a generic error snackbar if it fails. + /// Return a TaskResult with true if the task succeeded, false if it failed. + /// + Task> TryAsync(Task task, string message, LogLevel level = LogLevel.Error, int timeoutMilliseconds = 5000); } 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..98b7b10d 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; diff --git a/StabilityMatrix/LaunchPage.xaml b/StabilityMatrix/LaunchPage.xaml index 238e8b5b..adb0dfc6 100644 --- a/StabilityMatrix/LaunchPage.xaml +++ b/StabilityMatrix/LaunchPage.xaml @@ -99,6 +99,25 @@ + + + + + + + + + + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:converters="clr-namespace:StabilityMatrix.Converters"> + + + + + + + + @@ -35,7 +46,10 @@ - + - - -