Skip to content

Commit

Permalink
Added menu support for un/re/install of cores (mattpannella#238)
Browse files Browse the repository at this point in the history
* Added menu support for un/re/install of cores

- Added menu item for uninstalling one or more of the installed cores
- Added menu item for reinstalling one or more of the installed cores
- Added a .DotSettings file to ignore some warnings
- Little bit of cleanup on Program.cs

* Converted Main Menu string array into Enum

Using the enum makes it a lot easier to change the order of the menu items and and/remove menu items.

* Reorganized the menus & added missing await
  • Loading branch information
hallem authored Feb 8, 2024
1 parent 99e0405 commit 29173db
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 121 deletions.
7 changes: 7 additions & 0 deletions pupdate.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cpartials/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
86 changes: 56 additions & 30 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,9 @@ private static async Task Main(string[] args)
backupSaves_Path = o.BackupPath;
backupSaves_SaveConfig = o.Save;
})
.WithNotParsed(o =>
.WithNotParsed(_ =>
{
if (o.IsHelp())
{
Environment.Exit(1);
}

if (o.IsVersion())
{
Environment.Exit(1);
}
Environment.Exit(1);
});

#endregion
Expand Down Expand Up @@ -257,7 +249,8 @@ private static async Task Main(string[] args)
coreUpdater.StatusUpdated += coreUpdater_StatusUpdated;
coreUpdater.UpdateProcessComplete += coreUpdater_UpdateProcessComplete;
coreUpdater.DownloadAssets(GlobalHelper.SettingsManager.GetConfig().download_assets);
coreUpdater.BackupSaves(GlobalHelper.SettingsManager.GetConfig().backup_saves, GlobalHelper.SettingsManager.GetConfig().backup_saves_location);
coreUpdater.BackupSaves(GlobalHelper.SettingsManager.GetConfig().backup_saves,
GlobalHelper.SettingsManager.GetConfig().backup_saves_location);

// If we have any missing cores, handle them.
if (GlobalHelper.SettingsManager.GetMissingCores().Any())
Expand Down Expand Up @@ -381,66 +374,99 @@ private static async Task Main(string[] args)

while (flag)
{
int choice = DisplayMenuNew();
MainMenuItems choice = DisplayMenuNew();

switch (choice)
{
case 1:
case MainMenuItems.UpdateFirmware:
await coreUpdater.UpdateFirmware();
Pause();
break;

case 2:
case MainMenuItems.DownloadRequiredAssets:
Console.WriteLine("Checking for required files...");
await coreUpdater.RunAssetDownloader();
Pause();
break;

case 3:
case MainMenuItems.SelectCores:
List<Core> cores = await CoresService.GetCores();
AskAboutNewCores(true);
RunCoreSelector(cores);
// Is reloading the settings file necessary?
GlobalHelper.ReloadSettings();
break;

case 4:
case MainMenuItems.DownloadPlatformImagePacks:
await ImagePackSelector(path);
break;

case 5:
case MainMenuItems.GenerateInstanceJsonFiles:
RunInstanceGenerator(coreUpdater);
Pause();
break;

case 6:
case MainMenuItems.GenerateGameAndWatchRoms:
await BuildGameAndWatchRoms(path);
Pause();
break;

case 7:
case MainMenuItems.EnableAllDisplayModes:
coreUpdater.ForceDisplayModes();
Pause();
break;

case 8:
case MainMenuItems.BackupSavesDirectory:
AssetsService.BackupSaves(path, GlobalHelper.SettingsManager.GetConfig().backup_saves_location);
Pause();
break;

case 9:
case MainMenuItems.ReinstallCores:
{
var results = ShowCoresMenu(
GlobalHelper.InstalledCores,
"Which cores would you like to reinstall?",
false);

foreach (var item in results.Where(x => x.Value))
{
await coreUpdater.RunUpdates(item.Key, true);
}

break;
}

case MainMenuItems.UninstallCores:
{
var results = ShowCoresMenu(
GlobalHelper.InstalledCores,
"Which cores would you like to uninstall?",
false);

nuke = AskAboutCoreSpecificAssets();

foreach (var item in results.Where(x => x.Value))
{
coreUpdater.DeleteCore(GlobalHelper.GetCore(item.Key), true, nuke);
}

break;
}

case MainMenuItems.Settings:
SettingsMenu();

coreUpdater.DeleteSkippedCores(GlobalHelper.SettingsManager.GetConfig().delete_skipped_cores);
coreUpdater.DownloadFirmware(GlobalHelper.SettingsManager.GetConfig().download_firmware);
coreUpdater.DownloadAssets(GlobalHelper.SettingsManager.GetConfig().download_assets);
coreUpdater.RenameJotegoCores(GlobalHelper.SettingsManager.GetConfig().fix_jt_names);
coreUpdater.BackupSaves(GlobalHelper.SettingsManager.GetConfig().backup_saves, GlobalHelper.SettingsManager.GetConfig().backup_saves_location);
coreUpdater.BackupSaves(GlobalHelper.SettingsManager.GetConfig().backup_saves,
GlobalHelper.SettingsManager.GetConfig().backup_saves_location);
// Is reloading the settings file necessary?
GlobalHelper.ReloadSettings();
break;

case 10:
case MainMenuItems.Exit:
flag = false;
break;

Expand All @@ -466,7 +492,7 @@ private static void coreUpdater_StatusUpdated(object sender, StatusUpdatedEventA
Console.WriteLine(e.Message);
}

static void coreUpdater_UpdateProcessComplete(object sender, UpdateProcessCompleteEventArgs e)
private static void coreUpdater_UpdateProcessComplete(object sender, UpdateProcessCompleteEventArgs e)
{
Console.WriteLine("-------------");
Console.WriteLine(e.Message);
Expand All @@ -477,10 +503,10 @@ static void coreUpdater_UpdateProcessComplete(object sender, UpdateProcessComple

foreach (Dictionary<string, string> core in e.InstalledCores)
{
Console.WriteLine(core["core"] + " " + core["version"]);
Console.WriteLine($"{core["core"]} {core["version"]}");
}

Console.WriteLine("");
Console.WriteLine();
}

if (e.InstalledAssets.Count > 0)
Expand All @@ -503,14 +529,14 @@ static void coreUpdater_UpdateProcessComplete(object sender, UpdateProcessComple
Console.WriteLine(asset);
}

Console.WriteLine("");
Console.WriteLine();
}

if (e.FirmwareUpdated != "")
if (e.FirmwareUpdated != string.Empty)
{
Console.WriteLine("New Firmware was downloaded. Restart your Pocket to install");
Console.WriteLine(e.FirmwareUpdated);
Console.WriteLine("");
Console.WriteLine();
}

if (e.MissingBetaKeys.Count > 0)
Expand All @@ -521,7 +547,7 @@ static void coreUpdater_UpdateProcessComplete(object sender, UpdateProcessComple
Console.WriteLine(core);
}

Console.WriteLine("");
Console.WriteLine();
}

Console.WriteLine(GetRandomSponsorLinks());
Expand Down
Loading

0 comments on commit 29173db

Please sign in to comment.