mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] Move object classes to DLL
This commit is contained in:
@@ -153,7 +153,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the list of processed roms
|
// Retrieve the list of processed roms
|
||||||
Dictionary<string, List<RomData>> dict = ProcessRoms();
|
Dictionary<string, List<Rom>> dict = ProcessRoms();
|
||||||
|
|
||||||
// If the output is null, nothing was found so return false
|
// If the output is null, nothing was found so return false
|
||||||
if (dict.Count == 0)
|
if (dict.Count == 0)
|
||||||
@@ -166,7 +166,7 @@ namespace SabreTools
|
|||||||
string intname = systemname + " (" + sourcename + ")";
|
string intname = systemname + " (" + sourcename + ")";
|
||||||
string datname = systemname + " (" + sourcename + " " + version + ")";
|
string datname = systemname + " (" + sourcename + " " + version + ")";
|
||||||
|
|
||||||
DatData datdata = new DatData
|
Dat datdata = new Dat
|
||||||
{
|
{
|
||||||
Name = intname,
|
Name = intname,
|
||||||
Description = datname,
|
Description = datname,
|
||||||
@@ -176,19 +176,19 @@ namespace SabreTools
|
|||||||
Author = "The Wizard of DATz",
|
Author = "The Wizard of DATz",
|
||||||
ForcePacking = ForcePacking.None,
|
ForcePacking = ForcePacking.None,
|
||||||
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
OutputFormat = (_old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
|
||||||
Roms = dict,
|
Files = dict,
|
||||||
};
|
};
|
||||||
|
|
||||||
return Output.WriteDatfile(datdata, _outdir, _logger);
|
return DatTools.WriteDatfile(datdata, _outdir, _logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Preprocess the rom data that is to be included in the outputted DAT
|
/// Preprocess the rom data that is to be included in the outputted DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A List of RomData objects containing all information about the files</returns>
|
/// <returns>A List of Rom objects containing all information about the files</returns>
|
||||||
public Dictionary<string, List<RomData>> ProcessRoms()
|
public Dictionary<string, List<Rom>> ProcessRoms()
|
||||||
{
|
{
|
||||||
Dictionary<string, List<RomData>> roms = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<Rom>> roms = new Dictionary<string, List<Rom>>();
|
||||||
|
|
||||||
// Check if we have listed sources or systems
|
// Check if we have listed sources or systems
|
||||||
bool sysmerged = (_systems == "" || _systems.Split(',').Length > 1);
|
bool sysmerged = (_systems == "" || _systems.Split(',').Length > 1);
|
||||||
@@ -236,39 +236,47 @@ JOIN checksums
|
|||||||
// Retrieve and process the roms for merging
|
// Retrieve and process the roms for merging
|
||||||
while (sldr.Read())
|
while (sldr.Read())
|
||||||
{
|
{
|
||||||
RomData temp = new RomData
|
Rom temp = new Rom
|
||||||
{
|
{
|
||||||
|
Name = sldr.GetString(7),
|
||||||
|
Type = (sldr.GetString(8) == "disk" ? ItemType.Disk : ItemType.Rom),
|
||||||
|
Machine = new Machine
|
||||||
|
{
|
||||||
|
Name = sldr.GetString(6),
|
||||||
Manufacturer = sldr.GetString(0),
|
Manufacturer = sldr.GetString(0),
|
||||||
|
},
|
||||||
|
Metadata = new SourceMetadata
|
||||||
|
{
|
||||||
System = sldr.GetString(1),
|
System = sldr.GetString(1),
|
||||||
SystemID = sldr.GetInt32(2),
|
SystemID = sldr.GetInt32(2),
|
||||||
Source = sldr.GetString(3),
|
Source = sldr.GetString(3),
|
||||||
URL = sldr.GetString(4),
|
|
||||||
SourceID = sldr.GetInt32(5),
|
SourceID = sldr.GetInt32(5),
|
||||||
Game = sldr.GetString(6),
|
},
|
||||||
Name = sldr.GetString(7),
|
HashData = new Hash
|
||||||
Type = sldr.GetString(8),
|
{
|
||||||
Size = sldr.GetInt64(9),
|
Size = sldr.GetInt64(9),
|
||||||
CRC = sldr.GetString(10),
|
CRC = sldr.GetString(10),
|
||||||
MD5 = sldr.GetString(11),
|
MD5 = sldr.GetString(11),
|
||||||
SHA1 = sldr.GetString(12),
|
SHA1 = sldr.GetString(12),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Rename the game associated if it's still valid and we allow renames
|
// Rename the game associated if it's still valid and we allow renames
|
||||||
if (merged && !_norename)
|
if (merged && !_norename)
|
||||||
{
|
{
|
||||||
temp.Game = temp.Game +
|
temp.Machine.Name = temp.Machine.Name +
|
||||||
(sysmerged ? " [" + temp.Manufacturer + " - " + temp.System + "]" : "") +
|
(sysmerged ? " [" + temp.Machine.Manufacturer + " - " + temp.Metadata.System + "]" : "") +
|
||||||
(srcmerged ? " [" + temp.Source + "]" : "");
|
(srcmerged ? " [" + temp.Metadata.Source + "]" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
string key = temp.Size + "-" + temp.CRC;
|
string key = temp.HashData.Size + "-" + temp.HashData.CRC;
|
||||||
if (roms.ContainsKey(key))
|
if (roms.ContainsKey(key))
|
||||||
{
|
{
|
||||||
roms[key].Add(temp);
|
roms[key].Add(temp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<RomData> templist = new List<RomData>();
|
List<Rom> templist = new List<Rom>();
|
||||||
templist.Add(temp);
|
templist.Add(temp);
|
||||||
roms.Add(key, templist);
|
roms.Add(key, templist);
|
||||||
}
|
}
|
||||||
@@ -336,7 +344,7 @@ JOIN source
|
|||||||
// If the hash is different than the last
|
// If the hash is different than the last
|
||||||
if (lastid != -1 && sldr.GetInt64(0) != lastid)
|
if (lastid != -1 && sldr.GetInt64(0) != lastid)
|
||||||
{
|
{
|
||||||
RomData temp = new RomData
|
Rom temp = new Rom
|
||||||
{
|
{
|
||||||
Manufacturer = manufacturer,
|
Manufacturer = manufacturer,
|
||||||
System = system,
|
System = system,
|
||||||
@@ -356,7 +364,7 @@ JOIN source
|
|||||||
// Rename the game associated if it's still valid and we allow renames
|
// Rename the game associated if it's still valid and we allow renames
|
||||||
if (merged && !_norename)
|
if (merged && !_norename)
|
||||||
{
|
{
|
||||||
temp.Game = temp.Game +
|
temp.Machine = temp.Machine +
|
||||||
(sysmerged ? " [" + temp.Manufacturer + " - " + temp.System + "]" : "") +
|
(sysmerged ? " [" + temp.Manufacturer + " - " + temp.System + "]" : "") +
|
||||||
(srcmerged ? " [" + temp.Source + "]" : "");
|
(srcmerged ? " [" + temp.Source + "]" : "");
|
||||||
}
|
}
|
||||||
@@ -368,7 +376,7 @@ JOIN source
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<RomData> templist = new List<RomData>();
|
List<Rom> templist = new List<Rom>();
|
||||||
templist.Add(temp);
|
templist.Add(temp);
|
||||||
roms.Add(key, templist);
|
roms.Add(key, templist);
|
||||||
}
|
}
|
||||||
@@ -427,7 +435,7 @@ JOIN source
|
|||||||
string lastname = "", lastgame = "";
|
string lastname = "", lastgame = "";
|
||||||
for (int i = 0; i < roms.Count; i++)
|
for (int i = 0; i < roms.Count; i++)
|
||||||
{
|
{
|
||||||
RomData rom = roms[i];
|
Rom rom = roms[i];
|
||||||
|
|
||||||
// Now relable any roms that have the same name inside of the same game
|
// Now relable any roms that have the same name inside of the same game
|
||||||
bool samename = false, samegame = false;
|
bool samename = false, samegame = false;
|
||||||
@@ -435,13 +443,13 @@ JOIN source
|
|||||||
{
|
{
|
||||||
samename = (lastname == rom.Name);
|
samename = (lastname == rom.Name);
|
||||||
}
|
}
|
||||||
if (rom.Game != "")
|
if (rom.Machine != "")
|
||||||
{
|
{
|
||||||
samegame = (lastgame == rom.Game);
|
samegame = (lastgame == rom.Machine);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastname = rom.Name;
|
lastname = rom.Name;
|
||||||
lastgame = rom.Game;
|
lastgame = rom.Machine;
|
||||||
|
|
||||||
// If the name and set are the same, rename it with whatever is different
|
// If the name and set are the same, rename it with whatever is different
|
||||||
if (samename && samegame)
|
if (samename && samegame)
|
||||||
@@ -150,12 +150,12 @@ namespace SabreTools
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case DatType.Good:
|
case DatType.Good:
|
||||||
if (!Remapping.DatMaps["Good"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["Good"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GroupCollection goodInfo = Regex.Match(Remapping.DatMaps["Good"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection goodInfo = Regex.Match(Mappings.DatMaps["Good"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = goodInfo[1].Value;
|
manufacturer = goodInfo[1].Value;
|
||||||
system = goodInfo[2].Value;
|
system = goodInfo[2].Value;
|
||||||
@@ -163,12 +163,12 @@ namespace SabreTools
|
|||||||
date = File.GetLastWriteTime(_filepath).ToString("yyyy-MM-dd HH:mm:ss");
|
date = File.GetLastWriteTime(_filepath).ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
break;
|
break;
|
||||||
case DatType.MAME:
|
case DatType.MAME:
|
||||||
if (!Remapping.DatMaps["MAME"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["MAME"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GroupCollection mameInfo = Regex.Match(Remapping.DatMaps["MAME"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection mameInfo = Regex.Match(Mappings.DatMaps["MAME"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = mameInfo[1].Value;
|
manufacturer = mameInfo[1].Value;
|
||||||
system = mameInfo[2].Value;
|
system = mameInfo[2].Value;
|
||||||
@@ -176,12 +176,12 @@ namespace SabreTools
|
|||||||
date = File.GetLastWriteTime(_filepath).ToString("yyyy-MM-dd HH:mm:ss");
|
date = File.GetLastWriteTime(_filepath).ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
break;
|
break;
|
||||||
case DatType.MaybeIntro:
|
case DatType.MaybeIntro:
|
||||||
if (!Remapping.DatMaps["MaybeIntro"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["MaybeIntro"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GroupCollection maybeIntroInfo = Regex.Match(Remapping.DatMaps["MaybeIntro"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection maybeIntroInfo = Regex.Match(Mappings.DatMaps["MaybeIntro"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = maybeIntroInfo[1].Value;
|
manufacturer = maybeIntroInfo[1].Value;
|
||||||
system = maybeIntroInfo[2].Value;
|
system = maybeIntroInfo[2].Value;
|
||||||
@@ -191,12 +191,12 @@ namespace SabreTools
|
|||||||
date = miDateInfo[1].Value + "-" + miDateInfo[2].Value + "-" + miDateInfo[3].Value + " 00:00:00";
|
date = miDateInfo[1].Value + "-" + miDateInfo[2].Value + "-" + miDateInfo[3].Value + " 00:00:00";
|
||||||
break;
|
break;
|
||||||
case DatType.NoIntro:
|
case DatType.NoIntro:
|
||||||
if (!Remapping.DatMaps["NoIntro"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["NoIntro"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GroupCollection nointroInfo = Regex.Match(Remapping.DatMaps["NoIntro"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection nointroInfo = Regex.Match(Mappings.DatMaps["NoIntro"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = nointroInfo[1].Value;
|
manufacturer = nointroInfo[1].Value;
|
||||||
system = nointroInfo[2].Value;
|
system = nointroInfo[2].Value;
|
||||||
@@ -220,12 +220,12 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DatType.NonGood:
|
case DatType.NonGood:
|
||||||
if (!Remapping.DatMaps["NonGood"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["NonGood"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GroupCollection nonGoodInfo = Regex.Match(Remapping.DatMaps["NonGood"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection nonGoodInfo = Regex.Match(Mappings.DatMaps["NonGood"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = nonGoodInfo[1].Value;
|
manufacturer = nonGoodInfo[1].Value;
|
||||||
system = nonGoodInfo[2].Value;
|
system = nonGoodInfo[2].Value;
|
||||||
@@ -233,18 +233,18 @@ namespace SabreTools
|
|||||||
date = File.GetLastWriteTime(_filepath).ToString("yyyy-MM-dd HH:mm:ss");
|
date = File.GetLastWriteTime(_filepath).ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
break;
|
break;
|
||||||
case DatType.Redump:
|
case DatType.Redump:
|
||||||
if (!Remapping.DatMaps["Redump"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["Redump"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
// Handle special case mappings found only in Redump
|
// Handle special case mappings found only in Redump
|
||||||
fileinfo = Regex.Match(filename, Constants.RedumpBiosPattern).Groups;
|
fileinfo = Regex.Match(filename, Constants.RedumpBiosPattern).Groups;
|
||||||
|
|
||||||
if (!Remapping.DatMaps["Redump"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["Redump"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GroupCollection redumpInfo = Regex.Match(Remapping.DatMaps["Redump"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection redumpInfo = Regex.Match(Mappings.DatMaps["Redump"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = redumpInfo[1].Value;
|
manufacturer = redumpInfo[1].Value;
|
||||||
system = redumpInfo[2].Value;
|
system = redumpInfo[2].Value;
|
||||||
@@ -264,23 +264,23 @@ namespace SabreTools
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case DatType.TOSEC:
|
case DatType.TOSEC:
|
||||||
if (!Remapping.DatMaps["TOSEC"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["TOSEC"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
// Handle special case mappings found only in TOSEC
|
// Handle special case mappings found only in TOSEC
|
||||||
fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternA).Groups;
|
fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternA).Groups;
|
||||||
|
|
||||||
if (!Remapping.DatMaps["TOSEC"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["TOSEC"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternB).Groups;
|
fileinfo = Regex.Match(filename, Constants.TosecSpecialPatternB).Groups;
|
||||||
|
|
||||||
if (!Remapping.DatMaps["TOSEC"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["TOSEC"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GroupCollection tosecInfo = Regex.Match(Remapping.DatMaps["TOSEC"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection tosecInfo = Regex.Match(Mappings.DatMaps["TOSEC"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = tosecInfo[1].Value;
|
manufacturer = tosecInfo[1].Value;
|
||||||
system = tosecInfo[2].Value;
|
system = tosecInfo[2].Value;
|
||||||
@@ -290,12 +290,12 @@ namespace SabreTools
|
|||||||
date = toDateInfo[1].Value + "-" + toDateInfo[2].Value + "-" + toDateInfo[3].Value + " 00:00:00";
|
date = toDateInfo[1].Value + "-" + toDateInfo[2].Value + "-" + toDateInfo[3].Value + " 00:00:00";
|
||||||
break;
|
break;
|
||||||
case DatType.TruRip:
|
case DatType.TruRip:
|
||||||
if (!Remapping.DatMaps["TruRip"].ContainsKey(fileinfo[1].Value))
|
if (!Mappings.DatMaps["TruRip"].ContainsKey(fileinfo[1].Value))
|
||||||
{
|
{
|
||||||
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
_logger.Warning("The filename " + fileinfo[1].Value + " could not be mapped! Please check the mappings and try again");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
GroupCollection truripInfo = Regex.Match(Remapping.DatMaps["TruRip"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
GroupCollection truripInfo = Regex.Match(Mappings.DatMaps["TruRip"][fileinfo[1].Value], Constants.RemappedPattern).Groups;
|
||||||
|
|
||||||
manufacturer = truripInfo[1].Value;
|
manufacturer = truripInfo[1].Value;
|
||||||
system = truripInfo[2].Value;
|
system = truripInfo[2].Value;
|
||||||
@@ -366,31 +366,31 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get all roms that are found in the DAT to see what needs to be added
|
// Get all roms that are found in the DAT to see what needs to be added
|
||||||
DatData datdata = new DatData();
|
Dat datdata = new Dat();
|
||||||
datdata = DatTools.Parse(_filepath, sysid, srcid, datdata, _logger);
|
datdata = DatTools.Parse(_filepath, sysid, srcid, datdata, _logger);
|
||||||
|
|
||||||
// Sort inputted roms into games
|
// Sort inputted roms into games
|
||||||
SortedDictionary<string, List<RomData>> sortable = new SortedDictionary<string, List<RomData>>();
|
SortedDictionary<string, List<Rom>> sortable = new SortedDictionary<string, List<Rom>>();
|
||||||
long count = 0;
|
long count = 0;
|
||||||
foreach (List<RomData> roms in datdata.Roms.Values)
|
foreach (List<Rom> roms in datdata.Files.Values)
|
||||||
{
|
{
|
||||||
List<RomData> newroms = roms;
|
List<Rom> newroms = roms;
|
||||||
if (datdata.MergeRoms)
|
if (datdata.MergeRoms)
|
||||||
{
|
{
|
||||||
newroms = RomTools.Merge(newroms, _logger);
|
newroms = RomTools.Merge(newroms, _logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (RomData rom in newroms)
|
foreach (Rom rom in newroms)
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
string key = rom.SystemID.ToString().PadLeft(10, '0') + "-" + rom.SourceID.ToString().PadLeft(10, '0') + "-" + rom.Game.ToLowerInvariant();
|
string key = rom.Metadata.SystemID.ToString().PadLeft(10, '0') + "-" + rom.Metadata.SourceID.ToString().PadLeft(10, '0') + "-" + rom.Machine.Name.ToLowerInvariant();
|
||||||
if (sortable.ContainsKey(key))
|
if (sortable.ContainsKey(key))
|
||||||
{
|
{
|
||||||
sortable[key].Add(rom);
|
sortable[key].Add(rom);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<RomData> temp = new List<RomData>();
|
List<Rom> temp = new List<Rom>();
|
||||||
temp.Add(rom);
|
temp.Add(rom);
|
||||||
sortable.Add(key, temp);
|
sortable.Add(key, temp);
|
||||||
}
|
}
|
||||||
@@ -400,7 +400,7 @@ namespace SabreTools
|
|||||||
// Loop over all roms, checking for adds
|
// Loop over all roms, checking for adds
|
||||||
foreach (string key in sortable.Keys)
|
foreach (string key in sortable.Keys)
|
||||||
{
|
{
|
||||||
List<RomData> roms = sortable[key];
|
List<Rom> roms = sortable[key];
|
||||||
RomTools.Sort(roms, true);
|
RomTools.Sort(roms, true);
|
||||||
|
|
||||||
long gameid = -1;
|
long gameid = -1;
|
||||||
@@ -409,9 +409,9 @@ namespace SabreTools
|
|||||||
dbc.Open();
|
dbc.Open();
|
||||||
|
|
||||||
// For each game, check for a new ID
|
// For each game, check for a new ID
|
||||||
gameid = AddGame(sysid, roms[0].Game, srcid, dbc);
|
gameid = AddGame(sysid, roms[0].Machine.Name, srcid, dbc);
|
||||||
|
|
||||||
foreach (RomData rom in roms)
|
foreach (Rom rom in roms)
|
||||||
{
|
{
|
||||||
// BEGIN COMMENT
|
// BEGIN COMMENT
|
||||||
// Try to add the rom with the game information
|
// Try to add the rom with the game information
|
||||||
@@ -492,12 +492,12 @@ namespace SabreTools
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a file to the database if it doesn't already exist
|
/// Add a file to the database if it doesn't already exist
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rom">RomData object representing the rom</param>
|
/// <param name="rom">Rom object representing the rom</param>
|
||||||
/// <param name="gameid">ID of the parent game to be mapped to</param>
|
/// <param name="gameid">ID of the parent game to be mapped to</param>
|
||||||
/// <param name="date">Last updated date</param>
|
/// <param name="date">Last updated date</param>
|
||||||
/// <param name="dbc">SQLite database connection to use</param>
|
/// <param name="dbc">SQLite database connection to use</param>
|
||||||
/// <returns>True if the file exists or could be added, false on error</returns>
|
/// <returns>True if the file exists or could be added, false on error</returns>
|
||||||
private bool AddRom(RomData rom, long gameid, string date, SqliteConnection dbc)
|
private bool AddRom(Rom rom, long gameid, string date, SqliteConnection dbc)
|
||||||
{
|
{
|
||||||
// WOD origninally stripped out any subdirs from the imported files, we do the same
|
// WOD origninally stripped out any subdirs from the imported files, we do the same
|
||||||
rom.Name = Path.GetFileName(rom.Name);
|
rom.Name = Path.GetFileName(rom.Name);
|
||||||
@@ -507,9 +507,9 @@ namespace SabreTools
|
|||||||
rom.Name = Style.RussianToLatin(rom.Name);
|
rom.Name = Style.RussianToLatin(rom.Name);
|
||||||
rom.Name = Regex.Replace(rom.Name, @"(.*) \.(.*)", "$1.$2");
|
rom.Name = Regex.Replace(rom.Name, @"(.*) \.(.*)", "$1.$2");
|
||||||
|
|
||||||
if (rom.Type != "rom" && rom.Type != "disk")
|
if (rom.Type != ItemType.Rom && rom.Type != ItemType.Disk)
|
||||||
{
|
{
|
||||||
rom.Type = "rom";
|
rom.Type = ItemType.Rom;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if this exact file is in the database already
|
// Check to see if this exact file is in the database already
|
||||||
@@ -520,10 +520,10 @@ SELECT files.id FROM files
|
|||||||
WHERE files.name='" + rom.Name.Replace("'", "''") + @"'
|
WHERE files.name='" + rom.Name.Replace("'", "''") + @"'
|
||||||
AND files.type='" + rom.Type + @"'
|
AND files.type='" + rom.Type + @"'
|
||||||
AND files.setid=" + gameid +
|
AND files.setid=" + gameid +
|
||||||
" AND checksums.size=" + rom.Size +
|
" AND checksums.size=" + rom.HashData.Size +
|
||||||
" AND checksums.crc='" + rom.CRC + "'" +
|
" AND checksums.crc='" + rom.HashData.CRC + "'" +
|
||||||
" AND checksums.md5='" + rom.MD5 + "'" +
|
" AND checksums.md5='" + rom.HashData.MD5 + "'" +
|
||||||
" AND checksums.sha1='" + rom.SHA1 + "'";
|
" AND checksums.sha1='" + rom.HashData.SHA1 + "'";
|
||||||
|
|
||||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||||
{
|
{
|
||||||
@@ -536,7 +536,7 @@ SELECT files.id FROM files
|
|||||||
INSERT INTO files (setid, name, type, lastupdated)
|
INSERT INTO files (setid, name, type, lastupdated)
|
||||||
VALUES (" + gameid + ", '" + rom.Name.Replace("'", "''") + "', '" + rom.Type + "', '" + date + @"');
|
VALUES (" + gameid + ", '" + rom.Name.Replace("'", "''") + "', '" + rom.Type + "', '" + date + @"');
|
||||||
INSERT INTO checksums (file, size, crc, md5, sha1)
|
INSERT INTO checksums (file, size, crc, md5, sha1)
|
||||||
VALUES ((SELECT last_insertConstants.Rowid()), " + rom.Size + ", '" + rom.CRC + "'" + ", '" + rom.MD5 + "'" + ", '" + rom.SHA1 + @"');
|
VALUES ((SELECT last_insertConstants.Rowid()), " + rom.HashData.Size + ", '" + rom.HashData.CRC + "'" + ", '" + rom.HashData.MD5 + "'" + ", '" + rom.HashData.SHA1 + @"');
|
||||||
COMMIT;";
|
COMMIT;";
|
||||||
using (SqliteCommand slc2 = new SqliteCommand(query, dbc))
|
using (SqliteCommand slc2 = new SqliteCommand(query, dbc))
|
||||||
{
|
{
|
||||||
@@ -559,28 +559,28 @@ COMMIT;";
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a hash to the database if it doesn't exist already
|
/// Add a hash to the database if it doesn't exist already
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rom">RomData object representing the rom</param>
|
/// <param name="rom">Rom object representing the rom</param>
|
||||||
/// <param name="sysid">System ID for the game to be added with</param>
|
/// <param name="sysid">System ID for the game to be added with</param>
|
||||||
/// <param name="srcid">Source ID for the game to be added with</param>
|
/// <param name="srcid">Source ID for the game to be added with</param>
|
||||||
/// <param name="date">Last updated date</param>
|
/// <param name="date">Last updated date</param>
|
||||||
/// <param name="dbc">SQLite database connection to use</param>
|
/// <param name="dbc">SQLite database connection to use</param>
|
||||||
/// <returns>True if the hash exists or could be added, false on error</returns>
|
/// <returns>True if the hash exists or could be added, false on error</returns>
|
||||||
/// <remarks>This is currently unused. It is a test method for the new SabreTools DB schema</remarks>
|
/// <remarks>This is currently unused. It is a test method for the new SabreTools DB schema</remarks>
|
||||||
private bool AddHash(RomData rom, int sysid, int srcid, string date, SqliteConnection dbc)
|
private bool AddHash(Rom rom, int sysid, int srcid, string date, SqliteConnection dbc)
|
||||||
{
|
{
|
||||||
// Process the game name
|
// Process the game name
|
||||||
|
|
||||||
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same
|
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same
|
||||||
string stripPattern = @"(([[(].*[\)\]] )?([^([]+))";
|
string stripPattern = @"(([[(].*[\)\]] )?([^([]+))";
|
||||||
Regex stripRegex = new Regex(stripPattern);
|
Regex stripRegex = new Regex(stripPattern);
|
||||||
Match stripMatch = stripRegex.Match(rom.Game);
|
Match stripMatch = stripRegex.Match(rom.Machine.Name);
|
||||||
rom.Game = stripMatch.Groups[1].Value;
|
rom.Machine.Name = stripMatch.Groups[1].Value;
|
||||||
|
|
||||||
// Run the name through the filters to make sure that it's correct
|
// Run the name through the filters to make sure that it's correct
|
||||||
rom.Game = Style.NormalizeChars(rom.Game);
|
rom.Machine.Name = Style.NormalizeChars(rom.Machine.Name);
|
||||||
rom.Game = Style.RussianToLatin(rom.Game);
|
rom.Machine.Name = Style.RussianToLatin(rom.Machine.Name);
|
||||||
rom.Game = Style.SearchPattern(rom.Game);
|
rom.Machine.Name = Style.SearchPattern(rom.Machine.Name);
|
||||||
rom.Game = rom.Game.Trim();
|
rom.Machine.Name = rom.Machine.Name.Trim();
|
||||||
|
|
||||||
// Process the rom name
|
// Process the rom name
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ COMMIT;";
|
|||||||
|
|
||||||
// Retrieve or insert the hash
|
// Retrieve or insert the hash
|
||||||
long hashid = -1;
|
long hashid = -1;
|
||||||
string query = "SELECT id FROM hash WHERE size=" + rom.Size + " AND crc='" + rom.CRC + "' AND md5='" + rom.MD5 + "' AND sha1='" + rom.SHA1 + "'";
|
string query = "SELECT id FROM hash WHERE size=" + rom.HashData.Size + " AND crc='" + rom.HashData.CRC + "' AND md5='" + rom.HashData.MD5 + "' AND sha1='" + rom.HashData.SHA1 + "'";
|
||||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||||
{
|
{
|
||||||
using (SqliteDataReader sldr = slc.ExecuteReader())
|
using (SqliteDataReader sldr = slc.ExecuteReader())
|
||||||
@@ -603,7 +603,7 @@ COMMIT;";
|
|||||||
if (!sldr.HasRows)
|
if (!sldr.HasRows)
|
||||||
{
|
{
|
||||||
query = "INSERT INTO hash (size, crc, md5, sha1)" +
|
query = "INSERT INTO hash (size, crc, md5, sha1)" +
|
||||||
" VALUES (" + rom.Size + ", '" + rom.CRC + "', '" + rom.MD5 + "', '" + rom.SHA1 + "')";
|
" VALUES (" + rom.HashData.Size + ", '" + rom.HashData.CRC + "', '" + rom.HashData.MD5 + "', '" + rom.HashData.SHA1 + "')";
|
||||||
|
|
||||||
using (SqliteCommand slc2 = new SqliteCommand(query, dbc))
|
using (SqliteCommand slc2 = new SqliteCommand(query, dbc))
|
||||||
{
|
{
|
||||||
@@ -629,11 +629,11 @@ COMMIT;";
|
|||||||
query = @"BEGIN;
|
query = @"BEGIN;
|
||||||
INSERT OR IGNORE INTO hashdata (hashid, key, value) VALUES " +
|
INSERT OR IGNORE INTO hashdata (hashid, key, value) VALUES " +
|
||||||
"(" + hashid + ", 'name', '" + rom.Name.Replace("'", "''") + "'), " +
|
"(" + hashid + ", 'name', '" + rom.Name.Replace("'", "''") + "'), " +
|
||||||
"(" + hashid + ", 'game', '" + rom.Game.Replace("'", "''") + "'), " +
|
"(" + hashid + ", 'game', '" + rom.Machine.Name.Replace("'", "''") + "'), " +
|
||||||
"(" + hashid + ", 'type', '" + rom.Type + "'), " +
|
"(" + hashid + ", 'type', '" + rom.Type + "'), " +
|
||||||
"(" + hashid + ", 'lastupdated', '" + date + @"');
|
"(" + hashid + ", 'lastupdated', '" + date + @"');
|
||||||
INSERT OR IGNORE INTO gamesystem (game, systemid) VALUES ('" + rom.Game.Replace("'", "''") + "', " + sysid + @");
|
INSERT OR IGNORE INTO gamesystem (game, systemid) VALUES ('" + rom.Machine.Name.Replace("'", "''") + "', " + sysid + @");
|
||||||
INSERT OR IGNORE INTO gamesource (game, sourceid) VALUES ('" + rom.Game.Replace("'", "''") + "', " + srcid + @");
|
INSERT OR IGNORE INTO gamesource (game, sourceid) VALUES ('" + rom.Machine.Name.Replace("'", "''") + "', " + srcid + @");
|
||||||
COMMIT;";
|
COMMIT;";
|
||||||
|
|
||||||
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
using (SqliteCommand slc = new SqliteCommand(query, dbc))
|
||||||
@@ -86,6 +86,14 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Data\Constants.cs" />
|
<Compile Include="Data\Constants.cs" />
|
||||||
<Compile Include="External\OptimizedCRC.cs" />
|
<Compile Include="External\OptimizedCRC.cs" />
|
||||||
|
<Compile Include="Objects\DATFromDir.cs" />
|
||||||
|
<Compile Include="Objects\DATFromDirParallel.cs" />
|
||||||
|
<Compile Include="Objects\Generate.cs" />
|
||||||
|
<Compile Include="Objects\GenerateTwo.cs" />
|
||||||
|
<Compile Include="Objects\Import.cs" />
|
||||||
|
<Compile Include="Objects\ImportTwo.cs" />
|
||||||
|
<Compile Include="Objects\OfflineMerge.cs" />
|
||||||
|
<Compile Include="Objects\Split.cs" />
|
||||||
<Compile Include="Resources\Resources.de-DE.Designer.cs">
|
<Compile Include="Resources\Resources.de-DE.Designer.cs">
|
||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DesignTime>True</DesignTime>
|
<DesignTime>True</DesignTime>
|
||||||
@@ -121,7 +129,7 @@
|
|||||||
<Compile Include="Tools\FileToolsHash.cs" />
|
<Compile Include="Tools\FileToolsHash.cs" />
|
||||||
<Compile Include="Tools\RomTools.cs" />
|
<Compile Include="Tools\RomTools.cs" />
|
||||||
<Compile Include="Tools\RomToolsHash.cs" />
|
<Compile Include="Tools\RomToolsHash.cs" />
|
||||||
<Compile Include="Tools\Stats.cs" />
|
<Compile Include="Objects\Stats.cs" />
|
||||||
<Compile Include="Tools\Style.cs" />
|
<Compile Include="Tools\Style.cs" />
|
||||||
<Compile Include="Data\Build.cs" />
|
<Compile Include="Data\Build.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -164,6 +172,7 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets" Condition="Exists('..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets')" />
|
<Import Project="..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets" Condition="Exists('..\packages\Mono.Data.Sqlite.Portable.1.0.3.5\tools\Mono.Data.Sqlite.Portable.targets')" />
|
||||||
<Target Name="EnsureMonoDataSqlitePortableImported" BeforeTargets="BeforeBuild" Condition="'$(MonoDataSqlitePortableImported)' == ''">
|
<Target Name="EnsureMonoDataSqlitePortableImported" BeforeTargets="BeforeBuild" Condition="'$(MonoDataSqlitePortableImported)' == ''">
|
||||||
|
|||||||
@@ -100,13 +100,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DATFromDir.cs" />
|
|
||||||
<Compile Include="DATFromDirParallel.cs" />
|
|
||||||
<Compile Include="OfflineMerge.cs" />
|
|
||||||
<Compile Include="Split.cs" />
|
|
||||||
<Compile Include="ImportExport\GenerateTwo.cs" />
|
|
||||||
<Compile Include="SabreTools.cs" />
|
<Compile Include="SabreTools.cs" />
|
||||||
<Compile Include="ImportExport\ImportTwo.cs" />
|
|
||||||
<Compile Include="Partials\SabreTools_Helpers.cs" />
|
<Compile Include="Partials\SabreTools_Helpers.cs" />
|
||||||
<Compile Include="Partials\SabreTools_Inits.cs" />
|
<Compile Include="Partials\SabreTools_Inits.cs" />
|
||||||
<Compile Include="Partials\SabreTools_Menus.cs" />
|
<Compile Include="Partials\SabreTools_Menus.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user