[DatFile] Make the file dictionary transparent

This commit is contained in:
Matt Nadareski
2016-11-08 15:29:52 -08:00
parent a13f0f1635
commit 82a31ed470
10 changed files with 276 additions and 380 deletions

View File

@@ -443,9 +443,9 @@ namespace SabreTools
// Loop through the Dictionary and add all data // Loop through the Dictionary and add all data
_logger.User("Adding new DAT information"); _logger.User("Adding new DAT information");
start = DateTime.Now; start = DateTime.Now;
foreach (string key in datroot.Files.Keys) foreach (string key in datroot.Keys())
{ {
foreach (Rom value in datroot.Files[key]) foreach (Rom value in datroot[key])
{ {
AddDatToDatabase(value, dbc); AddDatToDatabase(value, dbc);
} }
@@ -481,7 +481,7 @@ namespace SabreTools
// If the Dat wasn't empty, add the information // If the Dat wasn't empty, add the information
SqliteCommand slc = new SqliteCommand(); SqliteCommand slc = new SqliteCommand();
if (tempdat.Files.Count != 0) if (tempdat.Count != 0)
{ {
string crcquery = "INSERT OR IGNORE INTO crc (crc) VALUES"; string crcquery = "INSERT OR IGNORE INTO crc (crc) VALUES";
string md5query = "INSERT OR IGNORE INTO md5 (md5) VALUES"; string md5query = "INSERT OR IGNORE INTO md5 (md5) VALUES";

View File

@@ -106,16 +106,7 @@ namespace SabreTools
} }
// Add to the Dat // Add to the Dat
if (need.Files.ContainsKey(key)) need.Add(key, rom);
{
need.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
need.Files.Add(key, temp);
}
} }
} }
// Otherwise, just add the file to the list // Otherwise, just add the file to the list
@@ -145,16 +136,7 @@ namespace SabreTools
} }
// Add to the Dat // Add to the Dat
if (need.Files.ContainsKey(key)) need.Add(key, rom);
{
need.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
need.Files.Add(key, temp);
}
} }
} }
} }

View File

@@ -159,7 +159,7 @@ namespace SabreTools.Helper.Dats
get { return _mergeRoms; } get { return _mergeRoms; }
set { _mergeRoms = value; } set { _mergeRoms = value; }
} }
public SortedDictionary<string, List<DatItem>> Files protected SortedDictionary<string, List<DatItem>> Files
{ {
get get
{ {
@@ -273,6 +273,209 @@ namespace SabreTools.Helper.Dats
#region Instance Methods #region Instance Methods
#region Accessors
/// <summary>
/// Passthrough to access the file dictionary
/// </summary>
/// <param name="key">Key in the dictionary to reference</param>
public List<DatItem> this[string key]
{
get
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
// If the key is missing from the dictionary, add it
if (!_files.ContainsKey(key))
{
_files.Add(key, new List<DatItem>());
}
// Now return the value
return _files[key];
}
set
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
// If the key is missing from the dictionary, add it
if (!_files.ContainsKey(key))
{
_files.Add(key, new List<DatItem>());
}
// Now set the value
_files[key] = value;
}
}
/// <summary>
/// Add a new key to the file dictionary
/// </summary>
/// <param name="key">Key in the dictionary to add to</param>
public void Add(string key)
{
lock (_files)
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
// If the key is missing from the dictionary, add it
if (!_files.ContainsKey(key))
{
_files.Add(key, new List<DatItem>());
}
}
}
/// <summary>
/// Add a value to the file dictionary
/// </summary>
/// <param name="key">Key in the dictionary to add to</param>
/// <param name="value">Value to add to the dictionary</param>
public void Add(string key, DatItem value)
{
lock (_files)
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
// If the key is missing from the dictionary, add it
if (!_files.ContainsKey(key))
{
_files.Add(key, new List<DatItem>());
}
// Now add the value
_files[key].Add(value);
}
}
/// <summary>
/// Add a range of values to the file dictionary
/// </summary>
/// <param name="key">Key in the dictionary to add to</param>
/// <param name="value">Value to add to the dictionary</param>
public void AddRange(string key, List<DatItem> value)
{
lock (_files)
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
// If the key is missing from the dictionary, add it
if (!_files.ContainsKey(key))
{
_files.Add(key, new List<DatItem>());
}
// Now add the value
_files[key].AddRange(value);
}
}
/// <summary>
/// Get if the file dictionary contains the key
/// </summary>
/// <param name="key">Key in the dictionary to check</param>
/// <returns>True if the key exists, false otherwise</returns>
public bool ContainsKey(string key)
{
lock (_files)
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
return _files.ContainsKey(key);
}
}
/// <summary>
/// Get the number of keys in the file dictionary
/// </summary>
/// <returns>Number of keys in the file dictionary</returns>
public long Count
{
get
{
lock (_files)
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
return _files.Count;
}
}
}
/// <summary>
/// Get the keys from the file dictionary
/// </summary>
/// <returns>IEnumerable of the keys</returns>
public IEnumerable<string> Keys
{
get
{
lock (_files)
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
return _files.Keys;
}
}
}
/// <summary>
/// Remove a key from the file dictionary
/// </summary>
/// <param name="key"></param>
public void Remove(string key)
{
lock (_files)
{
// If the dictionary is null, create it
if (_files == null)
{
_files = new SortedDictionary<string, List<DatItem>>();
}
// If the key is in the dictionary, remove it
if (_files.ContainsKey(key))
{
_files.Remove(key);
}
}
}
#endregion
#region Cloning Methods [MODULAR DONE] #region Cloning Methods [MODULAR DONE]
public object Clone() public object Clone()

