[DatFile, DatItem] Make items cloneable, fix nonmerged output again

This commit is contained in:
Matt Nadareski
2017-01-09 14:37:41 -08:00
parent 9403277551
commit 4b211c4597
9 changed files with 250 additions and 58 deletions

View File

@@ -1,8 +1,9 @@
using SabreTools.Helper.Data;
using System;
using SabreTools.Helper.Data;
namespace SabreTools.Helper.Dats
{
public class Archive : DatItem
public class Archive : DatItem, ICloneable
{
#region Constructors
@@ -17,6 +18,36 @@ namespace SabreTools.Helper.Dats
#endregion
#region Cloning Methods
public object Clone()
{
return new Archive()
{
Name = this.Name,
Type = this.Type,
Dupe = this.Dupe,
Machine = this.Machine,
Supported = this.Supported,
Publisher = this.Publisher,
Infos = this.Infos,
PartName = this.PartName,
PartInterface = this.PartInterface,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)

View File

@@ -1,8 +1,9 @@
using SabreTools.Helper.Data;
using System;
using SabreTools.Helper.Data;
namespace SabreTools.Helper.Dats
{
public class BiosSet : DatItem
public class BiosSet : DatItem, ICloneable
{
#region Private instance variables
@@ -39,6 +40,39 @@ namespace SabreTools.Helper.Dats
#endregion
#region Cloning Methods
public object Clone()
{
return new BiosSet()
{
Name = this.Name,
Type = this.Type,
Dupe = this.Dupe,
Machine = this.Machine,
Supported = this.Supported,
Publisher = this.Publisher,
Infos = this.Infos,
PartName = this.PartName,
PartInterface = this.PartInterface,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
Description = this.Description,
Default = this.Default,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)

View File

@@ -4,7 +4,7 @@ using SabreTools.Helper.Data;
namespace SabreTools.Helper.Dats
{
public class Disk : DatItem
public class Disk : DatItem, ICloneable
{
#region Private instance variables
@@ -52,6 +52,40 @@ namespace SabreTools.Helper.Dats
#endregion
#region Cloning Methods
public object Clone()
{
return new Disk()
{
Name = this.Name,
Type = this.Type,
Dupe = this.Dupe,
Machine = this.Machine,
Supported = this.Supported,
Publisher = this.Publisher,
Infos = this.Infos,
PartName = this.PartName,
PartInterface = this.PartInterface,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
MD5 = this.MD5,
SHA1 = this.SHA1,
ItemStatus = this.ItemStatus,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)

View File

@@ -378,50 +378,42 @@ namespace SabreTools.Helper.Dats
/// <param name="output">True if the number of hashes counted is to be output (default), false otherwise</param>
public void CreateFullyMergedSets(bool mergeroms, Logger logger, bool output = true)
{
// First, we try to add all device items first
/*
Here, we require that device_ref tags got read first, and then we can add them accordingly.
As of right now, those tags are NOT being read into the machine. We'd have to do this in
order to get this working correctly. At least this is a good placeholder for now.
*/
// For sake of ease, the first thing we want to do is sort by game
BucketByGame(mergeroms, false, logger, output);
BucketByGame(mergeroms, true, logger, output);
_sortedBy = SortedBy.Default;
// Now we want to loop through all of the games and set the correct information
List<string> games = Keys.ToList();
foreach (string game in games)
{
// First, we try to add all device items first
/*
Here, we require that device_ref tags got read first, and then we can add them accordingly.
As of right now, those tags are NOT being read into the machine. We'd have to do this in
order to get this working correctly. At least this is a good placeholder for now.
*/
// Determine if the game has a parent or not
string parent = null;
if (this[game][0].Machine.CloneOf != null)
if (!String.IsNullOrEmpty(this[game][0].Machine.CloneOf))
{
parent = this[game][0].Machine.CloneOf;
}
else if (this[game][0].Machine.RomOf != null)
{
parent = this[game][0].Machine.RomOf;
}
// If there is no parent, then we continue
if (parent == null)
{
continue;
}
// If the parent doesn't exist, then we continue
if (this[parent].Count == 0)
if (String.IsNullOrEmpty(parent))
{
continue;
}
// Otherwise, move the items from the current game to a subfolder of the parent game
Machine parentMachine = this[parent][0].Machine;
Machine parentMachine = this[parent].Count == 0 ? new Machine { Name = parent, Description = parent } : this[parent][0].Machine;
List<DatItem> items = this[game];
foreach (DatItem item in items)
{
item.Name = item.Machine.Name + "\\" + item.Name;
item.Machine = parentMachine;
this[parent].Add(item);
}
// Finally, remove the old game so it's not picked up by the writer
@@ -438,7 +430,8 @@ namespace SabreTools.Helper.Dats
public void CreateMergedSets(bool mergeroms, Logger logger, bool output = true)
{
// For sake of ease, the first thing we want to do is sort by game
BucketByGame(mergeroms, false, logger, output);
BucketByGame(mergeroms, true, logger, output);
_sortedBy = SortedBy.Default;
// Now we want to loop through all of the games and set the correct information
List<string> games = Keys.ToList();
@@ -446,34 +439,25 @@ namespace SabreTools.Helper.Dats
{
// Determine if the game has a parent or not
string parent = null;
if (this[game][0].Machine.CloneOf != null)
if (!String.IsNullOrEmpty(this[game][0].Machine.CloneOf))
{
parent = this[game][0].Machine.CloneOf;
}
else if (this[game][0].Machine.RomOf != null)
{
parent = this[game][0].Machine.RomOf;
}
// If there is no parent, then we continue
if (parent == null)
{
continue;
}
// If the parent doesn't exist, then we continue
if (this[parent].Count == 0)
if (String.IsNullOrEmpty(parent))
{
continue;
}
// Otherwise, move the items from the current game to a subfolder of the parent game
Machine parentMachine = this[parent][0].Machine;
Machine parentMachine = this[parent].Count == 0 ? new Machine { Name = parent, Description = parent } : this[parent][0].Machine;
List<DatItem> items = this[game];
foreach (DatItem item in items)
{
item.Name = item.Machine.Name + "\\" + item.Name;
item.Machine = parentMachine;
this[parent].Add(item);
}
// Finally, remove the old game so it's not picked up by the writer
@@ -482,15 +466,16 @@ namespace SabreTools.Helper.Dats
}
/// <summary>
/// Use cloneof tags to create split sets and remove the tags
/// Use cloneof tags to create non-merged sets and remove the tags
/// </summary>
/// <param name="mergeroms">True if roms should be deduped, false otherwise</param>
/// <param name="logger">Logger object for file and console output</param>
/// <param name="output">True if the number of hashes counted is to be output (default), false otherwise</param>
public void CreateSplitSets(bool mergeroms, Logger logger, bool output = true)
public void CreateNonMergedSets(bool mergeroms, Logger logger, bool output = true)
{
// For sake of ease, the first thing we want to do is sort by game
BucketByGame(mergeroms, false, logger, output);
BucketByGame(mergeroms, true, logger, output);
_sortedBy = SortedBy.Default;
// Now we want to loop through all of the games and set the correct information
List<string> games = Keys.ToList();
@@ -498,17 +483,17 @@ namespace SabreTools.Helper.Dats
{
// Determine if the game has a parent or not
string parent = null;
if (this[game][0].Machine.CloneOf != null)
if (!String.IsNullOrEmpty(this[game][0].Machine.CloneOf))
{
parent = this[game][0].Machine.CloneOf;
}
else if (this[game][0].Machine.RomOf != null)
else if (!String.IsNullOrEmpty(this[game][0].Machine.RomOf))
{
parent = this[game][0].Machine.RomOf;
}
// If there is no parent, then we continue
if (parent == null)
if (String.IsNullOrEmpty(parent))
{
continue;
}
@@ -522,6 +507,7 @@ namespace SabreTools.Helper.Dats
item.Machine.CloneOf = null;
item.Machine.RomOf = null;
}
continue;
}
@@ -534,32 +520,32 @@ namespace SabreTools.Helper.Dats
switch (item.Type)
{
case ItemType.Archive:
Archive archive = (Archive)item;
Archive archive = ((Archive)item).Clone() as Archive;
archive.Machine = currentMachine;
this[game].Add(archive);
break;
case ItemType.BiosSet:
BiosSet biosSet = (BiosSet)item;
BiosSet biosSet = ((BiosSet)item).Clone() as BiosSet;
biosSet.Machine = currentMachine;
this[game].Add(biosSet);
break;
case ItemType.Disk:
Disk disk = (Disk)item;
Disk disk = ((Disk)item).Clone() as Disk;
disk.Machine = currentMachine;
this[game].Add(disk);
break;
case ItemType.Release:
Release release = (Release)item;
Release release = ((Release)item).Clone() as Release;
release.Machine = currentMachine;
this[game].Add(release);
break;
case ItemType.Rom:
Rom rom = (Rom)item;
Rom rom = ((Rom)item).Clone() as Rom;
rom.Machine = currentMachine;
this[game].Add(rom);
break;
case ItemType.Sample:
Sample sample = (Sample)item;
Sample sample = ((Sample)item).Clone() as Sample;
sample.Machine = currentMachine;
this[game].Add(sample);
break;

View File

@@ -129,7 +129,7 @@ namespace SabreTools.Helper.Dats
// Now we pre-process the DAT with the splitting/merging mode
if (splitType == SplitType.NonMerged)
{
CreateSplitSets(false, logger, output: false);
CreateNonMergedSets(false, logger, output: false);
}
else if (splitType == SplitType.Merged)
{

View File

@@ -1,8 +1,10 @@
using SabreTools.Helper.Data;
using System;
using SabreTools.Helper.Data;
namespace SabreTools.Helper.Dats
{
public class Release : DatItem
public class Release : DatItem, ICloneable
{
#region Private instance variables
@@ -55,6 +57,41 @@ namespace SabreTools.Helper.Dats
#endregion
#region Cloning Methods
public object Clone()
{
return new Release()
{
Name = this.Name,
Type = this.Type,
Dupe = this.Dupe,
Machine = this.Machine,
Supported = this.Supported,
Publisher = this.Publisher,
Infos = this.Infos,
PartName = this.PartName,
PartInterface = this.PartInterface,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
Region = this.Region,
Language = this.Language,
Date = this.Date,
Default = this.Default,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)

View File

@@ -4,7 +4,7 @@ using SabreTools.Helper.Data;
namespace SabreTools.Helper.Dats
{
public class Rom : Disk
public class Rom : Disk, ICloneable
{
#region Private instance variables
@@ -74,6 +74,43 @@ namespace SabreTools.Helper.Dats
#endregion
#region Cloning Methods
public new object Clone()
{
return new Rom()
{
Name = this.Name,
Type = this.Type,
Dupe = this.Dupe,
Machine = this.Machine,
Supported = this.Supported,
Publisher = this.Publisher,
Infos = this.Infos,
PartName = this.PartName,
PartInterface = this.PartInterface,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
MD5 = this.MD5,
SHA1 = this.SHA1,
ItemStatus = this.ItemStatus,
Size = this.Size,
CRC = this.CRC,
Date = this.Date,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)

View File

@@ -1,8 +1,10 @@
using SabreTools.Helper.Data;
using System;
using SabreTools.Helper.Data;
namespace SabreTools.Helper.Dats
{
public class Sample : DatItem
public class Sample : DatItem, ICloneable
{
#region Constructors
@@ -17,6 +19,36 @@ namespace SabreTools.Helper.Dats
#endregion
#region Cloning Methods
public object Clone()
{
return new Sample()
{
Name = this.Name,
Type = this.Type,
Dupe = this.Dupe,
Machine = this.Machine,
Supported = this.Supported,
Publisher = this.Publisher,
Infos = this.Infos,
PartName = this.PartName,
PartInterface = this.PartInterface,
Features = this.Features,
AreaName = this.AreaName,
AreaSize = this.AreaSize,
SystemID = this.SystemID,
System = this.System,
SourceID = this.SourceID,
Source = this.Source,
};
}
#endregion
#region Comparision Methods
public override bool Equals(DatItem other)

1
debug.log Normal file
View File

@@ -0,0 +1 @@
[0109/130254.459:ERROR:exception_handler_server.cc(524)] ConnectNamedPipe: The pipe is being closed. (0xE8)