Fix generate and import code for other DAT types

This commit is contained in:
Matt Nadareski
2016-03-18 15:01:00 -07:00
parent 5ddfec5360
commit 22d50e3162
2 changed files with 152 additions and 151 deletions

View File

@@ -103,6 +103,12 @@ namespace DATabase
// Retrieve the list of processed roms
List<RomData> roms = ProcessRoms();
// If the output is null, nothing was found so return false
if (roms == null)
{
return false;
}
// Create a name for the file based on the retrieved information
string version = DateTime.Now.ToString("yyyyMMddHHmmss");
string datname = systemname + " (" + sourcename + " " + version + ")";
@@ -234,7 +240,7 @@ JOIN checksums
(!srcmerged ? " sources.id=" + _source : "") +
(!srcmerged && !sysmerged ? " AND" : "") +
(!sysmerged ? " systems.id=" + _system : "") +
(merged ? " GROUP BY checksums.size, checksums.crc, checksums.md5, checksums.sha1" : "") +
(merged ? "\nGROUP BY checksums.size, checksums.crc, checksums.md5, checksums.sha1" : "") +
"\nORDER BY systems.id, sources.id, games.name, files.name";
using (SQLiteConnection dbc = new SQLiteConnection(_connectionString))
{

View File

@@ -3,6 +3,7 @@ using System.Data.SQLite;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Reflection;
@@ -29,7 +30,7 @@ namespace DATabase
private static string _defaultDatePattern = @"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})";
private static string _nointroDatePattern = @"(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})";
private static string _redumpDatePattern = @"(\d{4})(\d{2})(\d{2}) (\d{2})-(\d{2})-(\d{2})";
private static string _tosecDatePattern = @"(\d{4})-(\d{2})-(\d{2}))";
private static string _tosecDatePattern = @"(\d{4})-(\d{2})-(\d{2})";
private enum DatType
{
@@ -104,7 +105,7 @@ namespace DATabase
// If the type is still unmatched, the data can't be imported yet
else
{
Console.WriteLine("File " + filename + " cannot be imported at this time.");
Console.WriteLine("File " + filename + " cannot be imported at this time because it is not a known pattern.\nPlease try again with an unrenamed version.");
return false;
}
@@ -178,11 +179,6 @@ namespace DATabase
break;
}
/*
Console.WriteLine(manufacturer + " - " + system + " (" + source + " " + date + ")");
return true;
*/
// Check to make sure that the manufacturer and system are valid according to the database
int sysid = -1;
string query = "SELECT id FROM systems WHERE manufacturer='" + manufacturer + "' AND system='" + system +"'";
@@ -232,17 +228,10 @@ namespace DATabase
}
// Attempt to open the given file
StreamReader sr;
try
{
FileStream fs = File.OpenRead(_filepath);
sr = new StreamReader(fs);
}
catch (Exception ex)
{
Console.WriteLine(ex);
return false;
}
StreamReader sr = new StreamReader(fs);
// Set necessary dat values
string format = "";
@@ -275,10 +264,6 @@ namespace DATabase
{
format = "romvault";
}
else
{
format = "unknown";
}
}
// If there's an XML-style comment, stop the presses and skip until it's over
@@ -298,8 +283,9 @@ namespace DATabase
{
machinefound = true;
XmlReader xml = XmlReader.Create(new StringReader(line + (line.IndexOf("<machine") != -1 ? "</machine>" : "</game>")));
machinename = xml.GetAttribute("name");
XElement xml = XElement.Parse(line + (line.IndexOf("<machine") != -1 ? "</machine>" : "</game>"));
machinename = xml.Attribute("name").Value;
gameid = AddGame(sysid, machinename, srcid);
}
else if (line.IndexOf("<rom") != -1 && machinefound)
@@ -326,8 +312,8 @@ namespace DATabase
{
machinefound = true;
XmlReader xml = XmlReader.Create(new StringReader(line + "</software>"));
machinename = xml.GetAttribute("name");
XElement xml = XElement.Parse(line + (line.IndexOf("<machine") != -1 ? "</machine>" : "</game>"));
machinename = xml.Attribute("name").Value;
gameid = AddGame(sysid, machinename, srcid);
}
else if (line.IndexOf("<rom") != -1 && machinefound)
@@ -371,7 +357,7 @@ namespace DATabase
gameid = AddGame(sysid, machinename, srcid);
}
else if (line.IndexOf(")") != -1)
else if (line.IndexOf("description \"") == -1 && line.IndexOf(")") != -1)
{
machinefound = false;
machinename = "";
@@ -381,6 +367,15 @@ namespace DATabase
}
}
sr.Close();
fs.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex);
return false;
}
return true;
}
@@ -442,10 +437,10 @@ namespace DATabase
private bool AddRom(string line, string machinename, string romtype, long gameid, string date)
{
XmlReader xml = XmlReader.Create(new StringReader(line));
return AddRomHelper(machinename, romtype, gameid, xml.GetAttribute("name"),
date, Int32.Parse(xml.GetAttribute("size")), xml.GetAttribute("crc"),
xml.GetAttribute("md5"), xml.GetAttribute("sha1"));
XElement xml = XElement.Parse(line);
return AddRomHelper(machinename, romtype, gameid, xml.Attribute("name").Value,
date, Int32.Parse(xml.Attribute("size").Value), xml.Attribute("crc").Value,
xml.Attribute("md5").Value, xml.Attribute("sha1").Value);
}
private bool AddRomOld(string line, string machinename, string romtype, long gameid, string date)