Skip to content

Commit

Permalink
Display modes persistence
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
hallem committed Sep 14, 2024
1 parent 7bdcf09 commit 1e925a2
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/models/Settings/CoreSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/partials/Program.DisplayModes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private static void EnableDisplayModes(List<string> coreIdentifiers = null, stri

Console.WriteLine("Updating " + core);
ServiceHelper.CoresService.AddDisplayModes(core, displayModes, isCurated);
ServiceHelper.SettingsService.Save();
}
catch (Exception e)
{
Expand Down
7 changes: 4 additions & 3 deletions src/partials/Program.Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 13 additions & 1 deletion src/services/CoresService.Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.IO.Compression;
using Pannella.Helpers;
using Pannella.Models.Analogue.Shared;
using Pannella.Models.Extras;
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion src/services/CoresService.Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<string, Video> output = new Dictionary<string, Video> { { "video", video } };
Expand Down
9 changes: 5 additions & 4 deletions src/services/CoresService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public Core GetInstalledCore(string identifier)

public void RefreshInstalledCores()
{
installedCores ??= new List<Core>();
coresNotInstalled ??= new List<Core>();
installedCoresWithSponsors ??= new List<Core>();
installedCores = new List<Core>();
coresNotInstalled = new List<Core>();
installedCoresWithSponsors = new List<Core>();

foreach (var core in cores)
{
Expand Down Expand Up @@ -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);
Expand All @@ -160,6 +160,7 @@ public bool Install(Core core, bool clean = false)
if (clean)
{
this.settingsService.DisableDisplayModes(core.identifier);
this.settingsService.Save();
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions src/services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Core> GetMissingCores() => this.missingCores;

public void EnableMissingCores()
Expand Down

0 comments on commit 1e925a2

Please sign in to comment.