Create Constants class and consolodate

This commit is contained in:
Matt Nadareski
2016-05-22 13:15:13 -07:00
parent e8224606b7
commit 66795c8b18
12 changed files with 192 additions and 214 deletions

View File

@@ -7,14 +7,6 @@ namespace SabreTools.Helper
{
public class Build
{
/// <summary>
/// The current toolset version to be used by all child applications
/// </summary>
public static string Version
{
get { return "0.7.5.0"; }
}
/// <summary>
/// Returns true if running in a Mono environment
/// </summary>
@@ -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);

View File

@@ -14,11 +14,6 @@ namespace SabreTools.Helper
/// </summary>
public class Converters
{
// Regex matching patterns
private static string _headerPatternCMP = @"(^.*?) \($";
private static string _itemPatternCMP = @"^\s*(\S*?) (.*)";
private static string _endPatternCMP = @"^\s*\)\s*$";
/// <summary>
/// Convert a ClrMamePro style DAT to an Logiqx XML derived DAT
/// </summary>
@@ -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;

View File

@@ -0,0 +1,51 @@
namespace SabreTools.Helper
{
public class Constants
{
/// <summary>
/// The current toolset version to be used by all child applications
/// </summary>
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*$";
}
}

View File

@@ -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";
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
@@ -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

View File

@@ -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";
/// <summary>
/// Get what type of DAT the input file is
/// </summary>
@@ -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))

View File

@@ -90,16 +90,17 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Data\Constants.cs" />
<Compile Include="Converters.cs" />
<Compile Include="CRC32.cs" />
<Compile Include="DBTools.cs" />
<Compile Include="Enums.cs" />
<Compile Include="Data\Enums.cs" />
<Compile Include="Logger.cs" />
<Compile Include="Output.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Remapping.cs" />
<Compile Include="RomManipulation.cs" />
<Compile Include="Structs.cs" />
<Compile Include="Data\Structs.cs" />
<Compile Include="Style.cs" />
<Compile Include="Build.cs" />
</ItemGroup>