Skip to content

Commit

Permalink
feat: prompt user when removing managed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Nov 15, 2022
1 parent 623caeb commit 24feede
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Wolvenkit.Installer/Services/LibraryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public async Task<bool> 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();
Expand Down
49 changes: 43 additions & 6 deletions Wolvenkit.Installer/ViewModel/PackageViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
}
}
}

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Wolvenkit.Installer/ViewModel/RemotePackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 24feede

Please sign in to comment.