[ALL] Overhaul to internal system

This massive change replaces the old "Rom" struct system with a new one that have different objects for each major item type. This required a lot of work and a lot of changes and has unfortunately been untested. But this is the first step in moving away from using structs. The next major step is converting Dat over to this as well.
This commit is contained in:
Matt Nadareski
2016-09-19 18:04:24 -07:00
parent f059b5389c
commit 902070c542
22 changed files with 1615 additions and 3017 deletions

View File

@@ -76,7 +76,7 @@ namespace SabreTools.Helper
_cursorLeft = Console.CursorLeft;
_matched = new Dat
{
Files = new Dictionary<string, List<Rom>>(),
Files = new Dictionary<string, List<DatItem>>(),
};
}
@@ -145,7 +145,7 @@ namespace SabreTools.Helper
// Setup the fixdat
_matched = (Dat)_datdata.CloneHeader();
_matched.Files = new Dictionary<string, List<Rom>>();
_matched.Files = new Dictionary<string, List<DatItem>>();
_matched.FileName = "fixDat_" + _matched.FileName;
_matched.Name = "fixDat_" + _matched.Name;
_matched.Description = "fixDat_" + _matched.Description;
@@ -153,12 +153,12 @@ namespace SabreTools.Helper
// Now that all files are parsed, get only files found in directory
bool found = false;
foreach (List<Rom> roms in _datdata.Files.Values)
foreach (List<DatItem> roms in _datdata.Files.Values)
{
List<Rom> newroms = RomTools.Merge(roms, _logger);
List<DatItem> newroms = DatItem.Merge(roms, _logger);
foreach (Rom rom in newroms)
{
if (rom.Metadata.SourceID == 99)
if (rom.SourceID == 99)
{
found = true;
string key = rom.HashData.Size + "-" + rom.HashData.CRC;
@@ -168,7 +168,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> temp = new List<Rom>();
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
_matched.Files.Add(key, temp);
}
@@ -343,7 +343,7 @@ namespace SabreTools.Helper
_logger.User("Getting source file information...");
Dat matchdat = new Dat
{
Files = new Dictionary<string, List<Rom>>(),
Files = new Dictionary<string, List<DatItem>>(),
};
foreach (string file in files)
{
@@ -409,15 +409,15 @@ namespace SabreTools.Helper
#region Find all files to rebuild and bucket by game
// Create a dictionary of from/to Rom mappings
Dictionary<Rom, Rom> toFromMap = new Dictionary<Rom, Rom>();
Dictionary<DatItem, DatItem> toFromMap = new Dictionary<DatItem, DatItem>();
// Now populate it
foreach (string key in matchdat.Files.Keys)
{
foreach (Rom rom in matchdat.Files[key])
foreach (DatItem rom in matchdat.Files[key])
{
List<Rom> matched = RomTools.GetDuplicates(rom, _datdata, _logger, true);
foreach (Rom match in matched)
List<DatItem> matched = DatItem.GetDuplicates(rom, _datdata, _logger, true);
foreach (DatItem match in matched)
{
try
{
@@ -429,7 +429,7 @@ namespace SabreTools.Helper
}
// Then bucket the keys by game for better output
SortedDictionary<string, List<Rom>> keysByGame = DatTools.BucketByGame(toFromMap.Keys.ToList(), false, true, _logger);
SortedDictionary<string, List<DatItem>> keysByGame = DatTools.BucketByGame(toFromMap.Keys.ToList(), false, true, _logger);
#endregion
@@ -467,7 +467,7 @@ namespace SabreTools.Helper
}
// Otherwise, set the machine name as the full path to the file
rom.Machine.Name = Path.GetDirectoryName(Path.GetFullPath(file));
rom.MachineName = Path.GetDirectoryName(Path.GetFullPath(file));
// Add the rom information to the Dat
string key = rom.HashData.Size + "-" + rom.HashData.CRC;
@@ -477,7 +477,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> temp = new List<Rom>();
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
matchdat.Files.Add(key, temp);
}
@@ -494,7 +494,7 @@ namespace SabreTools.Helper
Skippers.TransformStream(input, output, rule, _logger, false, true);
Rom romNH = FileTools.GetSingleStreamInfo(output);
romNH.Name = "HEAD::" + rom.Name;
romNH.Machine.Name = rom.Machine.Name;
romNH.MachineName = rom.MachineName;
// Add the rom information to the Dat
key = romNH.HashData.Size + "-" + romNH.HashData.CRC;
@@ -504,7 +504,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> temp = new List<Rom>();
List<DatItem> temp = new List<DatItem>();
temp.Add(romNH);
matchdat.Files.Add(key, temp);
}
@@ -548,7 +548,7 @@ namespace SabreTools.Helper
}
// Try to find the matches to the file that was found
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger);
List<DatItem> foundroms = DatItem.GetDuplicates(rom, _datdata, _logger);
_logger.Log("File '" + input + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Rom found in foundroms)
{
@@ -562,7 +562,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> temp = new List<Rom>();
List<DatItem> temp = new List<DatItem>();
temp.Add(found);
_matched.Files.Add(key, temp);
}
@@ -570,7 +570,7 @@ namespace SabreTools.Helper
if (_toFolder)
{
// Copy file to output directory
string gamedir = Path.Combine(_outDir, found.Machine.Name);
string gamedir = Path.Combine(_outDir, found.MachineName);
if (!Directory.Exists(gamedir))
{
Directory.CreateDirectory(gamedir);
@@ -618,7 +618,7 @@ namespace SabreTools.Helper
}
// Try to find the matches to the file that was found
List<Rom> founddroms = RomTools.GetDuplicates(drom, _datdata, _logger);
List<DatItem> founddroms = DatItem.GetDuplicates(drom, _datdata, _logger);
_logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!");
foreach (Rom found in founddroms)
{
@@ -630,7 +630,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> temp = new List<Rom>();
List<DatItem> temp = new List<DatItem>();
temp.Add(found);
_matched.Files.Add(key, temp);
}
@@ -641,7 +641,7 @@ namespace SabreTools.Helper
if (_toFolder)
{
// Copy file to output directory
string gamedir = Path.Combine(_outDir, found.Machine.Name);
string gamedir = Path.Combine(_outDir, found.MachineName);
if (!Directory.Exists(gamedir))
{
Directory.CreateDirectory(gamedir);
@@ -683,7 +683,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> temp = new List<Rom>();
List<DatItem> temp = new List<DatItem>();
temp.Add(newfound);
_matched.Files.Add(key, temp);
}
@@ -691,7 +691,7 @@ namespace SabreTools.Helper
if (_toFolder)
{
// Copy file to output directory
string gamedir = Path.Combine(_outDir, found.Machine.Name);
string gamedir = Path.Combine(_outDir, found.MachineName);
if (!Directory.Exists(gamedir))
{
Directory.CreateDirectory(gamedir);
@@ -750,7 +750,7 @@ namespace SabreTools.Helper
foreach (Rom rom in internalRomData)
{
// Try to find the matches to the file that was found
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger);
List<DatItem> foundroms = DatItem.GetDuplicates(rom, _datdata, _logger);
_logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Rom found in foundroms)
{
@@ -762,7 +762,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> temp = new List<Rom>();
List<DatItem> temp = new List<DatItem>();
temp.Add(found);
_matched.Files.Add(key, temp);
}
@@ -774,7 +774,7 @@ namespace SabreTools.Helper
string outfile = FileTools.ExtractSingleItemFromArchive(input, rom.Name, _tempDir, _logger);
if (File.Exists(outfile))
{
string gamedir = Path.Combine(_outDir, found.Machine.Name);
string gamedir = Path.Combine(_outDir, found.MachineName);
if (!Directory.Exists(gamedir))
{
Directory.CreateDirectory(gamedir);
@@ -888,7 +888,7 @@ namespace SabreTools.Helper
}
// Now process the inputs (assumed that it's archived sets as of right now
Dictionary<string, List<Rom>> scanned = new Dictionary<string, List<Rom>>();
Dictionary<string, List<DatItem>> scanned = new Dictionary<string, List<DatItem>>();
foreach (string archive in Directory.EnumerateFiles(_outDir, "*", SearchOption.AllDirectories))
{
// If we are in quickscan, get the list of roms that way
@@ -921,7 +921,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> templist = new List<Rom>();
List<DatItem> templist = new List<DatItem>();
templist.Add(rom);
scanned.Add(key, templist);
}
@@ -935,7 +935,7 @@ namespace SabreTools.Helper
}
// Now that we have all of the from DAT and from folder roms, we try to match them, removing the perfect matches
Dictionary<string, List<Rom>> remove = new Dictionary<string, List<Rom>>();
Dictionary<string, List<DatItem>> remove = new Dictionary<string, List<DatItem>>();
foreach (string key in scanned.Keys)
{
// If the key doesn't even exist in the DAT, then mark the entire key for removal
@@ -953,8 +953,8 @@ namespace SabreTools.Helper
// Otherwise check each of the values individually
else
{
List<Rom> romsList = _datdata.Files[key];
List<Rom> scannedList = scanned[key];
List<DatItem> romsList = _datdata.Files[key];
List<DatItem> scannedList = scanned[key];
foreach (Rom rom in scannedList)
{
if (!romsList.Contains(rom))
@@ -965,7 +965,7 @@ namespace SabreTools.Helper
}
else
{
List<Rom> templist = new List<Rom>();
List<DatItem> templist = new List<DatItem>();
templist.Add(rom);
remove.Add(key, templist);
}