From 24feede2c773251b9afa9869608c0ceba2526e1e Mon Sep 17 00:00:00 2001 From: rfuzzo Date: Tue, 15 Nov 2022 15:21:41 +0100 Subject: [PATCH] feat: prompt user when removing managed packages --- .../Services/LibraryService.cs | 2 +- .../ViewModel/PackageViewModel.cs | 49 ++++++++++++++++--- .../ViewModel/RemotePackageViewModel.cs | 4 +- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Wolvenkit.Installer/Services/LibraryService.cs b/Wolvenkit.Installer/Services/LibraryService.cs index a15942d..5d5646b 100644 --- a/Wolvenkit.Installer/Services/LibraryService.cs +++ b/Wolvenkit.Installer/Services/LibraryService.cs @@ -402,7 +402,7 @@ public async Task InstallAsync(RemotePackageModel package, string installP InstalledPackages.Add(new(installedPackage, EPackageStatus.Installed, package.ImagePath)); // add start menu shortcut - AddShortcut(installedPackage, package); + // AddShortcut(installedPackage, package); // save await SaveAsync(); diff --git a/Wolvenkit.Installer/ViewModel/PackageViewModel.cs b/Wolvenkit.Installer/ViewModel/PackageViewModel.cs index d85eeea..70784df 100644 --- a/Wolvenkit.Installer/ViewModel/PackageViewModel.cs +++ b/Wolvenkit.Installer/ViewModel/PackageViewModel.cs @@ -1,9 +1,11 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; using System.IO; using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; +using Microsoft.UI.Xaml.Controls; using Wolvenkit.Installer.Models; using Wolvenkit.Installer.Services; @@ -112,14 +114,43 @@ private async Task Uninstall() if (Directory.Exists(_model.Path)) { - try + // managed packages need confirmation + if (_model.Files is null || _model.Files.Length == 0) { - Directory.Delete(_model.Path, true); - await _libraryService.RemoveAsync(_model); + var noWifiDialog = new ContentDialog() + { + XamlRoot = App.MainRoot.XamlRoot, + Title = "Remove", + Content = $"Are you sure you want to delete this folder? Path: {_model.Path}", + PrimaryButtonText = "Yes", + CloseButtonText = "Cancel" + }; + + var r = await noWifiDialog.ShowAsync(); + if (r == ContentDialogResult.Primary) + { + try + { + Directory.Delete(_model.Path, true); + await _libraryService.RemoveAsync(_model); + } + catch (System.Exception) + { + // todo logging + } + } } - catch (System.Exception) + else { - // todo logging + try + { + Directory.Delete(_model.Path, true); + await _libraryService.RemoveAsync(_model); + } + catch (System.Exception) + { + // todo logging + } } } @@ -141,6 +172,12 @@ private async Task Update() try { Directory.Delete(_model.Path, true); + //foreach (var f in _model.Files) + //{ + // File.Delete(f); + //} + + isuninstalled = await _libraryService.RemoveAsync(_model); } catch (System.Exception) diff --git a/Wolvenkit.Installer/ViewModel/RemotePackageViewModel.cs b/Wolvenkit.Installer/ViewModel/RemotePackageViewModel.cs index b66208c..1f07dec 100644 --- a/Wolvenkit.Installer/ViewModel/RemotePackageViewModel.cs +++ b/Wolvenkit.Installer/ViewModel/RemotePackageViewModel.cs @@ -6,7 +6,6 @@ using CommunityToolkit.Mvvm.Input; using Microsoft.Extensions.DependencyInjection; using Wolvenkit.Installer.Models; -using Wolvenkit.Installer.Pages; using Wolvenkit.Installer.Services; namespace Wolvenkit.Installer.ViewModel; @@ -85,7 +84,8 @@ private async Task PickFolder() } } - private bool CanInstall() => !Directory.Exists(InstallPath) || (Directory.Exists(InstallPath) && !Directory.GetFiles(InstallPath).Any()); + // Can only install into an empty folder + private bool CanInstall() => !Directory.Exists(InstallPath) || (Directory.Exists(InstallPath) && !Directory.GetFiles(InstallPath).Any() && !Directory.GetDirectories(InstallPath).Any()); public RemotePackageModel GetModel() => _model; }