mirror of
https://github.com/WB3000/nusdownloader.git
synced 2024-11-17 07:09:21 +01:00
Database is updatable from Wiibrew (NUS_Downloader/database)
This commit is contained in:
parent
fda8531e22
commit
94d0178987
32
NUS Downloader/Form1.Designer.cs
generated
32
NUS Downloader/Form1.Designer.cs
generated
@ -107,6 +107,8 @@
|
||||
this.radioButton1 = new System.Windows.Forms.RadioButton();
|
||||
this.radioButton2 = new System.Windows.Forms.RadioButton();
|
||||
this.button17 = new System.Windows.Forms.Button();
|
||||
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.updateDatabaseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.databaseStrip.SuspendLayout();
|
||||
this.tmdgpbox.SuspendLayout();
|
||||
this.ticketgpbox.SuspendLayout();
|
||||
@ -295,10 +297,12 @@
|
||||
this.VCMenuList,
|
||||
this.WiiWareMenuList,
|
||||
this.toolStripSeparator1,
|
||||
this.RegionCodesList});
|
||||
this.RegionCodesList,
|
||||
this.toolStripSeparator2,
|
||||
this.updateDatabaseToolStripMenuItem});
|
||||
this.databaseStrip.Name = "databaseStrip";
|
||||
this.databaseStrip.ShowItemToolTips = false;
|
||||
this.databaseStrip.Size = new System.Drawing.Size(155, 120);
|
||||
this.databaseStrip.Size = new System.Drawing.Size(164, 170);
|
||||
//
|
||||
// SystemMenuList
|
||||
//
|
||||
@ -310,7 +314,7 @@
|
||||
// IOSMenuList
|
||||
//
|
||||
this.IOSMenuList.Name = "IOSMenuList";
|
||||
this.IOSMenuList.Size = new System.Drawing.Size(154, 22);
|
||||
this.IOSMenuList.Size = new System.Drawing.Size(163, 22);
|
||||
this.IOSMenuList.Text = "IOS";
|
||||
//
|
||||
// VCMenuList
|
||||
@ -328,7 +332,7 @@
|
||||
this.TurboGrafxCDMenuList,
|
||||
this.VCArcadeMenuList});
|
||||
this.VCMenuList.Name = "VCMenuList";
|
||||
this.VCMenuList.Size = new System.Drawing.Size(154, 22);
|
||||
this.VCMenuList.Size = new System.Drawing.Size(163, 22);
|
||||
this.VCMenuList.Text = "Virtual Console";
|
||||
//
|
||||
// C64MenuList
|
||||
@ -400,18 +404,18 @@
|
||||
// WiiWareMenuList
|
||||
//
|
||||
this.WiiWareMenuList.Name = "WiiWareMenuList";
|
||||
this.WiiWareMenuList.Size = new System.Drawing.Size(154, 22);
|
||||
this.WiiWareMenuList.Size = new System.Drawing.Size(163, 22);
|
||||
this.WiiWareMenuList.Text = "WiiWare";
|
||||
//
|
||||
// toolStripSeparator1
|
||||
//
|
||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(151, 6);
|
||||
this.toolStripSeparator1.Size = new System.Drawing.Size(160, 6);
|
||||
//
|
||||
// RegionCodesList
|
||||
//
|
||||
this.RegionCodesList.Name = "RegionCodesList";
|
||||
this.RegionCodesList.Size = new System.Drawing.Size(154, 22);
|
||||
this.RegionCodesList.Size = new System.Drawing.Size(163, 22);
|
||||
this.RegionCodesList.Text = "Region Codes";
|
||||
this.RegionCodesList.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.RegionCodesList_DropDownItemClicked);
|
||||
//
|
||||
@ -873,6 +877,18 @@
|
||||
this.button17.UseVisualStyleBackColor = true;
|
||||
this.button17.Click += new System.EventHandler(this.button17_Click);
|
||||
//
|
||||
// toolStripSeparator2
|
||||
//
|
||||
this.toolStripSeparator2.Name = "toolStripSeparator2";
|
||||
this.toolStripSeparator2.Size = new System.Drawing.Size(160, 6);
|
||||
//
|
||||
// updateDatabaseToolStripMenuItem
|
||||
//
|
||||
this.updateDatabaseToolStripMenuItem.Name = "updateDatabaseToolStripMenuItem";
|
||||
this.updateDatabaseToolStripMenuItem.Size = new System.Drawing.Size(163, 22);
|
||||
this.updateDatabaseToolStripMenuItem.Text = "Update Database";
|
||||
this.updateDatabaseToolStripMenuItem.Click += new System.EventHandler(this.updateDatabaseToolStripMenuItem_Click);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@ -1006,6 +1022,8 @@
|
||||
private System.Windows.Forms.Button button13;
|
||||
private System.Windows.Forms.Button button16;
|
||||
private System.Windows.Forms.Button button17;
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
|
||||
private System.Windows.Forms.ToolStripMenuItem updateDatabaseToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,9 @@ using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Xml;
|
||||
using System.Drawing;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.ComponentModel;
|
||||
using System.Threading;
|
||||
|
||||
|
||||
namespace NUS_Downloader
|
||||
@ -237,13 +240,9 @@ namespace NUS_Downloader
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read version of Database.xml
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
xDoc.Load("database.xml");
|
||||
XmlNodeList DatabaseList = xDoc.GetElementsByTagName("database");
|
||||
XmlAttributeCollection Attributes = DatabaseList[0].Attributes;
|
||||
string version = GetDatabaseVersion("database.xml");
|
||||
WriteStatus("Database.xml detected.");
|
||||
WriteStatus(" - Version: " + Attributes[0].Value);
|
||||
WriteStatus(" - Version: " + version);
|
||||
|
||||
// Load it up...
|
||||
ClearDatabaseStrip();
|
||||
@ -255,6 +254,19 @@ namespace NUS_Downloader
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetDatabaseVersion(string file)
|
||||
{
|
||||
// Read version of Database.xml
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
if (file.Contains("<"))
|
||||
xDoc.LoadXml(file);
|
||||
else
|
||||
xDoc.Load(file);
|
||||
XmlNodeList DatabaseList = xDoc.GetElementsByTagName("database");
|
||||
XmlAttributeCollection Attributes = DatabaseList[0].Attributes;
|
||||
return Attributes[0].Value;
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Show dialog for opening TMD file...
|
||||
@ -3150,5 +3162,59 @@ namespace NUS_Downloader
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string RetrieveNewDatabase()
|
||||
{
|
||||
// Retrieve Wiibrew database page source code
|
||||
WebClient databasedl = new WebClient();
|
||||
string wiibrewsource = databasedl.DownloadString("http://www.wiibrew.org/wiki/NUS_Downloader/database");
|
||||
|
||||
// Strip out HTML
|
||||
wiibrewsource = Regex.Replace(wiibrewsource, @"<(.|\n)*?>", "");
|
||||
|
||||
// Shrink to fix only the database
|
||||
string startofdatabase = "<database v";
|
||||
string endofdatabase = "</database>";
|
||||
wiibrewsource = wiibrewsource.Substring(wiibrewsource.IndexOf(startofdatabase), wiibrewsource.Length - wiibrewsource.IndexOf(startofdatabase));
|
||||
wiibrewsource = wiibrewsource.Substring(0, wiibrewsource.IndexOf(endofdatabase) + endofdatabase.Length);
|
||||
|
||||
// Fix ", <, and >
|
||||
wiibrewsource = wiibrewsource.Replace("<","<");
|
||||
wiibrewsource = wiibrewsource.Replace(">",">");
|
||||
wiibrewsource = wiibrewsource.Replace(""",'"'.ToString());
|
||||
wiibrewsource = wiibrewsource.Replace(" ", ""); // Shouldn't occur, but they happen...
|
||||
|
||||
// Return parsed xml database...
|
||||
return wiibrewsource;
|
||||
}
|
||||
|
||||
private void updateDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
statusbox.Text = "";
|
||||
WriteStatus("Updating your database.xml from Wiibrew.org");
|
||||
WriteStatus(" - Database successfully parsed!");
|
||||
|
||||
string database = RetrieveNewDatabase();
|
||||
string currentversion = GetDatabaseVersion("database.xml");
|
||||
string onlineversion = GetDatabaseVersion(database);
|
||||
WriteStatus(" - Current Database Version: " + currentversion);
|
||||
WriteStatus(" - Online Database Version: " + onlineversion);
|
||||
|
||||
if (currentversion == onlineversion)
|
||||
{
|
||||
WriteStatus(" - You have the latest database version!");
|
||||
return;
|
||||
}
|
||||
|
||||
WriteStatus(" - Overwriting your current database.xml...");
|
||||
WriteStatus(" - The old database will become 'olddatabase.xml' in case the new one is faulty.");
|
||||
|
||||
string olddatabase = File.ReadAllText("database.xml");
|
||||
File.WriteAllText("olddatabase.xml", olddatabase);
|
||||
File.Delete("database.xml");
|
||||
File.WriteAllText("database.xml", database);
|
||||
|
||||
WriteStatus("Database successfully updated!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user