[DatFile] Remove cloneable, use constructor instead

This commit is contained in:
Matt Nadareski
2016-11-08 16:04:26 -08:00
parent 50d0a40ae3
commit 5ef4cb0efd
5 changed files with 55 additions and 46 deletions

View File

@@ -5,7 +5,7 @@ using SabreTools.Helper.Data;
namespace SabreTools.Helper.Dats
{
public partial class DatFile : ICloneable
public partial class DatFile
{
#region Private instance variables
@@ -486,43 +486,52 @@ namespace SabreTools.Helper.Dats
#endregion
#region Cloning Methods [MODULAR DONE]
#region Constructors
public object Clone()
/// <summary>
/// Create a new, empty DatFile object
/// </summary>
public DatFile()
{
return new DatFile
_files = new SortedDictionary<string, List<DatItem>>();
}
/// <summary>
/// Create a new DatFile from an existing one
/// </summary>
/// <param name="df"></param>
public DatFile(DatFile datFile)
{
FileName = _fileName,
Name = _name,
Description = _description,
RootDir = _rootDir,
Category = _category,
Version = _version,
Date = _date,
Author = _author,
Email = _email,
Homepage = _homepage,
Url = _url,
Comment = _comment,
Header = _header,
Type = _type,
ForceMerging = _forceMerging,
ForceNodump = _forceNodump,
ForcePacking = _forcePacking,
ExcludeOf = _excludeOf,
DatFormat = _datFormat,
MergeRoms = _mergeRoms,
SortedBy = SortedBy.Default,
UseGame = _useGame,
Prefix = _prefix,
Postfix = _postfix,
Quotes = _quotes,
RepExt = _repExt,
AddExt = _addExt,
RemExt = _remExt,
GameName = _gameName,
Romba = _romba,
};
_fileName = datFile.FileName;
_name = datFile.Name;
_description = datFile.Description;
_rootDir = datFile.RootDir;
_category = datFile.Category;
_version = datFile.Version;
_date = datFile.Date;
_author = datFile.Author;
_email = datFile.Email;
_homepage = datFile.Homepage;
_url = datFile.Url;
_comment = datFile.Comment;
_header = datFile.Header;
_type = datFile.Type;
_forceMerging = datFile.ForceMerging;
_forceNodump = datFile.ForceNodump;
_forcePacking = datFile.ForcePacking;
_excludeOf = datFile.ExcludeOf;
_datFormat = datFile.DatFormat;
_mergeRoms = datFile.MergeRoms;
_sortedBy = SortedBy.Default;
_useGame = datFile.UseGame;
_prefix = datFile.Prefix;
_postfix = datFile.Postfix;
_quotes = datFile.Quotes;
_repExt = datFile.RepExt;
_addExt = datFile.AddExt;
_remExt = datFile.RemExt;
_gameName = datFile.GameName;
_romba = datFile.Romba;
}
#endregion

View File

@@ -157,7 +157,7 @@ namespace SabreTools.Helper.Dats
if ((diff & DiffMode.NoDupes) != 0)
{
post = " (No Duplicates)";
outerDiffData = (DatFile)Clone();
outerDiffData = new DatFile(this);
outerDiffData.FileName += post;
outerDiffData.Name += post;
outerDiffData.Description += post;
@@ -168,7 +168,7 @@ namespace SabreTools.Helper.Dats
if ((diff & DiffMode.Dupes) != 0)
{
post = " (Duplicates)";
dupeData = (DatFile)Clone();
dupeData = new DatFile(this);
dupeData.FileName += post;
dupeData.Name += post;
dupeData.Description += post;
@@ -186,7 +186,7 @@ namespace SabreTools.Helper.Dats
Parallel.For(0, inputs.Count, j =>
{
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
DatFile diffData = (DatFile)Clone();
DatFile diffData = new DatFile(this);
diffData.FileName += innerpost;
diffData.Name += innerpost;
diffData.Description += innerpost;
@@ -319,7 +319,7 @@ namespace SabreTools.Helper.Dats
}
else
{
diffData = (DatFile)Clone();
diffData = new DatFile(this);
diffData.FileName += post;
diffData.Name += post;
diffData.Description += post;
@@ -459,7 +459,7 @@ namespace SabreTools.Helper.Dats
if (File.Exists(inputFileName))
{
DatFile innerDatdata = (DatFile)Clone();
DatFile innerDatdata = new DatFile(this);
logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\"");
innerDatdata.Parse(inputFileName, 0, 0, filter, trim, single,
root, logger, true, clean, softlist,
@@ -480,7 +480,7 @@ namespace SabreTools.Helper.Dats
file =>
{
logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\"");
DatFile innerDatdata = (DatFile)Clone();
DatFile innerDatdata = new DatFile(this);
innerDatdata.Parse(file, 0, 0, filter,
trim, single, root, logger, true, clean, softlist,
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));

View File

@@ -511,7 +511,7 @@ namespace SabreTools.Helper.Dats
}
// Setup the fixdat
DatFile matched = (DatFile)Clone();
DatFile matched = new DatFile(this);
matched.Reset();
matched.FileName = "fixDat_" + matched.FileName;
matched.Name = "fixDat_" + matched.Name;

View File

@@ -337,7 +337,7 @@ namespace SabreTools.Helper.Dats
BucketByGame(false, true, logger, output: false, lower: false);
// Create a temporary DAT to add things to
DatFile tempDat = (DatFile)Clone();
DatFile tempDat = new DatFile(this);
tempDat.Name = null;
// Sort the input keys
@@ -354,7 +354,7 @@ namespace SabreTools.Helper.Dats
SplitByLevelHelper(tempDat, outDir, shortname, basedat, logger);
// Reset the DAT for the next items
tempDat = (DatFile)Clone();
tempDat = new DatFile(this);
tempDat.Name = null;
}

View File

@@ -113,7 +113,7 @@ namespace SabreTools
if (Directory.Exists(path) || File.Exists(path))
{
// Clone the base Dat for information
DatFile datdata = (DatFile)basedat.Clone();
DatFile datdata = new DatFile(basedat);
string basePath = Path.GetFullPath(path);
bool success = datdata.PopulateFromDir(basePath, noMD5, noSHA1, removeDateFromAutomaticName, parseArchivesAsFiles, enableGzip,