diff --git a/RombaSharp/Partials/RombaSharp_Helpers.cs b/RombaSharp/Partials/RombaSharp_Helpers.cs index 9cfb707c..15bfd74b 100644 --- a/RombaSharp/Partials/RombaSharp_Helpers.cs +++ b/RombaSharp/Partials/RombaSharp_Helpers.cs @@ -423,9 +423,9 @@ namespace SabreTools { sldr.Read(); string hash = sldr.GetString(0); - if (datroot.Files.ContainsKey(hash)) + if (datroot.ContainsKey(hash)) { - datroot.Files[hash] = null; + datroot[hash] = null; databaseDats.Add(hash); } else if (!databaseDats.Contains(hash)) @@ -443,7 +443,7 @@ namespace SabreTools // Loop through the Dictionary and add all data _logger.User("Adding new DAT information"); start = DateTime.Now; - foreach (string key in datroot.Keys()) + foreach (string key in datroot.Keys) { foreach (Rom value in datroot[key]) { @@ -490,9 +490,9 @@ namespace SabreTools string md5sha1query = "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES"; // Loop through the parsed entries - foreach (string romkey in tempdat.Files.Keys) + foreach (string romkey in tempdat.Keys) { - foreach (DatItem datItem in tempdat.Files[romkey]) + foreach (DatItem datItem in tempdat[romkey]) { _logger.Verbose("Checking and adding file '" + datItem.Name); @@ -628,10 +628,10 @@ namespace SabreTools // Once we have both, check for any new files List dupehashes = new List(); - List keys = depot.Files.Keys.ToList(); + List keys = depot.Keys.ToList(); foreach (string key in keys) { - List roms = depot.Files[key]; + List roms = depot[key]; foreach (Rom rom in roms) { if (hashes.Contains(rom.SHA1)) diff --git a/RombaSharp/Partials/RombaSharp_Inits.cs b/RombaSharp/Partials/RombaSharp_Inits.cs index e9fbbbe5..f159b14c 100644 --- a/RombaSharp/Partials/RombaSharp_Inits.cs +++ b/RombaSharp/Partials/RombaSharp_Inits.cs @@ -52,7 +52,6 @@ namespace SabreTools // Create an empty Dat for files that need to be rebuilt DatFile need = new DatFile(); - need.Files = new SortedDictionary>(); // Open the database connection SqliteConnection dbc = new SqliteConnection(_connectionString); @@ -65,9 +64,9 @@ namespace SabreTools string crcsha1query = "INSERT OR IGNORE INTO crcsha1 (crc, sha1) VALUES"; string md5sha1query = "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES"; - foreach (string key in df.Files.Keys) + foreach (string key in df.Keys) { - List datItems = df.Files[key]; + List datItems = df[key]; foreach (Rom rom in datItems) { // If we care about if the file exists, check the databse first @@ -242,7 +241,6 @@ namespace SabreTools Name = Path.GetFileName(inputs[0]) + " Dir2Dat", Description = Path.GetFileName(inputs[0]) + " Dir2Dat", DatFormat = DatFormat.Logiqx, - Files = new SortedDictionary>(), }; Logger logger = new Logger(); diff --git a/SabreTools.Helper/Dats/DatFile.cs b/SabreTools.Helper/Dats/DatFile.cs index 236dee8f..8e0675ac 100644 --- a/SabreTools.Helper/Dats/DatFile.cs +++ b/SabreTools.Helper/Dats/DatFile.cs @@ -159,21 +159,6 @@ namespace SabreTools.Helper.Dats get { return _mergeRoms; } set { _mergeRoms = value; } } - protected SortedDictionary> Files - { - get - { - if (_files == null) - { - _files = new SortedDictionary>(); - } - return _files; - } - set - { - _files = value; - } - } public SortedBy SortedBy { get { return _sortedBy; } @@ -431,6 +416,14 @@ namespace SabreTools.Helper.Dats } } + /// + /// Delete the file dictionary + /// + public void Delete() + { + _files = null; + } + /// /// Get the keys from the file dictionary /// @@ -474,13 +467,30 @@ namespace SabreTools.Helper.Dats } } + /// + /// Reset the file dictionary + /// + public void Reset() + { + _files = new SortedDictionary>(); + } + + /// + /// Set a new file dictionary from an existing one + /// + /// + public void Set(SortedDictionary> newdict) + { + _files = newdict; + } + #endregion #region Cloning Methods [MODULAR DONE] public object Clone() { - return new DatFile + DatFile df = new DatFile { FileName = _fileName, Name = _name, @@ -502,7 +512,6 @@ namespace SabreTools.Helper.Dats ExcludeOf = _excludeOf, DatFormat = _datFormat, MergeRoms = _mergeRoms, - Files = _files, SortedBy = _sortedBy, UseGame = _useGame, Prefix = _prefix, @@ -522,6 +531,9 @@ namespace SabreTools.Helper.Dats BaddumpCount = _baddumpCount, NodumpCount = _nodumpCount, }; + + df.Set(_files); + return df; } public object CloneHeader() @@ -548,7 +560,6 @@ namespace SabreTools.Helper.Dats ExcludeOf = _excludeOf, DatFormat = _datFormat, MergeRoms = _mergeRoms, - Files = new SortedDictionary>(), SortedBy = SortedBy.Default, UseGame = _useGame, Prefix = _prefix, diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs index fad3c81a..22586b54 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Bucketing.cs @@ -33,19 +33,13 @@ namespace SabreTools.Helper.Dats SortedDictionary> sortable = new SortedDictionary>(); long count = 0; - // If we have a null dict or an empty one, output a new dictionary - if (Files == null || Files.Count == 0) - { - Files = sortable; - } - logger.User("Organizing " + (mergeroms ? "and merging " : "") + "roms by CRC"); // Process each all of the roms - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = Files[key]; + List roms = this[key]; // If we're merging the roms, do so if (mergeroms) @@ -83,7 +77,7 @@ namespace SabreTools.Helper.Dats } // Now assign the dictionary back - Files = sortable; + _files = sortable; } /// @@ -108,19 +102,13 @@ namespace SabreTools.Helper.Dats SortedDictionary> sortable = new SortedDictionary>(); long count = 0; - // If we have a null dict or an empty one, output a new dictionary - if (Files == null || Files.Count == 0) - { - Files = sortable; - } - logger.User("Organizing " + (mergeroms ? "and merging " : "") + "roms by game"); // Process each all of the roms - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = Files[key]; + List roms = this[key]; // If we're merging the roms, do so if (mergeroms) @@ -170,7 +158,7 @@ namespace SabreTools.Helper.Dats } // Now assign the dictionary back - Files = sortable; + _files = sortable; } /// @@ -193,19 +181,13 @@ namespace SabreTools.Helper.Dats SortedDictionary> sortable = new SortedDictionary>(); long count = 0; - // If we have a null dict or an empty one, output a new dictionary - if (Files == null || Files.Count == 0) - { - Files = sortable; - } - logger.User("Organizing " + (mergeroms ? "and merging " : "") + "roms by MD5"); // Process each all of the roms - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = Files[key]; + List roms = this[key]; // If we're merging the roms, do so if (mergeroms) @@ -247,7 +229,7 @@ namespace SabreTools.Helper.Dats } // Now assign the dictionary back - Files = sortable; + _files = sortable; } /// @@ -270,19 +252,13 @@ namespace SabreTools.Helper.Dats SortedDictionary> sortable = new SortedDictionary>(); long count = 0; - // If we have a null dict or an empty one, output a new dictionary - if (Files == null || Files.Count == 0) - { - Files = sortable; - } - logger.User("Organizing " + (mergeroms ? "and merging " : "") + "roms by SHA-1"); // Process each all of the roms - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = Files[key]; + List roms = this[key]; // If we're merging the roms, do so if (mergeroms) @@ -324,7 +300,7 @@ namespace SabreTools.Helper.Dats } // Now assign the dictionary back - Files = sortable; + _files = sortable; } /// @@ -347,19 +323,13 @@ namespace SabreTools.Helper.Dats SortedDictionary> sortable = new SortedDictionary>(); long count = 0; - // If we have a null dict or an empty one, output a new dictionary - if (Files == null || Files.Count == 0) - { - Files = sortable; - } - logger.User("Organizing " + (mergeroms ? "and merging " : "") + "roms by size"); // Process each all of the roms - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = Files[key]; + List roms = this[key]; // If we're merging the roms, do so if (mergeroms) @@ -397,7 +367,7 @@ namespace SabreTools.Helper.Dats } // Now assign the dictionary back - Files = sortable; + _files = sortable; } #endregion diff --git a/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs b/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs index 746c4bfe..aeeb1271 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs @@ -110,7 +110,6 @@ namespace SabreTools.Helper.Dats datHeaders[i] = new DatFile { DatFormat = (DatFormat != 0 ? DatFormat : 0), - Files = new SortedDictionary>(), MergeRoms = MergeRoms, }; @@ -120,16 +119,15 @@ namespace SabreTools.Helper.Dats logger.User("Processing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff")); logger.User("Populating internal DAT"); - Files = new SortedDictionary>(); for (int i = 0; i < inputs.Count; i++) { - List keys = datHeaders[i].Files.Keys.ToList(); + List keys = datHeaders[i].Keys.ToList(); foreach (string key in keys) { AddRange(key, datHeaders[i][key]); datHeaders[i].Remove(key); } - datHeaders[i].Files = null; + datHeaders[i].Delete(); } /// END @@ -163,7 +161,7 @@ namespace SabreTools.Helper.Dats outerDiffData.FileName += post; outerDiffData.Name += post; outerDiffData.Description += post; - outerDiffData.Files = new SortedDictionary>(); + outerDiffData.Reset(); } // Have External dupes @@ -174,7 +172,7 @@ namespace SabreTools.Helper.Dats dupeData.FileName += post; dupeData.Name += post; dupeData.Description += post; - dupeData.Files = new SortedDictionary>(); + dupeData.Reset(); } // Create a list of DatData objects representing individual output files @@ -192,7 +190,7 @@ namespace SabreTools.Helper.Dats diffData.FileName += innerpost; diffData.Name += innerpost; diffData.Description += innerpost; - diffData.Files = new SortedDictionary>(); + diffData.Reset(); outDatsArray[j] = diffData; }); @@ -203,10 +201,10 @@ namespace SabreTools.Helper.Dats // Now, loop through the dictionary and populate the correct DATs start = DateTime.Now; logger.User("Populating all output DATs"); - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = DatItem.Merge(Files[key], logger); + List roms = DatItem.Merge(this[key], logger); if (roms != null && roms.Count > 0) { @@ -278,7 +276,7 @@ namespace SabreTools.Helper.Dats : (Path.GetDirectoryName(split[0]).Remove(0, split[1].Length))); // If we have more than 0 roms, output - if (outDats[j].Files.Count > 0) + if (outDats[j].Count > 0) { outDats[j].WriteToFile(path, logger); } @@ -326,7 +324,7 @@ namespace SabreTools.Helper.Dats diffData.Name += post; diffData.Description += post; } - diffData.Files = new SortedDictionary>(); + diffData.Reset(); outDatsArray[j] = diffData; }); @@ -337,11 +335,11 @@ namespace SabreTools.Helper.Dats // Now, loop through the dictionary and populate the correct DATs start = DateTime.Now; logger.User("Populating all output DATs"); - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = DatItem.Merge(Files[key], logger); + List roms = DatItem.Merge(this[key], logger); if (roms != null && roms.Count > 0) { @@ -380,7 +378,7 @@ namespace SabreTools.Helper.Dats } // If we have more than 0 roms, output - if (outDats[j].Files.Count > 0) + if (outDats[j].Count > 0) { outDats[j].WriteToFile(path, logger); } @@ -400,11 +398,11 @@ namespace SabreTools.Helper.Dats // If we're in SuperDAT mode, prefix all games with their respective DATs if (Type == "SuperDAT") { - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { List newroms = new List(); - foreach (DatItem rom in Files[key]) + foreach (DatItem rom in this[key]) { DatItem newrom = rom; string filename = inputs[newrom.SystemID].Split('¬')[0]; @@ -417,12 +415,12 @@ namespace SabreTools.Helper.Dats + newrom.Machine.Name; newroms.Add(newrom); } - Files[key] = newroms; + this[key] = newroms; } } // Output a DAT only if there are roms - if (Files.Count != 0) + if (Count != 0) { WriteToFile(outDir, logger); } @@ -468,7 +466,7 @@ namespace SabreTools.Helper.Dats keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); // If we have roms, output them - if (innerDatdata.Files.Count != 0) + if (innerDatdata.Count != 0) { innerDatdata.WriteToFile((outDir == "" ? Path.GetDirectoryName(inputFileName) : outDir), logger, overwrite: (outDir != "")); } @@ -483,13 +481,13 @@ namespace SabreTools.Helper.Dats { logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\""); DatFile innerDatdata = (DatFile)Clone(); - innerDatdata.Files = null; + innerDatdata.Delete(); innerDatdata.Parse(file, 0, 0, filter, trim, single, root, logger, true, clean, softlist, keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); - // If we have roms, output them - if (innerDatdata.Files != null && innerDatdata.Files.Count != 0) + // If we have roms, output them + if (innerDatdata.Count > 0) { innerDatdata.WriteToFile((outDir == "" ? Path.GetDirectoryName(file) : outDir + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), logger, overwrite: (outDir != "")); } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs b/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs index 6c403455..abc23a72 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.DFD.cs @@ -62,12 +62,6 @@ namespace SabreTools.Helper.Dats Description = Name + (bare ? "" : " (" + Date + ")"); } - // Make sure the dictionary is defined - if (Files == null || Files.Keys.Count == 0) - { - Files = new SortedDictionary>(); - } - // Process the input if (Directory.Exists(basePath)) { @@ -159,7 +153,7 @@ namespace SabreTools.Helper.Dats } logger.Verbose("Adding blank empty folder: " + gamename); - Files["null"].Add(new Rom(romname, gamename)); + this["null"].Add(new Rom(romname, gamename)); } }); } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs index e9008910..1796f835 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs @@ -92,12 +92,6 @@ namespace SabreTools.Helper.Dats // If the output type isn't set already, get the internal output type DatFormat = (DatFormat == 0 ? FileTools.GetDatFormat(filename, logger) : DatFormat); - // Make sure there's a dictionary to read to - if (Files == null) - { - Files = new SortedDictionary>(); - } - // Now parse the correct type of DAT switch (FileTools.GetDatFormat(filename, logger)) { @@ -1582,14 +1576,14 @@ namespace SabreTools.Helper.Dats // If the rom is continue or ignore, add the size to the previous rom if (subreader.GetAttribute("loadflag") == "continue" || subreader.GetAttribute("loadflag") == "ignore") { - int index = Files[key].Count() - 1; - DatItem lastrom = Files[key][index]; + int index = this[key].Count() - 1; + DatItem lastrom = this[key][index]; if (lastrom.Type == ItemType.Rom) { ((Rom)lastrom).Size += size; } - Files[key].RemoveAt(index); - Files[key].Add(lastrom); + this[key].RemoveAt(index); + this[key].Add(lastrom); subreader.Read(); continue; } @@ -1763,14 +1757,14 @@ namespace SabreTools.Helper.Dats // If the rom is continue or ignore, add the size to the previous rom if (xtr.GetAttribute("loadflag") == "continue" || xtr.GetAttribute("loadflag") == "ignore") { - int index = Files[key].Count() - 1; - DatItem lastrom = Files[key][index]; + int index = this[key].Count() - 1; + DatItem lastrom = this[key][index]; if (lastrom.Type == ItemType.Rom) { ((Rom)lastrom).Size += size; } - Files[key].RemoveAt(index); - Files[key].Add(lastrom); + this[key].RemoveAt(index); + this[key].Add(lastrom); continue; } @@ -2320,48 +2314,45 @@ namespace SabreTools.Helper.Dats } } - lock (Files) + // Get the key and add statistical data + switch (item.Type) { - // Get the key and add statistical data - switch (item.Type) - { - case ItemType.Archive: - case ItemType.BiosSet: - case ItemType.Release: - case ItemType.Sample: - key = item.Type.ToString(); - break; - case ItemType.Disk: - key = ((Disk)item).MD5; + case ItemType.Archive: + case ItemType.BiosSet: + case ItemType.Release: + case ItemType.Sample: + key = item.Type.ToString(); + break; + case ItemType.Disk: + key = ((Disk)item).MD5; - // Add statistical data - DiskCount += 1; - TotalSize += 0; - MD5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1); - SHA1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1); - BaddumpCount += (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); - NodumpCount += (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0); - break; - case ItemType.Rom: - key = ((Rom)item).Size + "-" + ((Rom)item).CRC; + // Add statistical data + DiskCount += 1; + TotalSize += 0; + MD5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1); + SHA1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1); + BaddumpCount += (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); + NodumpCount += (((Disk)item).ItemStatus == ItemStatus.Nodump ? 1 : 0); + break; + case ItemType.Rom: + key = ((Rom)item).Size + "-" + ((Rom)item).CRC; - // Add statistical data - RomCount += 1; - TotalSize += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 0 : ((Rom)item).Size); - CRCCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1); - MD5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1); - SHA1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1); - BaddumpCount += (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); - NodumpCount += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0); - break; - default: - key = "default"; - break; - } - - // Add the item to the DAT - Add(key, item); + // Add statistical data + RomCount += 1; + TotalSize += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 0 : ((Rom)item).Size); + CRCCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1); + MD5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1); + SHA1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1); + BaddumpCount += (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); + NodumpCount += (((Rom)item).ItemStatus == ItemStatus.Nodump ? 1 : 0); + break; + default: + key = "default"; + break; } + + // Add the item to the DAT + Add(key, item); } } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs b/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs index 529bc6ff..dce6cad0 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs @@ -45,7 +45,7 @@ namespace SabreTools.Helper.Dats #region Perform setup // If the DAT is not populated and inverse is not set, inform the user and quit - if ((Files == null || Files.Count == 0) && !inverse) + if (Count == 0 && !inverse) { logger.User("No entries were found to rebuild, exiting..."); return false; @@ -149,22 +149,14 @@ namespace SabreTools.Helper.Dats { Rom rom = FileTools.GetFileInfo(file, logger, noMD5: quickScan, noSHA1: quickScan, header: headerToCheckAgainst); rom.Name = Path.GetFullPath(file); - - lock (Files) - { - current.Add(rom.Size + "-" + rom.CRC, rom); - } + current.Add(rom.Size + "-" + rom.CRC, rom); // If we had a header, we want the full file information too if (headerToCheckAgainst != null) { rom = FileTools.GetFileInfo(file, logger, noMD5: quickScan, noSHA1: quickScan); rom.Name = Path.GetFullPath(file); - - lock (Files) - { - current.Add(rom.Size + "-" + rom.CRC, rom); - } + current.Add(rom.Size + "-" + rom.CRC, rom); } } @@ -180,11 +172,7 @@ namespace SabreTools.Helper.Dats { Rom newrom = rom; newrom.Machine = new Machine(Path.GetFullPath(file), ""); - - lock (Files) - { - current.Add(rom.Size + "-" + rom.CRC, newrom); - } + current.Add(rom.Size + "-" + rom.CRC, newrom); } } // Otherwise, attempt to extract the files to the temporary directory @@ -203,22 +191,14 @@ namespace SabreTools.Helper.Dats { Rom rom = FileTools.GetFileInfo(entry, logger, noMD5: quickScan, noSHA1: quickScan, header: headerToCheckAgainst); rom.Machine = new Machine(Path.GetFullPath(file), ""); - - lock (Files) - { - current.Add(rom.Size + "-" + rom.CRC, rom); - } + current.Add(rom.Size + "-" + rom.CRC, rom); // If we had a header, we want the full file information too if (headerToCheckAgainst != null) { rom = FileTools.GetFileInfo(file, logger, noMD5: quickScan, noSHA1: quickScan); rom.Machine = new Machine(Path.GetFullPath(file), ""); - - lock (Files) - { - current.Add(rom.Size + "-" + rom.CRC, rom); - } + current.Add(rom.Size + "-" + rom.CRC, rom); } }); } @@ -227,11 +207,7 @@ namespace SabreTools.Helper.Dats { Rom rom = FileTools.GetFileInfo(file, logger, noMD5: quickScan, noSHA1: quickScan, header: headerToCheckAgainst); rom.Name = Path.GetFullPath(file); - - lock (Files) - { - current.Add(rom.Size + "-" + rom.CRC, rom); - } + current.Add(rom.Size + "-" + rom.CRC, rom); } } } @@ -263,7 +239,7 @@ namespace SabreTools.Helper.Dats current.BucketByCRC(false, logger, output: false); // Now loop over and find all files that need to be rebuilt - List keys = current.Files.Keys.ToList(); + List keys = current.Keys.ToList(); Parallel.ForEach(keys, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, key => @@ -272,7 +248,7 @@ namespace SabreTools.Helper.Dats if (inverse) { // Check for duplicates - List datItems = current.Files[key]; + List datItems = current[key]; foreach (Rom rom in datItems) { // If the rom has duplicates, we skip it @@ -312,13 +288,13 @@ namespace SabreTools.Helper.Dats else { // If the input DAT doesn't have the key, then nothing from the current DAT are there - if (!Files.ContainsKey(key)) + if (!ContainsKey(key)) { return; } // Otherwise, we try to find duplicates - List datItems = current.Files[key]; + List datItems = current[key]; foreach (Rom rom in datItems) { List found = rom.GetDuplicates(this, logger, false); @@ -536,7 +512,7 @@ namespace SabreTools.Helper.Dats // Setup the fixdat DatFile matched = (DatFile)CloneHeader(); - matched.Files = new SortedDictionary>(); + matched.Reset(); matched.FileName = "fixDat_" + matched.FileName; matched.Name = "fixDat_" + matched.Name; matched.Description = "fixDat_" + matched.Description; @@ -544,8 +520,9 @@ namespace SabreTools.Helper.Dats // Now that all files are parsed, get only files found in directory bool found = false; - foreach (List roms in Files.Values) + foreach (string key in Keys) { + List roms = this[key]; List newroms = DatItem.Merge(roms, logger); foreach (Rom rom in newroms) { diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Splitters.cs b/SabreTools.Helper/Dats/Partials/DatFile.Splitters.cs index b4dc661f..9caadb14 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Splitters.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Splitters.cs @@ -59,7 +59,6 @@ namespace SabreTools.Helper.Dats Homepage = this.Homepage, Url = this.Url, Comment = this.Comment, - Files = new SortedDictionary>(), DatFormat = this.DatFormat, }; DatFile datdataB = new DatFile @@ -75,20 +74,19 @@ namespace SabreTools.Helper.Dats Homepage = this.Homepage, Url = this.Url, Comment = this.Comment, - Files = new SortedDictionary>(), DatFormat = this.DatFormat, }; // If roms is empty, return false - if (this.Files.Count == 0) + if (Count == 0) { return false; } // Now separate the roms accordingly - foreach (string key in this.Files.Keys) + foreach (string key in Keys) { - foreach (DatItem rom in this.Files[key]) + foreach (DatItem rom in this[key]) { if (newExtA.Contains(Path.GetExtension(rom.Name.ToUpperInvariant()))) { @@ -157,7 +155,6 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; DatFile sha1 = new DatFile { @@ -179,7 +176,6 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; DatFile md5 = new DatFile { @@ -201,7 +197,6 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; DatFile crc = new DatFile { @@ -223,7 +218,6 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; DatFile other = new DatFile @@ -246,14 +240,13 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; // Now populate each of the DAT objects in turn - List keys = this.Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = this.Files[key]; + List roms = this[key]; foreach (DatItem rom in roms) { // If the file is not a Rom or Disk, continue @@ -306,19 +299,19 @@ namespace SabreTools.Helper.Dats // Now, output all of the files to the output directory logger.User("DAT information created, outputting new files"); bool success = true; - if (nodump.Files.Count > 0) + if (nodump.Count > 0) { success &= nodump.WriteToFile(outDir, logger); } - if (sha1.Files.Count > 0) + if (sha1.Count > 0) { success &= sha1.WriteToFile(outDir, logger); } - if (md5.Files.Count > 0) + if (md5.Count > 0) { success &= md5.WriteToFile(outDir, logger); } - if (crc.Files.Count > 0) + if (crc.Count > 0) { success &= crc.WriteToFile(outDir, logger); } @@ -348,7 +341,7 @@ namespace SabreTools.Helper.Dats tempDat.Name = null; // Sort the input keys - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(SplitByLevelSort); // Then, we loop over the games @@ -366,7 +359,7 @@ namespace SabreTools.Helper.Dats } // Clean the input list and set all games to be pathless - List items = Files[key]; + List items = this[key]; items.ForEach(item => item.Machine.Name = Style.GetFileName(item.Machine.Name)); items.ForEach(item => item.Machine.Description = Style.GetFileName(item.Machine.Description)); @@ -472,7 +465,6 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; DatFile diskdat = new DatFile { @@ -494,7 +486,6 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; DatFile sampledat = new DatFile { @@ -516,14 +507,13 @@ namespace SabreTools.Helper.Dats ForcePacking = this.ForcePacking, DatFormat = this.DatFormat, MergeRoms = this.MergeRoms, - Files = new SortedDictionary>(), }; // Now populate each of the DAT objects in turn - List keys = this.Files.Keys.ToList(); + List keys = Keys.ToList(); foreach (string key in keys) { - List roms = this.Files[key]; + List roms = this[key]; foreach (DatItem rom in roms) { // If the file is a Rom @@ -557,15 +547,15 @@ namespace SabreTools.Helper.Dats // Now, output all of the files to the output directory logger.User("DAT information created, outputting new files"); bool success = true; - if (romdat.Files.Count > 0) + if (romdat.Count > 0) { success &= romdat.WriteToFile(outDir, logger); } - if (diskdat.Files.Count > 0) + if (diskdat.Count > 0) { success &= diskdat.WriteToFile(outDir, logger); } - if (sampledat.Files.Count > 0) + if (sampledat.Count > 0) { success &= sampledat.WriteToFile(outDir, logger); } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs b/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs index 7da4212e..eab33abd 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs @@ -41,14 +41,15 @@ namespace SabreTools.Helper.Dats NodumpCount = 0; // If we have a blank Dat in any way, return - if (this == null || Files == null || Files.Count == 0) + if (this == null || Count == 0) { return; } // Loop through and add - foreach (List roms in Files.Values) + foreach (string key in Keys) { + List roms = this[key]; foreach (Rom rom in roms) { RomCount += (rom.Type == ItemType.Rom ? 1 : 0); @@ -101,7 +102,7 @@ namespace SabreTools.Helper.Dats string results = @"For '" + FileName + @"': -------------------------------------------------- Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @" - Games found: " + (game == -1 ? Files.Count : game) + @" + Games found: " + (game == -1 ? Count : game) + @" Roms found: " + RomCount + @" Disks found: " + DiskCount + @" Roms with CRC: " + CRCCount + @" @@ -126,7 +127,7 @@ namespace SabreTools.Helper.Dats case StatDatFormat.CSV: line = "\"" + FileName + "\"," + "\"" + Style.GetBytesReadable(TotalSize) + "\"," - + "\"" + (game == -1 ? Files.Count : game) + "\"," + + "\"" + (game == -1 ? Count : game) + "\"," + "\"" + RomCount + "\"," + "\"" + DiskCount + "\"," + "\"" + CRCCount + "\"," @@ -149,7 +150,7 @@ namespace SabreTools.Helper.Dats ? " class=\"dir\">" + HttpUtility.HtmlEncode(FileName.Remove(0, 5)) : ">" + HttpUtility.HtmlEncode(FileName)) + "" + "" + Style.GetBytesReadable(TotalSize) + "" - + "" + (game == -1 ? Files.Count : game) + "" + + "" + (game == -1 ? Count : game) + "" + "" + RomCount + "" + "" + DiskCount + "" + "" + CRCCount + "" @@ -172,7 +173,7 @@ namespace SabreTools.Helper.Dats line = @"'" + FileName + @"': -------------------------------------------------- Uncompressed size: " + Style.GetBytesReadable(TotalSize) + @" - Games found: " + (game == -1 ? Files.Count : game) + @" + Games found: " + (game == -1 ? Count : game) + @" Roms found: " + RomCount + @" Disks found: " + DiskCount + @" Roms with CRC: " + CRCCount + @" @@ -191,7 +192,7 @@ namespace SabreTools.Helper.Dats case StatDatFormat.TSV: line = "\"" + FileName + "\"\t" + "\"" + Style.GetBytesReadable(TotalSize) + "\"\t" - + "\"" + (game == -1 ? Files.Count : game) + "\"\t" + + "\"" + (game == -1 ? Count : game) + "\"\t" + "\"" + RomCount + "\"\t" + "\"" + DiskCount + "\"\t" + "\"" + CRCCount + "\"\t" @@ -347,7 +348,7 @@ namespace SabreTools.Helper.Dats // Add single DAT stats to dir dirSize += datdata.TotalSize; - dirGame += datdata.Files.Count; + dirGame += datdata.Count; dirRom += datdata.RomCount; dirDisk += datdata.DiskCount; dirCRC += datdata.CRCCount; @@ -358,7 +359,7 @@ namespace SabreTools.Helper.Dats // Add single DAT stats to totals totalSize += datdata.TotalSize; - totalGame += datdata.Files.Count; + totalGame += datdata.Count; totalRom += datdata.RomCount; totalDisk += datdata.DiskCount; totalCRC += datdata.CRCCount; diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs b/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs index 2cbf27a1..bf5c4689 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Writers.cs @@ -42,7 +42,7 @@ namespace SabreTools.Helper.Dats public bool WriteToFile(string outDir, Logger logger, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true) { // If there's nothing there, abort - if (Files == null || Files.Count == 0) + if (Count == 0) { return false; } @@ -116,7 +116,7 @@ namespace SabreTools.Helper.Dats try { // Get a properly sorted set of keys - List keys = Files.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (DatFormat datFormat in outfiles.Keys) @@ -137,7 +137,7 @@ namespace SabreTools.Helper.Dats foreach (string key in keys) { - List roms = Files[key]; + List roms = this[key]; for (int index = 0; index < roms.Count; index++) { @@ -310,7 +310,7 @@ namespace SabreTools.Helper.Dats + "\n" + "\t\n" + "\t\t" + HttpUtility.HtmlEncode(Name) + "\n" - + "\t\t" + Files.Count + "\n" + + "\t\t" + Count + "\n" + "\t\tnone\n" + "\t\t240\n" + "\t\t160\n" @@ -1290,7 +1290,7 @@ namespace SabreTools.Helper.Dats string footer = ""; // If we have roms, output the full footer - if (Files != null && Files.Count > 0) + if (Count > 0) { switch (datFormat) { diff --git a/SabreTools/Partials/SabreTools_Inits.cs b/SabreTools/Partials/SabreTools_Inits.cs index ddbc971a..b9a1a316 100644 --- a/SabreTools/Partials/SabreTools_Inits.cs +++ b/SabreTools/Partials/SabreTools_Inits.cs @@ -102,7 +102,6 @@ namespace SabreTools Romba = romba, ExcludeOf = excludeOf, Type = (superdat ? "SuperDAT" : ""), - Files = new SortedDictionary>(), }; // Clean the temp directory @@ -115,7 +114,7 @@ namespace SabreTools { // Clone the base Dat for information DatFile datdata = (DatFile)basedat.Clone(); - datdata.Files = new SortedDictionary>(); + datdata.Reset(); string basePath = Path.GetFullPath(path); bool success = datdata.PopulateFromDir(basePath, noMD5, noSHA1, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip,