From 2f83d4be11516fe6063bdbf8fe94ba165810fc10 Mon Sep 17 00:00:00 2001 From: Jesse Date: Wed, 25 Sep 2019 22:52:07 +0200 Subject: [PATCH] - Improved boxart folder detection. - Fixed scaling for 9.5.0+. --- TwilightBoxart.UX/MainForm.Designer.cs | 3 +- TwilightBoxart.UX/MainForm.cs | 16 +++-------- TwilightBoxart/BoxartConfig.cs | 38 +++++++++++++++++++++++-- TwilightBoxart/Helpers/ImgDownloader.cs | 7 +++++ TwilightBoxart/Models/Base/Rom.cs | 16 +++++++++++ 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/TwilightBoxart.UX/MainForm.Designer.cs b/TwilightBoxart.UX/MainForm.Designer.cs index 56238bd..311d4d7 100644 --- a/TwilightBoxart.UX/MainForm.Designer.cs +++ b/TwilightBoxart.UX/MainForm.Designer.cs @@ -72,7 +72,6 @@ private void InitializeComponent() this.txtSdRoot.Name = "txtSdRoot"; this.txtSdRoot.Size = new System.Drawing.Size(674, 31); this.txtSdRoot.TabIndex = 1; - this.txtSdRoot.TextChanged += new System.EventHandler(this.txtSdRoot_TextChanged); // // label1 // @@ -105,7 +104,6 @@ private void InitializeComponent() this.txtBoxart.ReadOnly = true; this.txtBoxart.Size = new System.Drawing.Size(674, 31); this.txtBoxart.TabIndex = 4; - this.txtBoxart.TextChanged += new System.EventHandler(this.txtBoxart_TextChanged); // // label2 // @@ -259,6 +257,7 @@ private void InitializeComponent() this.chkAspectRatio.Size = new System.Drawing.Size(318, 29); this.chkAspectRatio.TabIndex = 15; this.chkAspectRatio.Text = "Adjust to correct aspect ratio"; + this.toolTip.SetToolTip(this.chkAspectRatio, "Will resize the boxart to TwilightMenu++ compatible aspect ratio\'s"); this.chkAspectRatio.UseVisualStyleBackColor = true; // // MainForm diff --git a/TwilightBoxart.UX/MainForm.cs b/TwilightBoxart.UX/MainForm.cs index 8deaa9a..e8c0b35 100644 --- a/TwilightBoxart.UX/MainForm.cs +++ b/TwilightBoxart.UX/MainForm.cs @@ -37,7 +37,7 @@ private void DetectSd() path = allDrives[0].RootDirectory.FullName; foreach (var drive in allDrives) { - if (Directory.Exists(Path.Combine(drive.RootDirectory.FullName, "_nds"))) + if (Directory.Exists(Path.Combine(drive.RootDirectory.FullName, BoxartConfig.MagicDir))) { path = drive.RootDirectory.FullName; break; @@ -71,6 +71,9 @@ private void Go() // UI STUFF private void SetUx() { + if (!_isInitialized) + return; + btnBrowseBoxart.Enabled = chkManualBoxartLocation.Checked; if (!chkManualBoxartLocation.Checked && !string.IsNullOrEmpty(txtSdRoot.Text)) @@ -113,7 +116,6 @@ private void MainForm_Load(object sender, EventArgs e) if (!string.IsNullOrEmpty(_config.SdRoot)) { txtSdRoot.Text = _config.SdRoot; - txtBoxart.Text = _config.GetBoxartPath(); } else { @@ -174,16 +176,6 @@ private void chkBoxartSize_CheckedChanged(object sender, EventArgs e) SetUx(); } - private void txtSdRoot_TextChanged(object sender, EventArgs e) - { - SetUx(); - } - - private void txtBoxart_TextChanged(object sender, EventArgs e) - { - SetUx(); - } - private void btnGithub_Click(object sender, EventArgs e) { if (MessageBox.Show(BoxartConfig.Credits + Environment.NewLine + Environment.NewLine + "Visit Github now?", "Hello", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) diff --git a/TwilightBoxart/BoxartConfig.cs b/TwilightBoxart/BoxartConfig.cs index 1d5b318..3bdcfa3 100644 --- a/TwilightBoxart/BoxartConfig.cs +++ b/TwilightBoxart/BoxartConfig.cs @@ -15,7 +15,7 @@ public class BoxartConfig : IniSettings public int BoxartHeight { get; set; } = 115; public bool AdjustAspectRatio { get; set; } = true; - + public const string MagicDir = "_nds"; public const string FileName = "TwilightBoxart.ini"; public static string Credits = "TwilightBoxart - Created by KirovAir." + Environment.NewLine + "Loads of love to the devs of TwilightMenu++, LibRetro, GameTDB and the maintainers of the No-Intro DB."; @@ -36,6 +36,33 @@ public string GetBoxartPath(string root = "") return BoxartPath; } + if (root.Contains(Path.DirectorySeparatorChar.ToString())) + { + try + { + var split = root.Split(Path.DirectorySeparatorChar); + var tmpReplace = ""; + for (var i = split.Length; i-- > 0;) + { + tmpReplace = split[i] + Path.DirectorySeparatorChar + tmpReplace; + tmpReplace = tmpReplace.TrimEnd(Path.DirectorySeparatorChar); + + // Remove where we are. + var place = root.LastIndexOf(tmpReplace); + if (place == -1) + break; + var correctRoot = root.Remove(place, tmpReplace.Length); + + if (Directory.Exists(Path.Combine(correctRoot, MagicDir))) + { + root = correctRoot; + break; + } + } + } + catch { } + } + return Path.Combine(root.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, BoxartPath.Replace("{sdroot}", "").TrimStart(Path.DirectorySeparatorChar)); } @@ -85,13 +112,18 @@ public string GetBoxartPath(string root = "") public static Dictionary AspectRatioMapping = new Dictionary { + // FDS / GBC / GB {ConsoleType.FamicomDiskSystem, new Size(1, 1)}, - + {ConsoleType.GameBoy, new Size(1, 1)}, + {ConsoleType.GameBoyColor, new Size(1, 1)}, + + // NES / GEN/MD / SFC / MS/ GG {ConsoleType.NintendoEntertainmentSystem, new Size(84, 115)}, - {ConsoleType.SegaGameGear, new Size(84, 115)}, {ConsoleType.SegaGenesis, new Size(84, 115)}, {ConsoleType.SegaMasterSystem, new Size(84, 115)}, + {ConsoleType.SegaGameGear, new Size(84, 115)}, + // SNES {ConsoleType.SuperNintendoEntertainmentSystem, new Size(158, 115)} }; } diff --git a/TwilightBoxart/Helpers/ImgDownloader.cs b/TwilightBoxart/Helpers/ImgDownloader.cs index 5841dca..e5fc2b0 100644 --- a/TwilightBoxart/Helpers/ImgDownloader.cs +++ b/TwilightBoxart/Helpers/ImgDownloader.cs @@ -31,6 +31,13 @@ public void DownloadAndResize(string url, string targetFile) public void SetSizeAdjustedToAspectRatio(Size aspectRatio) { + if (_width == aspectRatio.Width || _height == aspectRatio.Height) + { + _height = aspectRatio.Height; + _width = aspectRatio.Width; + return; + } + var sourceWidth = aspectRatio.Width; var sourceHeight = aspectRatio.Height; var dWidth = _width; diff --git a/TwilightBoxart/Models/Base/Rom.cs b/TwilightBoxart/Models/Base/Rom.cs index d131585..3b3336d 100644 --- a/TwilightBoxart/Models/Base/Rom.cs +++ b/TwilightBoxart/Models/Base/Rom.cs @@ -103,6 +103,22 @@ public static IRom FromFile(string filename) } } + //if (filename.ToLower().Contains(".lz77.")) + //{ + // fs.Seek(0, SeekOrigin.Begin); + // using (var decompressedFileStream = new MemoryStream()) + // { + // using (DeflateStream decompressionStream = new DeflateStream(fs, CompressionMode.Decompress)) + // { + // decompressionStream.CopyTo(decompressedFileStream); + // } + + // decompressedFileStream.Seek(0, SeekOrigin.Begin); + // return FromStream(decompressedFileStream, filename); + + // } + //} + return FromStream(fs, filename); } }