From 7475c08f2b7f84c13401922ad02db29b32b3275e Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 30 Sep 2019 22:41:03 +0200 Subject: [PATCH] - Fixed searching for titles with '&', '/' in the name. Probably need to add more later. - Fixed crude japanese detection for some games. - Updated readme. --- README.md | 31 ++++++++++++---------- TwilightBoxart/BoxartCrawler.cs | 4 +-- TwilightBoxart/Helpers/StringExtensions.cs | 1 - TwilightBoxart/Models/Base/LibRetroRom.cs | 9 +++++-- TwilightBoxart/Models/Base/Rom.cs | 13 ++++++++- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 3f79a3e..7a65c7f 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,28 @@ -![Screenshot](https://github.com/KirovAir/TwilightBoxart/raw/master/img/screenshot.png) +![Screenshot](https://github.com/KirovAir/TwilightBoxart/raw/master/img/screenshot.png) # Twilight Boxart A boxart downloader written in C#. Uses various sources and scan methods to determine the correct boxart. -Written for TwilightMenu++ but can be used for other loader UI's with some config changes. 😊 +Written for [TwilightMenu++](https://github.com/DS-Homebrew/TWiLightMenu) but can be used for other loader UI's with some config changes. 😊 ## Supported rom types -* Nintendo - Game Boy -* Nintendo - Game Boy Color -* Nintendo - Game Boy Advance -* Nintendo - Nintendo DS -* Nintendo - Nintendo DSi -* Nintendo - Nintendo DSi (DSiWare) -* Nintendo - Nintendo Entertainment System -* Nintendo - Super Nintendo Entertainment System -* Sega - Mega Drive - Genesis -* Sega - Master System - Mark III -* Sega - Game Gear + System | Matching (in order) + --- | --- + Nintendo - Game Boy | (sha1 / filename) + Nintendo - Game Boy Color | (sha1 / filename) + Nintendo - Game Boy Advance | (sha1 / filename) + Nintendo - Nintendo DS | (titleid / sha1 / filename) + Nintendo - Nintendo DSi | (titleid / sha1 / filename) + Nintendo - Nintendo DSi (DSiWare) | (titleid / sha1 / filename) + Nintendo - Nintendo Entertainment System | (sha1 / filename) + Nintendo - Super Nintendo Entertainment System | (sha1 / filename) + Nintendo - Family Computer Disk System | (sha1 / filename) + Sega - Mega Drive - Genesis | (sha1 / filename) + Sega - Master System - Mark III | (sha1 / filename) + Sega - Game Gear | (sha1 / filename) ## Boxart sources * [GameTDB](https://gametdb.com) using titleid matching. -* [LibRetro](https://github.com/libretro/libretro-thumbnails) using [NoIntro](https://datomatic.no-intro.org) sha1 matching. +* [LibRetro](https://github.com/libretro/libretro-thumbnails) using [NoIntro](https://datomatic.no-intro.org) sha1 matching or simply filename matching. [LibRetro DAT](https://github.com/libretro/libretro-database/tree/master/dat) is currently added as extra NES sha1 source. ## Download [Here](https://github.com/KirovAir/TwilightBoxart/releases). diff --git a/TwilightBoxart/BoxartCrawler.cs b/TwilightBoxart/BoxartCrawler.cs index e2eb9e6..a923aef 100644 --- a/TwilightBoxart/BoxartCrawler.cs +++ b/TwilightBoxart/BoxartCrawler.cs @@ -67,8 +67,8 @@ public void DownloadArt(string romsPath, string boxArtPath, int defaultWidth, in { if (rom.ConsoleType == ConsoleType.SuperNintendoEntertainmentSystem) { - if ((rom.NoIntroName?.ToLower().EndsWith("(japan)") ?? false) || - (rom.SearchName?.ToLower().EndsWith("(japan)") ?? false)) + if ((rom.NoIntroName?.ToLower().Contains("(japan)") ?? false) || + (rom.SearchName?.ToLower().Contains("(japan)") ?? false)) { size = new Size(84, 115); } diff --git a/TwilightBoxart/Helpers/StringExtensions.cs b/TwilightBoxart/Helpers/StringExtensions.cs index 17dac70..53df984 100644 --- a/TwilightBoxart/Helpers/StringExtensions.cs +++ b/TwilightBoxart/Helpers/StringExtensions.cs @@ -1,5 +1,4 @@ using System.Linq; -using KirovAir.Core.Utilities; namespace KirovAir.Core.Extensions { diff --git a/TwilightBoxart/Models/Base/LibRetroRom.cs b/TwilightBoxart/Models/Base/LibRetroRom.cs index 0e13479..6bded1e 100644 --- a/TwilightBoxart/Models/Base/LibRetroRom.cs +++ b/TwilightBoxart/Models/Base/LibRetroRom.cs @@ -24,6 +24,10 @@ public override void DownloadBoxArt(string targetFile) } catch { + if (NoIntroName == SearchName) + { + throw new NoMatchException("Nothing was found! (Using sha1/filename)"); + } // Else try filename. DownloadByName(targetFile); } @@ -31,14 +35,13 @@ public override void DownloadBoxArt(string targetFile) private void DownloadByName(string targetFile) { - try { DownloadWithRetry(SearchName, targetFile); } catch { - throw new NoMatchException("Could not match rom using sha1 or filename.. Skipping."); + throw new NoMatchException("Nothing was found! (Using sha1/filename)"); } } @@ -67,6 +70,8 @@ private void Download(ConsoleType consoleType, string name, string targetFile) // We can generate the LibRetro content url based on the NoIntroDb name. var consoleStr = consoleType.GetDescription().Replace(" ", "_"); var url = $"https://github.com/libretro-thumbnails/{consoleStr}/raw/master/Named_Boxarts/"; + name = name.Replace("&", "_"); // Todo: There are probably more replacements going on, search & add them. + name = name.Replace("/", "_"); url = FileHelper.CombineUri(url, $"{name}.png"); ImgDownloader.DownloadAndResize(url, targetFile); } diff --git a/TwilightBoxart/Models/Base/Rom.cs b/TwilightBoxart/Models/Base/Rom.cs index c95067f..df1f717 100644 --- a/TwilightBoxart/Models/Base/Rom.cs +++ b/TwilightBoxart/Models/Base/Rom.cs @@ -20,7 +20,18 @@ public class Rom : IRom public virtual ConsoleType ConsoleType { get; set; } public string NoIntroName { get; set; } public ConsoleType NoIntroConsoleType { get; set; } - public string SearchName => !string.IsNullOrEmpty(FileName) ? Path.GetFileNameWithoutExtension(FileName?.Replace(".lz77", "")) : null; + public string SearchName + { + get + { + if (string.IsNullOrEmpty(FileName)) + return null; + + var name = Path.GetFileNameWithoutExtension(FileName?.Replace(".lz77", "")); + return name; + } + } + internal ImgDownloader ImgDownloader { get; set; } public static IRom FromStream(Stream stream, string filename)