[Structs] Create different, single struct

This commit is contained in:
Matt Nadareski
2016-06-16 17:27:32 -07:00
parent 0af0b420d1
commit 588a484e33
6 changed files with 44 additions and 55 deletions

View File

@@ -18,8 +18,7 @@ namespace SabreTools.Helper
public DupeType Dupe;
public bool Nodump;
public string Date;
public SystemData SystemData;
public SourceData SourceData;
public SourceMetadata Metadata;
public int CompareTo(object obj)
{
@@ -52,22 +51,14 @@ namespace SabreTools.Helper
}
/// <summary>
/// Intermediate struct for holding System information
/// Intermediate metadata kept with a RomData object representing source information
/// </summary>
public struct SystemData
public struct SourceMetadata
{
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;
public int SystemID;
public string System;
public int SourceID;
public string Source;
}
/// <summary>

View File

@@ -173,8 +173,7 @@ namespace SabreTools.Helper
{
Game = gamename,
Type = (line.Trim().StartsWith("disk (") ? "disk" : "rom"),
SystemData = new SystemData { ID = sysid },
SourceData = new SourceData { ID = srcid },
Metadata = new SourceMetadata { SystemID = sysid, SourceID = srcid },
};
string[] gc = line.Trim().Split(' ');
@@ -577,8 +576,7 @@ namespace SabreTools.Helper
Name = rominfo[5],
CRC = rominfo[6].ToLowerInvariant(),
Size = Int64.Parse(rominfo[7]),
SystemData = new SystemData { ID = sysid },
SourceData = new SourceData { ID = srcid },
Metadata = new SourceMetadata { SystemID = sysid, SourceID = srcid },
};
// Sanitize the hashes from null, hex sizes, and "true blank" strings
@@ -1158,8 +1156,7 @@ namespace SabreTools.Helper
SHA1 = sha1,
Nodump = nodump,
Date = date,
SystemData = new SystemData { ID = sysid, Name = filename },
SourceData = new SourceData { ID = srcid },
Metadata = new SourceMetadata { SystemID = sysid, System = filename, SourceID = srcid },
};
if (datdata.Roms.ContainsKey(key))
@@ -1394,8 +1391,7 @@ namespace SabreTools.Helper
SHA1 = sha1,
Nodump = nodump,
Date = date,
SystemData = new SystemData { ID = sysid, Name = filename },
SourceData = new SourceData { ID = srcid },
Metadata = new SourceMetadata { SystemID = sysid, System = filename, SourceID = srcid },
};
if (datdata.Roms.ContainsKey(key))
@@ -1465,7 +1461,7 @@ namespace SabreTools.Helper
foreach (RomData rom in newroms)
{
count++;
string key = (norename ? "" : rom.SystemData.ID.ToString().PadLeft(10, '0') + "-" + rom.SourceData.ID.ToString().PadLeft(10, '0') + "-") + rom.Game.ToLowerInvariant();
string key = (norename ? "" : rom.Metadata.SystemID.ToString().PadLeft(10, '0') + "-" + rom.Metadata.SourceID.ToString().PadLeft(10, '0') + "-") + rom.Game.ToLowerInvariant();
if (sortable.ContainsKey(key))
{
sortable[key].Add(rom);

View File

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

View File

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

View File

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

View File

@@ -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.SystemData.Name == _currentNewMerged)
if (rom.Dupe == DupeType.None && rom.Metadata.System == _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.SystemData.Name == _currentAllMerged)
if (rom.Dupe == DupeType.None && rom.Metadata.System == _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.SystemData.Name == _currentMissingMerged)
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentMissingMerged)
{
if (newMissing.ContainsKey(key))
{
@@ -177,7 +177,7 @@ namespace SabreTools
{
foreach (RomData rom in completeDats.Roms[key])
{
if (rom.SystemData.Name == _currentNewMerged)
if (rom.Metadata.System == _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.SystemData.Name == _currentNewMerged)
if (rom.Metadata.System == _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.SystemData.Name == _currentNewMerged)
if (rom.Dupe == DupeType.None && rom.Metadata.System == _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.SystemData.Name == _currentAllMerged)
if (rom.Dupe == DupeType.None && rom.Metadata.System == _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.SystemData.Name == _currentNewMerged)
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentNewMerged)
{
if (have.ContainsKey(key))
{