View File

@@ -241,7 +241,7 @@ namespace SabreTools.Helper.Dats
public bool HasDuplicates(DatFile datdata, Logger logger) public bool HasDuplicates(DatFile datdata, Logger logger)
{ {
// Check for an empty rom list first // Check for an empty rom list first
if (datdata.Files == null || datdata.Files.Count == 0) if (datdata.Count == 0)
{ {
return false; return false;
} }
@@ -285,13 +285,13 @@ namespace SabreTools.Helper.Dats
} }
// If the key doesn't exist, return the empty list // If the key doesn't exist, return the empty list
if (!datdata.Files.ContainsKey(key)) if (!datdata.ContainsKey(key))
{ {
return false; return false;
} }
// Try to find duplicates // Try to find duplicates
List<DatItem> roms = datdata.Files[key]; List<DatItem> roms = datdata[key];
foreach (DatItem rom in roms) foreach (DatItem rom in roms)
{ {
@@ -316,7 +316,7 @@ namespace SabreTools.Helper.Dats
List<DatItem> output = new List<DatItem>(); List<DatItem> output = new List<DatItem>();
// Check for an empty rom list first // Check for an empty rom list first
if (datdata.Files == null || datdata.Files.Count == 0) if (datdata.Count == 0)
{ {
return output; return output;
} }
@@ -360,13 +360,13 @@ namespace SabreTools.Helper.Dats
} }
// If the key doesn't exist, return the empty list // If the key doesn't exist, return the empty list
if (!datdata.Files.ContainsKey(key)) if (!datdata.ContainsKey(key))
{ {
return output; return output;
} }
// Try to find duplicates // Try to find duplicates
List<DatItem> roms = datdata.Files[key]; List<DatItem> roms = datdata[key];
List<DatItem> left = new List<DatItem>(); List<DatItem> left = new List<DatItem>();
foreach (DatItem rom in roms) foreach (DatItem rom in roms)
@@ -384,7 +384,7 @@ namespace SabreTools.Helper.Dats
// If we're in removal mode, replace the list with the new one // If we're in removal mode, replace the list with the new one
if (remove) if (remove)
{ {
datdata.Files[key] = left; datdata[key] = left;
} }
return output; return output;

View File

