mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Remove all references to Files as an independent variable
This commit is contained in:
@@ -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<string> dupehashes = new List<string>();
|
||||
List<string> keys = depot.Files.Keys.ToList();
|
||||
List<string> keys = depot.Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = depot.Files[key];
|
||||
List<DatItem> roms = depot[key];
|
||||
foreach (Rom rom in roms)
|
||||
{
|
||||
if (hashes.Contains(rom.SHA1))
|
||||
|
||||
@@ -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<string, List<DatItem>>();
|
||||
|
||||
// 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<DatItem> datItems = df.Files[key];
|
||||
List<DatItem> 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<string, List<DatItem>>(),
|
||||
};
|
||||
|
||||
Logger logger = new Logger();
|
||||
|
||||
@@ -159,21 +159,6 @@ namespace SabreTools.Helper.Dats
|
||||
get { return _mergeRoms; }
|
||||
set { _mergeRoms = value; }
|
||||
}
|
||||
protected SortedDictionary<string, List<DatItem>> Files
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_files == null)
|
||||
{
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
return _files;
|
||||
}
|
||||
set
|
||||
{
|
||||
_files = value;
|
||||
}
|
||||
}
|
||||
public SortedBy SortedBy
|
||||
{
|
||||
get { return _sortedBy; }
|
||||
@@ -431,6 +416,14 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the file dictionary
|
||||
/// </summary>
|
||||
public void Delete()
|
||||
{
|
||||
_files = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the keys from the file dictionary
|
||||
/// </summary>
|
||||
@@ -474,13 +467,30 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the file dictionary
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_files = new SortedDictionary<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set a new file dictionary from an existing one
|
||||
/// </summary>
|
||||
/// <param name="newdict"></param>
|
||||
public void Set(SortedDictionary<string, List<DatItem>> 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<string, List<DatItem>>(),
|
||||
SortedBy = SortedBy.Default,
|
||||
UseGame = _useGame,
|
||||
Prefix = _prefix,
|
||||
|
||||
@@ -33,19 +33,13 @@ namespace SabreTools.Helper.Dats
|
||||
SortedDictionary<string, List<DatItem>> sortable = new SortedDictionary<string, List<DatItem>>();
|
||||
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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = Files[key];
|
||||
List<DatItem> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,19 +102,13 @@ namespace SabreTools.Helper.Dats
|
||||
SortedDictionary<string, List<DatItem>> sortable = new SortedDictionary<string, List<DatItem>>();
|
||||
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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = Files[key];
|
||||
List<DatItem> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,19 +181,13 @@ namespace SabreTools.Helper.Dats
|
||||
SortedDictionary<string, List<DatItem>> sortable = new SortedDictionary<string, List<DatItem>>();
|
||||
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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = Files[key];
|
||||
List<DatItem> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -270,19 +252,13 @@ namespace SabreTools.Helper.Dats
|
||||
SortedDictionary<string, List<DatItem>> sortable = new SortedDictionary<string, List<DatItem>>();
|
||||
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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = Files[key];
|
||||
List<DatItem> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -347,19 +323,13 @@ namespace SabreTools.Helper.Dats
|
||||
SortedDictionary<string, List<DatItem>> sortable = new SortedDictionary<string, List<DatItem>>();
|
||||
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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = Files[key];
|
||||
List<DatItem> 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
|
||||
|
||||
@@ -110,7 +110,6 @@ namespace SabreTools.Helper.Dats
|
||||
datHeaders[i] = new DatFile
|
||||
{
|
||||
DatFormat = (DatFormat != 0 ? DatFormat : 0),
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
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<string, List<DatItem>>();
|
||||
for (int i = 0; i < inputs.Count; i++)
|
||||
{
|
||||
List<string> keys = datHeaders[i].Files.Keys.ToList();
|
||||
List<string> 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<string, List<DatItem>>();
|
||||
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<string, List<DatItem>>();
|
||||
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<string, List<DatItem>>();
|
||||
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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = DatItem.Merge(Files[key], logger);
|
||||
List<DatItem> 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<string, List<DatItem>>();
|
||||
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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = DatItem.Merge(Files[key], logger);
|
||||
List<DatItem> 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<string> keys = Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> newroms = new List<DatItem>();
|
||||
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 (innerDatdata.Count > 0)
|
||||
{
|
||||
innerDatdata.WriteToFile((outDir == "" ? Path.GetDirectoryName(file) : outDir + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), logger, overwrite: (outDir != ""));
|
||||
}
|
||||
|
||||
@@ -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<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<string, List<DatItem>>();
|
||||
}
|
||||
|
||||
// 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,8 +2314,6 @@ namespace SabreTools.Helper.Dats
|
||||
}
|
||||
}
|
||||
|
||||
lock (Files)
|
||||
{
|
||||
// Get the key and add statistical data
|
||||
switch (item.Type)
|
||||
{
|
||||
@@ -2363,7 +2355,6 @@ namespace SabreTools.Helper.Dats
|
||||
Add(key, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -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,24 +149,16 @@ 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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we're supposed to scan the file internally
|
||||
if (shouldInternalProcess)
|
||||
@@ -180,13 +172,9 @@ namespace SabreTools.Helper.Dats
|
||||
{
|
||||
Rom newrom = rom;
|
||||
newrom.Machine = new Machine(Path.GetFullPath(file), "");
|
||||
|
||||
lock (Files)
|
||||
{
|
||||
current.Add(rom.Size + "-" + rom.CRC, newrom);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Otherwise, attempt to extract the files to the temporary directory
|
||||
else
|
||||
{
|
||||
@@ -203,23 +191,15 @@ 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);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// Otherwise, just get the info on the file itself
|
||||
@@ -227,14 +207,10 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now delete the temp directory
|
||||
try
|
||||
@@ -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<string> keys = current.Files.Keys.ToList();
|
||||
List<string> 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<DatItem> datItems = current.Files[key];
|
||||
List<DatItem> 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<DatItem> datItems = current.Files[key];
|
||||
List<DatItem> datItems = current[key];
|
||||
foreach (Rom rom in datItems)
|
||||
{
|
||||
List<DatItem> 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<string, List<DatItem>>();
|
||||
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<DatItem> roms in Files.Values)
|
||||
foreach (string key in Keys)
|
||||
{
|
||||
List<DatItem> roms = this[key];
|
||||
List<DatItem> newroms = DatItem.Merge(roms, logger);
|
||||
foreach (Rom rom in newroms)
|
||||
{
|
||||
|
||||
@@ -59,7 +59,6 @@ namespace SabreTools.Helper.Dats
|
||||
Homepage = this.Homepage,
|
||||
Url = this.Url,
|
||||
Comment = this.Comment,
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
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<string, List<DatItem>>(),
|
||||
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<string, List<DatItem>>(),
|
||||
};
|
||||
DatFile sha1 = new DatFile
|
||||
{
|
||||
@@ -179,7 +176,6 @@ namespace SabreTools.Helper.Dats
|
||||
ForcePacking = this.ForcePacking,
|
||||
DatFormat = this.DatFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
};
|
||||
DatFile md5 = new DatFile
|
||||
{
|
||||
@@ -201,7 +197,6 @@ namespace SabreTools.Helper.Dats
|
||||
ForcePacking = this.ForcePacking,
|
||||
DatFormat = this.DatFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
};
|
||||
DatFile crc = new DatFile
|
||||
{
|
||||
@@ -223,7 +218,6 @@ namespace SabreTools.Helper.Dats
|
||||
ForcePacking = this.ForcePacking,
|
||||
DatFormat = this.DatFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
};
|
||||
|
||||
DatFile other = new DatFile
|
||||
@@ -246,14 +240,13 @@ namespace SabreTools.Helper.Dats
|
||||
ForcePacking = this.ForcePacking,
|
||||
DatFormat = this.DatFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
};
|
||||
|
||||
// Now populate each of the DAT objects in turn
|
||||
List<string> keys = this.Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = this.Files[key];
|
||||
List<DatItem> 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<string> keys = Files.Keys.ToList();
|
||||
List<string> 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<DatItem> items = Files[key];
|
||||
List<DatItem> 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<string, List<DatItem>>(),
|
||||
};
|
||||
DatFile diskdat = new DatFile
|
||||
{
|
||||
@@ -494,7 +486,6 @@ namespace SabreTools.Helper.Dats
|
||||
ForcePacking = this.ForcePacking,
|
||||
DatFormat = this.DatFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
};
|
||||
DatFile sampledat = new DatFile
|
||||
{
|
||||
@@ -516,14 +507,13 @@ namespace SabreTools.Helper.Dats
|
||||
ForcePacking = this.ForcePacking,
|
||||
DatFormat = this.DatFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
};
|
||||
|
||||
// Now populate each of the DAT objects in turn
|
||||
List<string> keys = this.Files.Keys.ToList();
|
||||
List<string> keys = Keys.ToList();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List<DatItem> roms = this.Files[key];
|
||||
List<DatItem> 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);
|
||||
}
|
||||
|
||||
@@ -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<DatItem> roms in Files.Values)
|
||||
foreach (string key in Keys)
|
||||
{
|
||||
List<DatItem> 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\"><td>" + HttpUtility.HtmlEncode(FileName.Remove(0, 5))
|
||||
: "><td>" + HttpUtility.HtmlEncode(FileName)) + "</td>"
|
||||
+ "<td align=\"right\">" + Style.GetBytesReadable(TotalSize) + "</td>"
|
||||
+ "<td align=\"right\">" + (game == -1 ? Files.Count : game) + "</td>"
|
||||
+ "<td align=\"right\">" + (game == -1 ? Count : game) + "</td>"
|
||||
+ "<td align=\"right\">" + RomCount + "</td>"
|
||||
+ "<td align=\"right\">" + DiskCount + "</td>"
|
||||
+ "<td align=\"right\">" + CRCCount + "</td>"
|
||||
@@ -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;
|
||||
|
||||
@@ -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<string> keys = Files.Keys.ToList();
|
||||
List<string> 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<DatItem> roms = Files[key];
|
||||
List<DatItem> roms = this[key];
|
||||
|
||||
for (int index = 0; index < roms.Count; index++)
|
||||
{
|
||||
@@ -310,7 +310,7 @@ namespace SabreTools.Helper.Dats
|
||||
+ "<dat xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"datas.xsd\">\n"
|
||||
+ "\t<configuration>\n"
|
||||
+ "\t\t<datName>" + HttpUtility.HtmlEncode(Name) + "</datName>\n"
|
||||
+ "\t\t<datVersion>" + Files.Count + "</datVersion>\n"
|
||||
+ "\t\t<datVersion>" + Count + "</datVersion>\n"
|
||||
+ "\t\t<system>none</system>\n"
|
||||
+ "\t\t<screenshotsWidth>240</screenshotsWidth>\n"
|
||||
+ "\t\t<screenshotsHeight>160</screenshotsHeight>\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)
|
||||
{
|
||||
|
||||
@@ -102,7 +102,6 @@ namespace SabreTools
|
||||
Romba = romba,
|
||||
ExcludeOf = excludeOf,
|
||||
Type = (superdat ? "SuperDAT" : ""),
|
||||
Files = new SortedDictionary<string, List<DatItem>>(),
|
||||
};
|
||||
|
||||
// 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<string, List<DatItem>>();
|
||||
datdata.Reset();
|
||||
|
||||
string basePath = Path.GetFullPath(path);
|
||||
bool success = datdata.PopulateFromDir(basePath, noMD5, noSHA1, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip,
|
||||
|
||||
Reference in New Issue
Block a user