mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Structs] Add two new structs for logical data management
This commit is contained in:
@@ -18,10 +18,8 @@ namespace SabreTools.Helper
|
||||
public DupeType Dupe;
|
||||
public bool Nodump;
|
||||
public string Date;
|
||||
public string System;
|
||||
public int SystemID;
|
||||
public string Source;
|
||||
public int SourceID;
|
||||
public SystemData SystemData;
|
||||
public SourceData SourceData;
|
||||
|
||||
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>
|
||||
/// Intermediate struct for holding DAT information
|
||||
/// </summary>
|
||||
|
||||
@@ -173,8 +173,8 @@ namespace SabreTools.Helper
|
||||
{
|
||||
Game = gamename,
|
||||
Type = (line.Trim().StartsWith("disk (") ? "disk" : "rom"),
|
||||
SystemID = sysid,
|
||||
SourceID = srcid,
|
||||
SystemData = new SystemData { ID = sysid },
|
||||
SourceData = new SourceData { ID = srcid },
|
||||
};
|
||||
|
||||
string[] gc = line.Trim().Split(' ');
|
||||
@@ -577,8 +577,8 @@ namespace SabreTools.Helper
|
||||
Name = rominfo[5],
|
||||
CRC = rominfo[6].ToLowerInvariant(),
|
||||
Size = Int64.Parse(rominfo[7]),
|
||||
SystemID = sysid,
|
||||
SourceID = srcid,
|
||||
SystemData = new SystemData { ID = sysid },
|
||||
SourceData = new SourceData { ID = srcid },
|
||||
};
|
||||
|
||||
// Sanitize the hashes from null, hex sizes, and "true blank" strings
|
||||
@@ -1152,15 +1152,14 @@ namespace SabreTools.Helper
|
||||
Game = tempname,
|
||||
Name = subreader.GetAttribute("name"),
|
||||
Type = subreader.Name,
|
||||
SystemID = sysid,
|
||||
SourceID = srcid,
|
||||
Size = size,
|
||||
CRC = crc,
|
||||
MD5 = md5,
|
||||
SHA1 = sha1,
|
||||
System = filename,
|
||||
Nodump = nodump,
|
||||
Date = date,
|
||||
SystemData = new SystemData { ID = sysid, Name = filename },
|
||||
SourceData = new SourceData { ID = srcid },
|
||||
};
|
||||
|
||||
if (datdata.Roms.ContainsKey(key))
|
||||
@@ -1389,15 +1388,14 @@ namespace SabreTools.Helper
|
||||
Game = tempname,
|
||||
Name = xtr.GetAttribute("name"),
|
||||
Type = xtr.GetAttribute("type"),
|
||||
SystemID = sysid,
|
||||
SourceID = srcid,
|
||||
Size = size,
|
||||
CRC = crc,
|
||||
MD5 = md5,
|
||||
SHA1 = sha1,
|
||||
System = filename,
|
||||
Nodump = nodump,
|
||||
Date = date,
|
||||
SystemData = new SystemData { ID = sysid, Name = filename },
|
||||
SourceData = new SourceData { ID = srcid },
|
||||
};
|
||||
|
||||
if (datdata.Roms.ContainsKey(key))
|
||||
@@ -1467,7 +1465,7 @@ namespace SabreTools.Helper
|
||||
foreach (RomData rom in newroms)
|
||||
{
|
||||
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))
|
||||
{
|
||||
sortable[key].Add(rom);
|
||||
|
||||
@@ -209,19 +209,17 @@ namespace SabreTools.Helper
|
||||
savedrom.Dupe = dupetype;
|
||||
|
||||
// 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.System = rom.System;
|
||||
savedrom.SystemData = rom.SystemData;
|
||||
savedrom.Game = rom.Game;
|
||||
savedrom.Name = rom.Name;
|
||||
}
|
||||
|
||||
// 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.Source = rom.Source;
|
||||
savedrom.SourceData = rom.SourceData;
|
||||
savedrom.Game = rom.Game;
|
||||
savedrom.Name = rom.Name;
|
||||
}
|
||||
@@ -334,7 +332,7 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
@@ -372,9 +370,9 @@ namespace SabreTools.Helper
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -382,9 +380,9 @@ namespace SabreTools.Helper
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -223,13 +223,13 @@ namespace SabreTools
|
||||
|
||||
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 (rom.SourceID == 0)
|
||||
if (rom.SourceData.ID == 0)
|
||||
{
|
||||
rom.SourceID = Int32.MaxValue;
|
||||
rom.SourceData.ID = Int32.MaxValue;
|
||||
}
|
||||
|
||||
temp.Add(rom);
|
||||
|
||||
@@ -287,20 +287,20 @@ namespace SabreTools
|
||||
if (rom.Dupe < DupeType.ExternalHash)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
tl.Add(rom);
|
||||
outDats[rom.SystemID].Roms.Add(key, tl);
|
||||
outDats[rom.SystemData.ID].Roms.Add(key, tl);
|
||||
}
|
||||
|
||||
// Merged no-duplicates DAT
|
||||
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))
|
||||
{
|
||||
@@ -318,7 +318,7 @@ namespace SabreTools
|
||||
if (rom.Dupe >= DupeType.ExternalHash)
|
||||
{
|
||||
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))
|
||||
{
|
||||
@@ -420,15 +420,15 @@ namespace SabreTools
|
||||
{
|
||||
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
|
||||
{
|
||||
List<RomData> tl = new List<RomData>();
|
||||
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])
|
||||
{
|
||||
RomData newrom = rom;
|
||||
string filename = _inputs[newrom.SystemID].Split('¬')[0];
|
||||
string rootpath = _inputs[newrom.SystemID].Split('¬')[1];
|
||||
string filename = _inputs[newrom.SystemData.ID].Split('¬')[0];
|
||||
string rootpath = _inputs[newrom.SystemData.ID].Split('¬')[1];
|
||||
|
||||
rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString());
|
||||
filename = filename.Remove(0, rootpath.Length);
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace SabreTools
|
||||
List<RomData> templist = RomTools.Merge(completeDats.Roms[key], _logger);
|
||||
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))
|
||||
{
|
||||
@@ -93,7 +93,7 @@ namespace SabreTools
|
||||
List<RomData> templist = RomTools.Merge(completeDats.Roms[key], _logger);
|
||||
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))
|
||||
{
|
||||
@@ -130,7 +130,7 @@ namespace SabreTools
|
||||
List<RomData> templist = RomTools.Merge(midMissing.Roms[key], _logger);
|
||||
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))
|
||||
{
|
||||
@@ -177,7 +177,7 @@ namespace SabreTools
|
||||
{
|
||||
foreach (RomData rom in completeDats.Roms[key])
|
||||
{
|
||||
if (rom.System == _currentNewMerged)
|
||||
if (rom.SystemData.Name == _currentNewMerged)
|
||||
{
|
||||
midHave[key].Add(rom);
|
||||
}
|
||||
@@ -188,7 +188,7 @@ namespace SabreTools
|
||||
List<RomData> roms = new List<RomData>();
|
||||
foreach (RomData rom in completeDats.Roms[key])
|
||||
{
|
||||
if (rom.System == _currentNewMerged)
|
||||
if (rom.SystemData.Name == _currentNewMerged)
|
||||
{
|
||||
roms.Add(rom);
|
||||
}
|
||||
@@ -202,7 +202,7 @@ namespace SabreTools
|
||||
List<RomData> templist = RomTools.Merge(midHave[key], _logger);
|
||||
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))
|
||||
{
|
||||
@@ -370,7 +370,7 @@ namespace SabreTools
|
||||
List<RomData> templist = RomTools.Merge(midHave.Roms[key], _logger);
|
||||
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))
|
||||
{
|
||||
@@ -440,7 +440,7 @@ namespace SabreTools
|
||||
List<RomData> templist = RomTools.Merge(midHave.Roms[key], _logger);
|
||||
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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user