@@ -58,16 +58,12 @@ namespace SabreTools.Helper.Dats
{ {
count++; count++;
string newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).CRC : Constants.CRCZero); string newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).CRC : Constants.CRCZero);
if (sortable.ContainsKey(newkey))
if (!sortable.ContainsKey(newkey))
{ {
sortable[newkey].Add(rom); sortable.Add(newkey, new List<DatItem>());
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sortable.Add(newkey, temp);
} }
sortable[newkey].Add(rom);
} }
} }
@@ -147,17 +143,14 @@ namespace SabreTools.Helper.Dats
{ {
newkey = newkey.ToLowerInvariant(); newkey = newkey.ToLowerInvariant();
} }
newkey = HttpUtility.HtmlEncode(newkey); newkey = HttpUtility.HtmlEncode(newkey);
if (sortable.ContainsKey(newkey))
if (!sortable.ContainsKey(newkey))
{ {
sortable[newkey].Add(rom); sortable.Add(newkey, new List<DatItem>());
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sortable.Add(newkey, temp);
} }
sortable[newkey].Add(rom);
} }
} }
@@ -229,16 +222,12 @@ namespace SabreTools.Helper.Dats
: (rom.Type == ItemType.Disk : (rom.Type == ItemType.Disk
? ((Disk)rom).MD5 ? ((Disk)rom).MD5
: Constants.MD5Zero)); : Constants.MD5Zero));
if (sortable.ContainsKey(newkey))
if (!sortable.ContainsKey(newkey))
{ {
sortable[newkey].Add(rom); sortable.Add(newkey, new List<DatItem>());
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sortable.Add(newkey, temp);
} }
sortable[newkey].Add(rom);
} }
} }
@@ -310,16 +299,12 @@ namespace SabreTools.Helper.Dats
: (rom.Type == ItemType.Disk : (rom.Type == ItemType.Disk
? ((Disk)rom).SHA1 ? ((Disk)rom).SHA1
: Constants.MD5Zero)); : Constants.MD5Zero));
if (sortable.ContainsKey(newkey))
if (!sortable.ContainsKey(newkey))
{ {
sortable[newkey].Add(rom); sortable.Add(newkey, new List<DatItem>());
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sortable.Add(newkey, temp);
} }
sortable[newkey].Add(rom);
} }
} }
@@ -387,16 +372,12 @@ namespace SabreTools.Helper.Dats
{ {
count++; count++;
string newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).Size.ToString() : "-1"); string newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).Size.ToString() : "-1");
if (sortable.ContainsKey(newkey))
if (!sortable.ContainsKey(newkey))
{ {
sortable[newkey].Add(rom); sortable.Add(newkey, new List<DatItem>());
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sortable.Add(newkey, temp);
} }
sortable[newkey].Add(rom);
} }
} }
@@ -472,16 +453,12 @@ namespace SabreTools.Helper.Dats
? "Default" ? "Default"
: rom.Machine.Name.ToLowerInvariant()); : rom.Machine.Name.ToLowerInvariant());
newkey = HttpUtility.HtmlEncode(newkey); newkey = HttpUtility.HtmlEncode(newkey);
if (sortable.ContainsKey(newkey))
if (!sortable.ContainsKey(newkey))
{ {
sortable[newkey].Add(rom); sortable.Add(newkey, new List<DatItem>());
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sortable.Add(newkey, temp);
} }
sortable[newkey].Add(rom);
} }
return sortable; return sortable;

View File

