diff --git a/TwilightBoxart.CLI/Program.cs b/TwilightBoxart.CLI/Program.cs index fe44735..75541e4 100644 --- a/TwilightBoxart.CLI/Program.cs +++ b/TwilightBoxart.CLI/Program.cs @@ -73,7 +73,7 @@ static void Main(string[] args) config.SdRoot = choice; } - var boxArtPath = config.GetBoxartPath(); + var boxArtPath = config.GetCorrectBoxartPath(); ConsoleEx.WriteGreenLine("Loaded settings:"); Console.WriteLine("SDRoot / Roms location: \t" + config.SdRoot); Console.WriteLine("BoxArt location: \t\t" + boxArtPath); @@ -87,6 +87,8 @@ static void Main(string[] args) var progress = new Progress(Console.WriteLine); var crawler = new BoxartCrawler(progress); + config.BoxartPath = boxArtPath; + config.SettingsPath = config.GetCorrectSettingsIniPath(); crawler.DownloadArt(config).Wait(); } } diff --git a/TwilightBoxart.CLI/TwilightBoxart.ini b/TwilightBoxart.CLI/TwilightBoxart.ini index 92b8c79..8086a6a 100644 --- a/TwilightBoxart.CLI/TwilightBoxart.ini +++ b/TwilightBoxart.CLI/TwilightBoxart.ini @@ -2,7 +2,9 @@ [Config] SdRoot= BoxartPath={sdroot}/_nds/TWiLightMenu/boxart -; Large for NDS = 256 x 192 +SettingsPath={sdroot}/_nds/TWiLightMenu/settings.ini + +; Large for NDS = 208 x 143 BoxartWidth=128 BoxartHeight=115 KeepAspectRatio=true diff --git a/TwilightBoxart.UX/MainForm.Designer.cs b/TwilightBoxart.UX/MainForm.Designer.cs index a5801c7..c336104 100644 --- a/TwilightBoxart.UX/MainForm.Designer.cs +++ b/TwilightBoxart.UX/MainForm.Designer.cs @@ -271,11 +271,10 @@ private void InitializeComponent() this.rbtFullscreen.Location = new System.Drawing.Point(346, 33); this.rbtFullscreen.Margin = new System.Windows.Forms.Padding(6); this.rbtFullscreen.Name = "rbtFullscreen"; - this.rbtFullscreen.Size = new System.Drawing.Size(143, 29); + this.rbtFullscreen.Size = new System.Drawing.Size(69, 29); this.rbtFullscreen.TabIndex = 9; - this.rbtFullscreen.Text = "Fullscreen"; + this.rbtFullscreen.Text = "XL"; this.rbtFullscreen.UseVisualStyleBackColor = true; - this.rbtFullscreen.Visible = false; this.rbtFullscreen.CheckedChanged += new System.EventHandler(this.rbtFullscreen_CheckedChanged); // // rbtCustom @@ -296,11 +295,10 @@ private void InitializeComponent() this.rbtLarge.Location = new System.Drawing.Point(182, 33); this.rbtLarge.Margin = new System.Windows.Forms.Padding(6); this.rbtLarge.Name = "rbtLarge"; - this.rbtLarge.Size = new System.Drawing.Size(98, 29); + this.rbtLarge.Size = new System.Drawing.Size(105, 29); this.rbtLarge.TabIndex = 8; - this.rbtLarge.Text = "Large"; + this.rbtLarge.Text = "Larger"; this.rbtLarge.UseVisualStyleBackColor = true; - this.rbtLarge.Visible = false; this.rbtLarge.CheckedChanged += new System.EventHandler(this.rbtLarge_CheckedChanged); // // rbtDefault diff --git a/TwilightBoxart.UX/MainForm.cs b/TwilightBoxart.UX/MainForm.cs index 719442f..4dc3d18 100644 --- a/TwilightBoxart.UX/MainForm.cs +++ b/TwilightBoxart.UX/MainForm.cs @@ -67,7 +67,7 @@ private void SetUx() if (!chkManualBoxartLocation.Checked && !string.IsNullOrEmpty(txtSdRoot.Text)) { - txtBoxart.Text = _config.GetBoxartPath(txtSdRoot.Text); + txtBoxart.Text = _config.GetCorrectBoxartPath(txtSdRoot.Text); } txtBoxart.ReadOnly = !chkManualBoxartLocation.Checked; @@ -171,6 +171,7 @@ private void Go() { SdRoot = txtSdRoot.Text, BoxartPath = txtBoxart.Text, + SettingsPath = _config.GetCorrectSettingsIniPath(txtSdRoot.Text), BoxartWidth = (int) numWidth.Value, BoxartHeight = (int) numHeight.Value, KeepAspectRatio = chkKeepAspectRatio.Checked, @@ -229,8 +230,9 @@ private void rbtCustom_CheckedChanged(object sender, EventArgs e) private void rbtLarge_CheckedChanged(object sender, EventArgs e) { - numWidth.Value = 210; // 200 - numHeight.Value = 146; // 180 + + numWidth.Value = 168; + numHeight.Value = 130; SetUx(); } @@ -243,8 +245,8 @@ private void rbtDefault_CheckedChanged(object sender, EventArgs e) private void rbtFullscreen_CheckedChanged(object sender, EventArgs e) { - numWidth.Value = 256; - numHeight.Value = 192; + numWidth.Value = 208; + numHeight.Value = 143; SetUx(); } diff --git a/TwilightBoxart/BoxartConfig.cs b/TwilightBoxart/BoxartConfig.cs index 1242856..cf76222 100644 --- a/TwilightBoxart/BoxartConfig.cs +++ b/TwilightBoxart/BoxartConfig.cs @@ -19,6 +19,7 @@ public interface IAppConfig : ISharedConfig { string SdRoot { get; set; } string BoxartPath { get; set; } + string SettingsPath { get; set; } bool OverwriteExisting { get; set; } } @@ -26,6 +27,7 @@ public class BoxartConfig : IniSettings, IAppConfig { public string SdRoot { get; set; } = ""; public string BoxartPath { get; set; } = @"{sdroot}\_nds\TWiLightMenu\boxart"; + public string SettingsPath { get; set; } = @"{sdroot}\_nds\TWiLightMenu\settings.ini"; public int BoxartWidth { get; set; } = 128; public int BoxartHeight { get; set; } = 115; public bool KeepAspectRatio { get; set; } = true; @@ -34,7 +36,6 @@ public class BoxartConfig : IniSettings, IAppConfig public int BoxartBorderThickness { get; set; } public uint BoxartBorderColor { get; set; } public bool DisableUpdates { get; set; } = false; - public const string MagicDir = "_nds"; public const string FileName = "TwilightBoxart.ini"; public const string Repository = "KirovAir/TwilightBoxart"; @@ -51,16 +52,26 @@ public void Load() Load(FileName); } - public string GetBoxartPath(string root = "") + public string GetCorrectBoxartPath(string root = "") + { + return GetCorrectPath(BoxartPath, root); + } + + public string GetCorrectSettingsIniPath(string root = "") + { + return GetCorrectPath(SettingsPath, root); + } + + public string GetCorrectPath(string pathMask, string root = "") { if (root == "") { root = SdRoot; } - if (!BoxartPath.StartsWith("{sdroot}")) + if (!pathMask.StartsWith("{sdroot}")) { - return BoxartPath; + return pathMask; } if (root.Contains(Path.DirectorySeparatorChar.ToString())) @@ -90,9 +101,9 @@ public string GetBoxartPath(string root = "") catch { } } - return Path.Combine(root.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, BoxartPath.Replace("{sdroot}", "").TrimStart(Path.DirectorySeparatorChar)); + return Path.Combine(root.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, pathMask.Replace("{sdroot}", "").TrimStart(Path.DirectorySeparatorChar)); } - + public static readonly List SupportedFiles = new List { ".nes", diff --git a/TwilightBoxart/BoxartCrawler.cs b/TwilightBoxart/BoxartCrawler.cs index c895bfe..a5a13ec 100644 --- a/TwilightBoxart/BoxartCrawler.cs +++ b/TwilightBoxart/BoxartCrawler.cs @@ -19,6 +19,8 @@ public class BoxartCrawler }; private readonly HttpClient _httpClient; + private const long MaxCacheSizeForTwilight = 43000; + public BoxartCrawler(IProgress progress = null) { _httpClient = new HttpClient(_handler); @@ -38,6 +40,7 @@ public async Task DownloadArt(IAppConfig downloadConfig) return; } + long maxLength = 0; foreach (var romFile in Directory.EnumerateFiles(downloadConfig.SdRoot, "*.*", SearchOption.AllDirectories)) { if (_cancelToken.IsCancellationRequested) @@ -92,6 +95,10 @@ public async Task DownloadArt(IAppConfig downloadConfig) using (var fs = new FileStream(targetArtFile, FileMode.Create)) { await result.Content.CopyToAsync(fs); + if (fs.Length > maxLength) + { + maxLength = fs.Length; + } } _progress?.Report("Got it!"); @@ -108,6 +115,18 @@ public async Task DownloadArt(IAppConfig downloadConfig) } } + if (maxLength >= MaxCacheSizeForTwilight) + { + try + { + FixTwilightSettings(downloadConfig.SettingsPath); + } + catch (Exception e) + { + _progress.Report($"Error while fixing TwilightMenu++ settings: {e}"); + } + } + _progress?.Report("Finished scan."); } catch (Exception e) @@ -116,6 +135,19 @@ public async Task DownloadArt(IAppConfig downloadConfig) } } + private void FixTwilightSettings(string path) + { + if (!File.Exists(path)) return; + + var settings = File.ReadAllText(path); + if (!settings.Contains("CACHE_BOX_ART = 1")) return; + + _progress?.Report("Detected large boxart size in output files. Disabling boxart cache in TwilightMenu++ settings so these will be displayed correctly."); + + settings = settings.Replace("CACHE_BOX_ART = 1", "CACHE_BOX_ART = 0"); + File.WriteAllText(path, settings); + } + public void Stop() { _cancelToken?.Cancel();