mirror of
https://github.com/WiiDatabase/nusdownloader.git
synced 2024-11-30 14:04:17 +01:00
Database loading from Database.cs (VERY WIP)
Needs a lot of work!
This commit is contained in:
parent
db536a2fbe
commit
407721c9c8
@ -23,7 +23,7 @@ namespace NUS_Downloader
|
|||||||
private string[] VcConsoles = new string[11] { "C64", "GEN", "MSX", "N64", "NEO", "NES",
|
private string[] VcConsoles = new string[11] { "C64", "GEN", "MSX", "N64", "NEO", "NES",
|
||||||
"SMS", "SNES", "TG16", "TGCD", "ARC" };
|
"SMS", "SNES", "TG16", "TGCD", "ARC" };
|
||||||
|
|
||||||
MemoryStream databaseStream;
|
private string databaseString;
|
||||||
|
|
||||||
private Image green = Properties.Resources.bullet_green;
|
private Image green = Properties.Resources.bullet_green;
|
||||||
private Image orange = Properties.Resources.bullet_orange;
|
private Image orange = Properties.Resources.bullet_orange;
|
||||||
@ -34,43 +34,43 @@ namespace NUS_Downloader
|
|||||||
public void LoadDatabaseToStream(string databaseFile)
|
public void LoadDatabaseToStream(string databaseFile)
|
||||||
{
|
{
|
||||||
// Load database.xml into MemoryStream
|
// Load database.xml into MemoryStream
|
||||||
string databasestr = File.ReadAllText(databaseFile);
|
databaseString = File.ReadAllText(databaseFile);
|
||||||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
/*System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||||
byte[] databasebytes = encoding.GetBytes(databasestr);
|
byte[] databasebytes = encoding.GetBytes(databasestr);
|
||||||
|
|
||||||
// Load the memory stream
|
// Load the memory stream
|
||||||
databaseStream = new MemoryStream(databasebytes);
|
databaseStream = new MemoryStream(databasebytes);
|
||||||
databaseStream.Seek(0, SeekOrigin.Begin);
|
databaseStream.Seek(0, SeekOrigin.Begin);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetDatabaseVersion()
|
public string GetDatabaseVersion()
|
||||||
{
|
{
|
||||||
if (databaseStream.Length < 1)
|
if (databaseString.Length < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Load the database into a memory stream first!");
|
throw new Exception("Load the database into a memory stream first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument xDoc = new XmlDocument();
|
XmlDocument xDoc = new XmlDocument();
|
||||||
xDoc.Load(databaseStream);
|
xDoc.LoadXml(databaseString);
|
||||||
XmlNodeList DatabaseList = xDoc.GetElementsByTagName("database");
|
XmlNodeList DatabaseList = xDoc.GetElementsByTagName("database");
|
||||||
XmlAttributeCollection Attributes = DatabaseList[0].Attributes;
|
XmlAttributeCollection Attributes = DatabaseList[0].Attributes;
|
||||||
return Attributes[0].Value;
|
return Attributes[0].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToolStripItemCollection LoadSystemTitles()
|
public ToolStripMenuItem[] LoadSystemTitles()
|
||||||
{
|
{
|
||||||
if (databaseStream.Length < 1)
|
if (databaseString.Length < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Load the database into a memory stream first!");
|
throw new Exception("Load the database into a memory stream first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument xDoc = new XmlDocument();
|
XmlDocument xDoc = new XmlDocument();
|
||||||
xDoc.Load(databaseStream);
|
xDoc.LoadXml(databaseString);
|
||||||
|
|
||||||
ToolStripItemCollection systemTitleCollection = new ToolStripItemCollection(null, null);
|
|
||||||
|
|
||||||
XmlNodeList SystemTitlesXMLNodes = xDoc.GetElementsByTagName(SystemTag);
|
XmlNodeList SystemTitlesXMLNodes = xDoc.GetElementsByTagName(SystemTag);
|
||||||
|
|
||||||
|
ToolStripMenuItem[] systemTitleCollection = new ToolStripMenuItem[SystemTitlesXMLNodes.Count];
|
||||||
|
|
||||||
for (int x = 0; x < SystemTitlesXMLNodes.Count; x++)
|
for (int x = 0; x < SystemTitlesXMLNodes.Count; x++)
|
||||||
{
|
{
|
||||||
ToolStripMenuItem XMLToolStripItem = new ToolStripMenuItem();
|
ToolStripMenuItem XMLToolStripItem = new ToolStripMenuItem();
|
||||||
@ -157,25 +157,23 @@ namespace NUS_Downloader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//AddToolStripItemToStrip(i, XMLToolStripItem, XMLAttributes);
|
//AddToolStripItemToStrip(i, XMLToolStripItem, XMLAttributes);
|
||||||
systemTitleCollection.Add(XMLToolStripItem);
|
systemTitleCollection[x] = XMLToolStripItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return systemTitleCollection;
|
return systemTitleCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToolStripItemCollection LoadIosTitles()
|
public ToolStripMenuItem[] LoadIosTitles()
|
||||||
{
|
{
|
||||||
if (databaseStream.Length < 1)
|
if (databaseString.Length < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Load the database into a memory stream first!");
|
throw new Exception("Load the database into a memory stream first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument xDoc = new XmlDocument();
|
XmlDocument xDoc = new XmlDocument();
|
||||||
xDoc.Load(databaseStream);
|
xDoc.LoadXml(databaseString);
|
||||||
|
|
||||||
ToolStripItemCollection iosTitleCollection = new ToolStripItemCollection(null, null);
|
|
||||||
|
|
||||||
XmlNodeList IosTitlesXMLNodes = xDoc.GetElementsByTagName(IosTag);
|
XmlNodeList IosTitlesXMLNodes = xDoc.GetElementsByTagName(IosTag);
|
||||||
|
ToolStripMenuItem[] iosTitleCollection = new ToolStripMenuItem[IosTitlesXMLNodes.Count];
|
||||||
|
|
||||||
for (int x = 0; x < IosTitlesXMLNodes.Count; x++)
|
for (int x = 0; x < IosTitlesXMLNodes.Count; x++)
|
||||||
{
|
{
|
||||||
@ -228,25 +226,28 @@ namespace NUS_Downloader
|
|||||||
XMLToolStripItem.Text = descname; //Huh
|
XMLToolStripItem.Text = descname; //Huh
|
||||||
}
|
}
|
||||||
|
|
||||||
iosTitleCollection.Add(XMLToolStripItem);
|
iosTitleCollection[x] = XMLToolStripItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return iosTitleCollection;
|
return iosTitleCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToolStripItemCollection[] LoadVirtualConsoleTitles()
|
public ToolStripMenuItem[][] LoadVirtualConsoleTitles()
|
||||||
{
|
{
|
||||||
if (databaseStream.Length < 1)
|
if (databaseString.Length < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Load the database into a memory stream first!");
|
throw new Exception("Load the database into a memory stream first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument xDoc = new XmlDocument();
|
XmlDocument xDoc = new XmlDocument();
|
||||||
xDoc.Load(databaseStream);
|
xDoc.LoadXml(databaseString);
|
||||||
|
|
||||||
ToolStripItemCollection[] vcTitleCollection = new ToolStripItemCollection[VcConsoles.Length];
|
|
||||||
|
|
||||||
XmlNodeList VirtualConsoleXMLNodes = xDoc.GetElementsByTagName(VcTag);
|
XmlNodeList VirtualConsoleXMLNodes = xDoc.GetElementsByTagName(VcTag);
|
||||||
|
ToolStripMenuItem[][] vcTitleCollection = new ToolStripMenuItem[VcConsoles.Length][];
|
||||||
|
|
||||||
|
for (int j = 0; j < vcTitleCollection.Length; j++)
|
||||||
|
{
|
||||||
|
vcTitleCollection[j] = new ToolStripMenuItem[0];
|
||||||
|
}
|
||||||
|
|
||||||
for (int x = 0; x < VirtualConsoleXMLNodes.Count; x++)
|
for (int x = 0; x < VirtualConsoleXMLNodes.Count; x++)
|
||||||
{
|
{
|
||||||
@ -337,26 +338,27 @@ namespace NUS_Downloader
|
|||||||
for (int a = 0; a < VcConsoles.Length; a++)
|
for (int a = 0; a < VcConsoles.Length; a++)
|
||||||
{
|
{
|
||||||
if (XMLAttributes[0].Value == VcConsoles[a])
|
if (XMLAttributes[0].Value == VcConsoles[a])
|
||||||
vcTitleCollection[a].Add(XMLToolStripItem);
|
{
|
||||||
|
Array.Resize(ref vcTitleCollection[a], vcTitleCollection[a].Length + 1);
|
||||||
|
vcTitleCollection[a][vcTitleCollection[a].Length - 1] = XMLToolStripItem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return vcTitleCollection;
|
return vcTitleCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToolStripItemCollection LoadWiiWareTitles()
|
public ToolStripMenuItem[] LoadWiiWareTitles()
|
||||||
{
|
{
|
||||||
if (databaseStream.Length < 1)
|
if (databaseString.Length < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Load the database into a memory stream first!");
|
throw new Exception("Load the database into a memory stream first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument xDoc = new XmlDocument();
|
XmlDocument xDoc = new XmlDocument();
|
||||||
xDoc.Load(databaseStream);
|
xDoc.LoadXml(databaseString);
|
||||||
|
|
||||||
ToolStripItemCollection wwTitleCollection = new ToolStripItemCollection(null, null);
|
|
||||||
|
|
||||||
XmlNodeList WiiWareTitlesXMLNodes = xDoc.GetElementsByTagName(WwTag);
|
XmlNodeList WiiWareTitlesXMLNodes = xDoc.GetElementsByTagName(WwTag);
|
||||||
|
ToolStripMenuItem[] wwTitleCollection = new ToolStripMenuItem[WiiWareTitlesXMLNodes.Count];
|
||||||
|
|
||||||
for (int x = 0; x < WiiWareTitlesXMLNodes.Count; x++)
|
for (int x = 0; x < WiiWareTitlesXMLNodes.Count; x++)
|
||||||
{
|
{
|
||||||
@ -444,7 +446,7 @@ namespace NUS_Downloader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wwTitleCollection.Add(XMLToolStripItem);
|
wwTitleCollection[x] = XMLToolStripItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
return wwTitleCollection;
|
return wwTitleCollection;
|
||||||
@ -475,13 +477,13 @@ namespace NUS_Downloader
|
|||||||
<region index=12>58 (Some Homebrew)</region>
|
<region index=12>58 (Some Homebrew)</region>
|
||||||
</REGIONS>
|
</REGIONS>
|
||||||
*/
|
*/
|
||||||
if (databaseStream.Length < 1)
|
if (databaseString.Length < 1)
|
||||||
{
|
{
|
||||||
throw new Exception("Load the database into a memory stream first!");
|
throw new Exception("Load the database into a memory stream first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlDocument xDoc = new XmlDocument();
|
XmlDocument xDoc = new XmlDocument();
|
||||||
xDoc.Load(databaseStream);
|
xDoc.LoadXml(databaseString);
|
||||||
|
|
||||||
XmlNodeList XMLRegionList = xDoc.GetElementsByTagName("REGIONS");
|
XmlNodeList XMLRegionList = xDoc.GetElementsByTagName("REGIONS");
|
||||||
XmlNodeList ChildrenOfTheNode = XMLRegionList[0].ChildNodes;
|
XmlNodeList ChildrenOfTheNode = XMLRegionList[0].ChildNodes;
|
||||||
|
@ -50,7 +50,7 @@ namespace NUS_Downloader
|
|||||||
|
|
||||||
// Cross-thread Windows Formsing
|
// Cross-thread Windows Formsing
|
||||||
private delegate void AddToolStripItemToStripCallback(
|
private delegate void AddToolStripItemToStripCallback(
|
||||||
int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes);
|
ToolStripMenuItem menulist, ToolStripMenuItem additionitem);
|
||||||
private delegate void WriteStatusCallback(string Update);
|
private delegate void WriteStatusCallback(string Update);
|
||||||
private delegate void BootChecksCallback();
|
private delegate void BootChecksCallback();
|
||||||
private delegate void SetEnableForDownloadCallback(bool enabled);
|
private delegate void SetEnableForDownloadCallback(bool enabled);
|
||||||
@ -183,6 +183,7 @@ namespace NUS_Downloader
|
|||||||
databaseButton.Text = "Download DB"; */
|
databaseButton.Text = "Download DB"; */
|
||||||
DatabaseEnabled(false);
|
DatabaseEnabled(false);
|
||||||
updateDatabaseToolStripMenuItem.Enabled = true;
|
updateDatabaseToolStripMenuItem.Enabled = true;
|
||||||
|
updateDatabaseToolStripMenuItem.Visible = true;
|
||||||
updateDatabaseToolStripMenuItem.Text = "Download Database";
|
updateDatabaseToolStripMenuItem.Text = "Download Database";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -767,6 +768,58 @@ namespace NUS_Downloader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void FillDatabaseStrip(BackgroundWorker worker)
|
private void FillDatabaseStrip(BackgroundWorker worker)
|
||||||
{
|
{
|
||||||
|
// Something needs to be done to remove this i guess
|
||||||
|
//Control.CheckForIllegalCrossThreadCalls = false;
|
||||||
|
|
||||||
|
Database databaseObj = new Database();
|
||||||
|
databaseObj.LoadDatabaseToStream(Path.Combine(CURRENT_DIR, "database.xml"));
|
||||||
|
|
||||||
|
ToolStripMenuItem[] systemItems = databaseObj.LoadSystemTitles();
|
||||||
|
for (int a = 0; a < systemItems.Length; a++)
|
||||||
|
{
|
||||||
|
systemItems[a].DropDownItemClicked += new ToolStripItemClickedEventHandler(sysitem_versionclicked);
|
||||||
|
AddToolStripItemToStrip(SystemMenuList, systemItems[a]);
|
||||||
|
//SystemMenuList.DropDownItems.Add(systemItems[a]);
|
||||||
|
}
|
||||||
|
SetPropertyThreadSafe(SystemMenuList, true, "Enabled");
|
||||||
|
SetPropertyThreadSafe(SystemMenuList, true, "Visible");
|
||||||
|
|
||||||
|
ToolStripMenuItem[] iosItems = databaseObj.LoadIosTitles();
|
||||||
|
for (int a = 0; a < iosItems.Length; a++)
|
||||||
|
{
|
||||||
|
iosItems[a].DropDownItemClicked += new ToolStripItemClickedEventHandler(sysitem_versionclicked);
|
||||||
|
AddToolStripItemToStrip(IOSMenuList, iosItems[a]);
|
||||||
|
//IOSMenuList.DropDownItems.Add(iosItems[a]);
|
||||||
|
}
|
||||||
|
SetPropertyThreadSafe(IOSMenuList, true, "Enabled");
|
||||||
|
SetPropertyThreadSafe(IOSMenuList, true, "Visible");
|
||||||
|
|
||||||
|
ToolStripMenuItem[][] vcItems = databaseObj.LoadVirtualConsoleTitles();
|
||||||
|
for (int a = 0; a < vcItems.Length; a++)
|
||||||
|
{
|
||||||
|
for (int b = 0; b < vcItems[a].Length; b++)
|
||||||
|
{
|
||||||
|
vcItems[a][b].DropDownItemClicked += new ToolStripItemClickedEventHandler(wwitem_regionclicked);
|
||||||
|
AddToolStripItemToStrip((ToolStripMenuItem)VCMenuList.DropDownItems[a], vcItems[a][b]);
|
||||||
|
//tsmi.DropDownItems.Add(vcItems[a][b]);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SetPropertyThreadSafe(VCMenuList, true, "Enabled");
|
||||||
|
SetPropertyThreadSafe(VCMenuList, true, "Visible");
|
||||||
|
|
||||||
|
ToolStripMenuItem[] wwItems = databaseObj.LoadWiiWareTitles();
|
||||||
|
for (int a = 0; a < wwItems.Length; a++)
|
||||||
|
{
|
||||||
|
wwItems[a].DropDownItemClicked += new ToolStripItemClickedEventHandler(sysitem_versionclicked);
|
||||||
|
AddToolStripItemToStrip(WiiWareMenuList, wwItems[a]);
|
||||||
|
//WiiWareMenuList.DropDownItems.Add(wwItems[a]);
|
||||||
|
}
|
||||||
|
SetPropertyThreadSafe(WiiWareMenuList, true, "Enabled");
|
||||||
|
SetPropertyThreadSafe(WiiWareMenuList, true, "Visible");
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
// Load database.xml into memorystream to perhaps reduce disk reads?
|
// Load database.xml into memorystream to perhaps reduce disk reads?
|
||||||
string databasestr = File.ReadAllText(Path.Combine(CURRENT_DIR, "database.xml"));
|
string databasestr = File.ReadAllText(Path.Combine(CURRENT_DIR, "database.xml"));
|
||||||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||||
@ -899,7 +952,7 @@ namespace NUS_Downloader
|
|||||||
SetPropertyThreadSafe(IOSMenuList, true, "Enabled");
|
SetPropertyThreadSafe(IOSMenuList, true, "Enabled");
|
||||||
break;
|
break;
|
||||||
case "SYS":
|
case "SYS":
|
||||||
SetPropertyThreadSafe(SystemMenuList, true, "Enabled");
|
|
||||||
break;
|
break;
|
||||||
case "VC":
|
case "VC":
|
||||||
SetPropertyThreadSafe(VCMenuList, true, "Enabled");
|
SetPropertyThreadSafe(VCMenuList, true, "Enabled");
|
||||||
@ -908,7 +961,7 @@ namespace NUS_Downloader
|
|||||||
SetPropertyThreadSafe(WiiWareMenuList, true, "Enabled");
|
SetPropertyThreadSafe(WiiWareMenuList, true, "Enabled");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -917,17 +970,20 @@ namespace NUS_Downloader
|
|||||||
/// <param name="type">The type.</param>
|
/// <param name="type">The type.</param>
|
||||||
/// <param name="additionitem">The additionitem.</param>
|
/// <param name="additionitem">The additionitem.</param>
|
||||||
/// <param name="attributes">The attributes.</param>
|
/// <param name="attributes">The attributes.</param>
|
||||||
private void AddToolStripItemToStrip(int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes)
|
private void AddToolStripItemToStrip(ToolStripMenuItem menulist, ToolStripMenuItem additionitem)
|
||||||
{
|
{
|
||||||
Debug.WriteLine(String.Format("Adding item (Type: {0})...", type));
|
Debug.WriteLine(String.Format("Adding item"));
|
||||||
// Check if thread-safe
|
|
||||||
if (this.InvokeRequired)
|
if (this.InvokeRequired)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("InvokeRequired...");
|
Debug.WriteLine("InvokeRequired...");
|
||||||
AddToolStripItemToStripCallback atsitsc = new AddToolStripItemToStripCallback(AddToolStripItemToStrip);
|
AddToolStripItemToStripCallback atsitsc = new AddToolStripItemToStripCallback(AddToolStripItemToStrip);
|
||||||
this.Invoke(atsitsc, new object[] {type, additionitem, attributes});
|
this.Invoke(atsitsc, new object[] {menulist, additionitem});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menulist.DropDownItems.Add(additionitem);
|
||||||
|
/*
|
||||||
// Deal with VC list depth...
|
// Deal with VC list depth...
|
||||||
if (type == 2)
|
if (type == 2)
|
||||||
{
|
{
|
||||||
@ -1014,7 +1070,7 @@ namespace NUS_Downloader
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
additionitem.DropDownItemClicked += new ToolStripItemClickedEventHandler(sysitem_versionclicked);
|
additionitem.DropDownItemClicked += new ToolStripItemClickedEventHandler(sysitem_versionclicked);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deepitem_clicked(object sender, ToolStripItemClickedEventArgs e)
|
private void deepitem_clicked(object sender, ToolStripItemClickedEventArgs e)
|
||||||
@ -2069,7 +2125,8 @@ namespace NUS_Downloader
|
|||||||
{
|
{
|
||||||
for (int a = 0; a < databaseStrip.Items.Count; a++)
|
for (int a = 0; a < databaseStrip.Items.Count; a++)
|
||||||
{
|
{
|
||||||
databaseStrip.Items[a].Enabled = false;
|
databaseStrip.Items[a].Enabled = enabled;
|
||||||
|
databaseStrip.Items[a].Visible = enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user