[Structs] Add two new structs for logical data management

This commit is contained in:
Matt Nadareski
2016-06-16 17:17:29 -07:00
parent 1899a7fd9b
commit 0af0b420d1
6 changed files with 60 additions and 47 deletions

View File

@@ -18,10 +18,8 @@ namespace SabreTools.Helper
public DupeType Dupe; public DupeType Dupe;
public bool Nodump; public bool Nodump;
public string Date; public string Date;
public string System; public SystemData SystemData;
public int SystemID; public SourceData SourceData;
public string Source;
public int SourceID;
public int CompareTo(object obj) public int CompareTo(object obj)
{ {
@@ -53,6 +51,25 @@ namespace SabreTools.Helper
} }
} }
/// <summary>
/// Intermediate struct for holding System information
/// </summary>
public struct SystemData
{
public int ID;
public string Name;
}
/// <summary>
/// Intermediate struct for holding Source information
/// </summary>
public struct SourceData
{
public int ID;
public string Name;
public string URL;
}
/// <summary> /// <summary>
/// Intermediate struct for holding DAT information /// Intermediate struct for holding DAT information
/// </summary> /// </summary>

View File

@@ -173,8 +173,8 @@ namespace SabreTools.Helper
{ {
Game = gamename, Game = gamename,
Type = (line.Trim().StartsWith("disk (") ? "disk" : "rom"), Type = (line.Trim().StartsWith("disk (") ? "disk" : "rom"),
SystemID = sysid, SystemData = new SystemData { ID = sysid },
SourceID = srcid, SourceData = new SourceData { ID = srcid },
}; };
string[] gc = line.Trim().Split(' '); string[] gc = line.Trim().Split(' ');
@@ -577,8 +577,8 @@ namespace SabreTools.Helper
Name = rominfo[5], Name = rominfo[5],
CRC = rominfo[6].ToLowerInvariant(), CRC = rominfo[6].ToLowerInvariant(),
Size = Int64.Parse(rominfo[7]), Size = Int64.Parse(rominfo[7]),
SystemID = sysid, SystemData = new SystemData { ID = sysid },
SourceID = srcid, SourceData = new SourceData { ID = srcid },
}; };
// Sanitize the hashes from null, hex sizes, and "true blank" strings // Sanitize the hashes from null, hex sizes, and "true blank" strings
@@ -1152,15 +1152,14 @@ namespace SabreTools.Helper
Game = tempname, Game = tempname,
Name = subreader.GetAttribute("name"), Name = subreader.GetAttribute("name"),
Type = subreader.Name, Type = subreader.Name,
SystemID = sysid,
SourceID = srcid,
Size = size, Size = size,
CRC = crc, CRC = crc,
MD5 = md5, MD5 = md5,
SHA1 = sha1, SHA1 = sha1,
System = filename,
Nodump = nodump, Nodump = nodump,
Date = date, Date = date,
SystemData = new SystemData { ID = sysid, Name = filename },
SourceData = new SourceData { ID = srcid },
}; };
if (datdata.Roms.ContainsKey(key)) if (datdata.Roms.ContainsKey(key))
@@ -1389,15 +1388,14 @@ namespace SabreTools.Helper
Game = tempname, Game = tempname,
Name = xtr.GetAttribute("name"), Name = xtr.GetAttribute("name"),
Type = xtr.GetAttribute("type"), Type = xtr.GetAttribute("type"),
SystemID = sysid,
SourceID = srcid,
Size = size, Size = size,
CRC = crc, CRC = crc,
MD5 = md5, MD5 = md5,
SHA1 = sha1, SHA1 = sha1,
System = filename,
Nodump = nodump, Nodump = nodump,
Date = date, Date = date,
SystemData = new SystemData { ID = sysid, Name = filename },
SourceData = new SourceData { ID = srcid },
}; };
if (datdata.Roms.ContainsKey(key)) if (datdata.Roms.ContainsKey(key))
@@ -1467,7 +1465,7 @@ namespace SabreTools.Helper
foreach (RomData rom in newroms) foreach (RomData rom in newroms)
{ {
count++; count++;
string key = (norename ? "" : rom.SystemID.ToString().PadLeft(10, '0') + "-" + rom.SourceID.ToString().PadLeft(10, '0') + "-") + rom.Game.ToLowerInvariant(); string key = (norename ? "" : rom.SystemData.ID.ToString().PadLeft(10, '0') + "-" + rom.SourceData.ID.ToString().PadLeft(10, '0') + "-") + rom.Game.ToLowerInvariant();
if (sortable.ContainsKey(key)) if (sortable.ContainsKey(key))
{ {
sortable[key].Add(rom); sortable[key].Add(rom);

View File

@@ -209,19 +209,17 @@ namespace SabreTools.Helper
savedrom.Dupe = dupetype; savedrom.Dupe = dupetype;
// If the current system has a lower ID than the previous, set the system accordingly // If the current system has a lower ID than the previous, set the system accordingly
if (rom.SystemID < savedrom.SystemID) if (rom.SystemData.ID < savedrom.SystemData.ID)
{ {
savedrom.SystemID = rom.SystemID; savedrom.SystemData = rom.SystemData;
savedrom.System = rom.System;
savedrom.Game = rom.Game; savedrom.Game = rom.Game;
savedrom.Name = rom.Name; savedrom.Name = rom.Name;
} }
// If the current source has a lower ID than the previous, set the source accordingly // If the current source has a lower ID than the previous, set the source accordingly
if (rom.SourceID < savedrom.SourceID) if (rom.SourceData.ID < savedrom.SourceData.ID)
{ {
savedrom.SourceID = rom.SourceID; savedrom.SourceData = rom.SourceData;
savedrom.Source = rom.Source;
savedrom.Game = rom.Game; savedrom.Game = rom.Game;
savedrom.Name = rom.Name; savedrom.Name = rom.Name;
} }
@@ -334,7 +332,7 @@ namespace SabreTools.Helper
} }
// If the duplicate is external already or should be, set it // If the duplicate is external already or should be, set it
if (lastrom.Dupe >= DupeType.ExternalHash || lastrom.SystemID != rom.SystemID || lastrom.SourceID != rom.SourceID) if (lastrom.Dupe >= DupeType.ExternalHash || lastrom.SystemData.ID != rom.SystemData.ID || lastrom.SourceData.ID != rom.SourceData.ID)
{ {
if (lastrom.Game == rom.Game && lastrom.Name == rom.Name) if (lastrom.Game == rom.Game && lastrom.Name == rom.Name)
{ {
@@ -372,9 +370,9 @@ namespace SabreTools.Helper
{ {
roms.Sort(delegate (RomData x, RomData y) roms.Sort(delegate (RomData x, RomData y)
{ {
if (x.SystemID == y.SystemID) if (x.SystemData.ID == y.SystemData.ID)
{ {
if (x.SourceID == y.SourceID) if (x.SourceData.ID == y.SourceData.ID)
{ {
if (x.Game == y.Game) if (x.Game == y.Game)
{ {
@@ -382,9 +380,9 @@ namespace SabreTools.Helper
} }
return String.Compare(x.Game, y.Game); return String.Compare(x.Game, y.Game);
} }
return (norename ? String.Compare(x.Game, y.Game) : x.SourceID - y.SourceID); return (norename ? String.Compare(x.Game, y.Game) : x.SourceData.ID - y.SourceData.ID);
} }
return (norename ? String.Compare(x.Game, y.Game) : x.SystemID - y.SystemID); return (norename ? String.Compare(x.Game, y.Game) : x.SystemData.ID - y.SystemData.ID);
}); });
return true; return true;
} }

View File

@@ -223,13 +223,13 @@ namespace SabreTools
if (!_norename) if (!_norename)
{ {
rom.Game += " [" + sources[rom.SourceID] + "]"; rom.Game += " [" + sources[rom.SourceData.ID] + "]";
} }
// If a game has source "0" it's Default. Make this Int32.MaxValue for sorting purposes // If a game has source "0" it's Default. Make this Int32.MaxValue for sorting purposes
if (rom.SourceID == 0) if (rom.SourceData.ID == 0)
{ {
rom.SourceID = Int32.MaxValue; rom.SourceData.ID = Int32.MaxValue;
} }
temp.Add(rom); temp.Add(rom);

View File

@@ -287,20 +287,20 @@ namespace SabreTools
if (rom.Dupe < DupeType.ExternalHash) if (rom.Dupe < DupeType.ExternalHash)
{ {
// Individual DATs that are output // Individual DATs that are output
if (outDats[rom.SystemID].Roms.ContainsKey(key)) if (outDats[rom.SystemData.ID].Roms.ContainsKey(key))
{ {
outDats[rom.SystemID].Roms[key].Add(rom); outDats[rom.SystemData.ID].Roms[key].Add(rom);
} }
else else
{ {
List<RomData> tl = new List<RomData>(); List<RomData> tl = new List<RomData>();
tl.Add(rom); tl.Add(rom);
outDats[rom.SystemID].Roms.Add(key, tl); outDats[rom.SystemData.ID].Roms.Add(key, tl);
} }
// Merged no-duplicates DAT // Merged no-duplicates DAT
RomData newrom = rom; RomData newrom = rom;
newrom.Game += " (" + Path.GetFileNameWithoutExtension(_inputs[newrom.SystemID].Split('¬')[0]) + ")"; newrom.Game += " (" + Path.GetFileNameWithoutExtension(_inputs[newrom.SystemData.ID].Split('¬')[0]) + ")";
if (outerDiffData.Roms.ContainsKey(key)) if (outerDiffData.Roms.ContainsKey(key))
{ {
@@ -318,7 +318,7 @@ namespace SabreTools
if (rom.Dupe >= DupeType.ExternalHash) if (rom.Dupe >= DupeType.ExternalHash)
{ {
RomData newrom = rom; RomData newrom = rom;
newrom.Game += " (" + Path.GetFileNameWithoutExtension(_inputs[newrom.SystemID].Split('¬')[0]) + ")"; newrom.Game += " (" + Path.GetFileNameWithoutExtension(_inputs[newrom.SystemData.ID].Split('¬')[0]) + ")";
if (dupeData.Roms.ContainsKey(key)) if (dupeData.Roms.ContainsKey(key))
{ {
@@ -420,15 +420,15 @@ namespace SabreTools
{ {
foreach (RomData rom in roms) foreach (RomData rom in roms)
{ {
if (outDats[rom.SystemID].Roms.ContainsKey(key)) if (outDats[rom.SystemData.ID].Roms.ContainsKey(key))
{ {
outDats[rom.SystemID].Roms[key].Add(rom); outDats[rom.SystemData.ID].Roms[key].Add(rom);
} }
else else
{ {
List<RomData> tl = new List<RomData>(); List<RomData> tl = new List<RomData>();
tl.Add(rom); tl.Add(rom);
outDats[rom.SystemID].Roms.Add(key, tl); outDats[rom.SystemData.ID].Roms.Add(key, tl);
} }
} }
} }
@@ -477,8 +477,8 @@ namespace SabreTools
foreach (RomData rom in userData.Roms[key]) foreach (RomData rom in userData.Roms[key])
{ {
RomData newrom = rom; RomData newrom = rom;
string filename = _inputs[newrom.SystemID].Split('¬')[0]; string filename = _inputs[newrom.SystemData.ID].Split('¬')[0];
string rootpath = _inputs[newrom.SystemID].Split('¬')[1]; string rootpath = _inputs[newrom.SystemData.ID].Split('¬')[1];
rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString()); rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString());
filename = filename.Remove(0, rootpath.Length); filename = filename.Remove(0, rootpath.Length);

View File

@@ -69,7 +69,7 @@ namespace SabreTools
List<RomData> templist = RomTools.Merge(completeDats.Roms[key], _logger); List<RomData> templist = RomTools.Merge(completeDats.Roms[key], _logger);
foreach (RomData rom in templist) foreach (RomData rom in templist)
{ {
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged) if (rom.Dupe == DupeType.None && rom.SystemData.Name == _currentNewMerged)
{ {
if (netNew.ContainsKey(key)) if (netNew.ContainsKey(key))
{ {
@@ -93,7 +93,7 @@ namespace SabreTools
List<RomData> templist = RomTools.Merge(completeDats.Roms[key], _logger); List<RomData> templist = RomTools.Merge(completeDats.Roms[key], _logger);
foreach (RomData rom in templist) foreach (RomData rom in templist)
{ {
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged) if (rom.Dupe == DupeType.None && rom.SystemData.Name == _currentAllMerged)
{ {
if (unneeded.ContainsKey(key)) if (unneeded.ContainsKey(key))
{ {
@@ -130,7 +130,7 @@ namespace SabreTools
List<RomData> templist = RomTools.Merge(midMissing.Roms[key], _logger); List<RomData> templist = RomTools.Merge(midMissing.Roms[key], _logger);
foreach (RomData rom in templist) foreach (RomData rom in templist)
{ {
if (rom.Dupe == DupeType.None && rom.System == _currentMissingMerged) if (rom.Dupe == DupeType.None && rom.SystemData.Name == _currentMissingMerged)
{ {
if (newMissing.ContainsKey(key)) if (newMissing.ContainsKey(key))
{ {
@@ -177,7 +177,7 @@ namespace SabreTools
{ {
foreach (RomData rom in completeDats.Roms[key]) foreach (RomData rom in completeDats.Roms[key])
{ {
if (rom.System == _currentNewMerged) if (rom.SystemData.Name == _currentNewMerged)
{ {
midHave[key].Add(rom); midHave[key].Add(rom);
} }
@@ -188,7 +188,7 @@ namespace SabreTools
List<RomData> roms = new List<RomData>(); List<RomData> roms = new List<RomData>();
foreach (RomData rom in completeDats.Roms[key]) foreach (RomData rom in completeDats.Roms[key])
{ {
if (rom.System == _currentNewMerged) if (rom.SystemData.Name == _currentNewMerged)
{ {
roms.Add(rom); roms.Add(rom);
} }
@@ -202,7 +202,7 @@ namespace SabreTools
List<RomData> templist = RomTools.Merge(midHave[key], _logger); List<RomData> templist = RomTools.Merge(midHave[key], _logger);
foreach (RomData rom in templist) foreach (RomData rom in templist)
{ {
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged) if (rom.Dupe == DupeType.None && rom.SystemData.Name == _currentNewMerged)
{ {
if (have.ContainsKey(key)) if (have.ContainsKey(key))
{ {
@@ -370,7 +370,7 @@ namespace SabreTools
List<RomData> templist = RomTools.Merge(midHave.Roms[key], _logger); List<RomData> templist = RomTools.Merge(midHave.Roms[key], _logger);
foreach (RomData rom in templist) foreach (RomData rom in templist)
{ {
if (rom.Dupe == DupeType.None && rom.System == _currentAllMerged) if (rom.Dupe == DupeType.None && rom.SystemData.Name == _currentAllMerged)
{ {
if (have.ContainsKey(key)) if (have.ContainsKey(key))
{ {
@@ -440,7 +440,7 @@ namespace SabreTools
List<RomData> templist = RomTools.Merge(midHave.Roms[key], _logger); List<RomData> templist = RomTools.Merge(midHave.Roms[key], _logger);
foreach (RomData rom in templist) foreach (RomData rom in templist)
{ {
if (rom.Dupe == DupeType.None && rom.System == _currentNewMerged) if (rom.Dupe == DupeType.None && rom.SystemData.Name == _currentNewMerged)
{ {
if (have.ContainsKey(key)) if (have.ContainsKey(key))
{ {