@@ -126,15 +126,8 @@ namespace SabreTools.Helper.Dats
List<string> keys = datHeaders[i].Files.Keys.ToList(); List<string> keys = datHeaders[i].Files.Keys.ToList();
foreach (string key in keys) foreach (string key in keys)
{ {
if (Files.ContainsKey(key)) AddRange(key, datHeaders[i][key]);
{ datHeaders[i].Remove(key);
Files[key].AddRange(datHeaders[i].Files[key]);
}
else
{
Files.Add(key, datHeaders[i].Files[key]);
}
datHeaders[i].Files.Remove(key);
} }
datHeaders[i].Files = null; datHeaders[i].Files = null;
} }
@@ -227,16 +220,7 @@ namespace SabreTools.Helper.Dats
// Individual DATs that are output // Individual DATs that are output
if ((diff & DiffMode.Individuals) != 0) if ((diff & DiffMode.Individuals) != 0)
{ {
if (outDats[rom.SystemID].Files.ContainsKey(key)) outDats[rom.SystemID].Add(key, rom);
{
outDats[rom.SystemID].Files[key].Add(rom);
}
else
{
List<DatItem> tl = new List<DatItem>();
tl.Add(rom);
outDats[rom.SystemID].Files.Add(key, tl);
}
} }
// Merged no-duplicates DAT // Merged no-duplicates DAT
@@ -245,16 +229,7 @@ namespace SabreTools.Helper.Dats
DatItem newrom = rom; DatItem newrom = rom;
newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")"; newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")";
if (outerDiffData.Files.ContainsKey(key)) outerDiffData.Add(key, newrom);
{
outerDiffData.Files[key].Add(newrom);
}
else
{
List<DatItem> tl = new List<DatItem>();
tl.Add(rom);
outerDiffData.Files.Add(key, tl);
}
} }
} }
} }
@@ -267,16 +242,7 @@ namespace SabreTools.Helper.Dats
DatItem newrom = rom; DatItem newrom = rom;
newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")"; newrom.Machine.Name += " (" + Path.GetFileNameWithoutExtension(inputs[newrom.SystemID].Split('¬')[0]) + ")";
if (dupeData.Files.ContainsKey(key)) dupeData.Add(key, newrom);
{
dupeData.Files[key].Add(newrom);
}
else
{
List<DatItem> tl = new List<DatItem>();
tl.Add(rom);
dupeData.Files.Add(key, tl);
}
} }
} }
} }
@@ -388,16 +354,7 @@ namespace SabreTools.Helper.Dats
continue; continue;
} }
if (outDats[rom.SystemID].Files.ContainsKey(key)) outDats[rom.SystemID].Add(key, rom);
{
outDats[rom.SystemID].Files[key].Add(rom);
}
else
{
List<DatItem> tl = new List<DatItem>();
tl.Add(rom);
outDats[rom.SystemID].Files.Add(key, tl);
}
} }
} }
} }

View File

@@ -220,18 +220,8 @@ namespace SabreTools.Helper.Dats
if (rom != null && rom.Name != null) if (rom != null && rom.Name != null)
{ {
// Add the list if it doesn't exist already // Add the list if it doesn't exist already
string key = rom.Size + "-" + rom.CRC; Add(rom.Size + "-" + rom.CRC, rom);
logger.User("File added: " + Path.GetFileNameWithoutExtension(item) + Environment.NewLine);
lock (Files)
{
if (!Files.ContainsKey(key))
{
Files.Add(key, new List<DatItem>());
}
Files[key].Add(rom);
logger.User("File added: " + Path.GetFileNameWithoutExtension(item) + Environment.NewLine);
}
} }
else else
{ {
@@ -379,13 +369,7 @@ namespace SabreTools.Helper.Dats
} }
// Add the list if it doesn't exist already // Add the list if it doesn't exist already
lock (Files) Add(key);
{
if (!Files.ContainsKey(key))
{
Files.Add(key, new List<DatItem>());
}
}
try try
{ {
@@ -478,19 +462,7 @@ namespace SabreTools.Helper.Dats
} }
// Add the file information to the DAT // Add the file information to the DAT
lock (Files) Add(key, datItem);
{
if (Files.ContainsKey(key))
{
Files[key].Add(datItem);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(datItem);
Files.Add(key, temp);
}
}
logger.User("File added: " + romname + Environment.NewLine); logger.User("File added: " + romname + Environment.NewLine);
} }

View File

@@ -2360,16 +2360,7 @@ namespace SabreTools.Helper.Dats
} }
// Add the item to the DAT // Add the item to the DAT
if (Files.ContainsKey(key)) Add(key, item);
{
Files[key].Add(item);
}
else
{
List<DatItem> newvalue = new List<DatItem>();
newvalue.Add(item);
Files.Add(key, newvalue);
}
} }
} }
} }

View File

