Commit e5e351ee authored by Amyn Bennamane's avatar Amyn Bennamane
Browse files

Try more alternative images from Cucholix banners repo

parent c1c93074
......@@ -174,16 +174,17 @@ namespace TeconMoon_s_WiiVC_Injector
IconSourceDirectory.Text = "Icon file has not been specified";
BannerSourceDirectory.Text = "Banner file has not been specified";
}
public void DownloadFromRepo()
public void DownloadFromRepo(string cucholixRepoID)
{
var client = new WebClient();
IconPreviewBox.Load(Properties.Settings.Default.BannersRepository + SystemType + "/image/" + CucholixRepoID + "/iconTex.png");
IconPreviewBox.Load(Properties.Settings.Default.BannersRepository + SystemType + "/image/" + cucholixRepoID + "/iconTex.png");
if (File.Exists(Path.GetTempPath() + "WiiVCInjector\\SOURCETEMP\\iconTex.png")) { File.Delete(Path.GetTempPath() + "WiiVCInjector\\SOURCETEMP\\iconTex.png"); }
client.DownloadFile(IconPreviewBox.ImageLocation, Path.GetTempPath() + "WiiVCInjector\\SOURCETEMP\\iconTex.png");
IconSourceDirectory.Text = "iconTex.png downloaded from Cucholix's Repo";
IconSourceDirectory.ForeColor = Color.Black;
FlagIconSpecified = true;
BannerPreviewBox.Load(Properties.Settings.Default.BannersRepository + SystemType + "/image/" + CucholixRepoID + "/bootTvTex.png");
BannerPreviewBox.Load(Properties.Settings.Default.BannersRepository + SystemType + "/image/" + cucholixRepoID + "/bootTvTex.png");
if (File.Exists(Path.GetTempPath() + "WiiVCInjector\\SOURCETEMP\\bootTvTex.png")) { File.Delete(Path.GetTempPath() + "WiiVCInjector\\SOURCETEMP\\bootTvTex.png"); }
client.DownloadFile(BannerPreviewBox.ImageLocation, Path.GetTempPath() + "WiiVCInjector\\SOURCETEMP\\bootTvTex.png");
BannerSourceDirectory.Text = "bootTvTex.png downloaded from Cucholix's Repo";
......@@ -973,78 +974,36 @@ namespace TeconMoon_s_WiiVC_Injector
}
else
{
if (SystemType == "wiiware")
if (!TryDownloadImages(CucholixRepoID))
{
if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID + "/iconTex.png") == true)
{
DownloadFromRepo();
}
else if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID.Substring(0, 3) + "E" + "/iconTex.png") == true)
{
CucholixRepoID = CucholixRepoID.Substring(0, 3) + "E";
DownloadFromRepo();
}
else if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID.Substring(0, 3) + "P" + "/iconTex.png") == true)
{
CucholixRepoID = CucholixRepoID.Substring(0, 3) + "P";
DownloadFromRepo();
}
else if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID.Substring(0, 3) + "J" + "/iconTex.png") == true)
{
CucholixRepoID = CucholixRepoID.Substring(0, 3) + "J";
DownloadFromRepo();
}
else
FlagRepo = false;
if (MessageBox.Show("Cucholix's Repo does not have assets for your game. You will need to provide your own. Would you like to visit the GBAtemp request thread?"
, "Game not found on Repo"
, MessageBoxButtons.YesNo
, MessageBoxIcon.Asterisk
, MessageBoxDefaultButton.Button1,
(MessageBoxOptions)0x40000) == DialogResult.Yes)
{
FlagRepo = false;
if (MessageBox.Show("Cucholix's Repo does not have assets for your game. You will need to provide your own. Would you like to visit the GBAtemp request thread?"
, "Game not found on Repo"
, MessageBoxButtons.YesNo
, MessageBoxIcon.Asterisk
, MessageBoxDefaultButton.Button1,
(MessageBoxOptions)0x40000) == DialogResult.Yes)
{
System.Diagnostics.Process.Start("https://gbatemp.net/threads/483080/");
}
Process.Start("https://gbatemp.net/threads/483080/");
}
}
else
}
}
private bool TryDownloadImages(string cucholixRepoID)
{
IEnumerable<string> ids = GameTdb.GetAlternativeIds(cucholixRepoID);
foreach (var id in ids)
{
if (RemoteFileExists(Properties.Settings.Default.BannersRepository + SystemType + "/image/" + id + "/iconTex.png"))
{
if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID + "/iconTex.png") == true)
{
DownloadFromRepo();
}
else if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID.Substring(0, 3) + "E" + CucholixRepoID.Substring(4, 2) + "/iconTex.png") == true)
{
CucholixRepoID = CucholixRepoID.Substring(0, 3) + "E" + CucholixRepoID.Substring(4, 2);
DownloadFromRepo();
}
else if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID.Substring(0, 3) + "P" + CucholixRepoID.Substring(4, 2) + "/iconTex.png") == true)
{
CucholixRepoID = CucholixRepoID.Substring(0, 3) + "P" + CucholixRepoID.Substring(4, 2);
DownloadFromRepo();
}
else if (RemoteFileExists("https://raw.githubusercontent.com/cucholix/wiivc-bis/master/" + SystemType + "/image/" + CucholixRepoID.Substring(0, 3) + "J" + CucholixRepoID.Substring(4, 2) + "/iconTex.png") == true)
{
CucholixRepoID = CucholixRepoID.Substring(0, 3) + "J" + CucholixRepoID.Substring(4, 2);
DownloadFromRepo();
}
else
{
FlagRepo = false;
if (MessageBox.Show("Cucholix's Repo does not have assets for your game. You will need to provide your own. Would you like to visit the GBAtemp request thread?"
, "Game not found on Repo"
, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk
, MessageBoxDefaultButton.Button1
, (MessageBoxOptions)0x40000) == DialogResult.Yes)
{
System.Diagnostics.Process.Start("https://gbatemp.net/threads/483080/");
}
}
DownloadFromRepo(id);
return true;
}
}
return false;
}
//Events for the "Optional Source Files" Tab
private void GC2SourceButton_Click(object sender, EventArgs e)
......
......@@ -30,5 +30,85 @@ namespace TeconMoon_s_WiiVC_Injector
return null;
}
}
public static List<string> GetIds(string name)
{
var assembly = Assembly.GetExecutingAssembly();
var wiitdb = "TeconMoon_s_WiiVC_Injector.Resources.wiitdb.txt";
using (var stream = assembly.GetManifestResourceStream(wiitdb))
using (var reader = new StreamReader(stream))
{
var ids = new List<string>();
string line;
while ((line = reader.ReadLine()) != null)
{
var split = line.Split(new[] { " = " }, 2, StringSplitOptions.None);
if (split[1] == name)
ids.Add(split[0]);
}
return ids;
}
}
public static List<string> GetIdsStartingWith(string idStart)
{
var assembly = Assembly.GetExecutingAssembly();
var wiitdb = "TeconMoon_s_WiiVC_Injector.Resources.wiitdb.txt";
using (var stream = assembly.GetManifestResourceStream(wiitdb))
using (var reader = new StreamReader(stream))
{
var ids = new List<string>();
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("TITLES ="))
continue;
var split = line.Split(new[] { " = " }, 2, StringSplitOptions.None);
if (split[0].StartsWith(idStart))
ids.Add(split[0]);
// Gametdb titles are ordered alphabetically by id, so stop searching
if (string.Compare(idStart, split[0].Substring(0, idStart.Length)) < 0)
break;
}
return ids;
}
}
internal static IEnumerable<string> GetAlternativeIds(string initialId)
{
var tried = new HashSet<string>
{
initialId,
initialId.ReplaceAt(3, 'E'),
initialId.ReplaceAt(3, 'P'),
// don't try Japanese just yet
// (e.g. don't want Pandora's Tower SX3J01 before SX3EXJ)
};
foreach(var id in tried)
{
yield return id;
}
var gameName = GetName(initialId);
var ids = GetIds(gameName)
.Where(id => !tried.Contains(id));
foreach(var id in ids)
{
yield return id;
}
tried.UnionWith(ids);
// as last resort, try a match on only the 3 first characters of
// the key (e.g. for Obscure 2)
var moreIds = GetIdsStartingWith(initialId.Substring(0, 3))
.Where(id => !tried.Contains(id));
foreach (var id in moreIds)
{
yield return id;
}
}
}
}
......@@ -41,5 +41,16 @@ namespace TeconMoon_s_WiiVC_Injector
.Normalize(NormalizationForm.FormC);
}
public static string ReplaceAt(this string input, int index, char newChar)
{
if (input == null)
{
throw new ArgumentNullException("input");
}
char[] chars = input.ToCharArray();
chars[index] = newChar;
return new string(chars);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment