diff --git a/Apps/NesMiniApplication.cs b/Apps/NesMiniApplication.cs index 153629f94..24d953f45 100644 --- a/Apps/NesMiniApplication.cs +++ b/Apps/NesMiniApplication.cs @@ -21,6 +21,7 @@ public class NesMiniApplication : INesMenuElement public static Image DefaultCover = Resources.blank_app; public static Form ParentForm; public static bool? NeedPatch; + public static bool? NeedAutoDownloadCover; public static string GamesDirectory { diff --git a/Apps/SnesGame.cs b/Apps/SnesGame.cs index 9980498ff..4eac1e422 100644 --- a/Apps/SnesGame.cs +++ b/Apps/SnesGame.cs @@ -86,6 +86,14 @@ public SnesGame(string path, bool ignoreEmptyConfig = false) public static bool Patch(string inputFileName, ref byte[] rawRomData, ref char prefix, ref string application, ref string outputFileName, ref string args, ref Image cover, ref byte saveCount, ref uint crc32) { + var ext = Path.GetExtension(inputFileName); + if ((ext.ToLower() == ".smc") && ((rawRomData.Length % 1024) != 0)) + { + var stripped = new byte[rawRomData.Length - 512]; + Array.Copy(rawRomData, 512, stripped, 0, stripped.Length); + rawRomData = stripped; + crc32 = CRC32(rawRomData); + } FindPatch(ref rawRomData, inputFileName, crc32); if (inputFileName.Contains("(E)") || inputFileName.Contains("(J)")) cover = Resources.blank_snes_eu_jp; @@ -93,16 +101,8 @@ public static bool Patch(string inputFileName, ref byte[] rawRomData, ref char p { application = "/bin/clover-canoe-shvc-wr -rom"; args = DefaultArgs; - var ext = Path.GetExtension(inputFileName); if (ext.ToLower() != ".sfrom") // Need to patch for canoe { - if ((ext.ToLower() == ".smc") && ((rawRomData.Length % 1024) != 0)) - { - var stripped = new byte[rawRomData.Length - 512]; - Array.Copy(rawRomData, 512, stripped, 0, stripped.Length); - rawRomData = stripped; - crc32 = CRC32(rawRomData); - } Debug.WriteLine($"Trying to convert {inputFileName}"); MakeSfrom(ref rawRomData, ref saveCount); outputFileName = Path.GetFileNameWithoutExtension(outputFileName) + ".sfrom"; @@ -439,6 +439,7 @@ private struct CachedGameInfo public string ReleaseDate; public string Publisher; public string Region; + public string CoverUrl; } public static void LoadCache() @@ -484,6 +485,12 @@ public static void LoadCache() v = cartridge.Select("publisher"); if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value)) info.Publisher = v.Current.Value; + v = cartridge.Select("region"); + if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value)) + info.Region = v.Current.Value; + v = cartridge.Select("cover"); + if (v.MoveNext() && !string.IsNullOrEmpty(v.Current.Value)) + info.CoverUrl = v.Current.Value; } catch { @@ -514,6 +521,38 @@ public bool TryAutofill(uint crc32) if (ReleaseDate.Length == 4) ReleaseDate += "-01"; if (ReleaseDate.Length == 7) ReleaseDate += "-01"; Publisher = gameinfo.Publisher.ToUpper(); + + if (!string.IsNullOrEmpty(gameinfo.CoverUrl)) + { + if (NeedAutoDownloadCover != true) + { + if (NeedAutoDownloadCover != false) + { + var r = WorkerForm.MessageBoxFromThread(ParentForm, + string.Format(Resources.DownloadCoverQ, Name), + Resources.Cover, + MessageBoxButtons.AbortRetryIgnore, + MessageBoxIcon.Question, + MessageBoxDefaultButton.Button2, true); + if (r == DialogResult.Abort) + NeedPatch = true; + if (r == DialogResult.Ignore) + return true; + } + else return true; + } + + try + { + var cover = ImageGooglerForm.DownloadImage(gameinfo.CoverUrl); + Image = cover; + } + catch (Exception ex) + { + Debug.WriteLine(ex.Message + ex.StackTrace); + } + } + return true; } return false; diff --git a/MainForm.cs b/MainForm.cs index 5f949f771..a10b69f07 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -28,6 +28,7 @@ public enum ConsoleType { NES = 0, Famicom = 1, SNES = 2, SuperFamicom = 3, Unkn public static IEnumerable InternalMods; public static ClovershellConnection Clovershell; mooftpserv.Server ftpServer; + public static bool? DownloadCover; static NesDefaultGame[] defaultNesGames = new NesDefaultGame[] { new NesDefaultGame { Code = "CLV-P-NAAAE", Name = "Super Mario Bros.", Size = 571031 }, diff --git a/Properties/Resources.resx b/Properties/Resources.resx index c7d196bc9..896434531 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -685,4 +685,10 @@ ..\images\gamepad_snes.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Box art + + + Do you want to try to download box art for "{0}"? + \ No newline at end of file diff --git a/WorkerForm.cs b/WorkerForm.cs index 81056349b..b2b1d44ac 100644 --- a/WorkerForm.cs +++ b/WorkerForm.cs @@ -845,7 +845,7 @@ public void UploadGames() case MainForm.ConsoleType.SNES: case MainForm.ConsoleType.SuperFamicom: originalSyncCode = $"mkdir -p \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " + - $"rsync -ac \"{gamesPath}/{originalCode}/\" \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" &&" + + $"rsync -ac \"{gamesPath}/{originalCode}/\" \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " + $"sed -i -e 's/\\/usr\\/bin\\/clover-canoe-shvc/\\/bin\\/clover-canoe-shvc-wr/g' \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/{originalCode}.desktop\""; /* // With compression but very slow @@ -1259,9 +1259,10 @@ public ICollection AddGames(IEnumerable files, Form { var apps = new List(); addedApplications = null; - NesGame.ParentForm = this; - NesGame.NeedPatch = null; + NesMiniApplication.ParentForm = this; + NesMiniApplication.NeedPatch = null; NesGame.IgnoreMapper = null; + SnesGame.NeedAutoDownloadCover = null; int count = 0; SetStatus(Resources.AddingGames); foreach (var sourceFileName in files)