Skip to content

Commit

Permalink
Implement app uninstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Aug 5, 2023
1 parent 1838498 commit 1f5a9ab
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/NxEditor.Launcher/Helpers/AppUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,36 @@ public static async Task Install(bool addToPath = true)
}
}

public static Task<bool> Uninstall()
{
try {
if (File.Exists(_versionFile)) {
File.Delete(_versionFile);
}

if (Directory.Exists(_path)) {
Directory.Delete(_path, true);
}

string pluginsDirectory = Path.Combine(GlobalConfig.Shared.StorageFolder, "plugins");
if (Directory.Exists(pluginsDirectory)) {
Directory.Delete(pluginsDirectory, true);
}

string logsDirectory = Path.Combine(GlobalConfig.Shared.StorageFolder, "logs");
if (Directory.Exists(logsDirectory)) {
Directory.Delete(logsDirectory, true);
}

DeleteShortcuts();
}
catch (Exception ex) {
Console.WriteLine(ex);
return Task.FromResult(false);
}

return Task.FromResult(true);
}

private static void CopyLauncher()
{
Expand All @@ -62,4 +92,11 @@ public static void CreateShortcuts()
Shortcut.Create("NX Editor Launcher", Location.Application, _launcher, "nxe");
Shortcut.Create("NX Editor", Location.Desktop, app, "nxe");
}

public static void DeleteShortcuts()
{
Shortcut.Remove("NX Editor", Location.Application);
Shortcut.Remove("NX Editor Launcher", Location.Application);
Shortcut.Remove("NX Editor", Location.Desktop);
}
}
13 changes: 11 additions & 2 deletions src/NxEditor.Launcher/ViewModels/ShellViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,18 @@ public async Task PrimaryButton()
}

[RelayCommand]
public static Task Uninstall()
public async Task Uninstall()
{
return Task.CompletedTask;
IsLoading = true;

await AppUpdater.Uninstall();

Plugins.Clear();
await ShowOnlinePlugins();

IsEditorInstalled = false;
PrimaryButtonContent = "Install NX Editor";
IsLoading = false;
}

[RelayCommand]
Expand Down

0 comments on commit 1f5a9ab

Please sign in to comment.