2017-10-06 13:29:58 -07:00
using System ;
2020-07-15 09:41:59 -07:00
using System.Collections.Generic ;
using System.IO ;
2020-09-07 14:47:27 -07:00
using System.Xml.Serialization ;
2024-02-28 19:19:50 -05:00
using Newtonsoft.Json ;
2020-12-08 13:23:59 -08:00
using SabreTools.Core ;
2020-12-08 16:37:08 -08:00
using SabreTools.Core.Tools ;
2020-12-09 22:11:35 -08:00
using SabreTools.DatFiles.Formats ;
2024-03-10 21:03:53 -04:00
using SabreTools.Filter ;
2024-03-11 15:46:44 -04:00
using SabreTools.Serialization ;
2017-06-16 16:24:26 -07:00
2020-12-08 16:37:08 -08:00
namespace SabreTools.DatFiles
2017-06-16 16:24:26 -07:00
{
2019-01-08 11:06:26 -08:00
/// <summary>
/// Represents all possible DAT header information
/// </summary>
2020-09-08 10:12:41 -07:00
[JsonObject("header"), XmlRoot("header")]
2019-01-08 11:06:26 -08:00
public class DatHeader : ICloneable
{
2024-03-10 16:49:07 -04:00
#region Constants
2017-06-16 16:24:26 -07:00
2019-01-08 11:49:31 -08:00
/// <summary>
2024-03-10 16:49:07 -04:00
/// Add a new extension to all items
2019-01-08 11:49:31 -08:00
/// </summary>
2024-03-10 16:49:07 -04:00
public const string AddExtensionKey = "ADDEXTENSION" ;
2019-01-08 11:49:31 -08:00
2024-03-10 21:54:07 -04:00
/// <summary>
/// Read or write format
/// </summary>
public const string DatFormatKey = "DATFORMAT" ;
2024-03-10 21:41:49 -04:00
/// <summary>
/// External name of the DAT
/// </summary>
public const string FileNameKey = "FILENAME" ;
2019-01-08 11:49:31 -08:00
/// <summary>
2024-03-10 16:49:07 -04:00
/// Output the machine name
2019-01-08 11:49:31 -08:00
/// </summary>
2024-03-10 16:49:07 -04:00
public const string GameNameKey = "GAMENAME" ;
2020-08-20 15:13:57 -07:00
2024-03-10 22:08:08 -04:00
/// <summary>
/// Input depot information
/// </summary>
public const string InputDepotKey = "INPUTDEPOT" ;
/// <summary>
/// Output depot information
/// </summary>
public const string OutputDepotKey = "OUTPUTDEPOT" ;
2020-08-20 15:13:57 -07:00
/// <summary>
2024-03-10 16:49:07 -04:00
/// Text to append to all outputted lines
2020-08-20 15:13:57 -07:00
/// </summary>
2024-03-10 16:49:07 -04:00
public const string PostfixKey = "POSTFIX" ;
2019-01-08 11:49:31 -08:00
/// <summary>
/// Text to prepend to all outputted lines
/// </summary>
2024-03-10 16:49:07 -04:00
public const string PrefixKey = "PREFIX" ;
2019-01-08 11:49:31 -08:00
/// <summary>
2024-03-10 16:49:07 -04:00
/// Wrap quotes around the entire line, sans prefix and postfix
2019-01-08 11:49:31 -08:00
/// </summary>
2024-03-10 16:49:07 -04:00
public const string QuotesKey = "QUOTES" ;
2019-01-08 11:49:31 -08:00
/// <summary>
2024-03-10 16:49:07 -04:00
/// Remove all item extensions
2019-01-08 11:49:31 -08:00
/// </summary>
2024-03-10 16:49:07 -04:00
public const string RemoveExtensionKey = "REMOVEEXTENSION" ;
2019-01-08 11:49:31 -08:00
/// <summary>
/// Replace all item extensions
/// </summary>
2024-03-10 16:49:07 -04:00
public const string ReplaceExtensionKey = "REPLACEEXTENSION" ;
2019-01-08 11:49:31 -08:00
/// <summary>
2024-03-10 16:49:07 -04:00
/// Output the item name
2019-01-08 11:49:31 -08:00
/// </summary>
2024-03-10 16:49:07 -04:00
public const string UseRomNameKey = "USEROMNAME" ;
#endregion
#region Fields
2019-01-08 11:49:31 -08:00
2024-03-10 16:49:07 -04:00
[JsonIgnore]
public bool InfosSpecified
{
get
{
var infos = GetFieldValue < OfflineListInfo [ ] ? > ( Models . Metadata . Header . InfosKey ) ;
return infos ! = null & & infos . Length > 0 ;
}
}
[JsonIgnore]
public bool CanOpenSpecified
{
get
{
2024-03-11 01:37:47 -04:00
var canOpen = GetFieldValue < Models . OfflineList . CanOpen [ ] ? > ( Models . Metadata . Header . CanOpenKey ) ;
2024-03-10 16:49:07 -04:00
return canOpen ! = null & & canOpen . Length > 0 ;
}
}
2019-01-08 11:49:31 -08:00
2024-03-11 01:37:47 -04:00
[JsonIgnore]
public bool NewDatSpecified
{
get
{
2024-03-11 15:46:44 -04:00
return GetStringFieldValue ( "DATVERSIONURL" ) ! = null
2024-03-11 01:37:47 -04:00
//&& GetFieldValue<Models.OfflineList.DatUrl?>("DATURL") != null // TODO: Add to internal model
2024-03-11 15:46:44 -04:00
& & GetStringFieldValue ( "IMURL" ) ! = null ;
2024-03-11 01:37:47 -04:00
}
}
2024-03-10 04:10:37 -04:00
/// <summary>
/// Internal Header model
/// </summary>
[JsonIgnore]
2024-03-10 21:42:37 -04:00
private readonly Models . Metadata . Header _header = [ ] ;
2024-03-10 04:10:37 -04:00
2019-01-08 11:06:26 -08:00
#endregion
2017-10-06 13:29:58 -07:00
2019-01-08 11:06:26 -08:00
#region Instance Methods
2017-10-06 13:29:58 -07:00
2024-03-10 22:49:15 -04:00
#region Constructors
public DatHeader ( ) { }
public DatHeader ( Models . Metadata . Header header )
{
// Get all fields to automatically copy without processing
var nonItemFields = TypeHelper . GetConstants ( typeof ( Models . Metadata . Header ) ) ;
if ( nonItemFields = = null )
return ;
// Populate the internal machine from non-filter fields
_header = [ ] ;
foreach ( string fieldName in nonItemFields )
{
if ( header . ContainsKey ( fieldName ) )
_header [ fieldName ] = header [ fieldName ] ;
}
}
#endregion
2024-03-10 04:10:37 -04:00
#region Accessors
/// <summary>
/// Get the value from a field based on the type provided
/// </summary>
/// <typeparam name="T">Type of the value to get from the internal model</typeparam>
/// <param name="fieldName">Field to retrieve</param>
/// <returns>Value from the field, if possible</returns>
public T ? GetFieldValue < T > ( string? fieldName )
{
// Invalid field cannot be processed
2024-03-11 15:46:44 -04:00
if ( string . IsNullOrEmpty ( fieldName ) | | ! _header . ContainsKey ( fieldName ! ) )
2024-03-10 04:10:37 -04:00
return default ;
// Get the value based on the type
return _header . Read < T > ( fieldName ! ) ;
}
2024-03-11 15:46:44 -04:00
/// <summary>
/// Get the value from a field based on the type provided
/// </summary>
/// <param name="fieldName">Field to retrieve</param>
/// <returns>Value from the field, if possible</returns>
public bool? GetBoolFieldValue ( string? fieldName )
{
// Invalid field cannot be processed
if ( string . IsNullOrEmpty ( fieldName ) | | ! _header . ContainsKey ( fieldName ! ) )
return default ;
// Get the value based on the type
return _header . ReadBool ( fieldName ! ) ;
}
/// <summary>
/// Get the value from a field based on the type provided
/// </summary>
/// <param name="fieldName">Field to retrieve</param>
/// <returns>Value from the field, if possible</returns>
public double? GetDoubleFieldValue ( string? fieldName )
{
// Invalid field cannot be processed
if ( string . IsNullOrEmpty ( fieldName ) | | ! _header . ContainsKey ( fieldName ! ) )
return default ;
// Get the value based on the type
return _header . ReadDouble ( fieldName ! ) ;
}
/// <summary>
/// Get the value from a field based on the type provided
/// </summary>
/// <param name="fieldName">Field to retrieve</param>
/// <returns>Value from the field, if possible</returns>
public long? GetInt64FieldValue ( string? fieldName )
{
// Invalid field cannot be processed
if ( string . IsNullOrEmpty ( fieldName ) | | ! _header . ContainsKey ( fieldName ! ) )
return default ;
// Get the value based on the type
return _header . ReadLong ( fieldName ! ) ;
}
/// <summary>
/// Get the value from a field based on the type provided
/// </summary>
/// <param name="fieldName">Field to retrieve</param>
/// <returns>Value from the field, if possible</returns>
public string? GetStringFieldValue ( string? fieldName )
{
// Invalid field cannot be processed
if ( string . IsNullOrEmpty ( fieldName ) | | ! _header . ContainsKey ( fieldName ! ) )
return default ;
// Get the value based on the type
return _header . ReadString ( fieldName ! ) ;
}
/// <summary>
/// Get the value from a field based on the type provided
/// </summary>
/// <param name="fieldName">Field to retrieve</param>
/// <returns>Value from the field, if possible</returns>
public string [ ] ? GetStringArrayFieldValue ( string? fieldName )
{
// Invalid field cannot be processed
if ( string . IsNullOrEmpty ( fieldName ) | | ! _header . ContainsKey ( fieldName ! ) )
return default ;
// Get the value based on the type
return _header . ReadStringArray ( fieldName ! ) ;
}
2024-03-10 04:10:37 -04:00
/// <summary>
/// Set the value from a field based on the type provided
/// </summary>
/// <typeparam name="T">Type of the value to set in the internal model</typeparam>
/// <param name="fieldName">Field to set</param>
/// <param name="value">Value to set</param>
/// <returns>True if the value was set, false otherwise</returns>
public bool SetFieldValue < T > ( string? fieldName , T ? value )
{
// Invalid field cannot be processed
if ( string . IsNullOrEmpty ( fieldName ) )
return false ;
// Set the value based on the type
_header [ fieldName ! ] = value ;
return true ;
}
2024-03-11 11:07:21 -04:00
/// <summary>
/// Get a clone of the current internal model
/// </summary>
public Models . Metadata . Header GetInternalClone ( ) = > ( _header . Clone ( ) as Models . Metadata . Header ) ! ;
2024-03-10 04:10:37 -04:00
#endregion
2019-01-08 11:06:26 -08:00
#region Cloning Methods
2017-10-06 13:29:58 -07:00
2019-01-08 11:06:26 -08:00
/// <summary>
/// Clone the current header
/// </summary>
public object Clone ( )
{
2024-03-10 22:08:08 -04:00
var header = new DatHeader ( ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( DatHeader . AddExtensionKey , GetStringFieldValue ( DatHeader . AddExtensionKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . AuthorKey , GetStringFieldValue ( Models . Metadata . Header . AuthorKey ) ) ;
2024-03-11 21:30:24 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . BiosModeKey , GetStringFieldValue ( Models . Metadata . Header . BiosModeKey ) . AsEnumValue < MergingFlag > ( ) . AsStringValue ( ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . BuildKey , GetStringFieldValue ( Models . Metadata . Header . BuildKey ) ) ;
header . SetFieldValue < string [ ] ? > ( Models . Metadata . Header . CanOpenKey , GetStringArrayFieldValue ( Models . Metadata . Header . CanOpenKey ) ) ; // TODO: Perform a deep clone
header . SetFieldValue < string? > ( Models . Metadata . Header . CategoryKey , GetStringFieldValue ( Models . Metadata . Header . CategoryKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . CommentKey , GetStringFieldValue ( Models . Metadata . Header . CommentKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . DateKey , GetStringFieldValue ( Models . Metadata . Header . DateKey ) ) ;
2024-03-10 21:54:07 -04:00
header . SetFieldValue < DatFormat > ( DatHeader . DatFormatKey , GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . DatVersionKey , GetStringFieldValue ( Models . Metadata . Header . DatVersionKey ) ) ;
header . SetFieldValue < bool? > ( Models . Metadata . Header . DebugKey , GetBoolFieldValue ( Models . Metadata . Header . DebugKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . DescriptionKey , GetStringFieldValue ( Models . Metadata . Header . DescriptionKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . EmailKey , GetStringFieldValue ( Models . Metadata . Header . EmailKey ) ) ;
header . SetFieldValue < string? > ( DatHeader . FileNameKey , GetStringFieldValue ( DatHeader . FileNameKey ) ) ;
2024-03-11 21:30:24 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . ForceMergingKey , GetStringFieldValue ( Models . Metadata . Header . ForceMergingKey ) . AsEnumValue < MergingFlag > ( ) . AsStringValue ( ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . ForceNodumpKey , GetStringFieldValue ( Models . Metadata . Header . ForceNodumpKey ) . AsEnumValue < NodumpFlag > ( ) . AsStringValue ( ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . ForcePackingKey , GetStringFieldValue ( Models . Metadata . Header . ForcePackingKey ) . AsEnumValue < PackingFlag > ( ) . AsStringValue ( ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < bool? > ( DatHeader . GameNameKey , GetBoolFieldValue ( DatHeader . GameNameKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . HeaderKey , GetStringFieldValue ( Models . Metadata . Header . HeaderKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . HomepageKey , GetStringFieldValue ( Models . Metadata . Header . HomepageKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . IdKey , GetStringFieldValue ( Models . Metadata . Header . IdKey ) ) ;
2024-03-10 04:10:37 -04:00
header . SetFieldValue < OfflineListInfo [ ] ? > ( Models . Metadata . Header . InfosKey , GetFieldValue < OfflineListInfo [ ] ? > ( Models . Metadata . Header . InfosKey ) ) ; // TODO: Perform a deep clone
2024-03-10 22:08:08 -04:00
header . SetFieldValue < DepotInformation ? > ( DatHeader . InputDepotKey , GetFieldValue < DepotInformation ? > ( DatHeader . InputDepotKey ) ? . Clone ( ) as DepotInformation ) ;
header . SetFieldValue < DepotInformation ? > ( DatHeader . OutputDepotKey , GetFieldValue < DepotInformation ? > ( DatHeader . OutputDepotKey ) ? . Clone ( ) as DepotInformation ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < bool? > ( Models . Metadata . Header . LockBiosModeKey , GetBoolFieldValue ( Models . Metadata . Header . LockBiosModeKey ) ) ;
header . SetFieldValue < bool? > ( Models . Metadata . Header . LockRomModeKey , GetBoolFieldValue ( Models . Metadata . Header . LockRomModeKey ) ) ;
header . SetFieldValue < bool? > ( Models . Metadata . Header . LockSampleModeKey , GetBoolFieldValue ( Models . Metadata . Header . LockSampleModeKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . MameConfigKey , GetStringFieldValue ( Models . Metadata . Header . MameConfigKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . NameKey , GetStringFieldValue ( Models . Metadata . Header . NameKey ) ) ;
header . SetFieldValue < string? > ( DatHeader . PostfixKey , GetStringFieldValue ( DatHeader . PostfixKey ) ) ;
header . SetFieldValue < string? > ( DatHeader . PrefixKey , GetStringFieldValue ( DatHeader . PrefixKey ) ) ;
header . SetFieldValue < bool? > ( DatHeader . QuotesKey , GetBoolFieldValue ( DatHeader . QuotesKey ) ) ;
header . SetFieldValue < bool? > ( DatHeader . RemoveExtensionKey , GetBoolFieldValue ( DatHeader . RemoveExtensionKey ) ) ;
header . SetFieldValue < string? > ( DatHeader . ReplaceExtensionKey , GetStringFieldValue ( DatHeader . ReplaceExtensionKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . RomTitleKey , GetStringFieldValue ( Models . Metadata . Header . RomTitleKey ) ) ;
2024-03-11 21:30:24 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . RomModeKey , GetStringFieldValue ( Models . Metadata . Header . RomModeKey ) . AsEnumValue < MergingFlag > ( ) . AsStringValue ( ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . RootDirKey , GetStringFieldValue ( Models . Metadata . Header . RootDirKey ) ) ;
2024-03-11 21:30:24 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . SampleModeKey , GetStringFieldValue ( Models . Metadata . Header . SampleModeKey ) . AsEnumValue < MergingFlag > ( ) . AsStringValue ( ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . ScreenshotsHeightKey , GetStringFieldValue ( Models . Metadata . Header . ScreenshotsHeightKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . ScreenshotsWidthKey , GetStringFieldValue ( Models . Metadata . Header . ScreenshotsWidthKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . SystemKey , GetStringFieldValue ( Models . Metadata . Header . SystemKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . TypeKey , GetStringFieldValue ( Models . Metadata . Header . TypeKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . UrlKey , GetStringFieldValue ( Models . Metadata . Header . UrlKey ) ) ;
header . SetFieldValue < bool? > ( DatHeader . UseRomNameKey , GetBoolFieldValue ( DatHeader . UseRomNameKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . VersionKey , GetStringFieldValue ( Models . Metadata . Header . VersionKey ) ) ;
2024-03-10 16:49:07 -04:00
2024-03-10 04:10:37 -04:00
return header ;
2019-01-08 11:06:26 -08:00
}
2017-10-06 13:29:58 -07:00
2020-07-15 09:41:59 -07:00
/// <summary>
/// Clone the standard parts of the current header
/// </summary>
public DatHeader CloneStandard ( )
{
2024-03-10 21:54:07 -04:00
var header = new DatHeader ( ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . AuthorKey , GetStringFieldValue ( Models . Metadata . Header . AuthorKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . CategoryKey , GetStringFieldValue ( Models . Metadata . Header . CategoryKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . CommentKey , GetStringFieldValue ( Models . Metadata . Header . CommentKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . DateKey , GetStringFieldValue ( Models . Metadata . Header . DateKey ) ) ;
2024-03-10 21:54:07 -04:00
header . SetFieldValue < DatFormat > ( DatHeader . DatFormatKey , GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . DescriptionKey , GetStringFieldValue ( Models . Metadata . Header . DescriptionKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . EmailKey , GetStringFieldValue ( Models . Metadata . Header . EmailKey ) ) ;
header . SetFieldValue < string? > ( DatHeader . FileNameKey , GetStringFieldValue ( DatHeader . FileNameKey ) ) ;
2024-03-11 21:30:24 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . ForceMergingKey , GetStringFieldValue ( Models . Metadata . Header . ForceMergingKey ) . AsEnumValue < MergingFlag > ( ) . AsStringValue ( ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . ForceNodumpKey , GetStringFieldValue ( Models . Metadata . Header . ForceNodumpKey ) . AsEnumValue < NodumpFlag > ( ) . AsStringValue ( ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . ForcePackingKey , GetStringFieldValue ( Models . Metadata . Header . ForcePackingKey ) . AsEnumValue < PackingFlag > ( ) . AsStringValue ( ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( Models . Metadata . Header . HeaderKey , GetStringFieldValue ( Models . Metadata . Header . HeaderKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . HomepageKey , GetStringFieldValue ( Models . Metadata . Header . HomepageKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . NameKey , GetStringFieldValue ( Models . Metadata . Header . NameKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . RootDirKey , GetStringFieldValue ( Models . Metadata . Header . RootDirKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . TypeKey , GetStringFieldValue ( Models . Metadata . Header . TypeKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . UrlKey , GetStringFieldValue ( Models . Metadata . Header . UrlKey ) ) ;
header . SetFieldValue < string? > ( Models . Metadata . Header . VersionKey , GetStringFieldValue ( Models . Metadata . Header . VersionKey ) ) ;
2024-03-10 04:10:37 -04:00
return header ;
2020-07-15 09:41:59 -07:00
}
/// <summary>
/// Clone the filtering parts of the current header
/// </summary>
public DatHeader CloneFiltering ( )
{
2024-03-10 22:08:08 -04:00
var header = new DatHeader ( ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( DatHeader . AddExtensionKey , GetStringFieldValue ( DatHeader . AddExtensionKey ) ) ;
2024-03-10 21:54:07 -04:00
header . SetFieldValue < DatFormat > ( DatHeader . DatFormatKey , GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < bool? > ( DatHeader . GameNameKey , GetBoolFieldValue ( DatHeader . GameNameKey ) ) ;
2024-03-10 22:08:08 -04:00
header . SetFieldValue < DepotInformation ? > ( DatHeader . InputDepotKey , GetFieldValue < DepotInformation ? > ( DatHeader . InputDepotKey ) ? . Clone ( ) as DepotInformation ) ;
header . SetFieldValue < DepotInformation ? > ( DatHeader . OutputDepotKey , GetFieldValue < DepotInformation ? > ( DatHeader . OutputDepotKey ) ? . Clone ( ) as DepotInformation ) ;
2024-03-11 15:46:44 -04:00
header . SetFieldValue < string? > ( DatHeader . PostfixKey , GetStringFieldValue ( DatHeader . PostfixKey ) ) ;
header . SetFieldValue < string? > ( DatHeader . PrefixKey , GetStringFieldValue ( DatHeader . PrefixKey ) ) ;
header . SetFieldValue < bool? > ( DatHeader . RemoveExtensionKey , GetBoolFieldValue ( DatHeader . RemoveExtensionKey ) ) ;
header . SetFieldValue < string? > ( DatHeader . ReplaceExtensionKey , GetStringFieldValue ( DatHeader . ReplaceExtensionKey ) ) ;
header . SetFieldValue < bool? > ( DatHeader . QuotesKey , GetBoolFieldValue ( DatHeader . QuotesKey ) ) ;
header . SetFieldValue < bool? > ( DatHeader . UseRomNameKey , GetBoolFieldValue ( DatHeader . UseRomNameKey ) ) ;
2024-03-10 16:49:07 -04:00
return header ;
2020-07-15 09:41:59 -07:00
}
/// <summary>
/// Overwrite local values from another DatHeader if not default
/// </summary>
/// <param name="datHeader">DatHeader to get the values from</param>
2023-08-10 23:22:14 -04:00
public void ConditionalCopy ( DatHeader ? datHeader )
2020-07-15 09:41:59 -07:00
{
2023-08-10 23:22:14 -04:00
if ( datHeader = = null )
return ;
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( DatHeader . FileNameKey ) ) )
SetFieldValue < string? > ( DatHeader . FileNameKey , datHeader . GetStringFieldValue ( DatHeader . FileNameKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . NameKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . NameKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . NameKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . DescriptionKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . DescriptionKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . DescriptionKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . RootDirKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . RootDirKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . RootDirKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . CategoryKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . CategoryKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . CategoryKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . VersionKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . VersionKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . VersionKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . DateKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . DateKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . DateKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . AuthorKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . AuthorKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . AuthorKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . EmailKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . EmailKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . EmailKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . HomepageKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . HomepageKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . HomepageKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . UrlKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . UrlKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . UrlKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . CommentKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . CommentKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . CommentKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . HeaderKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . HeaderKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . HeaderKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( Models . Metadata . Header . TypeKey ) ) )
SetFieldValue < string? > ( Models . Metadata . Header . TypeKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . TypeKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 21:30:24 -04:00
if ( datHeader . GetStringFieldValue ( Models . Metadata . Header . ForceMergingKey ) . AsEnumValue < MergingFlag > ( ) ! = MergingFlag . None )
SetFieldValue < string? > ( Models . Metadata . Header . ForceMergingKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . ForceMergingKey ) . AsEnumValue < MergingFlag > ( ) . AsStringValue ( ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 21:30:24 -04:00
if ( datHeader . GetStringFieldValue ( Models . Metadata . Header . ForceNodumpKey ) . AsEnumValue < NodumpFlag > ( ) ! = NodumpFlag . None )
SetFieldValue < string? > ( Models . Metadata . Header . ForceNodumpKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . ForceNodumpKey ) . AsEnumValue < NodumpFlag > ( ) . AsStringValue ( ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 21:30:24 -04:00
if ( datHeader . GetStringFieldValue ( Models . Metadata . Header . ForcePackingKey ) . AsEnumValue < PackingFlag > ( ) ! = PackingFlag . None )
SetFieldValue < string? > ( Models . Metadata . Header . ForcePackingKey , datHeader . GetStringFieldValue ( Models . Metadata . Header . ForcePackingKey ) . AsEnumValue < PackingFlag > ( ) . AsStringValue ( ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-10 21:54:07 -04:00
if ( datHeader . GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) ! = 0x00 )
SetFieldValue < DatFormat > ( DatHeader . DatFormatKey , datHeader . GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( DatHeader . PrefixKey ) ) )
SetFieldValue < string? > ( DatHeader . PrefixKey , datHeader . GetStringFieldValue ( DatHeader . PrefixKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( DatHeader . PostfixKey ) ) )
SetFieldValue < string? > ( DatHeader . PostfixKey , datHeader . GetStringFieldValue ( DatHeader . PostfixKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( DatHeader . AddExtensionKey ) ) )
SetFieldValue < string? > ( DatHeader . AddExtensionKey , datHeader . GetStringFieldValue ( DatHeader . AddExtensionKey ) ) ;
2020-07-15 09:41:59 -07:00
2024-03-11 15:46:44 -04:00
if ( ! string . IsNullOrEmpty ( datHeader . GetStringFieldValue ( DatHeader . ReplaceExtensionKey ) ) )
SetFieldValue < string? > ( DatHeader . ReplaceExtensionKey , datHeader . GetStringFieldValue ( DatHeader . ReplaceExtensionKey ) ) ;
2020-08-20 11:23:48 -07:00
2024-03-10 22:08:08 -04:00
SetFieldValue < DepotInformation ? > ( DatHeader . InputDepotKey , datHeader . GetFieldValue < DepotInformation ? > ( DatHeader . InputDepotKey ) ? . Clone ( ) as DepotInformation ) ;
SetFieldValue < DepotInformation ? > ( DatHeader . OutputDepotKey , datHeader . GetFieldValue < DepotInformation ? > ( DatHeader . OutputDepotKey ) ? . Clone ( ) as DepotInformation ) ;
2024-03-11 15:46:44 -04:00
SetFieldValue < bool? > ( DatHeader . GameNameKey , datHeader . GetBoolFieldValue ( DatHeader . GameNameKey ) ) ;
SetFieldValue < bool? > ( DatHeader . QuotesKey , datHeader . GetBoolFieldValue ( DatHeader . QuotesKey ) ) ;
SetFieldValue < bool? > ( DatHeader . RemoveExtensionKey , datHeader . GetBoolFieldValue ( DatHeader . RemoveExtensionKey ) ) ;
SetFieldValue < bool? > ( DatHeader . UseRomNameKey , datHeader . GetBoolFieldValue ( DatHeader . UseRomNameKey ) ) ;
2020-07-15 09:41:59 -07:00
}
#endregion
2024-03-06 00:33:45 -05:00
#region Manipulation
2024-03-10 21:03:53 -04:00
/// <summary>
/// Runs a filter and determines if it passes or not
/// </summary>
/// <param name="filterRunner">Filter runner to use for checking</param>
/// <returns>True if the Machine passes the filter, false otherwise</returns>
public bool PassesFilter ( FilterRunner filterRunner ) = > filterRunner . Run ( _header ) ;
2024-03-10 04:10:37 -04:00
/// <summary>
2024-03-06 00:33:45 -05:00
/// Remove a field from the header
/// </summary>
/// <param name="fieldName">Field to remove</param>
/// <returns>True if the removal was successful, false otherwise</returns>
public bool RemoveField ( string fieldName )
2024-03-10 21:03:53 -04:00
= > FieldManipulator . RemoveField ( _header , fieldName ) ;
2024-03-06 00:33:45 -05:00
2024-03-10 21:03:53 -04:00
/// <summary>
/// Replace a field from another DatHeader
/// </summary>
/// <param name="other">DatHeader to replace field from</param>
/// <param name="fieldName">Field to replace</param>
/// <returns>True if the replacement was successful, false otherwise</returns>
public bool ReplaceField ( DatHeader ? other , string? fieldName )
= > FieldManipulator . ReplaceField ( other ? . _header , _header , fieldName ) ;
2024-03-06 00:33:45 -05:00
/// <summary>
/// Set a field in the header from a mapping string
/// </summary>
/// <param name="fieldName">Field to set</param>
/// <param name="value">String representing the value to set</param>
/// <returns>True if the setting was successful, false otherwise</returns>
/// <remarks>This only performs minimal validation before setting</remarks>
public bool SetField ( string? fieldName , string value )
2024-03-10 21:03:53 -04:00
= > FieldManipulator . SetField ( _header , fieldName , value ) ;
2024-03-06 00:33:45 -05:00
#endregion
2020-07-15 09:41:59 -07:00
#region Writing
/// <summary>
/// Generate a proper outfile name based on a DAT and output directory
/// </summary>
/// <param name="outDir">Output directory</param>
/// <param name="overwrite">True if we ignore existing files (default), false otherwise</param>
/// <returns>Dictionary of output formats mapped to file names</returns>
public Dictionary < DatFormat , string > CreateOutFileNames ( string outDir , bool overwrite = true )
{
// Create the output dictionary
2024-02-28 19:19:50 -05:00
Dictionary < DatFormat , string > outfileNames = [ ] ;
2020-07-15 09:41:59 -07:00
// Double check the outDir for the end delim
if ( ! outDir . EndsWith ( Path . DirectorySeparatorChar . ToString ( ) ) )
outDir + = Path . DirectorySeparatorChar ;
// Get all used extensions
2024-02-28 19:19:50 -05:00
List < string > usedExtensions = [ ] ;
2020-07-15 09:41:59 -07:00
// Get the extensions from the output type
#region . csv
// CSV
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . CSV ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . CSV ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . CSV , CreateOutFileNamesHelper ( outDir , ".csv" , overwrite ) ) ;
usedExtensions . Add ( ".csv" ) ;
} ;
#endregion
#region . dat
// ClrMamePro
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . ClrMamePro ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . ClrMamePro ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . ClrMamePro , CreateOutFileNamesHelper ( outDir , ".dat" , overwrite ) ) ;
usedExtensions . Add ( ".dat" ) ;
} ;
// RomCenter
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RomCenter ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RomCenter ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . DOSCenter ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . DOSCenter ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . SabreJSON ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . SabreJSON ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
2020-09-07 22:40:27 -07:00
outfileNames . Add ( DatFormat . SabreJSON , CreateOutFileNamesHelper ( outDir , ".json" , overwrite ) ) ;
2020-07-15 09:41:59 -07:00
usedExtensions . Add ( ".json" ) ;
}
#endregion
#region . md5
// Redump MD5
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RedumpMD5 ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RedumpMD5 ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . RedumpMD5 , CreateOutFileNamesHelper ( outDir , ".md5" , overwrite ) ) ;
usedExtensions . Add ( ".md5" ) ;
} ;
#endregion
#region . sfv
// Redump SFV
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RedumpSFV ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RedumpSFV ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . RedumpSFV , CreateOutFileNamesHelper ( outDir , ".sfv" , overwrite ) ) ;
usedExtensions . Add ( ".sfv" ) ;
} ;
#endregion
#region . sha1
// Redump SHA-1
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RedumpSHA1 ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RedumpSHA1 ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . RedumpSHA1 , CreateOutFileNamesHelper ( outDir , ".sha1" , overwrite ) ) ;
usedExtensions . Add ( ".sha1" ) ;
} ;
#endregion
#region . sha256
// Redump SHA-256
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RedumpSHA256 ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RedumpSHA256 ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . RedumpSHA256 , CreateOutFileNamesHelper ( outDir , ".sha256" , overwrite ) ) ;
usedExtensions . Add ( ".sha256" ) ;
} ;
#endregion
#region . sha384
// Redump SHA-384
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RedumpSHA384 ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RedumpSHA384 ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . RedumpSHA384 , CreateOutFileNamesHelper ( outDir , ".sha384" , overwrite ) ) ;
usedExtensions . Add ( ".sha384" ) ;
} ;
#endregion
#region . sha512
// Redump SHA-512
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RedumpSHA512 ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RedumpSHA512 ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . RedumpSHA512 , CreateOutFileNamesHelper ( outDir , ".sha512" , overwrite ) ) ;
usedExtensions . Add ( ".sha512" ) ;
} ;
#endregion
2020-09-04 15:02:15 -07:00
#region . spamsum
// Redump SpamSum
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . RedumpSpamSum ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . RedumpSpamSum ) )
2024-02-28 22:54:56 -05:00
#endif
2020-09-04 15:02:15 -07:00
{
outfileNames . Add ( DatFormat . RedumpSpamSum , CreateOutFileNamesHelper ( outDir , ".spamsum" , overwrite ) ) ;
usedExtensions . Add ( ".spamsum" ) ;
} ;
#endregion
2020-07-15 09:41:59 -07:00
#region . ssv
// SSV
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . SSV ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . SSV ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . SSV , CreateOutFileNamesHelper ( outDir , ".ssv" , overwrite ) ) ;
usedExtensions . Add ( ".ssv" ) ;
} ;
#endregion
#region . tsv
// TSV
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . TSV ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . TSV ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . TSV , CreateOutFileNamesHelper ( outDir , ".tsv" , overwrite ) ) ;
usedExtensions . Add ( ".tsv" ) ;
} ;
#endregion
#region . txt
// AttractMode
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . AttractMode ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . AttractMode ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . AttractMode , CreateOutFileNamesHelper ( outDir , ".txt" , overwrite ) ) ;
usedExtensions . Add ( ".txt" ) ;
}
// MAME Listroms
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . Listrom ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . Listrom ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . MissFile ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . MissFile ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . EverdriveSMDB ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . EverdriveSMDB ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . Logiqx ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . Logiqx ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . Logiqx , CreateOutFileNamesHelper ( outDir , ".xml" , overwrite ) ) ;
2020-08-31 21:02:26 -07:00
usedExtensions . Add ( ".xml" ) ;
2020-07-15 09:41:59 -07:00
}
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . LogiqxDeprecated ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . LogiqxDeprecated ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
outfileNames . Add ( DatFormat . LogiqxDeprecated , CreateOutFileNamesHelper ( outDir , ".xml" , overwrite ) ) ;
2020-08-31 21:02:26 -07:00
usedExtensions . Add ( ".xml" ) ;
2020-07-15 09:41:59 -07:00
}
// SabreDAT
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . SabreXML ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . SabreXML ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
if ( usedExtensions . Contains ( ".xml" ) )
{
2020-09-07 22:57:44 -07:00
outfileNames . Add ( DatFormat . SabreXML , CreateOutFileNamesHelper ( outDir , ".sd.xml" , overwrite ) ) ;
2020-07-15 09:41:59 -07:00
usedExtensions . Add ( ".sd.xml" ) ;
}
else
{
2020-09-07 22:57:44 -07:00
outfileNames . Add ( DatFormat . SabreXML , CreateOutFileNamesHelper ( outDir , ".xml" , overwrite ) ) ;
2020-07-15 09:41:59 -07:00
usedExtensions . Add ( ".xml" ) ;
}
}
// Software List
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . SoftwareList ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . SoftwareList ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . Listxml ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . Listxml ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . OfflineList ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . OfflineList ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . OpenMSX ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . OpenMSX ) )
2024-02-28 22:54:56 -05:00
#endif
2020-07-15 09:41:59 -07:00
{
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" ) ;
}
}
2021-07-19 10:39:21 -07:00
// Archive.org
2024-02-28 22:54:56 -05:00
#if NETFRAMEWORK
2024-03-10 21:54:07 -04:00
if ( ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) & DatFormat . ArchiveDotOrg ) ! = 0 )
2024-02-28 22:54:56 -05:00
#else
2024-03-10 21:54:07 -04:00
if ( GetFieldValue < DatFormat > ( DatHeader . DatFormatKey ) . HasFlag ( DatFormat . ArchiveDotOrg ) )
2024-02-28 22:54:56 -05:00
#endif
2021-07-19 10:39:21 -07:00
{
if ( usedExtensions . Contains ( ".xml" ) )
{
outfileNames . Add ( DatFormat . ArchiveDotOrg , CreateOutFileNamesHelper ( outDir , ".ado.xml" , overwrite ) ) ;
usedExtensions . Add ( ".ado.xml" ) ;
}
else
{
outfileNames . Add ( DatFormat . ArchiveDotOrg , CreateOutFileNamesHelper ( outDir , ".xml" , overwrite ) ) ;
usedExtensions . Add ( ".xml" ) ;
}
}
2020-07-15 09:41:59 -07:00
#endregion
return outfileNames ;
}
/// <summary>
/// Help generating the outfile name
/// </summary>
/// <param name="outDir">Output directory</param>
/// <param name="extension">Extension to use for the file</param>
/// <param name="overwrite">True if we ignore existing files, false otherwise</param>
/// <returns>String containing the new filename</returns>
private string CreateOutFileNamesHelper ( string outDir , string extension , bool overwrite )
{
2024-03-11 15:46:44 -04:00
string? filename = string . IsNullOrEmpty ( GetStringFieldValue ( DatHeader . FileNameKey ) )
? GetStringFieldValue ( Models . Metadata . Header . DescriptionKey )
: GetStringFieldValue ( DatHeader . FileNameKey ) ;
2020-07-19 21:59:34 -07:00
// Strip off the extension if it's a holdover from the DAT
2020-12-10 23:24:09 -08:00
if ( Utilities . HasValidDatExtension ( filename ) )
2020-07-19 21:59:34 -07:00
filename = Path . GetFileNameWithoutExtension ( filename ) ;
2020-07-15 09:41:59 -07:00
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 ;
}
2019-01-08 11:06:26 -08:00
#endregion
2017-10-06 13:29:58 -07:00
2019-01-08 11:06:26 -08:00
#endregion // Instance Methods
}
2017-06-16 16:24:26 -07:00
}