Skip to content

Commit

Permalink
Embedded Redump/GameTDB data
Browse files Browse the repository at this point in the history
  • Loading branch information
GreyWolfSC committed Nov 28, 2016
1 parent a03aeb1 commit 726e2fd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 99 deletions.
80 changes: 26 additions & 54 deletions GCVerify/Data/GameTDB.cs
Expand Up @@ -19,68 +19,40 @@ static class GameTDB
static Dictionary<string, string> titles;
static string _dataPath;

public static async Task Open(string dataPath)
static GameTDB()
{
_dataPath = dataPath;

await Task.Run(() =>
StringReader r = new StringReader(Properties.Resources.titles);
string line;
titles = new Dictionary<string, string>();
string[] spl;
while ((line = r.ReadLine()) != null)
{
var dbPath = Path.Combine(dataPath, "wiitdb.zip");
if (!File.Exists(dbPath))
Update(dataPath);
var titlePath = Path.Combine(dataPath, "titles.txt");
if (File.Exists(titlePath))
{
var list = File.ReadAllLines(titlePath);
titles = new Dictionary<string, string>(list.Length);
string[] spl;
foreach(var item in list)
{
spl = item.Split('=');
titles.Add(spl[0].Trim(), spl[1].Trim());
}
}
using (var arc = new ZipArchive(File.OpenRead(dbPath), ZipArchiveMode.Read))
{
var entries = arc.Entries;
if (entries.Count > 0)
{
foreach (var entry in entries)
{
if (entry.Name.Contains(".xml"))
{
doc = XDocument.Load(entry.Open());
return;
}
}
}
}
});
spl = line.Split('=');
titles.Add(spl[0].Trim(), spl[1].Trim());
}
}

public static void Update(string dataPath)
{
var filePath = Path.Combine(dataPath, "wiitdb.zip");
var req = HttpWebRequest.Create(string.Format("http://www.gametdb.com/wiitdb.zip?LANG={0}&FALLBACK=true&GAMECUBE=true&WIIWARE=true", "EN"));
var resp = req.GetResponse();
//var filePath = Path.Combine(dataPath, "wiitdb.zip");
//var req = HttpWebRequest.Create(string.Format("http://www.gametdb.com/wiitdb.zip?LANG={0}&FALLBACK=true&GAMECUBE=true&WIIWARE=true", "EN"));
//var resp = req.GetResponse();
Stream strm = null;
if (resp != null)
{
strm = resp.GetResponseStream();
if (strm != null)
{
var f = File.Create(filePath);
strm.CopyTo(f);
f.Close();
strm.Close();
}
}
//if (resp != null)
//{
// strm = resp.GetResponseStream();
// if (strm != null)
// {
// var f = File.Create(filePath);
// strm.CopyTo(f);
// f.Close();
// strm.Close();
// }
//}

filePath = Path.Combine(dataPath, "titles.txt");
req = HttpWebRequest.Create(string.Format("http://www.gametdb.com/titles.txt?LANG={0}", "EN"));
resp = req.GetResponse();
var filePath = Path.Combine(dataPath, "titles.txt");
var req = HttpWebRequest.Create(string.Format("http://www.gametdb.com/titles.txt?LANG={0}", "EN"));
var resp = req.GetResponse();
if (resp != null)
{
strm = resp.GetResponseStream();
Expand Down
28 changes: 9 additions & 19 deletions GCVerify/Data/Redump.cs
Expand Up @@ -16,33 +16,23 @@ static class Redump
const string redumpUri = "http://redump.org/datfile/gc/";
static XDocument doc;

public static async Task Open(string dataPath)
static Redump()
{
await Task.Run(() =>
using (var arc = new ZipArchive(new MemoryStream(Properties.Resources.redump), ZipArchiveMode.Read))
{
var path = Path.Combine(dataPath, "redump.zip");
if (!File.Exists(path))
Update(dataPath);
if (File.Exists(path))
var entries = arc.Entries;
if (entries.Count > 0)
{
using (var arc = new ZipArchive(File.OpenRead(path), ZipArchiveMode.Read))
foreach (var entry in entries)
{
var entries = arc.Entries;
if (entries.Count > 0)
if (entry.Name.Contains(".dat"))
{
foreach (var entry in entries)
{
if (entry.Name.Contains(".dat"))
{
doc = XDocument.Load(entry.Open());
break;
}
}
doc = XDocument.Load(entry.Open());
break;
}
}
}
});
}
}

public static void Update(string dataPath)
Expand Down
15 changes: 15 additions & 0 deletions GCVerify/GCVerify.csproj
Expand Up @@ -104,6 +104,11 @@
</ApplicationDefinition>
<Compile Include="Data\GameTDB.cs" />
<Compile Include="Data\Redump.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="ScanPage.xaml.cs">
<DependentUpon>ScanPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -151,6 +156,7 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<AppDesigner Include="Properties\" />
<None Include="Resources\redump.zip" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand All @@ -175,6 +181,15 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\titles.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
27 changes: 1 addition & 26 deletions GCVerify/StartPage.xaml.cs
Expand Up @@ -28,33 +28,8 @@ public StartPage()
InitializeComponent();
}

private async void Page_Loaded(object sender, RoutedEventArgs e)
private void Page_Loaded(object sender, RoutedEventArgs e)
{
var dataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "GCVerify");

if (!Directory.Exists(dataPath))
Directory.CreateDirectory(dataPath);

SetStatus("Getting Redump data...");
try
{
await Redump.Open(dataPath);
}
catch (WebException)
{
SetStatus("Could not retrieve Redump data.");
}

SetStatus("Getting GameTDB data...");
try
{
await GameTDB.Open(dataPath);
}
catch (WebException)
{
SetStatus("Could not retrieve GameTDB data.");
}

SetStatus("Drop Gamecube game images or folders here to start");
dropTarget.AllowDrop = true;
displayText.AllowDrop = true;
Expand Down

0 comments on commit 726e2fd

Please sign in to comment.