@@ -152,17 +152,7 @@ namespace SabreTools.Helper.Dats
lock (Files) lock (Files)
{ {
string key = rom.Size + "-" + rom.CRC; current.Add(rom.Size + "-" + rom.CRC, rom);
if (current.Files.ContainsKey(key))
{
current.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
current.Files.Add(key, temp);
}
} }
// If we had a header, we want the full file information too // If we had a header, we want the full file information too
@@ -173,17 +163,7 @@ namespace SabreTools.Helper.Dats
lock (Files) lock (Files)
{ {
string key = rom.Size + "-" + rom.CRC; current.Add(rom.Size + "-" + rom.CRC, rom);
if (current.Files.ContainsKey(key))
{
current.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
current.Files.Add(key, temp);
}
} }
} }
} }
@@ -203,17 +183,7 @@ namespace SabreTools.Helper.Dats
lock (Files) lock (Files)
{ {
string key = rom.Size + "-" + rom.CRC; current.Add(rom.Size + "-" + rom.CRC, newrom);
if (current.Files.ContainsKey(key))
{
current.Files[key].Add(newrom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(newrom);
current.Files.Add(key, temp);
}
} }
} }
} }
@@ -236,17 +206,7 @@ namespace SabreTools.Helper.Dats
lock (Files) lock (Files)
{ {
string key = rom.Size + "-" + rom.CRC; current.Add(rom.Size + "-" + rom.CRC, rom);
if (current.Files.ContainsKey(key))
{
current.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
current.Files.Add(key, temp);
}
} }
// If we had a header, we want the full file information too // If we had a header, we want the full file information too
@@ -257,17 +217,7 @@ namespace SabreTools.Helper.Dats
lock (Files) lock (Files)
{ {
string key = rom.Size + "-" + rom.CRC; current.Add(rom.Size + "-" + rom.CRC, rom);
if (current.Files.ContainsKey(key))
{
current.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
current.Files.Add(key, temp);
}
} }
} }
}); });
@@ -280,17 +230,7 @@ namespace SabreTools.Helper.Dats
lock (Files) lock (Files)
{ {
string key = rom.Size + "-" + rom.CRC; current.Add(rom.Size + "-" + rom.CRC, rom);
if (current.Files.ContainsKey(key))
{
current.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
current.Files.Add(key, temp);
}
} }
} }
} }
@@ -612,17 +552,7 @@ namespace SabreTools.Helper.Dats
if (rom.SourceID == 99) if (rom.SourceID == 99)
{ {
found = true; found = true;
string key = rom.Size + "-" + rom.CRC; matched.Add(rom.Size + "-" + rom.CRC, rom);
if (matched.Files.ContainsKey(key))
{
matched.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
matched.Files.Add(key, temp);
}
} }
} }
} }

View File

@@ -92,52 +92,16 @@ namespace SabreTools.Helper.Dats
{ {
if (newExtA.Contains(Path.GetExtension(rom.Name.ToUpperInvariant()))) if (newExtA.Contains(Path.GetExtension(rom.Name.ToUpperInvariant())))
{ {
if (datdataA.Files.ContainsKey(key)) datdataA.Add(key, rom);
{
datdataA.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
datdataA.Files.Add(key, temp);
}
} }
else if (newExtB.Contains(Path.GetExtension(rom.Name.ToUpperInvariant()))) else if (newExtB.Contains(Path.GetExtension(rom.Name.ToUpperInvariant())))
{ {
if (datdataB.Files.ContainsKey(key)) datdataB.Add(key, rom);
{
datdataB.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
datdataB.Files.Add(key, temp);
}
} }
else else
{ {
if (datdataA.Files.ContainsKey(key)) datdataA.Add(key, rom);
{ datdataB.Add(key, rom);
datdataA.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
datdataA.Files.Add(key, temp);
}
if (datdataB.Files.ContainsKey(key))
{
datdataB.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
datdataB.Files.Add(key, temp);
}
} }
} }
} }
@@ -173,7 +137,7 @@ namespace SabreTools.Helper.Dats
// Create each of the respective output DATs // Create each of the respective output DATs
logger.User("Creating and populating new DATs"); logger.User("Creating and populating new DATs");
DatFile itemStatus = new DatFile DatFile nodump = new DatFile
{ {
FileName = this.FileName + " (Nodump)", FileName = this.FileName + " (Nodump)",
Name = this.Name + " (Nodump)", Name = this.Name + " (Nodump)",
@@ -298,78 +262,33 @@ namespace SabreTools.Helper.Dats
continue; continue;
} }
// If the file is a itemStatus // If the file is a nodump
if ((rom.Type == ItemType.Rom && ((Rom)rom).ItemStatus == ItemStatus.Nodump) if ((rom.Type == ItemType.Rom && ((Rom)rom).ItemStatus == ItemStatus.Nodump)
|| (rom.Type == ItemType.Disk && ((Disk)rom).ItemStatus == ItemStatus.Nodump)) || (rom.Type == ItemType.Disk && ((Disk)rom).ItemStatus == ItemStatus.Nodump))
{ {
if (itemStatus.Files.ContainsKey(key)) nodump.Add(key, rom);
{
itemStatus.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
itemStatus.Files.Add(key, temp);
}
} }
// If the file has a SHA-1 // If the file has a SHA-1
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA1)) else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA1))
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA1))) || (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA1)))
{ {
if (sha1.Files.ContainsKey(key)) sha1.Add(key, rom);
{
sha1.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sha1.Files.Add(key, temp);
}
} }
// If the file has no SHA-1 but has an MD5 // If the file has no SHA-1 but has an MD5
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).MD5)) else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).MD5))
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).MD5))) || (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).MD5)))
{ {
if (md5.Files.ContainsKey(key)) md5.Add(key, rom);
{
md5.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
md5.Files.Add(key, temp);
}
} }
// If the file has no MD5 but a CRC // If the file has no MD5 but a CRC
else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA1)) else if ((rom.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)rom).SHA1))
|| (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA1))) || (rom.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)rom).SHA1)))
{ {
if (crc.Files.ContainsKey(key)) crc.Add(key, rom);
{
crc.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
crc.Files.Add(key, temp);
}
} }
else else
{ {
if (other.Files.ContainsKey(key)) other.Add(key, rom);
{
other.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
other.Files.Add(key, temp);
}
} }
} }
} }
@@ -387,9 +306,9 @@ namespace SabreTools.Helper.Dats
// Now, output all of the files to the output directory // Now, output all of the files to the output directory
logger.User("DAT information created, outputting new files"); logger.User("DAT information created, outputting new files");
bool success = true; bool success = true;
if (itemStatus.Files.Count > 0) if (nodump.Files.Count > 0)
{ {
success &= itemStatus.WriteToFile(outDir, logger); success &= nodump.WriteToFile(outDir, logger);
} }
if (sha1.Files.Count > 0) if (sha1.Files.Count > 0)
{ {
@@ -452,14 +371,7 @@ namespace SabreTools.Helper.Dats
items.ForEach(item => item.Machine.Description = Style.GetFileName(item.Machine.Description)); items.ForEach(item => item.Machine.Description = Style.GetFileName(item.Machine.Description));
// Now add the game to the output DAT // Now add the game to the output DAT
if (tempDat.Files.ContainsKey(key)) tempDat.AddRange(key, items);
{
tempDat.Files[key].AddRange(items);
}
else
{
tempDat.Files.Add(key, items);
}
// Then set the DAT name to be the parent directory name // Then set the DAT name to be the parent directory name
tempDat.Name = Style.GetDirectoryName(key); tempDat.Name = Style.GetDirectoryName(key);
@@ -617,45 +529,17 @@ namespace SabreTools.Helper.Dats
// If the file is a Rom // If the file is a Rom
if (rom.Type == ItemType.Rom) if (rom.Type == ItemType.Rom)
{ {
if (romdat.Files.ContainsKey(key)) romdat.Add(key, rom);
{
romdat.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
romdat.Files.Add(key, temp);
}
} }
// If the file is a Disk // If the file is a Disk
else if (rom.Type == ItemType.Disk) else if (rom.Type == ItemType.Disk)
{ {
if (diskdat.Files.ContainsKey(key)) diskdat.Add(key, rom);
{
diskdat.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
diskdat.Files.Add(key, temp);
}
} }
// If the file is a Sample // If the file is a Sample
else if (rom.Type == ItemType.Sample) else if (rom.Type == ItemType.Sample)
{ {
if (sampledat.Files.ContainsKey(key)) sampledat.Add(key, rom);
{
sampledat.Files[key].Add(rom);
}
else
{
List<DatItem> temp = new List<DatItem>();
temp.Add(rom);
sampledat.Files.Add(key, temp);
}
} }
} }
} }