diff --git a/DATabase/Import.cs b/DATabase/Import.cs index c10e22c8..6e7b6e43 100644 --- a/DATabase/Import.cs +++ b/DATabase/Import.cs @@ -19,36 +19,6 @@ namespace SabreTools private string _connectionString; private Logger _logger; - // Regex File Name Patterns - private static string _defaultPattern = @"^(.+?) - (.+?) \((.*) (.*)\)\.dat$"; - private static string _defaultSpecialPattern = @"^(.+?) - (.+?) \((.*) (.*)\)\.xml$"; - private static string _goodPattern = @"^(Good.*?)_.*\.dat"; - private static string _goodXmlPattern = @"^(Good.*?)_.*\.xml"; - private static string _mamePattern = @"^(.*)\.xml$"; - private static string _maybeIntroPattern = @"(.*?) \[T-En\].*\((\d{8})\)\.dat$"; - private static string _noIntroPattern = @"^(.*?) \((\d{8}-\d{6})_CM\)\.dat$"; - private static string _noIntroNumberedPattern = @"(.*? - .*?) \(\d.*?_CM\).dat"; - private static string _noIntroSpecialPattern = @"(.*? - .*?) \((\d{8})\)\.dat"; - private static string _nonGoodPattern = @"^(NonGood.*?)( .*?)?.xml"; - private static string _nonGoodSpecialPattern = @"^(NonGood.*?)( .*)?.dat"; - private static string _redumpPattern = @"^(.*?) \((\d{8} \d{2}-\d{2}-\d{2})\)\.dat$"; - private static string _redumpBiosPattern = @"^(.*?) \(\d+\) \((\d{4}-\d{2}-\d{2})\)\.dat$"; - private static string _tosecPattern = @"^(.*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; - private static string _tosecSpecialPatternA = @"^(.*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; - private static string _tosecSpecialPatternB = @"^(.*? - .*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; - private static string _truripPattern = @"^(.*) - .* \(trurip_XML\)\.dat$"; - private static string _zandroPattern = @"^SMW-.*.xml"; - - // Regex Mapped Name Patterns - private static string _remappedPattern = @"^(.*) - (.*)$"; - - // Regex Date Patterns - 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 _noIntroSpecialDatePattern = @"(\d{4})(\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})"; - /// /// Initialize an Import object with the given information /// @@ -80,88 +50,88 @@ namespace SabreTools GroupCollection fileinfo; DatType type = DatType.none; - if (Regex.IsMatch(filename, _nonGoodPattern)) + if (Regex.IsMatch(filename, Constants.NonGoodPattern)) { - fileinfo = Regex.Match(filename, _nonGoodPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NonGoodPattern).Groups; type = DatType.NonGood; } - else if (Regex.IsMatch(filename, _nonGoodSpecialPattern)) + else if (Regex.IsMatch(filename, Constants.NonGoodSpecialPattern)) { - fileinfo = Regex.Match(filename, _nonGoodSpecialPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NonGoodSpecialPattern).Groups; type = DatType.NonGood; } - else if (Regex.IsMatch(filename, _goodPattern)) + else if (Regex.IsMatch(filename, Constants.GoodPattern)) { - fileinfo = Regex.Match(filename, _goodPattern).Groups; + fileinfo = Regex.Match(filename, Constants.GoodPattern).Groups; type = DatType.Good; } - else if (Regex.IsMatch(filename, _goodXmlPattern)) + else if (Regex.IsMatch(filename, Constants.GoodXmlPattern)) { - fileinfo = Regex.Match(filename, _goodXmlPattern).Groups; + fileinfo = Regex.Match(filename, Constants.GoodXmlPattern).Groups; type = DatType.Good; } - else if (Regex.IsMatch(filename, _maybeIntroPattern)) + else if (Regex.IsMatch(filename, Constants.MaybeIntroPattern)) { - fileinfo = Regex.Match(filename, _maybeIntroPattern).Groups; + fileinfo = Regex.Match(filename, Constants.MaybeIntroPattern).Groups; type = DatType.MaybeIntro; } - else if (Regex.IsMatch(filename, _noIntroPattern)) + else if (Regex.IsMatch(filename, Constants.NoIntroPattern)) { - fileinfo = Regex.Match(filename, _noIntroPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NoIntroPattern).Groups; type = DatType.NoIntro; } // For numbered DATs only - else if (Regex.IsMatch(filename, _noIntroNumberedPattern)) + else if (Regex.IsMatch(filename, Constants.NoIntroNumberedPattern)) { - fileinfo = Regex.Match(filename, _noIntroNumberedPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NoIntroNumberedPattern).Groups; type = DatType.NoIntro; } // For N-Gage and Gizmondo only - else if (Regex.IsMatch(filename, _noIntroSpecialPattern)) + else if (Regex.IsMatch(filename, Constants.NoIntroSpecialPattern)) { - fileinfo = Regex.Match(filename, _noIntroSpecialPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NoIntroSpecialPattern).Groups; type = DatType.NoIntro; } - else if (Regex.IsMatch(filename, _redumpPattern)) + else if (Regex.IsMatch(filename, Constants.RedumpPattern)) { - fileinfo = Regex.Match(filename, _redumpPattern).Groups; + fileinfo = Regex.Match(filename, Constants.RedumpPattern).Groups; type = DatType.Redump; } // For special BIOSes only - else if (Regex.IsMatch(filename, _redumpBiosPattern)) + else if (Regex.IsMatch(filename, Constants.RedumpBiosPattern)) { - fileinfo = Regex.Match(filename, _redumpBiosPattern).Groups; + fileinfo = Regex.Match(filename, Constants.RedumpBiosPattern).Groups; type = DatType.Redump; } - else if (Regex.IsMatch(filename, _tosecPattern)) + else if (Regex.IsMatch(filename, Constants.TosecPattern)) { - fileinfo = Regex.Match(filename, _tosecPattern).Groups; + fileinfo = Regex.Match(filename, Constants.TosecPattern).Groups; type = DatType.TOSEC; } - else if (Regex.IsMatch(filename, _truripPattern)) + else if (Regex.IsMatch(filename, Constants.TruripPattern)) { - fileinfo = Regex.Match(filename, _truripPattern).Groups; + fileinfo = Regex.Match(filename, Constants.TruripPattern).Groups; type = DatType.TruRip; } - else if (Regex.IsMatch(filename, _zandroPattern)) + else if (Regex.IsMatch(filename, Constants.ZandroPattern)) { filename = "Nintendo - Super Nintendo Entertainment System (Zandro " + File.GetLastWriteTime(_filepath).ToString("yyyyMMddHHmmss") + ").dat"; - fileinfo = Regex.Match(filename, _defaultPattern).Groups; + fileinfo = Regex.Match(filename, Constants.DefaultPattern).Groups; type = DatType.Custom; } - else if (Regex.IsMatch(filename, _defaultPattern)) + else if (Regex.IsMatch(filename, Constants.DefaultPattern)) { - fileinfo = Regex.Match(filename, _defaultPattern).Groups; + fileinfo = Regex.Match(filename, Constants.DefaultPattern).Groups; type = DatType.Custom; } - else if (Regex.IsMatch(filename, _defaultSpecialPattern)) + else if (Regex.IsMatch(filename, Constants.DefaultSpecialPattern)) { - fileinfo = Regex.Match(filename, _defaultSpecialPattern).Groups; + fileinfo = Regex.Match(filename, Constants.DefaultSpecialPattern).Groups; type = DatType.Custom; } - else if (Regex.IsMatch(filename, _mamePattern)) + else if (Regex.IsMatch(filename, Constants.MamePattern)) { - fileinfo = Regex.Match(filename, _mamePattern).Groups; + fileinfo = Regex.Match(filename, Constants.MamePattern).Groups; type = DatType.MAME; } // If the type is still unmatched, the data can't be imported yet @@ -188,7 +158,7 @@ namespace SabreTools _logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again"); return false; } - GroupCollection goodInfo = Regex.Match(Remapping.Good[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection goodInfo = Regex.Match(Remapping.Good[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = goodInfo[1].Value; system = goodInfo[2].Value; @@ -201,7 +171,7 @@ namespace SabreTools _logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again"); return false; } - GroupCollection mameInfo = Regex.Match(Remapping.MAME[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection mameInfo = Regex.Match(Remapping.MAME[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = mameInfo[1].Value; system = mameInfo[2].Value; @@ -214,13 +184,13 @@ namespace SabreTools _logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again"); return false; } - GroupCollection maybeIntroInfo = Regex.Match(Remapping.MaybeIntro[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection maybeIntroInfo = Regex.Match(Remapping.MaybeIntro[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = maybeIntroInfo[1].Value; system = maybeIntroInfo[2].Value; source = "Maybe-Intro"; datestring = fileinfo[2].Value; - GroupCollection miDateInfo = Regex.Match(datestring, _noIntroSpecialDatePattern).Groups; + GroupCollection miDateInfo = Regex.Match(datestring, Constants.NoIntroSpecialDatePattern).Groups; date = miDateInfo[1].Value + "-" + miDateInfo[2].Value + "-" + miDateInfo[3].Value + " 00:00:00"; break; case DatType.NoIntro: @@ -229,7 +199,7 @@ namespace SabreTools _logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again"); return false; } - GroupCollection nointroInfo = Regex.Match(Remapping.NoIntro[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection nointroInfo = Regex.Match(Remapping.NoIntro[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = nointroInfo[1].Value; system = nointroInfo[2].Value; @@ -238,17 +208,17 @@ namespace SabreTools { date = File.GetLastWriteTime(_filepath).ToString("yyyy-MM-dd HH:mm:ss"); } - else if (Regex.IsMatch(fileinfo[2].Value, _noIntroDatePattern)) + else if (Regex.IsMatch(fileinfo[2].Value, Constants.NoIntroDatePattern)) { datestring = fileinfo[2].Value; - GroupCollection niDateInfo = Regex.Match(datestring, _noIntroDatePattern).Groups; + GroupCollection niDateInfo = Regex.Match(datestring, Constants.NoIntroDatePattern).Groups; date = niDateInfo[1].Value + "-" + niDateInfo[2].Value + "-" + niDateInfo[3].Value + " " + niDateInfo[4].Value + ":" + niDateInfo[5].Value + ":" + niDateInfo[6].Value; } else { datestring = fileinfo[2].Value; - GroupCollection niDateInfo = Regex.Match(datestring, _noIntroSpecialDatePattern).Groups; + GroupCollection niDateInfo = Regex.Match(datestring, Constants.NoIntroSpecialDatePattern).Groups; date = niDateInfo[1].Value + "-" + niDateInfo[2].Value + "-" + niDateInfo[3].Value + " 00:00:00"; } break; @@ -258,7 +228,7 @@ namespace SabreTools _logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again"); return false; } - GroupCollection nonGoodInfo = Regex.Match(Remapping.NonGood[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection nonGoodInfo = Regex.Match(Remapping.NonGood[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = nonGoodInfo[1].Value; system = nonGoodInfo[2].Value; @@ -269,7 +239,7 @@ namespace SabreTools if (!Remapping.Redump.ContainsKey(fileinfo[1].Value)) { // Handle special case mappings found only in Redump - fileinfo = Regex.Match(filename, _redumpBiosPattern).Groups; + fileinfo = Regex.Match(filename, Constants.RedumpBiosPattern).Groups; if (!Remapping.Redump.ContainsKey(fileinfo[1].Value)) { @@ -277,21 +247,21 @@ namespace SabreTools return false; } } - GroupCollection redumpInfo = Regex.Match(Remapping.Redump[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection redumpInfo = Regex.Match(Remapping.Redump[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = redumpInfo[1].Value; system = redumpInfo[2].Value; source = "Redump"; datestring = fileinfo[2].Value; - if (Regex.IsMatch(datestring, _redumpDatePattern)) + if (Regex.IsMatch(datestring, Constants.RedumpDatePattern)) { - GroupCollection rdDateInfo = Regex.Match(datestring, _redumpDatePattern).Groups; + GroupCollection rdDateInfo = Regex.Match(datestring, Constants.RedumpDatePattern).Groups; date = rdDateInfo[1].Value + "-" + rdDateInfo[2].Value + "-" + rdDateInfo[3].Value + " " + rdDateInfo[4].Value + ":" + rdDateInfo[5].Value + ":" + rdDateInfo[6].Value; } else { - GroupCollection rdDateInfo = Regex.Match(datestring, _tosecDatePattern).Groups; + GroupCollection rdDateInfo = Regex.Match(datestring, Constants.TosecDatePattern).Groups; date = rdDateInfo[1].Value + "-" + rdDateInfo[2].Value + "-" + rdDateInfo[3].Value + " 00:00:00"; } @@ -300,11 +270,11 @@ namespace SabreTools if (!Remapping.TOSEC.ContainsKey(fileinfo[1].Value)) { // Handle special case mappings found only in TOSEC - fileinfo = Regex.Match(filename, _tosecSpecialPatternA).Groups; + fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternA).Groups; if (!Remapping.TOSEC.ContainsKey(fileinfo[1].Value)) { - fileinfo = Regex.Match(filename, _tosecSpecialPatternB).Groups; + fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternB).Groups; if (!Remapping.TOSEC.ContainsKey(fileinfo[1].Value)) { @@ -313,13 +283,13 @@ namespace SabreTools } } } - GroupCollection tosecInfo = Regex.Match(Remapping.TOSEC[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection tosecInfo = Regex.Match(Remapping.TOSEC[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = tosecInfo[1].Value; system = tosecInfo[2].Value; source = "TOSEC"; datestring = fileinfo[2].Value; - GroupCollection toDateInfo = Regex.Match(datestring, _tosecDatePattern).Groups; + GroupCollection toDateInfo = Regex.Match(datestring, Constants.TosecDatePattern).Groups; date = toDateInfo[1].Value + "-" + toDateInfo[2].Value + "-" + toDateInfo[3].Value + " 00:00:00"; break; case DatType.TruRip: @@ -328,7 +298,7 @@ namespace SabreTools _logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again"); return false; } - GroupCollection truripInfo = Regex.Match(Remapping.TruRip[fileinfo[1].Value], _remappedPattern).Groups; + GroupCollection truripInfo = Regex.Match(Remapping.TruRip[fileinfo[1].Value], Constants.RemappedPattern).Groups; manufacturer = truripInfo[1].Value; system = truripInfo[2].Value; @@ -342,7 +312,7 @@ namespace SabreTools source = fileinfo[3].Value; datestring = fileinfo[4].Value; - GroupCollection cDateInfo = Regex.Match(datestring, _defaultDatePattern).Groups; + GroupCollection cDateInfo = Regex.Match(datestring, Constants.DefaultDatePattern).Groups; date = cDateInfo[1].Value + "-" + cDateInfo[2].Value + "-" + cDateInfo[3].Value + " " + cDateInfo[4].Value + ":" + cDateInfo[5].Value + ":" + cDateInfo[6].Value; break; @@ -504,7 +474,7 @@ namespace SabreTools slc2.ExecuteNonQuery(); } - query = "SELECT last_insert_rowid()"; + query = "SELECT last_insertConstants.Rowid()"; using (SqliteCommand slc2 = new SqliteCommand(query, dbc)) { gameid = (long)slc2.ExecuteScalar(); @@ -569,7 +539,7 @@ SELECT files.id FROM files INSERT INTO files (setid, name, type, lastupdated) VALUES (" + gameid + ", '" + rom.Name.Replace("'", "''") + "', '" + rom.Type + "', '" + date + @"'); INSERT INTO checksums (file, size, crc, md5, sha1) -VALUES ((SELECT last_insert_rowid()), " + rom.Size + ", '" + rom.CRC + "'" + ", '" + rom.MD5 + "'" + ", '" + rom.SHA1 + @"'); +VALUES ((SELECT last_insertConstants.Rowid()), " + rom.Size + ", '" + rom.CRC + "'" + ", '" + rom.MD5 + "'" + ", '" + rom.SHA1 + @"'); COMMIT;"; using (SqliteCommand slc2 = new SqliteCommand(query, dbc)) { @@ -643,7 +613,7 @@ COMMIT;"; slc2.ExecuteNonQuery(); } - query = "SELECT last_insert_rowid()"; + query = "SELECT last_insertConstants.Rowid()"; using (SqliteCommand slc2 = new SqliteCommand(query, dbc)) { hashid = (long)slc2.ExecuteScalar(); diff --git a/DATabase/TrimMerge.cs b/DATabase/TrimMerge.cs index fd4d1209..acf4da90 100644 --- a/DATabase/TrimMerge.cs +++ b/DATabase/TrimMerge.cs @@ -10,8 +10,8 @@ namespace SabreTools public class TrimMerge { // Instance variables - private string _filename = ""; - private string _path = ""; + private string _filename; + private string _path; private bool _rename; private bool _forceunpack; private Logger _logger; diff --git a/DATabaseTwo/Import.cs b/DATabaseTwo/Import.cs index 66b8602f..341ee363 100644 --- a/DATabaseTwo/Import.cs +++ b/DATabaseTwo/Import.cs @@ -17,26 +17,6 @@ namespace SabreTools private Logger _logger; private bool _ignore; - // Regex File Name Patterns - private static string _defaultPattern = @"^(.+?) - (.+?) \((.*) (.*)\)\.dat$"; - private static string _defaultSpecialPattern = @"^(.+?) - (.+?) \((.*) (.*)\)\.xml$"; - private static string _goodPattern = @"^(Good.*?)_.*\.dat"; - private static string _goodXmlPattern = @"^(Good.*?)_.*\.xml"; - private static string _mamePattern = @"^(.*)\.xml$"; - private static string _maybeIntroPattern = @"(.*?) \[T-En\].*\((\d{8})\)\.dat$"; - private static string _noIntroPattern = @"^(.*?) \((\d{8}-\d{6})_CM\)\.dat$"; - private static string _noIntroNumberedPattern = @"(.*? - .*?) \(\d.*?_CM\).dat"; - private static string _noIntroSpecialPattern = @"(.*? - .*?) \((\d{8})\)\.dat"; - private static string _nonGoodPattern = @"^(NonGood.*?)( .*?)?.xml"; - private static string _nonGoodSpecialPattern = @"^(NonGood.*?)( .*)?.dat"; - private static string _redumpPattern = @"^(.*?) \((\d{8} \d{2}-\d{2}-\d{2})\)\.dat$"; - private static string _redumpBiosPattern = @"^(.*?) \(\d+\) \((\d{4}-\d{2}-\d{2})\)\.dat$"; - private static string _tosecPattern = @"^(.*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; - private static string _tosecSpecialPatternA = @"^(.*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; - private static string _tosecSpecialPatternB = @"^(.*? - .*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; - private static string _truripPattern = @"^(.*) - .* \(trurip_XML\)\.dat$"; - private static string _zandroPattern = @"^SMW-.*.xml"; - /// /// Initialize an Import object with the given information /// @@ -108,7 +88,7 @@ namespace SabreTools string squery = @"BEGIN; INSERT INTO dats (size, sha1, name) VALUES (" + (new FileInfo(file)).Length + ", '" + hash + "', '" + file.Replace("'", "''") + @"'); -SELECT last_insert_rowid(); +SELECT last_insertConstants.Rowid(); COMMIT;"; using (SqliteCommand sslc = new SqliteCommand(squery, dbc)) { @@ -189,7 +169,7 @@ COMMIT;"; string tquery = @"BEGIN; INSERT INTO source (name, url) VALUES ('" + source + @"', ''); -SELECT last_insert_rowid(); +SELECT last_insertConstants.Rowid(); COMMIT;"; using (SqliteCommand sslc = new SqliteCommand(tquery, dbc)) { @@ -263,9 +243,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), // Determine which dattype we have GroupCollection fileinfo; - if (Regex.IsMatch(filename, _nonGoodPattern)) + if (Regex.IsMatch(filename, Constants.NonGoodPattern)) { - fileinfo = Regex.Match(filename, _nonGoodPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NonGoodPattern).Groups; if (!Remapping.NonGood.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as NonGood but could not be mapped."); @@ -273,9 +253,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "NonGood"; } - else if (Regex.IsMatch(filename, _nonGoodSpecialPattern)) + else if (Regex.IsMatch(filename, Constants.NonGoodSpecialPattern)) { - fileinfo = Regex.Match(filename, _nonGoodSpecialPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NonGoodSpecialPattern).Groups; if (!Remapping.NonGood.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as NonGood but could not be mapped."); @@ -283,9 +263,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "NonGood"; } - else if (Regex.IsMatch(filename, _goodPattern)) + else if (Regex.IsMatch(filename, Constants.GoodPattern)) { - fileinfo = Regex.Match(filename, _goodPattern).Groups; + fileinfo = Regex.Match(filename, Constants.GoodPattern).Groups; if (!Remapping.Good.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as Good but could not be mapped."); @@ -293,13 +273,13 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "Good"; } - else if (Regex.IsMatch(filename, _goodXmlPattern)) + else if (Regex.IsMatch(filename, Constants.GoodXmlPattern)) { - fileinfo = Regex.Match(filename, _goodXmlPattern).Groups; + fileinfo = Regex.Match(filename, Constants.GoodXmlPattern).Groups; } - else if (Regex.IsMatch(filename, _maybeIntroPattern)) + else if (Regex.IsMatch(filename, Constants.MaybeIntroPattern)) { - fileinfo = Regex.Match(filename, _maybeIntroPattern).Groups; + fileinfo = Regex.Match(filename, Constants.MaybeIntroPattern).Groups; if (!Remapping.MaybeIntro.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as Maybe-Intro but could not be mapped."); @@ -307,9 +287,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "Maybe-Intro"; } - else if (Regex.IsMatch(filename, _noIntroPattern)) + else if (Regex.IsMatch(filename, Constants.NoIntroPattern)) { - fileinfo = Regex.Match(filename, _noIntroPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NoIntroPattern).Groups; if (!Remapping.NoIntro.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as No-Intro but could not be mapped."); @@ -318,9 +298,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), source = "no-Intro"; } // For numbered DATs only - else if (Regex.IsMatch(filename, _noIntroNumberedPattern)) + else if (Regex.IsMatch(filename, Constants.NoIntroNumberedPattern)) { - fileinfo = Regex.Match(filename, _noIntroNumberedPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NoIntroNumberedPattern).Groups; if (!Remapping.NoIntro.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as No-Intro but could not be mapped."); @@ -329,9 +309,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), source = "no-Intro"; } // For N-Gage and Gizmondo only - else if (Regex.IsMatch(filename, _noIntroSpecialPattern)) + else if (Regex.IsMatch(filename, Constants.NoIntroSpecialPattern)) { - fileinfo = Regex.Match(filename, _noIntroSpecialPattern).Groups; + fileinfo = Regex.Match(filename, Constants.NoIntroSpecialPattern).Groups; if (!Remapping.NoIntro.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as No-Intro but could not be mapped."); @@ -339,9 +319,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "no-Intro"; } - else if (Regex.IsMatch(filename, _redumpPattern)) + else if (Regex.IsMatch(filename, Constants.RedumpPattern)) { - fileinfo = Regex.Match(filename, _redumpPattern).Groups; + fileinfo = Regex.Match(filename, Constants.RedumpPattern).Groups; if (!Remapping.Redump.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as Redump but could not be mapped."); @@ -350,9 +330,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), source = "Redump"; } // For special BIOSes only - else if (Regex.IsMatch(filename, _redumpBiosPattern)) + else if (Regex.IsMatch(filename, Constants.RedumpBiosPattern)) { - fileinfo = Regex.Match(filename, _redumpBiosPattern).Groups; + fileinfo = Regex.Match(filename, Constants.RedumpBiosPattern).Groups; if (!Remapping.Redump.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as Redump but could not be mapped."); @@ -360,17 +340,17 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "Redump"; } - else if (Regex.IsMatch(filename, _tosecPattern)) + else if (Regex.IsMatch(filename, Constants.TosecPattern)) { - fileinfo = Regex.Match(filename, _tosecPattern).Groups; + fileinfo = Regex.Match(filename, Constants.TosecPattern).Groups; if (!Remapping.TOSEC.ContainsKey(fileinfo[1].Value)) { // Handle special case mappings found only in TOSEC - fileinfo = Regex.Match(filename, _tosecSpecialPatternA).Groups; + fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternA).Groups; if (!Remapping.TOSEC.ContainsKey(fileinfo[1].Value)) { - fileinfo = Regex.Match(filename, _tosecSpecialPatternB).Groups; + fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternB).Groups; if (!Remapping.TOSEC.ContainsKey(fileinfo[1].Value)) { @@ -381,9 +361,9 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "TOSEC"; } - else if (Regex.IsMatch(filename, _truripPattern)) + else if (Regex.IsMatch(filename, Constants.TruripPattern)) { - fileinfo = Regex.Match(filename, _truripPattern).Groups; + fileinfo = Regex.Match(filename, Constants.TruripPattern).Groups; if (!Remapping.TruRip.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as TruRip but could not be mapped."); @@ -391,23 +371,23 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'), } source = "trurip"; } - else if (Regex.IsMatch(filename, _zandroPattern)) + else if (Regex.IsMatch(filename, Constants.ZandroPattern)) { source = "Zandro"; } - else if (Regex.IsMatch(filename, _defaultPattern)) + else if (Regex.IsMatch(filename, Constants.DefaultPattern)) { - fileinfo = Regex.Match(filename, _defaultPattern).Groups; + fileinfo = Regex.Match(filename, Constants.DefaultPattern).Groups; source = fileinfo[3].Value; } - else if (Regex.IsMatch(filename, _defaultSpecialPattern)) + else if (Regex.IsMatch(filename, Constants.DefaultSpecialPattern)) { - fileinfo = Regex.Match(filename, _defaultSpecialPattern).Groups; + fileinfo = Regex.Match(filename, Constants.DefaultSpecialPattern).Groups; source = fileinfo[3].Value; } - else if (Regex.IsMatch(filename, _mamePattern)) + else if (Regex.IsMatch(filename, Constants.MamePattern)) { - fileinfo = Regex.Match(filename, _mamePattern).Groups; + fileinfo = Regex.Match(filename, Constants.MamePattern).Groups; if (!Remapping.MAME.ContainsKey(fileinfo[1].Value)) { _logger.Warning("The filename " + fileinfo[1].Value + " was matched as MAME but could not be mapped."); diff --git a/OfflineMerge/OfflineMerge.cs b/OfflineMerge/OfflineMerge.cs index 84a68bab..31fcfae7 100644 --- a/OfflineMerge/OfflineMerge.cs +++ b/OfflineMerge/OfflineMerge.cs @@ -317,10 +317,10 @@ namespace SabreTools for (int i = 0; i < roms.Count; i++) { RomData rom = roms[i]; - rom.Size = RomManipulation.SizeZero; - rom.CRC = RomManipulation.CRCZero; - rom.MD5 = RomManipulation.MD5Zero; - rom.SHA1 = RomManipulation.SHA1Zero; + rom.Size = Constants.SizeZero; + rom.CRC = Constants.CRCZero; + rom.MD5 = Constants.MD5Zero; + rom.SHA1 = Constants.SHA1Zero; temp.Add(rom); } netNew[key] = temp; @@ -335,10 +335,10 @@ namespace SabreTools for (int i = 0; i < roms.Count; i++) { RomData rom = roms[i]; - rom.Size = RomManipulation.SizeZero; - rom.CRC = RomManipulation.CRCZero; - rom.MD5 = RomManipulation.MD5Zero; - rom.SHA1 = RomManipulation.SHA1Zero; + rom.Size = Constants.SizeZero; + rom.CRC = Constants.CRCZero; + rom.MD5 = Constants.MD5Zero; + rom.SHA1 = Constants.SHA1Zero; temp.Add(rom); } unneeded[key] = temp; @@ -353,10 +353,10 @@ namespace SabreTools for (int i = 0; i < roms.Count; i++) { RomData rom = roms[i]; - rom.Size = RomManipulation.SizeZero; - rom.CRC = RomManipulation.CRCZero; - rom.MD5 = RomManipulation.MD5Zero; - rom.SHA1 = RomManipulation.SHA1Zero; + rom.Size = Constants.SizeZero; + rom.CRC = Constants.CRCZero; + rom.MD5 = Constants.MD5Zero; + rom.SHA1 = Constants.SHA1Zero; temp.Add(rom); } newMissing[key] = temp; @@ -371,10 +371,10 @@ namespace SabreTools for (int i = 0; i < roms.Count; i++) { RomData rom = roms[i]; - rom.Size = RomManipulation.SizeZero; - rom.CRC = RomManipulation.CRCZero; - rom.MD5 = RomManipulation.MD5Zero; - rom.SHA1 = RomManipulation.SHA1Zero; + rom.Size = Constants.SizeZero; + rom.CRC = Constants.CRCZero; + rom.MD5 = Constants.MD5Zero; + rom.SHA1 = Constants.SHA1Zero; temp.Add(rom); } have[key] = temp; @@ -485,10 +485,10 @@ namespace SabreTools for (int i = 0; i < roms.Count; i++) { RomData rom = roms[i]; - rom.Size = RomManipulation.SizeZero; - rom.CRC = RomManipulation.CRCZero; - rom.MD5 = RomManipulation.MD5Zero; - rom.SHA1 = RomManipulation.SHA1Zero; + rom.Size = Constants.SizeZero; + rom.CRC = Constants.CRCZero; + rom.MD5 = Constants.MD5Zero; + rom.SHA1 = Constants.SHA1Zero; temp.Add(rom); } have[key] = temp; @@ -555,10 +555,10 @@ namespace SabreTools for (int i = 0; i < roms.Count; i++) { RomData rom = roms[i]; - rom.Size = RomManipulation.SizeZero; - rom.CRC = RomManipulation.CRCZero; - rom.MD5 = RomManipulation.MD5Zero; - rom.SHA1 = RomManipulation.SHA1Zero; + rom.Size = Constants.SizeZero; + rom.CRC = Constants.CRCZero; + rom.MD5 = Constants.MD5Zero; + rom.SHA1 = Constants.SHA1Zero; temp.Add(rom); } have[key] = temp; diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index 656da896..0f245689 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -7,14 +7,6 @@ namespace SabreTools.Helper { public class Build { - /// - /// The current toolset version to be used by all child applications - /// - public static string Version - { - get { return "0.7.5.0"; } - } - /// /// Returns true if running in a Mono environment /// @@ -32,7 +24,7 @@ namespace SabreTools.Helper { // Dynamically create the header string string border = "+-----------------------------------------------------------------------------+"; - string mid = name + " " + Build.Version; + string mid = name + " " + Constants.Version; mid = "|" + mid.PadLeft(((77 - mid.Length) / 2) + mid.Length).PadRight(77) + "|"; // Set the console to ready state @@ -47,7 +39,7 @@ namespace SabreTools.Helper Console.BackgroundColor = ConsoleColor.Blue; } - Console.Title = "SabreTools-" + name + " " + Build.Version; + Console.Title = "SabreTools-" + name + " " + Constants.Version; // Output the header Console.WriteLine(border); diff --git a/SabreHelper/Converters.cs b/SabreHelper/Converters.cs index f8bcd97d..5166acaa 100644 --- a/SabreHelper/Converters.cs +++ b/SabreHelper/Converters.cs @@ -14,11 +14,6 @@ namespace SabreTools.Helper /// public class Converters { - // Regex matching patterns - private static string _headerPatternCMP = @"(^.*?) \($"; - private static string _itemPatternCMP = @"^\s*(\S*?) (.*)"; - private static string _endPatternCMP = @"^\s*\)\s*$"; - /// /// Convert a ClrMamePro style DAT to an Logiqx XML derived DAT /// @@ -40,9 +35,9 @@ namespace SabreTools.Helper } // If the line is the header or a game - if (Regex.IsMatch(line, _headerPatternCMP)) + if (Regex.IsMatch(line, Constants.HeaderPatternCMP)) { - GroupCollection gc = Regex.Match(line, _headerPatternCMP).Groups; + GroupCollection gc = Regex.Match(line, Constants.HeaderPatternCMP).Groups; if (gc[1].Value == "clrmamepro" || gc[1].Value == "romvault") { @@ -133,9 +128,9 @@ namespace SabreTools.Helper elem.Add(new XElement(temp)); } // If the line is anything but a rom or disk and we're in a block - else if (Regex.IsMatch(line, _itemPatternCMP) && block) + else if (Regex.IsMatch(line, Constants.ItemPatternCMP) && block) { - GroupCollection gc = Regex.Match(line, _itemPatternCMP).Groups; + GroupCollection gc = Regex.Match(line, Constants.ItemPatternCMP).Groups; if (gc[1].Value == "name" && elem.Name != "header") { @@ -149,7 +144,7 @@ namespace SabreTools.Helper } // If we find an end bracket that's not associated with anything else, the block is done - else if (Regex.IsMatch(line, _endPatternCMP) && block) + else if (Regex.IsMatch(line, Constants.EndPatternCMP) && block) { block = false; elem = elem.Parent; diff --git a/SabreHelper/Data/Constants.cs b/SabreHelper/Data/Constants.cs new file mode 100644 index 00000000..afa28bd3 --- /dev/null +++ b/SabreHelper/Data/Constants.cs @@ -0,0 +1,51 @@ +namespace SabreTools.Helper +{ + public class Constants + { + /// + /// The current toolset version to be used by all child applications + /// + public static string Version = "0.7.5.0"; + + // 0-byte file constants + public static long SizeZero = 0; + public static string CRCZero = "00000000"; + public static string MD5Zero = "d41d8cd98f00b204e9800998ecf8427e"; + public static string SHA1Zero = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; + + // Regex File Name Patterns + public static string DefaultPattern = @"^(.+?) - (.+?) \((.*) (.*)\)\.dat$"; + public static string DefaultSpecialPattern = @"^(.+?) - (.+?) \((.*) (.*)\)\.xml$"; + public static string GoodPattern = @"^(Good.*?)_.*\.dat"; + public static string GoodXmlPattern = @"^(Good.*?)_.*\.xml"; + public static string MamePattern = @"^(.*)\.xml$"; + public static string MaybeIntroPattern = @"(.*?) \[T-En\].*\((\d{8})\)\.dat$"; + public static string NoIntroPattern = @"^(.*?) \((\d{8}-\d{6})_CM\)\.dat$"; + public static string NoIntroNumberedPattern = @"(.*? - .*?) \(\d.*?_CM\).dat"; + public static string NoIntroSpecialPattern = @"(.*? - .*?) \((\d{8})\)\.dat"; + public static string NonGoodPattern = @"^(NonGood.*?)( .*?)?.xml"; + public static string NonGoodSpecialPattern = @"^(NonGood.*?)( .*)?.dat"; + public static string RedumpPattern = @"^(.*?) \((\d{8} \d{2}-\d{2}-\d{2})\)\.dat$"; + public static string RedumpBiosPattern = @"^(.*?) \(\d+\) \((\d{4}-\d{2}-\d{2})\)\.dat$"; + public static string TosecPattern = @"^(.*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; + public static string TosecSpecialPatternA = @"^(.*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; + public static string TosecSpecialPatternB = @"^(.*? - .*? - .*?) - .* \(TOSEC-v(\d{4}-\d{2}-\d{2})_CM\)\.dat$"; + public static string TruripPattern = @"^(.*) - .* \(trurip_XML\)\.dat$"; + public static string ZandroPattern = @"^SMW-.*.xml"; + + // Regex Mapped Name Patterns + public static string RemappedPattern = @"^(.*) - (.*)$"; + + // Regex Date Patterns + public static string DefaultDatePattern = @"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})"; + public static string NoIntroDatePattern = @"(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})"; + public static string NoIntroSpecialDatePattern = @"(\d{4})(\d{2})(\d{2})"; + public static string RedumpDatePattern = @"(\d{4})(\d{2})(\d{2}) (\d{2})-(\d{2})-(\d{2})"; + public static string TosecDatePattern = @"(\d{4})-(\d{2})-(\d{2})"; + + // Regex conversion patterns + public static string HeaderPatternCMP = @"(^.*?) \($"; + public static string ItemPatternCMP = @"^\s*(\S*?) (.*)"; + public static string EndPatternCMP = @"^\s*\)\s*$"; + } +} diff --git a/SabreHelper/Enums.cs b/SabreHelper/Data/Enums.cs similarity index 100% rename from SabreHelper/Enums.cs rename to SabreHelper/Data/Enums.cs diff --git a/SabreHelper/Structs.cs b/SabreHelper/Data/Structs.cs similarity index 100% rename from SabreHelper/Structs.cs rename to SabreHelper/Data/Structs.cs diff --git a/SabreHelper/Output.cs b/SabreHelper/Output.cs index 716651f3..c1e115a5 100644 --- a/SabreHelper/Output.cs +++ b/SabreHelper/Output.cs @@ -10,12 +10,6 @@ namespace SabreTools.Helper { public class Output { - // 0-byte file constants - public static long SizeZero = 0; - public static string CRCZero = "00000000"; - public static string MD5Zero = "d41d8cd98f00b204e9800998ecf8427e"; - public static string SHA1Zero = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; - /// /// Create and open an output file for writing direct from a dictionary /// @@ -250,10 +244,10 @@ namespace SabreTools.Helper if (datdata.OutputFormat != OutputFormat.SabreDat && datdata.OutputFormat != OutputFormat.MissFile) { rom.Name = "-"; - rom.Size = SizeZero; - rom.CRC = CRCZero; - rom.MD5 = MD5Zero; - rom.SHA1 = SHA1Zero; + rom.Size = Constants.SizeZero; + rom.CRC = Constants.CRCZero; + rom.MD5 = Constants.MD5Zero; + rom.SHA1 = Constants.SHA1Zero; } // Otherwise, set the new path and such, write out, and continue diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 0c338843..7f86ba8c 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -10,12 +10,6 @@ namespace SabreTools.Helper { public class RomManipulation { - // 0-byte file constants - public static long SizeZero = 0; - public static string CRCZero = "00000000"; - public static string MD5Zero = "d41d8cd98f00b204e9800998ecf8427e"; - public static string SHA1Zero = "da39a3ee5e6b4b0d3255bfef95601890afd80709"; - /// /// Get what type of DAT the input file is /// @@ -504,12 +498,13 @@ namespace SabreTools.Helper sha1 = (sha1 == "" ? "" : sha1.PadLeft(40, '0')); // If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info - if (subreader.Name == "rom" && (size == 0 || size == -1) && ((crc == CRCZero || crc == "") || md5 == MD5Zero || sha1 == SHA1Zero)) + if (subreader.Name == "rom" && (size == 0 || size == -1) && + ((crc == Constants.CRCZero || crc == "") || md5 == Constants.MD5Zero || sha1 == Constants.SHA1Zero)) { - size = SizeZero; - crc = CRCZero; - md5 = MD5Zero; - sha1 = SHA1Zero; + size = Constants.SizeZero; + crc = Constants.CRCZero; + md5 = Constants.MD5Zero; + sha1 = Constants.SHA1Zero; } // If the file has no size and it's not the above case, skip and log else if (subreader.Name == "rom" && (size == 0 || size == -1)) @@ -716,12 +711,12 @@ namespace SabreTools.Helper sha1 = (sha1 == "" ? "" : sha1.PadLeft(40, '0')); // If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info - if (xtr.GetAttribute("type") == "rom" && (size == 0 || size == -1) && ((crc == CRCZero || crc == "") || md5 == MD5Zero || sha1 == SHA1Zero)) + if (xtr.GetAttribute("type") == "rom" && (size == 0 || size == -1) && ((crc == Constants.CRCZero || crc == "") || md5 == Constants.MD5Zero || sha1 == Constants.SHA1Zero)) { - size = SizeZero; - crc = CRCZero; - md5 = MD5Zero; - sha1 = SHA1Zero; + size = Constants.SizeZero; + crc = Constants.CRCZero; + md5 = Constants.MD5Zero; + sha1 = Constants.SHA1Zero; } // If the file has no size and it's not the above case, skip and log else if (xtr.GetAttribute("type") == "rom" && (size == 0 || size == -1)) diff --git a/SabreHelper/SabreHelper.csproj b/SabreHelper/SabreHelper.csproj index a1b47597..e3239456 100644 --- a/SabreHelper/SabreHelper.csproj +++ b/SabreHelper/SabreHelper.csproj @@ -90,16 +90,17 @@ + - + - +