mirror of
https://github.com/WiiDatabase/nusdownloader.git
synced 2024-11-27 04:34:14 +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",
|
||||
"SMS", "SNES", "TG16", "TGCD", "ARC" };
|
||||
|
||||
MemoryStream databaseStream;
|
||||
private string databaseString;
|
||||
|
||||
private Image green = Properties.Resources.bullet_green;
|
||||
private Image orange = Properties.Resources.bullet_orange;
|
||||
@ -34,43 +34,43 @@ namespace NUS_Downloader
|
||||
public void LoadDatabaseToStream(string databaseFile)
|
||||
{
|
||||
// Load database.xml into MemoryStream
|
||||
string databasestr = File.ReadAllText(databaseFile);
|
||||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||
databaseString = File.ReadAllText(databaseFile);
|
||||
/*System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||
byte[] databasebytes = encoding.GetBytes(databasestr);
|
||||
|
||||
// Load the memory stream
|
||||
databaseStream = new MemoryStream(databasebytes);
|
||||
databaseStream.Seek(0, SeekOrigin.Begin);
|
||||
databaseStream.Seek(0, SeekOrigin.Begin);*/
|
||||
}
|
||||
|
||||
public string GetDatabaseVersion()
|
||||
{
|
||||
if (databaseStream.Length < 1)
|
||||
if (databaseString.Length < 1)
|
||||
{
|
||||
throw new Exception("Load the database into a memory stream first!");
|
||||
}
|
||||
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
xDoc.Load(databaseStream);
|
||||
xDoc.LoadXml(databaseString);
|
||||
XmlNodeList DatabaseList = xDoc.GetElementsByTagName("database");
|
||||
XmlAttributeCollection Attributes = DatabaseList[0].Attributes;
|
||||
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!");
|
||||
}
|
||||
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
xDoc.Load(databaseStream);
|
||||
|
||||
ToolStripItemCollection systemTitleCollection = new ToolStripItemCollection(null, null);
|
||||
xDoc.LoadXml(databaseString);
|
||||
|
||||
XmlNodeList SystemTitlesXMLNodes = xDoc.GetElementsByTagName(SystemTag);
|
||||
|
||||
ToolStripMenuItem[] systemTitleCollection = new ToolStripMenuItem[SystemTitlesXMLNodes.Count];
|
||||
|
||||
for (int x = 0; x < SystemTitlesXMLNodes.Count; x++)
|
||||
{
|
||||
ToolStripMenuItem XMLToolStripItem = new ToolStripMenuItem();
|
||||
@ -157,25 +157,23 @@ namespace NUS_Downloader
|
||||
}
|
||||
}
|
||||
//AddToolStripItemToStrip(i, XMLToolStripItem, XMLAttributes);
|
||||
systemTitleCollection.Add(XMLToolStripItem);
|
||||
systemTitleCollection[x] = XMLToolStripItem;
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
xDoc.Load(databaseStream);
|
||||
|
||||
ToolStripItemCollection iosTitleCollection = new ToolStripItemCollection(null, null);
|
||||
|
||||
xDoc.LoadXml(databaseString);
|
||||
XmlNodeList IosTitlesXMLNodes = xDoc.GetElementsByTagName(IosTag);
|
||||
ToolStripMenuItem[] iosTitleCollection = new ToolStripMenuItem[IosTitlesXMLNodes.Count];
|
||||
|
||||
for (int x = 0; x < IosTitlesXMLNodes.Count; x++)
|
||||
{
|
||||
@ -228,25 +226,28 @@ namespace NUS_Downloader
|
||||
XMLToolStripItem.Text = descname; //Huh
|
||||
}
|
||||
|
||||
iosTitleCollection.Add(XMLToolStripItem);
|
||||
iosTitleCollection[x] = XMLToolStripItem;
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
xDoc.Load(databaseStream);
|
||||
|
||||
ToolStripItemCollection[] vcTitleCollection = new ToolStripItemCollection[VcConsoles.Length];
|
||||
|
||||
xDoc.LoadXml(databaseString);
|
||||
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++)
|
||||
{
|
||||
@ -337,26 +338,27 @@ namespace NUS_Downloader
|
||||
for (int a = 0; a < VcConsoles.Length; 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;
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
xDoc.Load(databaseStream);
|
||||
|
||||
ToolStripItemCollection wwTitleCollection = new ToolStripItemCollection(null, null);
|
||||
|
||||
xDoc.LoadXml(databaseString);
|
||||
XmlNodeList WiiWareTitlesXMLNodes = xDoc.GetElementsByTagName(WwTag);
|
||||
ToolStripMenuItem[] wwTitleCollection = new ToolStripMenuItem[WiiWareTitlesXMLNodes.Count];
|
||||
|
||||
for (int x = 0; x < WiiWareTitlesXMLNodes.Count; x++)
|
||||
{
|
||||
@ -444,7 +446,7 @@ namespace NUS_Downloader
|
||||
}
|
||||
}
|
||||
|
||||
wwTitleCollection.Add(XMLToolStripItem);
|
||||
wwTitleCollection[x] = XMLToolStripItem;
|
||||
}
|
||||
|
||||
return wwTitleCollection;
|
||||
@ -475,13 +477,13 @@ namespace NUS_Downloader
|
||||
<region index=12>58 (Some Homebrew)</region>
|
||||
</REGIONS>
|
||||
*/
|
||||
if (databaseStream.Length < 1)
|
||||
if (databaseString.Length < 1)
|
||||
{
|
||||
throw new Exception("Load the database into a memory stream first!");
|
||||
}
|
||||
|
||||
XmlDocument xDoc = new XmlDocument();
|
||||
xDoc.Load(databaseStream);
|
||||
xDoc.LoadXml(databaseString);
|
||||
|
||||
XmlNodeList XMLRegionList = xDoc.GetElementsByTagName("REGIONS");
|
||||
XmlNodeList ChildrenOfTheNode = XMLRegionList[0].ChildNodes;
|
||||
|
@ -50,7 +50,7 @@ namespace NUS_Downloader
|
||||
|
||||
// Cross-thread Windows Formsing
|
||||
private delegate void AddToolStripItemToStripCallback(
|
||||
int type, ToolStripMenuItem additionitem, XmlAttributeCollection attributes);
|
||||
ToolStripMenuItem menulist, ToolStripMenuItem additionitem);
|
||||
private delegate void WriteStatusCallback(string Update);
|
||||
private delegate void BootChecksCallback();
|
||||
private delegate void SetEnableForDownloadCallback(bool enabled);
|
||||
@ -183,6 +183,7 @@ namespace NUS_Downloader
|
||||
databaseButton.Text = "Download DB"; */
|
||||
DatabaseEnabled(false);
|
||||
updateDatabaseToolStripMenuItem.Enabled = true;
|
||||
updateDatabaseToolStripMenuItem.Visible = true;
|
||||
updateDatabaseToolStripMenuItem.Text = "Download Database";
|
||||
}
|
||||
else
|
||||
@ -767,6 +768,58 @@ namespace NUS_Downloader
|
||||
/// </summary>
|
||||
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?
|
||||
string databasestr = File.ReadAllText(Path.Combine(CURRENT_DIR, "database.xml"));
|
||||
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
|
||||
@ -899,7 +952,7 @@ namespace NUS_Downloader
|
||||
SetPropertyThreadSafe(IOSMenuList, true, "Enabled");
|
||||
break;
|
||||
case "SYS":
|
||||
SetPropertyThreadSafe(SystemMenuList, true, "Enabled");
|
||||
|
||||
break;
|
||||
case "VC":
|
||||
SetPropertyThreadSafe(VCMenuList, true, "Enabled");
|
||||
@ -908,7 +961,7 @@ namespace NUS_Downloader
|
||||
SetPropertyThreadSafe(WiiWareMenuList, true, "Enabled");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -917,17 +970,20 @@ namespace NUS_Downloader
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="additionitem">The additionitem.</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));
|
||||
// Check if thread-safe
|
||||
Debug.WriteLine(String.Format("Adding item"));
|
||||
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
Debug.WriteLine("InvokeRequired...");
|
||||
AddToolStripItemToStripCallback atsitsc = new AddToolStripItemToStripCallback(AddToolStripItemToStrip);
|
||||
this.Invoke(atsitsc, new object[] {type, additionitem, attributes});
|
||||
this.Invoke(atsitsc, new object[] {menulist, additionitem});
|
||||
return;
|
||||
}
|
||||
|
||||
menulist.DropDownItems.Add(additionitem);
|
||||
/*
|
||||
// Deal with VC list depth...
|
||||
if (type == 2)
|
||||
{
|
||||
@ -1014,7 +1070,7 @@ namespace NUS_Downloader
|
||||
break;
|
||||
}
|
||||
additionitem.DropDownItemClicked += new ToolStripItemClickedEventHandler(sysitem_versionclicked);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
private void deepitem_clicked(object sender, ToolStripItemClickedEventArgs e)
|
||||
@ -2069,7 +2125,8 @@ namespace NUS_Downloader
|
||||
{
|
||||
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