Skip to content

Commit

Permalink
force full re-installs and new dedicate uninstall function (#225)
Browse files Browse the repository at this point in the history
* new delete option

* option for clean installs

* readme
  • Loading branch information
mattpannella authored Jan 27, 2024
1 parent 9775409 commit 4e81825
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/announce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
-d '{
"username": "mattpannella",
"avatar_url": "https://avatars.githubusercontent.com/u/4806679",
"content": "Pupdate Release",
"content": "Bark bark, motherfuckers. A new version of Pupdate is available.",
"embeds": [{
"color": 4819409,
"title": "${{ github.event.release.name }}",
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ Checks for missing required assets for each core you have selected (mainly arcad
-p, --path Absolute path to install location
-c, --core The core you want to update. Runs for all otherwise
-f, --platformsfolder Preserve the Platforms folder, so customizations aren't overwritten by updates.
-r, --clean Clean install. Remove all existing core files, and force a fresh re-install
uninstall Delete a core
-p, --path Absolute path to install location
-c, --core The core you want to uninstall. Required
-a, --assets Delete the core specific Assets folder. ex: Assets/{platform}/{corename}
assets Run the asset downloader
-p, --path Absolute path to install location
Expand Down
2 changes: 1 addition & 1 deletion pupdate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>3.0.0</Version>
<Version>3.1.0</Version>
<Description>Keep your Analogue Pocket up to date</Description>
<Copyright>2023 Matt Pannella</Copyright>
<Authors>Matt Pannella</Authors>
Expand Down
45 changes: 43 additions & 2 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ private static async Task Main(string[] args)
string? imagePackVariant = null;
bool downloadFirmware = false;
bool selfUpdate = false;
bool nuke = false;
bool cleanInstall = false;

ConsoleKey response;

string verb = "menu";
Dictionary<string, object?> data = new Dictionary<string, object?>();
Parser.Default.ParseArguments<MenuOptions, FundOptions, UpdateOptions,
AssetsOptions, FirmwareOptions, ImagesOptions, InstancegeneratorOptions, UpdateSelfOptions>(args)
AssetsOptions, FirmwareOptions, ImagesOptions, InstancegeneratorOptions, UpdateSelfOptions, UninstallOptions>(args)
.WithParsed<UpdateSelfOptions>(o => {
selfUpdate = true;
})
Expand All @@ -63,11 +65,27 @@ private static async Task Main(string[] args)
if(o.PreservePlatformsFolder) {
preservePlatformsFolder = true;
}
if(o.CleanInstall) {
cleanInstall = true;
}
if(o.CoreName != null && o.CoreName != "") {
coreName = o.CoreName;
}
}
)
.WithParsed<UninstallOptions>(async o =>
{
verb = "uninstall";
cliMode = true;
coreName = o.CoreName;
if(o.InstallPath != null && o.InstallPath != "") {
path = o.InstallPath;
}
if(o.DeleteAssets) {
nuke = true;
}
}
)
.WithParsed<AssetsOptions>(async o =>
{
verb = "assets";
Expand Down Expand Up @@ -238,7 +256,7 @@ private static async Task Main(string[] args)
}
if(forceUpdate) {
Console.WriteLine("Starting update process...");
await updater.RunUpdates(coreName);
await updater.RunUpdates(coreName, cleanInstall);
Pause();
} else if(downloadFirmware) {
await updater.UpdateFirmware();
Expand All @@ -257,6 +275,12 @@ private static async Task Main(string[] args)
variant = imagePackVariant
};
await InstallImagePack(path, pack);
} else if (verb == "uninstall") {
if (GlobalHelper.Instance.GetCore(coreName) == null) {
Console.WriteLine("Unknown core");
} else {
await updater.DeleteCore(GlobalHelper.Instance.GetCore(coreName), true, nuke);
}
} else {
bool flag = true;
while(flag) {
Expand Down Expand Up @@ -1011,6 +1035,23 @@ public class UpdateOptions

[Option('f', "platformsfolder", Required = false, HelpText = "Preserve the Platforms folder, so customizations aren't overwritten by updates.")]
public bool PreservePlatformsFolder { get; set; }

[Option('r', "clean", Required = false, HelpText = "Clean install. Remove all existing core files, before updating")]
public bool CleanInstall { get; set; }

}

[Verb("uninstall", HelpText = "Delete a core")]
public class UninstallOptions
{
[Option('p', "path", HelpText = "Absolute path to install location", Required = false)]
public string? InstallPath { get; set; }

[Option ('c', "core", Required = true, HelpText = "The core you want to delete.")]
public string CoreName { get; set; }

[Option('a', "assets", Required = false, HelpText = "Delete the core specific Assets folder")]
public bool DeleteAssets { get; set; }
}

[Verb("assets", HelpText = "Run the asset downloader")]
Expand Down
14 changes: 7 additions & 7 deletions src/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public async Task BuildInstanceJSON(bool overwrite = false, string? corename = n
/// <summary>
/// Run the full openFPGA core download and update process
/// </summary>
public async Task RunUpdates(string? id = null)
public async Task RunUpdates(string? id = null, bool clean = false)
{
List<Dictionary<string, string>> installed = new List<Dictionary<string, string>>();
List<string> installedAssets = new List<string>();
Expand Down Expand Up @@ -228,7 +228,7 @@ public async Task RunUpdates(string? id = null)
core.buildInstances = (Factory.GetGlobals().SettingsManager.GetConfig().build_instance_jsons && (id==null));
try {
if(Factory.GetGlobals().SettingsManager.GetCoreSettings(core.identifier).skip) {
_DeleteCore(core);
await DeleteCore(core);
continue;
}

Expand Down Expand Up @@ -270,7 +270,7 @@ public async Task RunUpdates(string? id = null)
_writeMessage("local core found: " + localVersion);
}

if (mostRecentRelease != localVersion){
if (mostRecentRelease != localVersion || clean){
_writeMessage("Updating core");
} else {
await CopyBetaKey(core);
Expand All @@ -289,7 +289,7 @@ public async Task RunUpdates(string? id = null)
_writeMessage("Downloading core");
}

if(await core.Install(_githubApiKey)) {
if(await core.Install(clean)) {
Dictionary<string, string> summary = new Dictionary<string, string>();
summary.Add("version", mostRecentRelease);
summary.Add("core", core.identifier);
Expand Down Expand Up @@ -545,13 +545,13 @@ public void DeleteSkippedCores(bool value)
_deleteSkippedCores = value;
}

private void _DeleteCore(Core core)
public async Task DeleteCore(Core core, bool force = false, bool nuke = false)
{
if(!_deleteSkippedCores) {
if(!_deleteSkippedCores || !force) {
return;
}

core.Uninstall();
core.Uninstall(nuke);
}

private void updater_StatusUpdated(object sender, StatusUpdatedEventArgs e)
Expand Down
32 changes: 27 additions & 5 deletions src/models/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ public override string ToString()
return platform.name;
}

public async Task<bool> Install(string githubApiKey = "")
public async Task<bool> Install(bool clean = false)
{
if(this.repository == null) {
_writeMessage("Core installed manually. Skipping.");
return false;
}
if (clean && this.isInstalled()) {
Delete();
}
//iterate through assets to find the zip release
return await _installGithubAsset();
}
Expand Down Expand Up @@ -95,19 +98,38 @@ private bool checkUpdateDirectory()
return true;
}

public void Uninstall()
public void Delete(bool nuke = false)
{
List<string> folders = new List<string>{"Cores", "Presets"};
List<string> folders = new List<string>{"Cores", "Presets", "Settings"};
foreach(string folder in folders) {
string path = Path.Combine(Factory.GetGlobals().UpdateDirectory, folder, this.identifier);
if(Directory.Exists(path)) {
_writeMessage("Uninstalling " + path);
_writeMessage("Deleting " + path);
Directory.Delete(path, true);
}
}
if(nuke) {
string path = Path.Combine(Factory.GetGlobals().UpdateDirectory, "Assets", this.platform_id, this.identifier);
if (Directory.Exists(path)) {
_writeMessage("Deleting " + path);
Directory.Delete(path, true);
Divide();
}
}
}

public void Uninstall(bool nuke = false)
{
_writeMessage("Uninstalling " + this.identifier);

Delete(nuke);

Factory.GetGlobals().SettingsManager.DisableCore(this.identifier);
Factory.GetGlobals().SettingsManager.SaveSettings();

_writeMessage("Finished");
Divide();
}

public Platform? ReadPlatformFile()
{
var info = this.getConfig();
Expand Down

0 comments on commit 4e81825

Please sign in to comment.