diff --git a/DATabase/Generate.cs b/DATabase/Generate.cs index bcf00237..c8c44152 100644 --- a/DATabase/Generate.cs +++ b/DATabase/Generate.cs @@ -103,6 +103,12 @@ namespace DATabase // Retrieve the list of processed roms List 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)) { diff --git a/DATabase/Importer.cs b/DATabase/Importer.cs index 85c51eb0..1392f8cb 100644 --- a/DATabase/Importer.cs +++ b/DATabase/Importer.cs @@ -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,11 +228,147 @@ namespace DATabase } // Attempt to open the given file - StreamReader sr; try { FileStream fs = File.OpenRead(_filepath); - sr = new StreamReader(fs); + StreamReader sr = new StreamReader(fs); + + // Set necessary dat values + string format = ""; + bool machinefound = false; + string machinename = ""; + string description = ""; + long gameid = 0; + bool comment = false; + + // Parse the file for its rom information + while (sr.Peek() > 0) + { + string line = sr.ReadLine(); + + // First each string has to be normalized + line = Style.NormalizeChars(line); + + // If the input style hasn't been set, set it according to the header + if (format == "") + { + if (line.IndexOf("") != -1) + { + comment = false; + } + else if (line.IndexOf("") != -1) - { - comment = false; - } - else if (line.IndexOf("