From 8189d25a56a4a4c4e11d321603fecaaf62e69e50 Mon Sep 17 00:00:00 2001 From: rfuzzo Date: Wed, 16 Nov 2022 10:42:11 +0100 Subject: [PATCH] fix: fixed a bug where the installer would not detect existing app paths --- .../Package.appxmanifest | 2 +- Wolvenkit.Installer/ItemTemplates.xaml | 3 +- .../Services/INotificationService.cs | 10 ++ .../Services/LibraryService.cs | 5 +- .../ViewModel/PackageViewModel.cs | 93 ++++++++++++------- 5 files changed, 74 insertions(+), 39 deletions(-) diff --git a/Wolvenkit.Installer.Package/Package.appxmanifest b/Wolvenkit.Installer.Package/Package.appxmanifest index 1efd144..9aff2b0 100644 --- a/Wolvenkit.Installer.Package/Package.appxmanifest +++ b/Wolvenkit.Installer.Package/Package.appxmanifest @@ -9,7 +9,7 @@ + Version="0.1.3.0" /> WolvenKit.Installer diff --git a/Wolvenkit.Installer/ItemTemplates.xaml b/Wolvenkit.Installer/ItemTemplates.xaml index eba80da..5b1edbb 100644 --- a/Wolvenkit.Installer/ItemTemplates.xaml +++ b/Wolvenkit.Installer/ItemTemplates.xaml @@ -68,7 +68,6 @@ --> - + diff --git a/Wolvenkit.Installer/Services/INotificationService.cs b/Wolvenkit.Installer/Services/INotificationService.cs index 23bb796..76d97f8 100644 --- a/Wolvenkit.Installer/Services/INotificationService.cs +++ b/Wolvenkit.Installer/Services/INotificationService.cs @@ -9,6 +9,7 @@ public interface INotificationService void CloseBanner(); void DisplayBanner(string title, string message, InfoBarSeverity severity); + void DisplayError(string message); void StartIndeterminate(); @@ -50,6 +51,15 @@ public void DisplayBanner(string title, string message, InfoBarSeverity severity BannerNotification.Title = title; } + public void DisplayError(string message) + { + BannerNotification.IsOpen = true; + + BannerNotification.Message = message; + BannerNotification.Severity = InfoBarSeverity.Error; + BannerNotification.Title = "Error"; + } + public void CloseBanner() => BannerNotification.IsOpen = false; public void StartIndeterminate() => Progress.IsIndeterminate = true; diff --git a/Wolvenkit.Installer/Services/LibraryService.cs b/Wolvenkit.Installer/Services/LibraryService.cs index 5d5646b..7c5d263 100644 --- a/Wolvenkit.Installer/Services/LibraryService.cs +++ b/Wolvenkit.Installer/Services/LibraryService.cs @@ -28,7 +28,7 @@ public interface ILibraryService Task GetLatestVersionAsync(RemotePackageModel model, bool prerelease); Task InstallAsync(RemotePackageModel id, string installPath); - Task InstallAsync(PackageModel id); + Task InstallAsync(PackageModel id, string installPath); Task InitAsync(); Task SaveAsync(); Task RemoveAsync(PackageModel model); @@ -294,7 +294,8 @@ public async Task RemoveAsync(PackageModel model) } } - public async Task InstallAsync(PackageModel package) => TryGetRemote(package.Name, out var remote) && await InstallAsync(remote.GetModel(), remote.InstallPath); + public async Task InstallAsync(PackageModel package, string installPath) + => TryGetRemote(package.Name, out var remote) && await InstallAsync(remote.GetModel(), installPath); public async Task InstallAsync(RemotePackageModel package, string installPath) { diff --git a/Wolvenkit.Installer/ViewModel/PackageViewModel.cs b/Wolvenkit.Installer/ViewModel/PackageViewModel.cs index 70784df..a9f14c9 100644 --- a/Wolvenkit.Installer/ViewModel/PackageViewModel.cs +++ b/Wolvenkit.Installer/ViewModel/PackageViewModel.cs @@ -105,19 +105,37 @@ private void Launch() } } - [RelayCommand()] - private async Task Uninstall() + private bool IsProcessRunning() { - _notificationService.StartIndeterminate(); - _notificationService.DisplayBanner("Uninstalling", $"Uninstalling {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational); + var pname = Process.GetProcessesByName("WolvenKit"); + return pname is not null && pname.Length != 0; + } + private async Task UninstallModal() + { + var isuninstalled = false; + + if (IsProcessRunning()) + { + var dlg = new ContentDialog() + { + XamlRoot = App.MainRoot.XamlRoot, + Title = "Process running", + Content = $"Please close WolvenKit before continuing", + PrimaryButtonText = "Ok" + }; + + var r = await dlg.ShowAsync(); + + return false; + } if (Directory.Exists(_model.Path)) { // managed packages need confirmation if (_model.Files is null || _model.Files.Length == 0) { - var noWifiDialog = new ContentDialog() + var dlg = new ContentDialog() { XamlRoot = App.MainRoot.XamlRoot, Title = "Remove", @@ -126,17 +144,17 @@ private async Task Uninstall() CloseButtonText = "Cancel" }; - var r = await noWifiDialog.ShowAsync(); + var r = await dlg.ShowAsync(); if (r == ContentDialogResult.Primary) { try { Directory.Delete(_model.Path, true); - await _libraryService.RemoveAsync(_model); + isuninstalled = await _libraryService.RemoveAsync(_model); } - catch (System.Exception) + catch (System.Exception e) { - // todo logging + _notificationService.DisplayError(e.Message); } } } @@ -145,56 +163,63 @@ private async Task Uninstall() try { Directory.Delete(_model.Path, true); - await _libraryService.RemoveAsync(_model); + isuninstalled = await _libraryService.RemoveAsync(_model); } - catch (System.Exception) + catch (System.Exception e) { - // todo logging + _notificationService.DisplayError(e.Message); } } } - _notificationService.CloseBanner(); - _notificationService.StopIndeterminate(); + return isuninstalled; } [RelayCommand()] - private async Task Update() + private async Task Uninstall() { _notificationService.StartIndeterminate(); - _notificationService.DisplayBanner("Updating", $"Updating {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational); + _notificationService.DisplayBanner("Uninstalling", $"Uninstalling {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational); - var isuninstalled = false; + if (await UninstallModal()) + { + _notificationService.CloseBanner(); + } - // remove - if (Directory.Exists(_model.Path)) + _notificationService.StopIndeterminate(); + } + + [RelayCommand()] + private async Task Update() + { + if (IsProcessRunning()) { - try + var dlg = new ContentDialog() { - Directory.Delete(_model.Path, true); - //foreach (var f in _model.Files) - //{ - // File.Delete(f); - //} + XamlRoot = App.MainRoot.XamlRoot, + Title = "Process running", + Content = $"Please close WolvenKit before continuing", + PrimaryButtonText = "Ok" + }; + var r = await dlg.ShowAsync(); - isuninstalled = await _libraryService.RemoveAsync(_model); - } - catch (System.Exception) - { - // todo logging - } + return; } + _notificationService.StartIndeterminate(); + _notificationService.DisplayBanner("Updating", $"Updating {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational); + // install - if (isuninstalled) + if (await UninstallModal()) { - await _libraryService.InstallAsync(_model); + await _libraryService.InstallAsync(_model, _model.Path); IsUpdateAvailable = false; //.Height = s_expandedHeight; + + _notificationService.CloseBanner(); } - _notificationService.CloseBanner(); _notificationService.StopIndeterminate(); } }