Skip to content

Commit

Permalink
Box art downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
ClusterM committed Oct 7, 2017
1 parent ef067b9 commit e27869a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions Apps/NesMiniApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
55 changes: 47 additions & 8 deletions Apps/SnesGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,23 @@ 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;
if (ConfigIni.ConsoleType == MainForm.ConsoleType.SNES || ConfigIni.ConsoleType == MainForm.ConsoleType.SuperFamicom)
{
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";
Expand Down Expand Up @@ -439,6 +439,7 @@ private struct CachedGameInfo
public string ReleaseDate;
public string Publisher;
public string Region;
public string CoverUrl;
}

public static void LoadCache()
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public enum ConsoleType { NES = 0, Famicom = 1, SNES = 2, SuperFamicom = 3, Unkn
public static IEnumerable<string> 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 },
Expand Down
6 changes: 6 additions & 0 deletions Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,10 @@
<data name="gamepad_SNES" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\gamepad_snes.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Cover" xml:space="preserve">
<value>Box art</value>
</data>
<data name="DownloadCoverQ" xml:space="preserve">
<value>Do you want to try to download box art for "{0}"?</value>
</data>
</root>
7 changes: 4 additions & 3 deletions WorkerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1259,9 +1259,10 @@ public ICollection<NesMiniApplication> AddGames(IEnumerable<string> files, Form
{
var apps = new List<NesMiniApplication>();
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)
Expand Down

0 comments on commit e27869a

Please sign in to comment.