From 3a23360246f97fef73d99016aed5abb4777e6d6c Mon Sep 17 00:00:00 2001 From: JT Date: Tue, 6 Jun 2023 23:45:32 -0700 Subject: [PATCH 1/3] code cleanup & fix accent color on fresh install bug --- StabilityMatrix/App.xaml | 13 ------------ StabilityMatrix/CheckpointBrowserPage.xaml | 6 +++++- StabilityMatrix/CheckpointBrowserPage.xaml.cs | 7 +------ StabilityMatrix/Extensions/EnumAttributes.cs | 2 -- StabilityMatrix/Helper/IPrerequisiteHelper.cs | 2 -- StabilityMatrix/Helper/ISettingsManager.cs | 7 ++++--- StabilityMatrix/Helper/PrerequisiteHelper.cs | 13 +++--------- StabilityMatrix/Helper/SettingsManager.cs | 8 +++++++ StabilityMatrix/MainWindow.xaml.cs | 2 -- .../Models/Api/CivitCommercialUse.cs | 3 +-- StabilityMatrix/Models/Api/CivitFileHashes.cs | 4 +--- StabilityMatrix/Models/Api/CivitModelType.cs | 3 +-- .../Models/Api/CivitModelsRequest.cs | 3 +-- StabilityMatrix/Models/Api/CivitSortMode.cs | 3 +-- StabilityMatrix/Models/ConnectedModelInfo.cs | 3 +-- StabilityMatrix/Models/Packages/A3WebUI.cs | 2 +- StabilityMatrix/Models/ProgressReport.cs | 3 --- StabilityMatrix/Models/Settings.cs | 1 + StabilityMatrix/OneClickInstallDialog.xaml | 2 +- StabilityMatrix/Services/DownloadService.cs | 1 - .../Services/INotificationBarService.cs | 8 +++++++ .../Services/NotificationBarService.cs | 21 ++++++++++++------- StabilityMatrix/StabilityMatrix.csproj | 3 --- StabilityMatrix/Styles/Styles.xaml | 12 +++++++++++ .../CheckpointBrowserCardViewModel.cs | 1 - .../ViewModels/OneClickInstallViewModel.cs | 11 ++++++---- 26 files changed, 71 insertions(+), 73 deletions(-) create mode 100644 StabilityMatrix/Services/INotificationBarService.cs diff --git a/StabilityMatrix/App.xaml b/StabilityMatrix/App.xaml index d2cec9bc..3a0c39ba 100644 --- a/StabilityMatrix/App.xaml +++ b/StabilityMatrix/App.xaml @@ -13,19 +13,6 @@ - - - - - - - - - - - - - diff --git a/StabilityMatrix/CheckpointBrowserPage.xaml b/StabilityMatrix/CheckpointBrowserPage.xaml index 59b6af14..c32b33d1 100644 --- a/StabilityMatrix/CheckpointBrowserPage.xaml +++ b/StabilityMatrix/CheckpointBrowserPage.xaml @@ -176,7 +176,11 @@ ItemsSource="{Binding ModelCards}" PreviewMouseWheel="VirtualizingGridView_OnPreviewMouseWheel"/> - + + + ? InstallProgressChanged; - event EventHandler? InstallComplete; Task InstallGitIfNecessary(IProgress? progress = null); } diff --git a/StabilityMatrix/Helper/ISettingsManager.cs b/StabilityMatrix/Helper/ISettingsManager.cs index 8f883566..f3748261 100644 --- a/StabilityMatrix/Helper/ISettingsManager.cs +++ b/StabilityMatrix/Helper/ISettingsManager.cs @@ -13,17 +13,18 @@ public interface ISettingsManager void RemoveInstalledPackage(InstalledPackage p); void SetActiveInstalledPackage(InstalledPackage? p); void SetNavExpanded(bool navExpanded); - void UpdatePackageVersionNumber(Guid id, string? newVersion); - void AddPathExtension(string pathExtension); string GetPathExtensionsAsString(); + /// /// Insert path extensions to the front of the PATH environment variable /// void InsertPathExtensions(); - + + void UpdatePackageVersionNumber(Guid id, string? newVersion); void SetLastUpdateCheck(InstalledPackage package); List GetLaunchArgs(Guid packageId); void SaveLaunchArgs(Guid packageId, List launchArgs); void SetWindowBackdropType(WindowBackdropType backdropType); + void SetHasSeenWelcomeNotification(bool hasSeenWelcomeNotification); } diff --git a/StabilityMatrix/Helper/PrerequisiteHelper.cs b/StabilityMatrix/Helper/PrerequisiteHelper.cs index 2c5308f8..d7ac3e67 100644 --- a/StabilityMatrix/Helper/PrerequisiteHelper.cs +++ b/StabilityMatrix/Helper/PrerequisiteHelper.cs @@ -22,7 +22,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper private static readonly string PortableGitDownloadPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix", - "PortableGit.tar.bz2"); + "PortableGit.7z"); private static readonly string GitExePath = Path.Combine(PortableGitInstallDir, "bin", "git.exe"); @@ -37,9 +37,6 @@ public class PrerequisiteHelper : IPrerequisiteHelper this.settingsManager = settingsManager; } - public event EventHandler? InstallProgressChanged; - public event EventHandler? InstallComplete; - public async Task InstallGitIfNecessary(IProgress? progress = null) { if (File.Exists(GitExePath)) @@ -52,7 +49,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper var latestRelease = await gitHubClient.Repository.Release.GetLatest("git-for-windows", "git"); var portableGitUrl = latestRelease.Assets - .First(a => a.Name.EndsWith("64-bit.tar.bz2")).BrowserDownloadUrl; + .First(a => a.Name.EndsWith("64-bit.7z.exe")).BrowserDownloadUrl; if (!File.Exists(PortableGitDownloadPath)) { @@ -65,19 +62,15 @@ public class PrerequisiteHelper : IPrerequisiteHelper private async Task UnzipGit(IProgress? progress = null) { - progress?.Report(new ProgressReport(-1, isIndeterminate: true, message: "")); + progress?.Report(new ProgressReport(1, isIndeterminate: true, message: "Installing git...")); await ArchiveHelper.Extract(PortableGitDownloadPath, PortableGitInstallDir, progress); logger.LogInformation("Extracted Git"); - OnInstallProgressChanged(this, new ProgressReport(-1, isIndeterminate: true)); File.Delete(PortableGitDownloadPath); // Also add git to the path settingsManager.AddPathExtension(GitBinPath); settingsManager.InsertPathExtensions(); - OnInstallComplete(this, new ProgressReport(progress: 1f)); } - private void OnInstallProgressChanged(object? sender, ProgressReport progress) => InstallProgressChanged?.Invoke(sender, progress); - private void OnInstallComplete(object? sender, ProgressReport progress) => InstallComplete?.Invoke(sender, progress); } diff --git a/StabilityMatrix/Helper/SettingsManager.cs b/StabilityMatrix/Helper/SettingsManager.cs index dbb57d23..b376a672 100644 --- a/StabilityMatrix/Helper/SettingsManager.cs +++ b/StabilityMatrix/Helper/SettingsManager.cs @@ -29,6 +29,8 @@ public class SettingsManager : ISettingsManager if (!File.Exists(SettingsPath)) { File.Create(SettingsPath).Close(); + Settings.Theme = "Dark"; + Settings.WindowBackdropType = WindowBackdropType.Mica; var defaultSettingsJson = JsonSerializer.Serialize(Settings); File.WriteAllText(SettingsPath, defaultSettingsJson); } @@ -141,6 +143,12 @@ public class SettingsManager : ISettingsManager Settings.WindowBackdropType = backdropType; SaveSettings(); } + + public void SetHasSeenWelcomeNotification(bool hasSeenWelcomeNotification) + { + Settings.HasSeenWelcomeNotification = hasSeenWelcomeNotification; + SaveSettings(); + } private void LoadSettings() { diff --git a/StabilityMatrix/MainWindow.xaml.cs b/StabilityMatrix/MainWindow.xaml.cs index 6b0cddbd..1c548609 100644 --- a/StabilityMatrix/MainWindow.xaml.cs +++ b/StabilityMatrix/MainWindow.xaml.cs @@ -1,8 +1,6 @@ using System; using System.Diagnostics; using System.Windows; -using System.Windows.Media; -using Octokit; using StabilityMatrix.Helper; using StabilityMatrix.Services; using StabilityMatrix.ViewModels; diff --git a/StabilityMatrix/Models/Api/CivitCommercialUse.cs b/StabilityMatrix/Models/Api/CivitCommercialUse.cs index 1b5a97fb..13603548 100644 --- a/StabilityMatrix/Models/Api/CivitCommercialUse.cs +++ b/StabilityMatrix/Models/Api/CivitCommercialUse.cs @@ -1,5 +1,4 @@ -using System.Diagnostics.CodeAnalysis; -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace StabilityMatrix.Models.Api; diff --git a/StabilityMatrix/Models/Api/CivitFileHashes.cs b/StabilityMatrix/Models/Api/CivitFileHashes.cs index 1d0d37e1..abd70334 100644 --- a/StabilityMatrix/Models/Api/CivitFileHashes.cs +++ b/StabilityMatrix/Models/Api/CivitFileHashes.cs @@ -1,6 +1,4 @@ -using System.Text.Json.Serialization; - -namespace StabilityMatrix.Models.Api; +namespace StabilityMatrix.Models.Api; public class CivitFileHashes { diff --git a/StabilityMatrix/Models/Api/CivitModelType.cs b/StabilityMatrix/Models/Api/CivitModelType.cs index 5198d15e..e9a72768 100644 --- a/StabilityMatrix/Models/Api/CivitModelType.cs +++ b/StabilityMatrix/Models/Api/CivitModelType.cs @@ -1,5 +1,4 @@ -using System; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; using StabilityMatrix.Extensions; diff --git a/StabilityMatrix/Models/Api/CivitModelsRequest.cs b/StabilityMatrix/Models/Api/CivitModelsRequest.cs index 38b0c91d..17ab5ecc 100644 --- a/StabilityMatrix/Models/Api/CivitModelsRequest.cs +++ b/StabilityMatrix/Models/Api/CivitModelsRequest.cs @@ -1,5 +1,4 @@ -using System.Text.Json.Serialization; -using Refit; +using Refit; namespace StabilityMatrix.Models.Api; diff --git a/StabilityMatrix/Models/Api/CivitSortMode.cs b/StabilityMatrix/Models/Api/CivitSortMode.cs index 4ea22673..25a5ec67 100644 --- a/StabilityMatrix/Models/Api/CivitSortMode.cs +++ b/StabilityMatrix/Models/Api/CivitSortMode.cs @@ -1,5 +1,4 @@ -using System.Diagnostics.CodeAnalysis; -using System.Runtime.Serialization; +using System.Runtime.Serialization; using System.Text.Json.Serialization; namespace StabilityMatrix.Models.Api; diff --git a/StabilityMatrix/Models/ConnectedModelInfo.cs b/StabilityMatrix/Models/ConnectedModelInfo.cs index 245feae2..ea4ef8c3 100644 --- a/StabilityMatrix/Models/ConnectedModelInfo.cs +++ b/StabilityMatrix/Models/ConnectedModelInfo.cs @@ -1,6 +1,5 @@ using System; using System.Text.Json; -using StabilityMatrix.Extensions; using StabilityMatrix.Models.Api; namespace StabilityMatrix.Models; @@ -24,7 +23,7 @@ public class ConnectedModelInfo // User settings public string? UserTitle { get; set; } public string? ThumbnailImageUrl { get; set; } - + public ConnectedModelInfo(CivitModel civitModel, CivitModelVersion civitModelVersion, CivitFile civitFile, DateTime importedAt) { ModelId = civitModel.Id; diff --git a/StabilityMatrix/Models/Packages/A3WebUI.cs b/StabilityMatrix/Models/Packages/A3WebUI.cs index 650b62dc..5b137299 100644 --- a/StabilityMatrix/Models/Packages/A3WebUI.cs +++ b/StabilityMatrix/Models/Packages/A3WebUI.cs @@ -134,7 +134,7 @@ public class A3WebUI : BaseGitPackage await venvRunner.PipInstall("xformers", InstallLocation, HandleConsoleOutput); } - await venvRunner.PipInstall("-r requirements.txt", InstallLocation, HandleConsoleOutput); + await venvRunner.PipInstall("-r requirements_versions.txt", InstallLocation, HandleConsoleOutput); Logger.Debug("Finished installing requirements"); progress?.Report(new ProgressReport(1f, "Install complete")); diff --git a/StabilityMatrix/Models/ProgressReport.cs b/StabilityMatrix/Models/ProgressReport.cs index e0cc8525..8252de5c 100644 --- a/StabilityMatrix/Models/ProgressReport.cs +++ b/StabilityMatrix/Models/ProgressReport.cs @@ -1,7 +1,4 @@ using System; -using Microsoft.Extensions.Logging; -using NLog; -using LogLevel = NLog.LogLevel; namespace StabilityMatrix.Models; diff --git a/StabilityMatrix/Models/Settings.cs b/StabilityMatrix/Models/Settings.cs index d0ed2783..0f2d8d2b 100644 --- a/StabilityMatrix/Models/Settings.cs +++ b/StabilityMatrix/Models/Settings.cs @@ -11,5 +11,6 @@ public class Settings public List InstalledPackages { get; set; } = new(); public Guid? ActiveInstalledPackage { get; set; } public bool IsNavExpanded { get; set; } + public bool HasSeenWelcomeNotification { get; set; } public List? PathExtensions { get; set; } } diff --git a/StabilityMatrix/OneClickInstallDialog.xaml b/StabilityMatrix/OneClickInstallDialog.xaml index 0307d972..5b2c0906 100644 --- a/StabilityMatrix/OneClickInstallDialog.xaml +++ b/StabilityMatrix/OneClickInstallDialog.xaml @@ -61,7 +61,7 @@ Command="{Binding InstallCommand}" FontSize="32" HorizontalAlignment="Center" - Appearance="Primary" + Appearance="Success" Margin="16" Padding="16, 8, 16, 8" /> diff --git a/StabilityMatrix/Services/DownloadService.cs b/StabilityMatrix/Services/DownloadService.cs index 2a5e3b73..f63dcbd8 100644 --- a/StabilityMatrix/Services/DownloadService.cs +++ b/StabilityMatrix/Services/DownloadService.cs @@ -2,7 +2,6 @@ using System.IO; using System.Net.Http; using System.Net.Http.Headers; -using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Polly.Contrib.WaitAndRetry; diff --git a/StabilityMatrix/Services/INotificationBarService.cs b/StabilityMatrix/Services/INotificationBarService.cs new file mode 100644 index 00000000..4308cabd --- /dev/null +++ b/StabilityMatrix/Services/INotificationBarService.cs @@ -0,0 +1,8 @@ +using Wpf.Ui.Contracts; + +namespace StabilityMatrix.Services; + +public interface INotificationBarService : ISnackbarService +{ + public void ShowStartupNotifications(); +} \ No newline at end of file diff --git a/StabilityMatrix/Services/NotificationBarService.cs b/StabilityMatrix/Services/NotificationBarService.cs index 8ab70584..40107ac5 100644 --- a/StabilityMatrix/Services/NotificationBarService.cs +++ b/StabilityMatrix/Services/NotificationBarService.cs @@ -1,26 +1,33 @@ using AsyncAwaitBestPractices; +using StabilityMatrix.Helper; using Wpf.Ui.Common; -using Wpf.Ui.Contracts; using Wpf.Ui.Controls; using Wpf.Ui.Controls.IconElements; -using Wpf.Ui.Services; +using SnackbarService = Wpf.Ui.Services.SnackbarService; namespace StabilityMatrix.Services; -public interface INotificationBarService : ISnackbarService -{ - public void ShowStartupNotifications(); -} - public class NotificationBarService : SnackbarService, INotificationBarService { + private readonly ISettingsManager settingsManager; + + public NotificationBarService(ISettingsManager settingsManager) + { + this.settingsManager = settingsManager; + } + public void ShowStartupNotifications() { + if (settingsManager.Settings.HasSeenWelcomeNotification) + return; + Timeout = 10000; var linkIcon = new SymbolIcon(SymbolRegular.Link24); var snackbar = ShowAsync( "Welcome to StabilityMatrix!", "You can join our Discord server for support and feedback.", linkIcon, ControlAppearance.Info); snackbar.SafeFireAndForget(); + + settingsManager.SetHasSeenWelcomeNotification(true); } } diff --git a/StabilityMatrix/StabilityMatrix.csproj b/StabilityMatrix/StabilityMatrix.csproj index d96c2b32..f20b2031 100644 --- a/StabilityMatrix/StabilityMatrix.csproj +++ b/StabilityMatrix/StabilityMatrix.csproj @@ -55,16 +55,13 @@ Always - - PreserveNewest Always - diff --git a/StabilityMatrix/Styles/Styles.xaml b/StabilityMatrix/Styles/Styles.xaml index 94c810f0..e84030b8 100644 --- a/StabilityMatrix/Styles/Styles.xaml +++ b/StabilityMatrix/Styles/Styles.xaml @@ -99,4 +99,16 @@ + + + + + + + + + + + + diff --git a/StabilityMatrix/ViewModels/CheckpointBrowserCardViewModel.cs b/StabilityMatrix/ViewModels/CheckpointBrowserCardViewModel.cs index c167ae5c..0821bbed 100644 --- a/StabilityMatrix/ViewModels/CheckpointBrowserCardViewModel.cs +++ b/StabilityMatrix/ViewModels/CheckpointBrowserCardViewModel.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; -using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.Logging; using StabilityMatrix.Extensions; diff --git a/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs b/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs index 9cf694d1..7366eff2 100644 --- a/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs +++ b/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs @@ -73,7 +73,7 @@ public partial class OneClickInstallViewModel : ObservableObject private async Task DoInstall() { var a1111 = packageFactory.FindPackageByName(DefaultPackageName)!; - HeaderText = "Installing Stable Diffusion WebUI..."; + HeaderText = "Installing Stable Diffusion WebUI"; var progressHandler = new Progress(progress => { @@ -81,11 +81,11 @@ public partial class OneClickInstallViewModel : ObservableObject { SubHeaderText = $"Downloading Git... {progress.Percentage:N0}%"; } - else if (string.IsNullOrWhiteSpace(progress.Message)) + else if (progress.Message?.Contains("Extracting") ?? false) { SubHeaderText = $"Installing Git... {progress.Percentage:N0}%"; } - else + else if (progress.Message != null) { SubHeaderText = progress.Message; } @@ -116,6 +116,9 @@ public partial class OneClickInstallViewModel : ObservableObject await DownloadPackage(a1111, latestVersion); await InstallPackage(a1111); + + SubHeaderText = "Setting up shared folder links..."; + sharedFolders.SetupLinksForPackage(a1111, a1111.InstallLocation); var package = new InstalledPackage { @@ -164,7 +167,7 @@ public partial class OneClickInstallViewModel : ObservableObject private async Task InstallPackage(BasePackage selectedPackage) { selectedPackage.ConsoleOutput += (_, output) => SubSubHeaderText = output; - SubHeaderText = "Installing package..."; + SubHeaderText = "Downloading and installing package requirements..."; var progress = new Progress(progress => { From 6d2d4c740d4345d73223a6f3b1f8f1202d95eda8 Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 7 Jun 2023 03:44:18 -0400 Subject: [PATCH 2/3] Add Extract7z using 7za and fixed git extract --- StabilityMatrix/Helper/ArchiveHelper.cs | 54 ++++++++++++++++++- StabilityMatrix/Helper/PrerequisiteHelper.cs | 13 +++-- StabilityMatrix/Models/ProgressReport.cs | 10 ++-- StabilityMatrix/Models/ProgressType.cs | 8 +++ .../ViewModels/InstallerViewModel.cs | 2 +- .../ViewModels/OneClickInstallViewModel.cs | 2 +- 6 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 StabilityMatrix/Models/ProgressType.cs diff --git a/StabilityMatrix/Helper/ArchiveHelper.cs b/StabilityMatrix/Helper/ArchiveHelper.cs index 84aeb5fd..aa32c09d 100644 --- a/StabilityMatrix/Helper/ArchiveHelper.cs +++ b/StabilityMatrix/Helper/ArchiveHelper.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows; @@ -22,7 +23,9 @@ public static class ArchiveHelper public static string SevenZipPath => Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, RelativeSevenZipPath)); private static readonly Regex Regex7ZOutput = new(@"(?<=Size:\s*)\d+|(?<=Compressed:\s*)\d+"); - + private static readonly Regex Regex7ZProgressDigits = new(@"(?<=\s*)\d+(?=%)"); + private static readonly Regex Regex7ZProgressFull = new(@"(\d+)%.*- (.*)"); + public static async Task TestArchive(string archivePath) { var process = ProcessRunner.StartProcess(SevenZipPath, new[] {"t", archivePath}); @@ -33,6 +36,55 @@ public static class ArchiveHelper var compressed = ulong.Parse(matches[1].Value); return new ArchiveInfo(size, compressed); } + + public static async Task Extract7Z(string archivePath, string extractDirectory) + { + var process = ProcessRunner.StartProcess(SevenZipPath, new[] + { + "x", archivePath, $"-o{ProcessRunner.Quote(extractDirectory)}", "-y" + }); + await process.WaitForExitAsync(); + var output = await process.StandardOutput.ReadToEndAsync(); + var matches = Regex7ZOutput.Matches(output); + var size = ulong.Parse(matches[0].Value); + var compressed = ulong.Parse(matches[1].Value); + return new ArchiveInfo(size, compressed); + } + + public static async Task Extract7Z(string archivePath, string extractDirectory, IProgress progress) + { + var outputStore = new StringBuilder(); + var onOutput = new Action(s => + { + // Parse progress + Logger.Trace($"7z: {s}"); + outputStore.AppendLine(s); + var match = Regex7ZProgressFull.Match(s ?? ""); + if (match.Success) + { + var percent = int.Parse(match.Groups[1].Value); + var currentFile = match.Groups[2].Value; + progress.Report(new ProgressReport(percent / (float) 100, "Extracting", currentFile, type: ProgressType.Extract)); + } + }); + progress.Report(new ProgressReport(-1, isIndeterminate: true, type: ProgressType.Extract)); + + // Need -bsp1 for progress reports + var process = ProcessRunner.StartProcess(SevenZipPath, new[] + { + "x", archivePath, $"-o{ProcessRunner.Quote(extractDirectory)}", "-y", "-bsp1" + }, outputDataReceived: onOutput); + + await process.WaitForExitAsync(); + + progress.Report(new ProgressReport(1, "Finished extracting", type: ProgressType.Extract)); + + var output = outputStore.ToString(); + var matches = Regex7ZOutput.Matches(output); + var size = ulong.Parse(matches[0].Value); + var compressed = ulong.Parse(matches[1].Value); + return new ArchiveInfo(size, compressed); + } /// /// Extract an archive to the output directory. diff --git a/StabilityMatrix/Helper/PrerequisiteHelper.cs b/StabilityMatrix/Helper/PrerequisiteHelper.cs index 2c5308f8..50c80832 100644 --- a/StabilityMatrix/Helper/PrerequisiteHelper.cs +++ b/StabilityMatrix/Helper/PrerequisiteHelper.cs @@ -22,7 +22,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper private static readonly string PortableGitDownloadPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StabilityMatrix", - "PortableGit.tar.bz2"); + "PortableGit.7z.exe"); private static readonly string GitExePath = Path.Combine(PortableGitInstallDir, "bin", "git.exe"); @@ -52,7 +52,7 @@ public class PrerequisiteHelper : IPrerequisiteHelper var latestRelease = await gitHubClient.Repository.Release.GetLatest("git-for-windows", "git"); var portableGitUrl = latestRelease.Assets - .First(a => a.Name.EndsWith("64-bit.tar.bz2")).BrowserDownloadUrl; + .First(a => a.Name.EndsWith("64-bit.7z.exe")).BrowserDownloadUrl; if (!File.Exists(PortableGitDownloadPath)) { @@ -66,7 +66,14 @@ public class PrerequisiteHelper : IPrerequisiteHelper private async Task UnzipGit(IProgress? progress = null) { progress?.Report(new ProgressReport(-1, isIndeterminate: true, message: "")); - await ArchiveHelper.Extract(PortableGitDownloadPath, PortableGitInstallDir, progress); + if (progress == null) + { + await ArchiveHelper.Extract7Z(PortableGitDownloadPath, PortableGitInstallDir); + } + else + { + await ArchiveHelper.Extract7Z(PortableGitDownloadPath, PortableGitInstallDir, progress); + } logger.LogInformation("Extracted Git"); diff --git a/StabilityMatrix/Models/ProgressReport.cs b/StabilityMatrix/Models/ProgressReport.cs index e0cc8525..3b1e8f68 100644 --- a/StabilityMatrix/Models/ProgressReport.cs +++ b/StabilityMatrix/Models/ProgressReport.cs @@ -23,16 +23,18 @@ public record struct ProgressReport public string? Message { get; init; } public bool IsIndeterminate { get; init; } = false; public float Percentage => (float) Math.Ceiling(Math.Clamp(Progress ?? 0, 0, 1) * 100); + public ProgressType Type { get; init; } = ProgressType.Generic; - public ProgressReport(double progress, string? title = null, string? message = null, bool isIndeterminate = false) + public ProgressReport(double progress, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic) { Progress = progress; Title = title; Message = message; IsIndeterminate = isIndeterminate; + Type = type; } - public ProgressReport(ulong current, ulong total, string? title = null, string? message = null, bool isIndeterminate = false) + public ProgressReport(ulong current, ulong total, string? title = null, string? message = null, bool isIndeterminate = false, ProgressType type = ProgressType.Generic) { Current = current; Total = total; @@ -40,13 +42,15 @@ public record struct ProgressReport Title = title; Message = message; IsIndeterminate = isIndeterminate; + Type = type; } - public ProgressReport(ulong current, string? title = null, string? message = null) + public ProgressReport(ulong current, string? title = null, string? message = null, ProgressType type = ProgressType.Generic) { Current = current; Title = title; Message = message; IsIndeterminate = true; + Type = type; } } diff --git a/StabilityMatrix/Models/ProgressType.cs b/StabilityMatrix/Models/ProgressType.cs new file mode 100644 index 00000000..14471f4f --- /dev/null +++ b/StabilityMatrix/Models/ProgressType.cs @@ -0,0 +1,8 @@ +namespace StabilityMatrix.Models; + +public enum ProgressType +{ + Generic, + Download, + Extract, +} diff --git a/StabilityMatrix/ViewModels/InstallerViewModel.cs b/StabilityMatrix/ViewModels/InstallerViewModel.cs index c0f1af45..c342ed30 100644 --- a/StabilityMatrix/ViewModels/InstallerViewModel.cs +++ b/StabilityMatrix/ViewModels/InstallerViewModel.cs @@ -397,7 +397,7 @@ public partial class InstallerViewModel : ObservableObject { ProgressText = $"Downloading Git... {progress.Percentage:N0}%"; } - else if (string.IsNullOrWhiteSpace(progress.Message)) + else if (progress.Type == ProgressType.Extract) { ProgressText = $"Installing Git... {progress.Percentage:N0}%"; } diff --git a/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs b/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs index 9cf694d1..479ddc6a 100644 --- a/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs +++ b/StabilityMatrix/ViewModels/OneClickInstallViewModel.cs @@ -81,7 +81,7 @@ public partial class OneClickInstallViewModel : ObservableObject { SubHeaderText = $"Downloading Git... {progress.Percentage:N0}%"; } - else if (string.IsNullOrWhiteSpace(progress.Message)) + else if (progress.Type == ProgressType.Extract) { SubHeaderText = $"Installing Git... {progress.Percentage:N0}%"; } From 7ac7c912f70479d0b91df5d723da75e6a0ec2a1b Mon Sep 17 00:00:00 2001 From: Ionite Date: Wed, 7 Jun 2023 03:46:34 -0400 Subject: [PATCH 3/3] Remove extra report --- StabilityMatrix/Helper/PrerequisiteHelper.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/StabilityMatrix/Helper/PrerequisiteHelper.cs b/StabilityMatrix/Helper/PrerequisiteHelper.cs index 50c80832..aceb6065 100644 --- a/StabilityMatrix/Helper/PrerequisiteHelper.cs +++ b/StabilityMatrix/Helper/PrerequisiteHelper.cs @@ -65,7 +65,6 @@ public class PrerequisiteHelper : IPrerequisiteHelper private async Task UnzipGit(IProgress? progress = null) { - progress?.Report(new ProgressReport(-1, isIndeterminate: true, message: "")); if (progress == null) { await ArchiveHelper.Extract7Z(PortableGitDownloadPath, PortableGitInstallDir);