From 1e925a281a5cd51afd9308599356c7be4d82e461 Mon Sep 17 00:00:00 2001 From: Michael Hallett Date: Sat, 14 Sep 2024 02:27:25 -0400 Subject: [PATCH] Display modes persistence - Display modes will get saved in the core settings - Display modes will be restored after a core gets updated - Display modes will be reset on core reinstall --- src/models/Settings/CoreSettings.cs | 9 +++++++++ src/partials/Program.DisplayModes.cs | 1 + src/partials/Program.Menus.cs | 7 ++++--- src/services/CoresService.Helpers.cs | 14 +++++++++++++- src/services/CoresService.Video.cs | 15 ++++++++++++++- src/services/CoresService.cs | 9 +++++---- src/services/SettingsService.cs | 10 ++++++++++ 7 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/models/Settings/CoreSettings.cs b/src/models/Settings/CoreSettings.cs index 834b3f06..0aa41300 100644 --- a/src/models/Settings/CoreSettings.cs +++ b/src/models/Settings/CoreSettings.cs @@ -13,4 +13,13 @@ public class CoreSettings [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string pocket_extras_version { get; set; } = null; + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public bool display_modes { get; set; } + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public string original_display_modes { get; set; } = null; + + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public string selected_display_modes { get; set; } = null; } diff --git a/src/partials/Program.DisplayModes.cs b/src/partials/Program.DisplayModes.cs index 3c6df477..3668fc5a 100644 --- a/src/partials/Program.DisplayModes.cs +++ b/src/partials/Program.DisplayModes.cs @@ -24,6 +24,7 @@ private static void EnableDisplayModes(List coreIdentifiers = null, stri Console.WriteLine("Updating " + core); ServiceHelper.CoresService.AddDisplayModes(core, displayModes, isCurated); + ServiceHelper.SettingsService.Save(); } catch (Exception e) { diff --git a/src/partials/Program.Menus.cs b/src/partials/Program.Menus.cs index 0a36f582..a8508bf9 100644 --- a/src/partials/Program.Menus.cs +++ b/src/partials/Program.Menus.cs @@ -168,9 +168,10 @@ private static void DisplayMenu(CoreUpdaterService coreUpdaterService) ServiceHelper.CoresService.InstalledCores, "Which cores would you like to reinstall?", false); - var identifiers = results.Where(x => x.Value) - .Select(x => x.Key) - .ToArray(); + var identifiers = results + .Where(x => x.Value) + .Select(x => x.Key) + .ToArray(); if (identifiers.Length > 0) { diff --git a/src/services/CoresService.Helpers.cs b/src/services/CoresService.Helpers.cs index 93976df6..2a0eeb80 100644 --- a/src/services/CoresService.Helpers.cs +++ b/src/services/CoresService.Helpers.cs @@ -1,4 +1,3 @@ -using System.IO.Compression; using Pannella.Helpers; using Pannella.Models.Analogue.Shared; using Pannella.Models.Extras; @@ -99,6 +98,19 @@ private void CheckForPocketExtras(string identifier) } } + private void CheckForDisplayModes(string identifier) + { + var coreSettings = this.settingsService.GetCoreSettings(identifier); + + if (coreSettings.display_modes) + { + var displayModes = coreSettings.selected_display_modes.Split(','); + + WriteMessage("Reapplying Display Modes..."); + this.AddDisplayModes(identifier, displayModes, forceOriginal: true); + } + } + private bool CheckCrc(string filePath, ArchiveFile archiveFile) { if (!this.settingsService.GetConfig().crc_check) diff --git a/src/services/CoresService.Video.cs b/src/services/CoresService.Video.cs index c97cec2b..c35e669a 100644 --- a/src/services/CoresService.Video.cs +++ b/src/services/CoresService.Video.cs @@ -24,7 +24,7 @@ public void ChangeAspectRatio(string identifier, int fromWidth, int fromHeight, File.WriteAllText(Path.Combine(this.installPath, "Cores", identifier, "video.json"), json); } - public void AddDisplayModes(string identifier, string[] displayModes = null, bool isCurated = false) + public void AddDisplayModes(string identifier, string[] displayModes = null, bool isCurated = false, bool forceOriginal = false) { var info = this.ReadCoreJson(identifier); var video = this.ReadVideoJson(identifier); @@ -76,6 +76,19 @@ public void AddDisplayModes(string identifier, string[] displayModes = null, boo toAdd = displayModes.Select(id => new DisplayMode { id = id }).ToList(); } + var settings = this.settingsService.GetCoreSettings(identifier); + + if (!settings.display_modes || forceOriginal) + { + // if this is the first time custom display modes are being applied, save the original ones + settings.original_display_modes = video.display_modes is { Count: > 0 } + ? string.Join(',', video.display_modes.Select(d => d.id)) + : string.Empty; + } + + settings.display_modes = true; + settings.selected_display_modes = string.Join(',', toAdd.Select(d => d.id)); + video.display_modes = toAdd; Dictionary output = new Dictionary { { "video", video } }; diff --git a/src/services/CoresService.cs b/src/services/CoresService.cs index a6f91a58..ad919297 100644 --- a/src/services/CoresService.cs +++ b/src/services/CoresService.cs @@ -110,9 +110,9 @@ public Core GetInstalledCore(string identifier) public void RefreshInstalledCores() { - installedCores ??= new List(); - coresNotInstalled ??= new List(); - installedCoresWithSponsors ??= new List(); + installedCores = new List(); + coresNotInstalled = new List(); + installedCoresWithSponsors = new List(); foreach (var core in cores) { @@ -151,7 +151,7 @@ public bool Install(Core core, bool clean = false) { this.ReplaceCheck(core.identifier); - // not resetting the pocket extras on a clean install (a.k.a resinstall) + // not resetting the pocket extras on a clean install (a.k.a reinstall) // the combination cores and variant cores aren't affected // the additional assets extras just add roms so they're not affected either this.CheckForPocketExtras(core.identifier); @@ -160,6 +160,7 @@ public bool Install(Core core, bool clean = false) if (clean) { this.settingsService.DisableDisplayModes(core.identifier); + this.settingsService.Save(); } else { diff --git a/src/services/SettingsService.cs b/src/services/SettingsService.cs index 85902c7b..a92cf019 100644 --- a/src/services/SettingsService.cs +++ b/src/services/SettingsService.cs @@ -116,6 +116,16 @@ public void DisablePocketExtras(string name) } } + public void DisableDisplayModes(string name) + { + if (settings.core_settings.TryGetValue(name, out CoreSettings value)) + { + value.display_modes = false; + value.original_display_modes = null; + value.selected_display_modes = null; + } + } + public List GetMissingCores() => this.missingCores; public void EnableMissingCores()