using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
using SabreTools.Library.DatItems;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatFiles
{
///
/// Represents all possible DAT header information
///
[JsonObject("header")]
[XmlRoot("header")]
public class DatHeader : ICloneable
{
#region Fields
#region Common
///
/// External name of the DAT
///
[JsonProperty("filename", DefaultValueHandling = DefaultValueHandling.Include)]
[XmlElement("filename")]
public string FileName { get; set; }
///
/// Internal name of the DAT
///
[JsonProperty("name", DefaultValueHandling = DefaultValueHandling.Include)]
[XmlElement("name")]
public string Name { get; set; }
///
/// DAT description
///
[JsonProperty("description", DefaultValueHandling = DefaultValueHandling.Include)]
[XmlElement("description")]
public string Description { get; set; }
///
/// Root directory for the files; currently TruRip/EmuARC-exclusive
///
[JsonProperty("rootdir", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("rootdir")]
public string RootDir { get; set; }
///
/// General category of items found in the DAT
///
[JsonProperty("category", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("category")]
public string Category { get; set; }
///
/// Version of the DAT
///
[JsonProperty("version", DefaultValueHandling = DefaultValueHandling.Include)]
[XmlElement("version")]
public string Version { get; set; }
///
/// Creation or modification date
///
[JsonProperty("date", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("date")]
public string Date { get; set; }
///
/// List of authors who contributed to the DAT
///
[JsonProperty("author", DefaultValueHandling = DefaultValueHandling.Include)]
[XmlElement("author")]
public string Author { get; set; }
///
/// Email address for DAT author(s)
///
[JsonProperty("email", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("email")]
public string Email { get; set; }
///
/// Author or distribution homepage name
///
[JsonProperty("homepage", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("homepage")]
public string Homepage { get; set; }
///
/// Author or distribution URL
///
[JsonProperty("url", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("url")]
public string Url { get; set; }
///
/// Any comment that does not already fit an existing field
///
[JsonProperty("comment", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("comment")]
public string Comment { get; set; }
///
/// Header skipper to be used when loading the DAT
///
[JsonProperty("header", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("header")]
public string HeaderSkipper { get; set; }
///
/// Classification of the DAT. Generally only used for SuperDAT
///
[JsonProperty("type", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("type")]
public string Type { get; set; }
///
/// Force a merging style when loaded
///
[JsonProperty("forcemerging", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("forcemerging")]
public MergingFlag ForceMerging { get; set; }
[JsonIgnore]
public bool ForceMergingSpecified { get { return ForceMerging != MergingFlag.None; } }
///
/// Force nodump handling when loaded
///
[JsonProperty("forcenodump", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("forcenodump")]
public NodumpFlag ForceNodump { get; set; }
[JsonIgnore]
public bool ForceNodumpSpecified { get { return ForceNodump != NodumpFlag.None; } }
///
/// Force output packing when loaded
///
[JsonProperty("forcepacking", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("forcepacking")]
public PackingFlag ForcePacking { get; set; }
[JsonIgnore]
public bool ForcePackingSpecified { get { return ForcePacking != PackingFlag.None; } }
///
/// Read or write format
///
[JsonIgnore]
[XmlIgnore]
public DatFormat DatFormat { get; set; }
#endregion
#region ListXML
///
/// Debug build flag
///
/// Also in Logiqx
[JsonProperty("debug", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("debug")]
public bool? Debug { get; set; } = null;
[JsonIgnore]
public bool DebugSpecified { get { return Debug != null; } }
///
/// MAME configuration name
///
[JsonProperty("mameconfig", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("mameconfig")]
public string MameConfig { get; set; }
#endregion
#region Logiqx
///
/// Build version
///
[JsonProperty("build", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("build")]
public string Build { get; set; }
///
/// Logiqx/RomCenter plugin, OfflineList System
///
[JsonProperty("system", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("system")]
public string System { get; set; }
///
/// RomCenter rom mode
///
/// (merged|split|unmerged) "split"
[JsonProperty("rommode", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("rommode")]
public MergingFlag RomMode { get; set; }
[JsonIgnore]
public bool RomModeSpecified { get { return RomMode != MergingFlag.None; } }
///
/// RomCenter bios mode
///
/// (merged|split|unmerged) "split"
[JsonProperty("biosmode", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("biosmode")]
public MergingFlag BiosMode { get; set; }
[JsonIgnore]
public bool BiosModeSpecified { get { return BiosMode != MergingFlag.None; } }
///
/// RomCenter sample mode
///
/// (merged|unmerged) "merged"
[JsonProperty("samplemode", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("samplemode")]
public MergingFlag SampleMode { get; set; }
[JsonIgnore]
public bool SampleModeSpecified { get { return SampleMode != MergingFlag.None; } }
///
/// RomCenter lock rom mode
///
[JsonProperty("lockrommode", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("lockrommode")]
public bool? LockRomMode { get; set; }
[JsonIgnore]
public bool LockRomModeSpecified { get { return LockRomMode != null; } }
///
/// RomCenter lock bios mode
///
[JsonProperty("lockbiosmode", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("lockbiosmode")]
public bool? LockBiosMode { get; set; }
[JsonIgnore]
public bool LockBiosModeSpecified { get { return LockBiosMode != null; } }
///
/// RomCenter lock sample mode
///
[JsonProperty("locksamplemode", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("locksamplemode")]
public bool? LockSampleMode { get; set; }
[JsonIgnore]
public bool LockSampleModeSpecified { get { return LockSampleMode != null; } }
#endregion
#region Missfile
///
/// Output the item name
///
[JsonIgnore]
[XmlIgnore]
public bool UseRomName { get; set; }
#endregion
#region OfflineList
///
/// Screenshots width
///
[JsonProperty("screenshotswidth", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("screenshotswidth")]
public string ScreenshotsWidth { get; set; }
///
/// Screenshots height
///
[JsonProperty("screenshotsheight", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("screenshotsheight")]
public string ScreenshotsHeight { get; set; }
///
/// OfflineList info list
///
[JsonProperty("infos", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("infos")]
public List Infos { get; set; }
[JsonIgnore]
public bool InfosSpecified { get { return Infos != null && Infos.Count > 0; } }
///
/// OfflineList can-open extensions
///
[JsonProperty("canopen", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("canopen")]
public List CanOpen { get; set; }
[JsonIgnore]
public bool CanOpenSpecified { get { return CanOpen != null && CanOpen.Count > 0; } }
// TODO: Implement the following header values:
// - newdat.datversionurl (currently reads and writes to Header.Url, not strictly correct)
// - newdat.daturl (currently writes to Header.Url, not strictly correct)
// - newdat.daturl[fileName] (currently writes to Header.FileName + ".zip", not strictly correct)
// - newdat.imurl (currently writes to Header.Url, not strictly correct)
// - search[...].to.find[operation, value (Int32?)]
// - search[...].to[value, default (true|false), auto (true, false)]
///
/// Rom title
///
[JsonProperty("romtitle", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("romtitle")]
public string RomTitle { get; set; }
#endregion
#region RomCenter
///
/// RomCenter DAT format version
///
[JsonProperty("rcversion", DefaultValueHandling = DefaultValueHandling.Ignore)]
[XmlElement("rcversion")]
public string RomCenterVersion { get; set; }
#endregion
#region Write pre-processing
///
/// Text to prepend to all outputted lines
///
[JsonIgnore]
[XmlIgnore]
public string Prefix { get; set; }
///
/// Text to append to all outputted lines
///
[JsonIgnore]
[XmlIgnore]
public string Postfix { get; set; }
///
/// Add a new extension to all items
///
[JsonIgnore]
[XmlIgnore]
public string AddExtension { get; set; }
///
/// Replace all item extensions
///
[JsonIgnore]
[XmlIgnore]
public string ReplaceExtension { get; set; }
///
/// Remove all item extensions
///
[JsonIgnore]
[XmlIgnore]
public bool RemoveExtension { get; set; }
///
/// Output the machine name
///
[JsonIgnore]
[XmlIgnore]
public bool GameName { get; set; }
///
/// Wrap quotes around the entire line, sans prefix and postfix
///
[JsonIgnore]
[XmlIgnore]
public bool Quotes { get; set; }
#endregion
#region Depot Information
///
/// Input depot information
///
[JsonIgnore]
[XmlIgnore]
public DepotInformation InputDepot { get; set; }
///
/// Output depot information
///
[JsonIgnore]
[XmlIgnore]
public DepotInformation OutputDepot { get; set; }
#endregion
#endregion
#region Instance Methods
#region Accessors
///
/// Set fields with given values
///
/// Mappings dictionary
public void SetFields(Dictionary mappings)
{
#region Common
if (mappings.Keys.Contains(Field.DatHeader_FileName))
FileName = mappings[Field.DatHeader_FileName];
if (mappings.Keys.Contains(Field.DatHeader_Name))
Name = mappings[Field.DatHeader_Name];
if (mappings.Keys.Contains(Field.DatHeader_Description))
Description = mappings[Field.DatHeader_Description];
if (mappings.Keys.Contains(Field.DatHeader_RootDir))
RootDir = mappings[Field.DatHeader_RootDir];
if (mappings.Keys.Contains(Field.DatHeader_Category))
Category = mappings[Field.DatHeader_Category];
if (mappings.Keys.Contains(Field.DatHeader_Version))
Version = mappings[Field.DatHeader_Version];
if (mappings.Keys.Contains(Field.DatHeader_Date))
Date = mappings[Field.DatHeader_Date];
if (mappings.Keys.Contains(Field.DatHeader_Author))
Author = mappings[Field.DatHeader_Author];
if (mappings.Keys.Contains(Field.DatHeader_Email))
Email = mappings[Field.DatHeader_Email];
if (mappings.Keys.Contains(Field.DatHeader_Homepage))
Homepage = mappings[Field.DatHeader_Homepage];
if (mappings.Keys.Contains(Field.DatHeader_Url))
Url = mappings[Field.DatHeader_Url];
if (mappings.Keys.Contains(Field.DatHeader_Comment))
Comment = mappings[Field.DatHeader_Comment];
if (mappings.Keys.Contains(Field.DatHeader_HeaderSkipper))
HeaderSkipper = mappings[Field.DatHeader_HeaderSkipper];
if (mappings.Keys.Contains(Field.DatHeader_Type))
Type = mappings[Field.DatHeader_Type];
if (mappings.Keys.Contains(Field.DatHeader_ForceMerging))
ForceMerging = mappings[Field.DatHeader_ForceMerging].AsMergingFlag();
if (mappings.Keys.Contains(Field.DatHeader_ForceNodump))
ForceNodump = mappings[Field.DatHeader_ForceNodump].AsNodumpFlag();
if (mappings.Keys.Contains(Field.DatHeader_ForcePacking))
ForcePacking = mappings[Field.DatHeader_ForcePacking].AsPackingFlag();
#endregion
#region ListXML
if (mappings.Keys.Contains(Field.DatHeader_Debug))
Debug = mappings[Field.DatHeader_Debug].AsYesNo();
if (mappings.Keys.Contains(Field.DatHeader_MameConfig))
MameConfig = mappings[Field.DatHeader_MameConfig];
#endregion
#region Logiqx
if (mappings.Keys.Contains(Field.DatHeader_Build))
Build = mappings[Field.DatHeader_Build];
if (mappings.Keys.Contains(Field.DatHeader_RomMode))
RomMode = mappings[Field.DatHeader_RomMode].AsMergingFlag();
if (mappings.Keys.Contains(Field.DatHeader_BiosMode))
BiosMode = mappings[Field.DatHeader_BiosMode].AsMergingFlag();
if (mappings.Keys.Contains(Field.DatHeader_SampleMode))
SampleMode = mappings[Field.DatHeader_SampleMode].AsMergingFlag();
if (mappings.Keys.Contains(Field.DatHeader_LockRomMode))
LockRomMode = mappings[Field.DatHeader_LockRomMode].AsYesNo();
if (mappings.Keys.Contains(Field.DatHeader_LockBiosMode))
LockBiosMode = mappings[Field.DatHeader_LockBiosMode].AsYesNo();
if (mappings.Keys.Contains(Field.DatHeader_LockSampleMode))
LockSampleMode = mappings[Field.DatHeader_LockSampleMode].AsYesNo();
#endregion
#region OfflineList
if (mappings.Keys.Contains(Field.DatHeader_System))
System = mappings[Field.DatHeader_System];
if (mappings.Keys.Contains(Field.DatHeader_ScreenshotsWidth))
ScreenshotsWidth = mappings[Field.DatHeader_ScreenshotsWidth];
if (mappings.Keys.Contains(Field.DatHeader_ScreenshotsHeight))
ScreenshotsHeight = mappings[Field.DatHeader_ScreenshotsHeight];
// TODO: Add DatHeader_Info*
// TDOO: Add DatHeader_CanOpen*
if (mappings.Keys.Contains(Field.DatHeader_RomTitle))
RomTitle = mappings[Field.DatHeader_RomTitle];
#endregion
#region RomCenter
if (mappings.Keys.Contains(Field.DatHeader_RomCenterVersion))
RomCenterVersion = mappings[Field.DatHeader_RomCenterVersion];
#endregion
}
#endregion
#region Cloning Methods
///
/// Clone the current header
///
public object Clone()
{
return new DatHeader()
{
FileName = this.FileName,
Name = this.Name,
Description = this.Description,
RootDir = this.RootDir,
Category = this.Category,
Version = this.Version,
Date = this.Date,
Author = this.Author,
Email = this.Email,
Homepage = this.Homepage,
Url = this.Url,
Comment = this.Comment,
HeaderSkipper = this.HeaderSkipper,
Type = this.Type,
ForceMerging = this.ForceMerging,
ForceNodump = this.ForceNodump,
ForcePacking = this.ForcePacking,
DatFormat = this.DatFormat,
UseRomName = this.UseRomName,
Prefix = this.Prefix,
Postfix = this.Postfix,
Quotes = this.Quotes,
ReplaceExtension = this.ReplaceExtension,
AddExtension = this.AddExtension,
RemoveExtension = this.RemoveExtension,
GameName = this.GameName,
InputDepot = this.InputDepot.Clone() as DepotInformation,
OutputDepot = this.OutputDepot.Clone() as DepotInformation,
};
}
///
/// Clone the standard parts of the current header
///
public DatHeader CloneStandard()
{
return new DatHeader()
{
FileName = this.FileName,
Name = this.Name,
Description = this.Description,
RootDir = this.RootDir,
Category = this.Category,
Version = this.Version,
Date = this.Date,
Author = this.Author,
Email = this.Email,
Homepage = this.Homepage,
Url = this.Url,
Comment = this.Comment,
HeaderSkipper = this.HeaderSkipper,
Type = this.Type,
ForceMerging = this.ForceMerging,
ForceNodump = this.ForceNodump,
ForcePacking = this.ForcePacking,
DatFormat = this.DatFormat,
};
}
///
/// Clone the filtering parts of the current header
///
public DatHeader CloneFiltering()
{
return new DatHeader()
{
DatFormat = this.DatFormat,
UseRomName = this.UseRomName,
Prefix = this.Prefix,
Postfix = this.Postfix,
Quotes = this.Quotes,
ReplaceExtension = this.ReplaceExtension,
AddExtension = this.AddExtension,
RemoveExtension = this.RemoveExtension,
GameName = this.GameName,
InputDepot = this.InputDepot.Clone() as DepotInformation,
OutputDepot = this.OutputDepot.Clone() as DepotInformation,
};
}
///
/// Overwrite local values from another DatHeader if not default
///
/// DatHeader to get the values from
public void ConditionalCopy(DatHeader datHeader)
{
if (!string.IsNullOrWhiteSpace(datHeader.FileName))
FileName = datHeader.FileName;
if (!string.IsNullOrWhiteSpace(datHeader.Name))
Name = datHeader.Name;
if (!string.IsNullOrWhiteSpace(datHeader.Description))
Description = datHeader.Description;
if (!string.IsNullOrWhiteSpace(datHeader.RootDir))
RootDir = datHeader.RootDir;
if (!string.IsNullOrWhiteSpace(datHeader.Category))
Category = datHeader.Category;
if (!string.IsNullOrWhiteSpace(datHeader.Version))
Version = datHeader.Version;
if (!string.IsNullOrWhiteSpace(datHeader.Date))
Date = datHeader.Date;
if (!string.IsNullOrWhiteSpace(datHeader.Author))
Author = datHeader.Author;
if (!string.IsNullOrWhiteSpace(datHeader.Email))
Email = datHeader.Email;
if (!string.IsNullOrWhiteSpace(datHeader.Homepage))
Homepage = datHeader.Homepage;
if (!string.IsNullOrWhiteSpace(datHeader.Url))
Url = datHeader.Url;
if (!string.IsNullOrWhiteSpace(datHeader.Comment))
Comment = datHeader.Comment;
if (!string.IsNullOrWhiteSpace(datHeader.HeaderSkipper))
HeaderSkipper = datHeader.HeaderSkipper;
if (!string.IsNullOrWhiteSpace(datHeader.Type))
Type = datHeader.Type;
if (datHeader.ForceMerging != MergingFlag.None)
ForceMerging = datHeader.ForceMerging;
if (datHeader.ForceNodump != NodumpFlag.None)
ForceNodump = datHeader.ForceNodump;
if (datHeader.ForcePacking != PackingFlag.None)
ForcePacking = datHeader.ForcePacking;
if (datHeader.DatFormat != 0x00)
DatFormat = datHeader.DatFormat;
if (!string.IsNullOrWhiteSpace(datHeader.Prefix))
Prefix = datHeader.Prefix;
if (!string.IsNullOrWhiteSpace(datHeader.Postfix))
Postfix = datHeader.Postfix;
if (!string.IsNullOrWhiteSpace(datHeader.AddExtension))
AddExtension = datHeader.AddExtension;
if (!string.IsNullOrWhiteSpace(datHeader.ReplaceExtension))
ReplaceExtension = datHeader.ReplaceExtension;
RemoveExtension = datHeader.RemoveExtension;
InputDepot = datHeader.InputDepot?.Clone() as DepotInformation;
OutputDepot = datHeader.OutputDepot?.Clone() as DepotInformation;
GameName = datHeader.GameName;
Quotes = datHeader.Quotes;
UseRomName = datHeader.UseRomName;
}
#endregion
#region Writing
///
/// Generate a proper outfile name based on a DAT and output directory
///
/// Output directory
/// True if we ignore existing files (default), false otherwise
/// Dictionary of output formats mapped to file names
public Dictionary CreateOutFileNames(string outDir, bool overwrite = true)
{
// Create the output dictionary
Dictionary outfileNames = new Dictionary();
// Double check the outDir for the end delim
if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
outDir += Path.DirectorySeparatorChar;
// Get all used extensions
List usedExtensions = new List();
// Get the extensions from the output type
// TODO: Can the system of adding be more automated?
#region .csv
// CSV
if (DatFormat.HasFlag(DatFormat.CSV))
{
outfileNames.Add(DatFormat.CSV, CreateOutFileNamesHelper(outDir, ".csv", overwrite));
usedExtensions.Add(".csv");
};
#endregion
#region .dat
// ClrMamePro
if (DatFormat.HasFlag(DatFormat.ClrMamePro))
{
outfileNames.Add(DatFormat.ClrMamePro, CreateOutFileNamesHelper(outDir, ".dat", overwrite));
usedExtensions.Add(".dat");
};
// RomCenter
if (DatFormat.HasFlag(DatFormat.RomCenter))
{
if (usedExtensions.Contains(".dat"))
{
outfileNames.Add(DatFormat.RomCenter, CreateOutFileNamesHelper(outDir, ".rc.dat", overwrite));
usedExtensions.Add(".rc.dat");
}
else
{
outfileNames.Add(DatFormat.RomCenter, CreateOutFileNamesHelper(outDir, ".dat", overwrite));
usedExtensions.Add(".dat");
}
}
// DOSCenter
if (DatFormat.HasFlag(DatFormat.DOSCenter))
{
if (usedExtensions.Contains(".dat"))
{
outfileNames.Add(DatFormat.DOSCenter, CreateOutFileNamesHelper(outDir, ".dc.dat", overwrite));
usedExtensions.Add(".dc.dat");
}
else
{
outfileNames.Add(DatFormat.DOSCenter, CreateOutFileNamesHelper(outDir, ".dat", overwrite));
usedExtensions.Add(".dat");
}
}
#endregion
#region .json
// JSON
if (DatFormat.HasFlag(DatFormat.Json))
{
outfileNames.Add(DatFormat.Json, CreateOutFileNamesHelper(outDir, ".json", overwrite));
usedExtensions.Add(".json");
}
#endregion
#region .md5
// Redump MD5
if (DatFormat.HasFlag(DatFormat.RedumpMD5))
{
outfileNames.Add(DatFormat.RedumpMD5, CreateOutFileNamesHelper(outDir, ".md5", overwrite));
usedExtensions.Add(".md5");
};
#endregion
#if NET_FRAMEWORK
#region .ripemd160
// Redump RIPEMD160
if (DatFormat.HasFlag(DatFormat.RedumpRIPEMD160))
{
outfileNames.Add(DatFormat.RedumpRIPEMD160, CreateOutFileNamesHelper(outDir, ".ripemd160", overwrite));
usedExtensions.Add(".ripemd160");
};
#endregion
#endif
#region .sfv
// Redump SFV
if (DatFormat.HasFlag(DatFormat.RedumpSFV))
{
outfileNames.Add(DatFormat.RedumpSFV, CreateOutFileNamesHelper(outDir, ".sfv", overwrite));
usedExtensions.Add(".sfv");
};
#endregion
#region .sha1
// Redump SHA-1
if (DatFormat.HasFlag(DatFormat.RedumpSHA1))
{
outfileNames.Add(DatFormat.RedumpSHA1, CreateOutFileNamesHelper(outDir, ".sha1", overwrite));
usedExtensions.Add(".sha1");
};
#endregion
#region .sha256
// Redump SHA-256
if (DatFormat.HasFlag(DatFormat.RedumpSHA256))
{
outfileNames.Add(DatFormat.RedumpSHA256, CreateOutFileNamesHelper(outDir, ".sha256", overwrite));
usedExtensions.Add(".sha256");
};
#endregion
#region .sha384
// Redump SHA-384
if (DatFormat.HasFlag(DatFormat.RedumpSHA384))
{
outfileNames.Add(DatFormat.RedumpSHA384, CreateOutFileNamesHelper(outDir, ".sha384", overwrite));
usedExtensions.Add(".sha384");
};
#endregion
#region .sha512
// Redump SHA-512
if (DatFormat.HasFlag(DatFormat.RedumpSHA512))
{
outfileNames.Add(DatFormat.RedumpSHA512, CreateOutFileNamesHelper(outDir, ".sha512", overwrite));
usedExtensions.Add(".sha512");
};
#endregion
#region .spamsum
// Redump SpamSum
if (DatFormat.HasFlag(DatFormat.RedumpSpamSum))
{
outfileNames.Add(DatFormat.RedumpSpamSum, CreateOutFileNamesHelper(outDir, ".spamsum", overwrite));
usedExtensions.Add(".spamsum");
};
#endregion
#region .ssv
// SSV
if (DatFormat.HasFlag(DatFormat.SSV))
{
outfileNames.Add(DatFormat.SSV, CreateOutFileNamesHelper(outDir, ".ssv", overwrite));
usedExtensions.Add(".ssv");
};
#endregion
#region .tsv
// TSV
if (DatFormat.HasFlag(DatFormat.TSV))
{
outfileNames.Add(DatFormat.TSV, CreateOutFileNamesHelper(outDir, ".tsv", overwrite));
usedExtensions.Add(".tsv");
};
#endregion
#region .txt
// AttractMode
if (DatFormat.HasFlag(DatFormat.AttractMode))
{
outfileNames.Add(DatFormat.AttractMode, CreateOutFileNamesHelper(outDir, ".txt", overwrite));
usedExtensions.Add(".txt");
}
// MAME Listroms
if (DatFormat.HasFlag(DatFormat.Listrom))
{
if (usedExtensions.Contains(".txt"))
{
outfileNames.Add(DatFormat.Listrom, CreateOutFileNamesHelper(outDir, ".lr.txt", overwrite));
usedExtensions.Add(".lr.txt");
}
else
{
outfileNames.Add(DatFormat.Listrom, CreateOutFileNamesHelper(outDir, ".txt", overwrite));
usedExtensions.Add(".txt");
}
}
// Missfile
if (DatFormat.HasFlag(DatFormat.MissFile))
{
if (usedExtensions.Contains(".txt"))
{
outfileNames.Add(DatFormat.MissFile, CreateOutFileNamesHelper(outDir, ".miss.txt", overwrite));
usedExtensions.Add(".miss.txt");
}
else
{
outfileNames.Add(DatFormat.MissFile, CreateOutFileNamesHelper(outDir, ".txt", overwrite));
usedExtensions.Add(".txt");
}
}
// Everdrive SMDB
if (DatFormat.HasFlag(DatFormat.EverdriveSMDB))
{
if (usedExtensions.Contains(".txt"))
{
outfileNames.Add(DatFormat.EverdriveSMDB, CreateOutFileNamesHelper(outDir, ".smdb.txt", overwrite));
usedExtensions.Add(".smdb.txt");
}
else
{
outfileNames.Add(DatFormat.EverdriveSMDB, CreateOutFileNamesHelper(outDir, ".txt", overwrite));
usedExtensions.Add(".txt");
}
}
#endregion
#region .xml
// Logiqx XML
if (DatFormat.HasFlag(DatFormat.Logiqx))
{
outfileNames.Add(DatFormat.Logiqx, CreateOutFileNamesHelper(outDir, ".xml", overwrite));
usedExtensions.Add(".xml");
}
if (DatFormat.HasFlag(DatFormat.LogiqxDeprecated))
{
outfileNames.Add(DatFormat.LogiqxDeprecated, CreateOutFileNamesHelper(outDir, ".xml", overwrite));
usedExtensions.Add(".xml");
}
// SabreDAT
if (DatFormat.HasFlag(DatFormat.SabreDat))
{
if (usedExtensions.Contains(".xml"))
{
outfileNames.Add(DatFormat.SabreDat, CreateOutFileNamesHelper(outDir, ".sd.xml", overwrite));
usedExtensions.Add(".sd.xml");
}
else
{
outfileNames.Add(DatFormat.SabreDat, CreateOutFileNamesHelper(outDir, ".xml", overwrite));
usedExtensions.Add(".xml");
}
}
// Software List
if (DatFormat.HasFlag(DatFormat.SoftwareList))
{
if (usedExtensions.Contains(".xml"))
{
outfileNames.Add(DatFormat.SoftwareList, CreateOutFileNamesHelper(outDir, ".sl.xml", overwrite));
usedExtensions.Add(".sl.xml");
}
else
{
outfileNames.Add(DatFormat.SoftwareList, CreateOutFileNamesHelper(outDir, ".xml", overwrite));
usedExtensions.Add(".xml");
}
}
// MAME Listxml
if (DatFormat.HasFlag(DatFormat.Listxml))
{
if (usedExtensions.Contains(".xml"))
{
outfileNames.Add(DatFormat.Listxml, CreateOutFileNamesHelper(outDir, ".mame.xml", overwrite));
usedExtensions.Add(".mame.xml");
}
else
{
outfileNames.Add(DatFormat.Listxml, CreateOutFileNamesHelper(outDir, ".xml", overwrite));
usedExtensions.Add(".xml");
}
}
// OfflineList
if (DatFormat.HasFlag(DatFormat.OfflineList))
{
if (usedExtensions.Contains(".xml"))
{
outfileNames.Add(DatFormat.OfflineList, CreateOutFileNamesHelper(outDir, ".ol.xml", overwrite));
usedExtensions.Add(".ol.xml");
}
else
{
outfileNames.Add(DatFormat.OfflineList, CreateOutFileNamesHelper(outDir, ".xml", overwrite));
usedExtensions.Add(".xml");
}
}
// openMSX
if (DatFormat.HasFlag(DatFormat.OpenMSX))
{
if (usedExtensions.Contains(".xml"))
{
outfileNames.Add(DatFormat.OpenMSX, CreateOutFileNamesHelper(outDir, ".msx.xml", overwrite));
usedExtensions.Add(".msx.xml");
}
else
{
outfileNames.Add(DatFormat.OpenMSX, CreateOutFileNamesHelper(outDir, ".xml", overwrite));
usedExtensions.Add(".xml");
}
}
#endregion
return outfileNames;
}
///
/// Help generating the outfile name
///
/// Output directory
/// Extension to use for the file
/// True if we ignore existing files, false otherwise
/// String containing the new filename
private string CreateOutFileNamesHelper(string outDir, string extension, bool overwrite)
{
string filename = (string.IsNullOrWhiteSpace(FileName) ? Description : FileName);
// Strip off the extension if it's a holdover from the DAT
if (PathExtensions.HasValidDatExtension(filename))
filename = Path.GetFileNameWithoutExtension(filename);
string outfile = $"{outDir}{filename}{extension}";
outfile = outfile.Replace($"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}", Path.DirectorySeparatorChar.ToString());
if (!overwrite)
{
int i = 1;
while (File.Exists(outfile))
{
outfile = $"{outDir}{filename}_{i}{extension}";
outfile = outfile.Replace($"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}", Path.DirectorySeparatorChar.ToString());
i++;
}
}
return outfile;
}
#endregion
#endregion // Instance Methods
}
}