2016-09-19 20:52:55 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
using System.Net;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2017-05-04 02:41:11 -07:00
|
|
|
|
using SabreTools.Library.Data;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
using SabreTools.Library.FileTypes;
|
2020-08-17 23:09:35 -07:00
|
|
|
|
using SabreTools.Library.Filtering;
|
2017-05-04 02:41:11 -07:00
|
|
|
|
using SabreTools.Library.Tools;
|
2016-10-24 12:58:57 -07:00
|
|
|
|
using NaturalSort;
|
2020-06-15 21:00:09 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2020-08-23 22:23:55 -07:00
|
|
|
|
using Newtonsoft.Json.Converters;
|
2016-09-19 20:52:55 -07:00
|
|
|
|
|
2017-11-02 15:44:15 -07:00
|
|
|
|
namespace SabreTools.Library.DatItems
|
2016-09-19 20:52:55 -07:00
|
|
|
|
{
|
2019-01-08 12:11:55 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Base class for all items included in a set
|
|
|
|
|
|
/// </summary>
|
2020-08-23 22:23:55 -07:00
|
|
|
|
[JsonObject("datitem")]
|
2019-01-08 12:11:55 -08:00
|
|
|
|
public abstract class DatItem : IEquatable<DatItem>, IComparable<DatItem>, ICloneable
|
|
|
|
|
|
{
|
2020-08-22 12:56:38 -07:00
|
|
|
|
// TODO: Should any of these be specific to certain types?
|
|
|
|
|
|
// Most of the "weird" fields might only apply to Rom or Disk?
|
2020-08-20 13:17:14 -07:00
|
|
|
|
#region Fields
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region Common Fields
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Name of the item
|
|
|
|
|
|
/// </summary>
|
2020-06-15 21:00:09 -07:00
|
|
|
|
[JsonProperty("name")]
|
2019-01-08 12:11:55 -08:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Item type for outputting
|
|
|
|
|
|
/// </summary>
|
2020-08-23 22:23:55 -07:00
|
|
|
|
[JsonProperty("type")]
|
|
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2019-01-08 12:11:55 -08:00
|
|
|
|
public ItemType ItemType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Duplicate type when compared to another item
|
|
|
|
|
|
/// </summary>
|
2020-06-15 21:00:09 -07:00
|
|
|
|
[JsonIgnore]
|
2019-01-08 12:11:55 -08:00
|
|
|
|
public DupeType DupeType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region Machine Fields
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-08-20 13:17:14 -07:00
|
|
|
|
/// Machine values
|
2019-01-08 12:11:55 -08:00
|
|
|
|
/// </summary>
|
2020-06-15 21:00:09 -07:00
|
|
|
|
[JsonIgnore]
|
2020-08-20 13:17:14 -07:00
|
|
|
|
public Machine Machine { get; set; } = new Machine();
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region AttractMode Fields
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Alternate name for the item
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("alt_romname", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-20 21:15:37 -07:00
|
|
|
|
public string AltName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Alternate title for the item
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("alt_title", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-20 21:15:37 -07:00
|
|
|
|
public string AltTitle { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
#region OpenMSX
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// OpenMSX sub item type
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("original", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 23:48:35 -07:00
|
|
|
|
public OpenMSXOriginal Original { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// OpenMSX sub item type
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("openmsx_subtype", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-23 22:23:55 -07:00
|
|
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
2020-08-21 23:48:35 -07:00
|
|
|
|
public OpenMSXSubType OpenMSXSubType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// OpenMSX sub item type
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>Not related to the subtype above</remarks>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("openmsx_type", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 23:48:35 -07:00
|
|
|
|
public string OpenMSXType { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Item remark (like a comment)
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("remark", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 23:48:35 -07:00
|
|
|
|
public string Remark { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Boot state
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("boot", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 23:48:35 -07:00
|
|
|
|
public string Boot { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-20 14:48:49 -07:00
|
|
|
|
#region SoftwareList Fields
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Original hardware part associated with the item
|
|
|
|
|
|
/// </summary>
|
2020-08-24 22:25:47 -07:00
|
|
|
|
[JsonProperty("part", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
|
|
|
|
|
public SoftwareListPart Part { get; set; }
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Features provided to/by the item
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("features", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 15:31:19 -07:00
|
|
|
|
public List<SoftwareListFeature> Features { get; set; }
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Original hardware part name within an item
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("areaname", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2019-01-08 12:11:55 -08:00
|
|
|
|
public string AreaName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Original hardware size within the part
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("areasize", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2019-01-08 12:11:55 -08:00
|
|
|
|
public long? AreaSize { get; set; }
|
|
|
|
|
|
|
2020-08-21 13:31:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Width of the data area in bytes
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// TODO: Convert to Int32
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("width", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 13:31:22 -07:00
|
|
|
|
public string AreaWidth { get; set; } // (8|16|32|64) "8"
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Endianness of the data area
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// TODO: Convert to Enum?
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("endianness", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 13:31:22 -07:00
|
|
|
|
public string AreaEndianness { get; set; } // (big|little) "little"
|
|
|
|
|
|
|
2020-08-21 14:20:17 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// SoftwareList value associated with the item
|
|
|
|
|
|
/// </summary>
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("value", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 14:20:17 -07:00
|
|
|
|
public string Value { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Loading flag
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// TODO: Convert to Enum?
|
2020-08-24 11:56:49 -07:00
|
|
|
|
[JsonProperty("loadflag", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
2020-08-21 14:20:17 -07:00
|
|
|
|
public string LoadFlag { get; set; } // (load16_byte|load16_word|load16_word_swap|load32_byte|load32_word|load32_word_swap|load32_dword|load64_word|load64_word_swap|reload|fill|continue|reload_plain|ignore)
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
#region Metadata information
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-08-20 13:17:14 -07:00
|
|
|
|
/// Source information
|
2019-01-08 12:11:55 -08:00
|
|
|
|
/// </summary>
|
2020-06-15 21:00:09 -07:00
|
|
|
|
[JsonIgnore]
|
2020-08-20 13:17:14 -07:00
|
|
|
|
public Source Source { get; set; } = new Source();
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Flag if item should be removed
|
|
|
|
|
|
/// </summary>
|
2020-06-15 21:00:09 -07:00
|
|
|
|
[JsonIgnore]
|
2019-01-08 12:11:55 -08:00
|
|
|
|
public bool Remove { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-19 13:12:42 -07:00
|
|
|
|
#region Static Values
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fields unique to a DatItem
|
|
|
|
|
|
/// </summary>
|
2020-08-25 11:20:50 -07:00
|
|
|
|
/// TODO: Ensure list
|
2020-08-19 13:12:42 -07:00
|
|
|
|
public static readonly List<Field> DatItemFields = new List<Field>()
|
|
|
|
|
|
{
|
2020-08-20 21:15:37 -07:00
|
|
|
|
// Common
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.DatItem_Name,
|
2020-08-20 21:15:37 -07:00
|
|
|
|
|
|
|
|
|
|
// AttractMode
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.DatItem_AltName,
|
|
|
|
|
|
Field.DatItem_AltTitle,
|
2020-08-20 21:15:37 -07:00
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
// OpenMSX
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.DatItem_Original,
|
|
|
|
|
|
Field.DatItem_OpenMSXSubType,
|
|
|
|
|
|
Field.DatItem_OpenMSXType,
|
|
|
|
|
|
Field.DatItem_Remark,
|
|
|
|
|
|
Field.DatItem_Boot,
|
2020-08-21 23:48:35 -07:00
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
//SoftwareList
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.DatItem_Part_Name,
|
|
|
|
|
|
Field.DatItem_Part_Interface,
|
|
|
|
|
|
Field.DatItem_Features,
|
|
|
|
|
|
Field.DatItem_AreaName,
|
|
|
|
|
|
Field.DatItem_AreaSize,
|
|
|
|
|
|
Field.DatItem_AreaWidth,
|
|
|
|
|
|
Field.DatItem_AreaEndianness,
|
|
|
|
|
|
Field.DatItem_Value,
|
|
|
|
|
|
Field.DatItem_LoadFlag,
|
2020-08-20 21:15:37 -07:00
|
|
|
|
|
|
|
|
|
|
// BiosSet
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.DatItem_Description,
|
|
|
|
|
|
Field.DatItem_Default,
|
2020-08-19 13:12:42 -07:00
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
// Disk
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.DatItem_MD5,
|
2020-08-19 13:12:42 -07:00
|
|
|
|
#if NET_FRAMEWORK
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.DatItem_RIPEMD160,
|
2020-08-19 13:12:42 -07:00
|
|
|
|
#endif
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.DatItem_SHA1,
|
|
|
|
|
|
Field.DatItem_SHA256,
|
|
|
|
|
|
Field.DatItem_SHA384,
|
|
|
|
|
|
Field.DatItem_SHA512,
|
|
|
|
|
|
Field.DatItem_Merge,
|
|
|
|
|
|
Field.DatItem_Region,
|
|
|
|
|
|
Field.DatItem_Index,
|
|
|
|
|
|
Field.DatItem_Writable,
|
|
|
|
|
|
Field.DatItem_Optional,
|
|
|
|
|
|
Field.DatItem_Status,
|
2020-08-20 21:15:37 -07:00
|
|
|
|
|
|
|
|
|
|
// Release
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.DatItem_Language,
|
|
|
|
|
|
Field.DatItem_Date,
|
2020-08-20 21:15:37 -07:00
|
|
|
|
|
|
|
|
|
|
// Rom
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.DatItem_Bios,
|
|
|
|
|
|
Field.DatItem_Size,
|
|
|
|
|
|
Field.DatItem_CRC,
|
|
|
|
|
|
Field.DatItem_Offset,
|
|
|
|
|
|
Field.DatItem_Inverted,
|
2020-08-19 13:12:42 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Fields unique to a Machine
|
|
|
|
|
|
/// </summary>
|
2020-08-25 11:20:50 -07:00
|
|
|
|
/// TODO: Ensure list
|
2020-08-19 13:12:42 -07:00
|
|
|
|
public static readonly List<Field> MachineFields = new List<Field>()
|
|
|
|
|
|
{
|
2020-08-20 14:36:36 -07:00
|
|
|
|
// Common
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_Name,
|
|
|
|
|
|
Field.Machine_Comment,
|
|
|
|
|
|
Field.Machine_Description,
|
|
|
|
|
|
Field.Machine_Year,
|
|
|
|
|
|
Field.Machine_Manufacturer,
|
|
|
|
|
|
Field.Machine_Publisher,
|
|
|
|
|
|
Field.Machine_RomOf,
|
|
|
|
|
|
Field.Machine_CloneOf,
|
|
|
|
|
|
Field.Machine_SampleOf,
|
|
|
|
|
|
Field.Machine_Type,
|
2020-08-20 14:36:36 -07:00
|
|
|
|
|
|
|
|
|
|
// AttractMode
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_Players,
|
|
|
|
|
|
Field.Machine_Rotation,
|
|
|
|
|
|
Field.Machine_Control,
|
2020-08-25 11:20:50 -07:00
|
|
|
|
Field.Machine_Status,
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_DisplayCount,
|
|
|
|
|
|
Field.Machine_DisplayType,
|
|
|
|
|
|
Field.Machine_Buttons,
|
2020-08-20 14:36:36 -07:00
|
|
|
|
|
|
|
|
|
|
// ListXML
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_SourceFile,
|
|
|
|
|
|
Field.Machine_Runnable,
|
|
|
|
|
|
Field.Machine_DeviceReference_Name,
|
|
|
|
|
|
Field.Machine_Slots,
|
|
|
|
|
|
Field.Machine_Infos,
|
2020-08-20 14:36:36 -07:00
|
|
|
|
|
|
|
|
|
|
// Logiqx
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_Board,
|
|
|
|
|
|
Field.Machine_RebuildTo,
|
2020-08-20 14:36:36 -07:00
|
|
|
|
|
2020-08-20 22:42:04 -07:00
|
|
|
|
// Logiqx EmuArc
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_TitleID,
|
|
|
|
|
|
Field.Machine_Developer,
|
|
|
|
|
|
Field.Machine_Genre,
|
|
|
|
|
|
Field.Machine_Subgenre,
|
|
|
|
|
|
Field.Machine_Ratings,
|
|
|
|
|
|
Field.Machine_Score,
|
|
|
|
|
|
Field.Machine_Enabled,
|
2020-08-25 12:15:28 -07:00
|
|
|
|
Field.Machine_CRC,
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_RelatedTo,
|
2020-08-20 22:42:04 -07:00
|
|
|
|
|
2020-08-21 17:27:11 -07:00
|
|
|
|
// OpenMSX
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_GenMSXID,
|
|
|
|
|
|
Field.Machine_System,
|
|
|
|
|
|
Field.Machine_Country,
|
2020-08-21 17:27:11 -07:00
|
|
|
|
|
2020-08-20 14:36:36 -07:00
|
|
|
|
// SoftwareList
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Field.Machine_Supported,
|
|
|
|
|
|
Field.Machine_SharedFeatures,
|
|
|
|
|
|
Field.Machine_DipSwitches,
|
2020-08-19 13:12:42 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Instance Methods
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
#region Accessors
|
|
|
|
|
|
|
2020-08-21 10:16:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Set fields with given values
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="mappings">Mappings dictionary</param>
|
|
|
|
|
|
public virtual void SetFields(Dictionary<Field, string> mappings)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Set machine fields
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (Machine == null)
|
|
|
|
|
|
Machine = new Machine();
|
|
|
|
|
|
|
2020-08-21 10:16:05 -07:00
|
|
|
|
Machine.SetFields(mappings);
|
|
|
|
|
|
|
|
|
|
|
|
#region Common
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_Name))
|
|
|
|
|
|
Name = mappings[Field.DatItem_Name];
|
2020-08-21 10:16:05 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AttractMode
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_AltName))
|
|
|
|
|
|
AltName = mappings[Field.DatItem_AltName];
|
2020-08-21 10:16:05 -07:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_AltTitle))
|
|
|
|
|
|
AltTitle = mappings[Field.DatItem_AltTitle];
|
2020-08-21 10:16:05 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
#region OpenMSX
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_Original))
|
|
|
|
|
|
Original = new OpenMSXOriginal() { Content = mappings[Field.DatItem_Original] };
|
2020-08-21 23:48:35 -07:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_OpenMSXSubType))
|
|
|
|
|
|
OpenMSXSubType = mappings[Field.DatItem_OpenMSXSubType].AsOpenMSXSubType();
|
2020-08-21 23:48:35 -07:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_OpenMSXType))
|
|
|
|
|
|
OpenMSXType = mappings[Field.DatItem_OpenMSXType];
|
2020-08-21 23:48:35 -07:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_Remark))
|
|
|
|
|
|
Remark = mappings[Field.DatItem_Remark];
|
2020-08-21 23:48:35 -07:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_Boot))
|
|
|
|
|
|
Boot = mappings[Field.DatItem_Boot];
|
2020-08-21 23:48:35 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-21 10:16:05 -07:00
|
|
|
|
#region SoftwareList
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
// TODO: Add DatItem_Part*
|
|
|
|
|
|
// TODO: Add DatItem_Feature*
|
2020-08-21 10:16:05 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
// TODO: These might be replaced by dataarea/diskarea
|
|
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_AreaName))
|
|
|
|
|
|
AreaName = mappings[Field.DatItem_AreaName];
|
2020-08-21 10:16:05 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_AreaSize))
|
2020-08-21 10:16:05 -07:00
|
|
|
|
{
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (Int64.TryParse(mappings[Field.DatItem_AreaSize], out long areaSize))
|
2020-08-21 10:16:05 -07:00
|
|
|
|
AreaSize = areaSize;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_AreaWidth))
|
|
|
|
|
|
AreaWidth = mappings[Field.DatItem_AreaWidth];
|
2020-08-21 13:31:22 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_AreaEndianness))
|
|
|
|
|
|
AreaEndianness = mappings[Field.DatItem_AreaEndianness];
|
2020-08-21 13:31:22 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_Value))
|
|
|
|
|
|
Value = mappings[Field.DatItem_Value];
|
2020-08-21 14:20:17 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (mappings.Keys.Contains(Field.DatItem_LoadFlag))
|
|
|
|
|
|
LoadFlag = mappings[Field.DatItem_LoadFlag];
|
2020-08-21 14:20:17 -07:00
|
|
|
|
|
2020-08-21 10:16:05 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a specific type of DatItem to be used based on an ItemType
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="itemType">Type of the DatItem to be created</param>
|
|
|
|
|
|
/// <returns>DatItem of the specific internal type that corresponds to the inputs</returns>
|
2020-08-25 11:20:50 -07:00
|
|
|
|
public static DatItem Create(ItemType? itemType)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
{
|
|
|
|
|
|
#if NET_FRAMEWORK
|
|
|
|
|
|
switch (itemType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case ItemType.Archive:
|
|
|
|
|
|
return new Archive();
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.BiosSet:
|
|
|
|
|
|
return new BiosSet();
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.Blank:
|
|
|
|
|
|
return new Blank();
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.Disk:
|
|
|
|
|
|
return new Disk();
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.Release:
|
|
|
|
|
|
return new Release();
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.Rom:
|
|
|
|
|
|
return new Rom();
|
|
|
|
|
|
|
|
|
|
|
|
case ItemType.Sample:
|
|
|
|
|
|
return new Sample();
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
return new Rom();
|
|
|
|
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
|
|
return itemType switch
|
|
|
|
|
|
{
|
|
|
|
|
|
ItemType.Archive => new Archive(),
|
|
|
|
|
|
ItemType.BiosSet => new BiosSet(),
|
|
|
|
|
|
ItemType.Blank => new Blank(),
|
|
|
|
|
|
ItemType.Disk => new Disk(),
|
|
|
|
|
|
ItemType.Release => new Release(),
|
|
|
|
|
|
ItemType.Rom => new Rom(),
|
|
|
|
|
|
ItemType.Sample => new Sample(),
|
|
|
|
|
|
_ => new Rom(),
|
|
|
|
|
|
};
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a specific type of DatItem to be used based on a BaseFile
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="baseFile">BaseFile containing information to be created</param>
|
|
|
|
|
|
/// <returns>DatItem of the specific internal type that corresponds to the inputs</returns>
|
|
|
|
|
|
public static DatItem Create(BaseFile baseFile)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (baseFile.Type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case FileType.CHD:
|
|
|
|
|
|
return new Disk(baseFile);
|
|
|
|
|
|
|
|
|
|
|
|
case FileType.GZipArchive:
|
|
|
|
|
|
case FileType.LRZipArchive:
|
|
|
|
|
|
case FileType.LZ4Archive:
|
|
|
|
|
|
case FileType.None:
|
|
|
|
|
|
case FileType.RarArchive:
|
|
|
|
|
|
case FileType.SevenZipArchive:
|
|
|
|
|
|
case FileType.TapeArchive:
|
|
|
|
|
|
case FileType.XZArchive:
|
|
|
|
|
|
case FileType.ZipArchive:
|
|
|
|
|
|
case FileType.ZPAQArchive:
|
|
|
|
|
|
case FileType.ZstdArchive:
|
|
|
|
|
|
return new Rom(baseFile);
|
|
|
|
|
|
|
|
|
|
|
|
case FileType.Folder:
|
|
|
|
|
|
default:
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
#region Cloning Methods
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Clone the DatItem
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>Clone of the DatItem</returns>
|
|
|
|
|
|
public abstract object Clone();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Copy all machine information over in one shot
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="item">Existing item to copy information from</param>
|
|
|
|
|
|
public void CopyMachineInformation(DatItem item)
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Machine = (Machine)item.Machine.Clone();
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Copy all machine information over in one shot
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="machine">Existing machine to copy information from</param>
|
|
|
|
|
|
public void CopyMachineInformation(Machine machine)
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
Machine = (Machine)machine.Clone();
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Comparision Methods
|
|
|
|
|
|
|
|
|
|
|
|
public int CompareTo(DatItem other)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-08-17 17:28:32 -07:00
|
|
|
|
if (Name == other.Name)
|
|
|
|
|
|
return Equals(other) ? 0 : 1;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-17 17:28:32 -07:00
|
|
|
|
return string.Compare(Name, other.Name);
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2020-07-15 09:41:59 -07:00
|
|
|
|
return 1;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determine if an item is a duplicate using partial matching logic
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="other">DatItem to use as a baseline</param>
|
|
|
|
|
|
/// <returns>True if the roms are duplicates, false otherwise</returns>
|
|
|
|
|
|
public abstract bool Equals(DatItem other);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Return the duplicate status of two items
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="lastItem">DatItem to check against</param>
|
|
|
|
|
|
/// <returns>The DupeType corresponding to the relationship between the two</returns>
|
|
|
|
|
|
public DupeType GetDuplicateStatus(DatItem lastItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
DupeType output = 0x00;
|
|
|
|
|
|
|
|
|
|
|
|
// If we don't have a duplicate at all, return none
|
2020-08-17 17:28:32 -07:00
|
|
|
|
if (!Equals(lastItem))
|
2019-01-08 12:11:55 -08:00
|
|
|
|
return output;
|
|
|
|
|
|
|
|
|
|
|
|
// If the duplicate is external already or should be, set it
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (lastItem.DupeType.HasFlag(DupeType.External) || lastItem.Source.Index != Source.Index)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (lastItem.Machine.Name == Machine.Name && lastItem.Name == Name)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
output = DupeType.External | DupeType.All;
|
|
|
|
|
|
else
|
|
|
|
|
|
output = DupeType.External | DupeType.Hash;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, it's considered an internal dupe
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (lastItem.Machine.Name == Machine.Name && lastItem.Name == Name)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
output = DupeType.Internal | DupeType.All;
|
|
|
|
|
|
else
|
|
|
|
|
|
output = DupeType.Internal | DupeType.Hash;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-17 23:09:35 -07:00
|
|
|
|
#region Filtering
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check to see if a DatItem passes the filter
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filter">Filter to check against</param>
|
|
|
|
|
|
/// <returns>True if the item passed the filter, false otherwise</returns>
|
|
|
|
|
|
public virtual bool PassesFilter(Filter filter)
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
// Filter on machine fields
|
|
|
|
|
|
if (!Machine.PassesFilter(filter))
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region Common
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on item name
|
|
|
|
|
|
if (filter.ItemName.MatchesPositiveSet(Name) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.ItemName.MatchesNegativeSet(Name) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-08-17 23:09:35 -07:00
|
|
|
|
// Filter on item type
|
|
|
|
|
|
if (filter.ItemTypes.MatchesPositiveSet(ItemType.ToString()) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.ItemTypes.MatchesNegativeSet(ItemType.ToString()) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AttractMode
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on alt name
|
|
|
|
|
|
if (filter.AltName.MatchesPositiveSet(AltName) == false)
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return false;
|
2020-08-20 21:15:37 -07:00
|
|
|
|
if (filter.AltName.MatchesNegativeSet(AltName) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on alt title
|
|
|
|
|
|
if (filter.AltTitle.MatchesPositiveSet(AltTitle) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.AltTitle.MatchesNegativeSet(AltTitle) == true)
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
#region OpenMSX
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on original
|
2020-08-24 10:18:31 -07:00
|
|
|
|
if (filter.Original.MatchesPositiveSet(Original?.Content) == false)
|
2020-08-21 23:48:35 -07:00
|
|
|
|
return false;
|
2020-08-24 10:18:31 -07:00
|
|
|
|
if (filter.Original.MatchesNegativeSet(Original?.Content) == true)
|
2020-08-21 23:48:35 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on OpenMSX subtype
|
|
|
|
|
|
if (filter.SubType.MatchesPositiveSet(OpenMSXSubType) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.SubType.MatchesNegativeSet(OpenMSXSubType) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on OpenMSX type
|
|
|
|
|
|
if (filter.OpenMSXType.MatchesPositiveSet(OpenMSXType) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.OpenMSXType.MatchesNegativeSet(OpenMSXType) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on remark
|
|
|
|
|
|
if (filter.Remark.MatchesPositiveSet(Remark) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.Remark.MatchesNegativeSet(Remark) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on boot
|
|
|
|
|
|
if (filter.Boot.MatchesPositiveSet(Boot) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.Boot.MatchesNegativeSet(Boot) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region SoftwareList
|
|
|
|
|
|
|
2020-08-17 23:09:35 -07:00
|
|
|
|
// Filter on part name
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (filter.PartName.MatchesPositiveSet(Part?.Name) == false)
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return false;
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (filter.PartName.MatchesNegativeSet(Part?.Name) == true)
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on part interface
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (filter.PartInterface.MatchesPositiveSet(Part?.Interface) == false)
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return false;
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (filter.PartInterface.MatchesNegativeSet(Part?.Interface) == true)
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on area name
|
|
|
|
|
|
if (filter.AreaName.MatchesPositiveSet(AreaName) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.AreaName.MatchesNegativeSet(AreaName) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on area size
|
|
|
|
|
|
if (filter.AreaSize.MatchesNeutral(null, AreaSize) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
else if (filter.AreaSize.MatchesPositive(null, AreaSize) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
else if (filter.AreaSize.MatchesNegative(null, AreaSize) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-08-21 13:31:22 -07:00
|
|
|
|
// Filter on area byte width
|
|
|
|
|
|
if (filter.AreaWidth.MatchesPositiveSet(AreaWidth) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.AreaWidth.MatchesNegativeSet(AreaWidth) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on area endianness
|
|
|
|
|
|
if (filter.AreaEndianness.MatchesPositiveSet(AreaEndianness) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.AreaEndianness.MatchesNegativeSet(AreaEndianness) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-08-21 14:20:17 -07:00
|
|
|
|
// Filter on softwarelist value
|
|
|
|
|
|
if (filter.Value.MatchesPositiveSet(Value) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.Value.MatchesNegativeSet(Value) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Filter on load flag
|
|
|
|
|
|
if (filter.LoadFlag.MatchesPositiveSet(LoadFlag) == false)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
if (filter.LoadFlag.MatchesNegativeSet(LoadFlag) == true)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-17 23:09:35 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-17 23:45:23 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove fields from the DatItem
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="fields">List of Fields to remove</param>
|
|
|
|
|
|
public virtual void RemoveFields(List<Field> fields)
|
|
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
// Remove machine fields
|
|
|
|
|
|
Machine.RemoveFields(fields);
|
2020-08-17 23:45:23 -07:00
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region Common
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Name))
|
2020-08-17 23:45:23 -07:00
|
|
|
|
Name = null;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AttractMode
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AltName))
|
2020-08-20 21:15:37 -07:00
|
|
|
|
AltName = null;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AltTitle))
|
2020-08-20 21:15:37 -07:00
|
|
|
|
AltTitle = null;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
#region OpenMSX
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Original))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Original = null;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_OpenMSXSubType))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
OpenMSXSubType = OpenMSXSubType.NULL;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_OpenMSXType))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
OpenMSXType = null;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Remark))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Remark = null;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Boot))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Boot = null;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region SoftwareList
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Part_Name) && Part != null)
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Part.Name = null;
|
2020-08-17 23:45:23 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Part_Interface) && Part != null)
|
2020-08-24 22:25:47 -07:00
|
|
|
|
Part.Interface = null;
|
2020-08-17 23:45:23 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Features))
|
2020-08-17 23:45:23 -07:00
|
|
|
|
Features = null;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaName))
|
2020-08-17 23:45:23 -07:00
|
|
|
|
AreaName = null;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaSize))
|
2020-08-17 23:45:23 -07:00
|
|
|
|
AreaSize = null;
|
2020-08-20 21:15:37 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaWidth))
|
2020-08-21 13:31:22 -07:00
|
|
|
|
AreaWidth = null;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaEndianness))
|
2020-08-21 13:31:22 -07:00
|
|
|
|
AreaEndianness = null;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Value))
|
2020-08-21 14:20:17 -07:00
|
|
|
|
Value = null;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_LoadFlag))
|
2020-08-21 14:20:17 -07:00
|
|
|
|
LoadFlag = null;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#endregion
|
2020-08-17 23:45:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-17 23:09:35 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
#region Sorting and Merging
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2020-07-15 10:47:13 -07:00
|
|
|
|
/// Get the dictionary key that should be used for a given item and bucketing type
|
2019-01-08 12:11:55 -08:00
|
|
|
|
/// </summary>
|
2020-08-22 23:02:30 -07:00
|
|
|
|
/// <param name="bucketedBy">Field value representing what key to get</param>
|
2020-07-15 09:41:59 -07:00
|
|
|
|
/// <param name="lower">True if the key should be lowercased (default), false otherwise</param>
|
|
|
|
|
|
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
|
|
|
|
|
|
/// <returns>String representing the key to be used for the DatItem</returns>
|
2020-08-22 23:02:30 -07:00
|
|
|
|
/// TODO: What other fields can we reasonably allow bucketing on?
|
|
|
|
|
|
public virtual string GetKey(Field bucketedBy, bool lower = true, bool norename = true)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-07-15 09:41:59 -07:00
|
|
|
|
// Set the output key as the default blank string
|
|
|
|
|
|
string key = string.Empty;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-07-15 10:47:13 -07:00
|
|
|
|
// Now determine what the key should be based on the bucketedBy value
|
|
|
|
|
|
switch (bucketedBy)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
{
|
2020-08-25 11:20:50 -07:00
|
|
|
|
case Field.DatItem_CRC:
|
2020-08-17 17:28:32 -07:00
|
|
|
|
key = Constants.CRCZero;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
break;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
case Field.Machine_Name:
|
2020-07-15 09:41:59 -07:00
|
|
|
|
key = (norename ? string.Empty
|
2020-08-20 13:17:14 -07:00
|
|
|
|
: Source.Index.ToString().PadLeft(10, '0')
|
2020-07-15 09:41:59 -07:00
|
|
|
|
+ "-")
|
2020-08-20 13:17:14 -07:00
|
|
|
|
+ (string.IsNullOrWhiteSpace(Machine.Name)
|
2020-07-15 09:41:59 -07:00
|
|
|
|
? "Default"
|
2020-08-20 13:17:14 -07:00
|
|
|
|
: Machine.Name);
|
2020-07-15 09:41:59 -07:00
|
|
|
|
if (lower)
|
|
|
|
|
|
key = key.ToLowerInvariant();
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
if (key == null)
|
|
|
|
|
|
key = "null";
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
key = WebUtility.HtmlEncode(key);
|
|
|
|
|
|
break;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
case Field.DatItem_MD5:
|
2020-08-17 17:28:32 -07:00
|
|
|
|
key = Constants.MD5Zero;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
break;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#if NET_FRAMEWORK
|
2020-08-25 11:20:50 -07:00
|
|
|
|
case Field.DatItem_RIPEMD160:
|
2020-08-17 17:28:32 -07:00
|
|
|
|
key = Constants.RIPEMD160Zero;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
break;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
case Field.DatItem_SHA1:
|
2020-08-17 17:28:32 -07:00
|
|
|
|
key = Constants.SHA1Zero;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
break;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
case Field.DatItem_SHA256:
|
2020-08-17 17:28:32 -07:00
|
|
|
|
key = Constants.SHA256Zero;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
break;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
case Field.DatItem_SHA384:
|
2020-08-17 17:28:32 -07:00
|
|
|
|
key = Constants.SHA384Zero;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
break;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
case Field.DatItem_SHA512:
|
2020-08-17 17:28:32 -07:00
|
|
|
|
key = Constants.SHA512Zero;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
break;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
// Double and triple check the key for corner cases
|
|
|
|
|
|
if (key == null)
|
|
|
|
|
|
key = string.Empty;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-07-15 09:41:59 -07:00
|
|
|
|
return key;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-17 22:35:17 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Replace fields from another item
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="item">DatItem to pull new information from</param>
|
2020-08-17 23:45:23 -07:00
|
|
|
|
/// <param name="fields">List of Fields representing what should be updated</param>
|
|
|
|
|
|
public virtual void ReplaceFields(DatItem item, List<Field> fields)
|
2020-08-17 22:35:17 -07:00
|
|
|
|
{
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region Common
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Name))
|
2020-08-17 22:35:17 -07:00
|
|
|
|
Name = item.Name;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region AttractMode
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AltName))
|
2020-08-20 21:15:37 -07:00
|
|
|
|
AltName = item.AltName;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AltTitle))
|
2020-08-20 21:15:37 -07:00
|
|
|
|
AltTitle = item.AltTitle;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-21 23:48:35 -07:00
|
|
|
|
#region OpenMSX
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Original))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Original = item.Original;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_OpenMSXSubType))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
OpenMSXSubType = item.OpenMSXSubType;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_OpenMSXType))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
OpenMSXType = item.OpenMSXType;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Remark))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Remark = item.Remark;
|
|
|
|
|
|
|
2020-08-24 22:25:47 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Boot))
|
2020-08-21 23:48:35 -07:00
|
|
|
|
Boot = item.Boot;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#region SoftwareList
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Part_Name))
|
2020-08-24 22:25:47 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (Part == null)
|
|
|
|
|
|
Part = new SoftwareListPart();
|
|
|
|
|
|
|
|
|
|
|
|
Part.Name = item.Part?.Name;
|
|
|
|
|
|
}
|
2020-08-17 22:35:17 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Part_Interface))
|
2020-08-24 22:25:47 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (Part == null)
|
|
|
|
|
|
Part = new SoftwareListPart();
|
|
|
|
|
|
|
|
|
|
|
|
Part.Interface = item.Part?.Interface;
|
|
|
|
|
|
}
|
2020-08-17 22:35:17 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Features))
|
2020-08-17 22:35:17 -07:00
|
|
|
|
Features = item.Features;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaName))
|
2020-08-17 22:35:17 -07:00
|
|
|
|
AreaName = item.AreaName;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaSize))
|
2020-08-17 22:35:17 -07:00
|
|
|
|
AreaSize = item.AreaSize;
|
2020-08-20 21:15:37 -07:00
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaWidth))
|
2020-08-21 13:31:22 -07:00
|
|
|
|
AreaWidth = item.AreaWidth;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_AreaEndianness))
|
2020-08-21 13:31:22 -07:00
|
|
|
|
AreaEndianness = item.AreaEndianness;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_Value))
|
2020-08-21 14:20:17 -07:00
|
|
|
|
Value = item.Value;
|
|
|
|
|
|
|
2020-08-25 11:20:50 -07:00
|
|
|
|
if (fields.Contains(Field.DatItem_LoadFlag))
|
2020-08-21 14:20:17 -07:00
|
|
|
|
LoadFlag = item.LoadFlag;
|
|
|
|
|
|
|
2020-08-20 21:15:37 -07:00
|
|
|
|
#endregion
|
2020-08-17 22:35:17 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion // Instance Methods
|
|
|
|
|
|
|
|
|
|
|
|
#region Static Methods
|
|
|
|
|
|
|
|
|
|
|
|
#region Sorting and Merging
|
|
|
|
|
|
|
2020-08-17 14:57:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determine if two hashes are equal for the purposes of merging
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="firstHash">First hash to compare</param>
|
|
|
|
|
|
/// <param name="secondHash">Second hash to compare</param>
|
|
|
|
|
|
/// <returns>True if either is empty OR the hashes exactly match, false otherwise</returns>
|
|
|
|
|
|
public static bool ConditionalHashEquals(byte[] firstHash, byte[] secondHash)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If either hash is empty, we say they're equal for merging
|
|
|
|
|
|
if (firstHash.IsNullOrEmpty() || secondHash.IsNullOrEmpty())
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
// If they're different sizes, they can't match
|
|
|
|
|
|
if (firstHash.Length != secondHash.Length)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, they need to match exactly
|
|
|
|
|
|
return Enumerable.SequenceEqual(firstHash, secondHash);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Merge an arbitrary set of ROMs based on the supplied information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="infiles">List of File objects representing the roms to be merged</param>
|
|
|
|
|
|
/// <returns>A List of DatItem objects representing the merged roms</returns>
|
|
|
|
|
|
public static List<DatItem> Merge(List<DatItem> infiles)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Check for null or blank roms first
|
|
|
|
|
|
if (infiles == null || infiles.Count == 0)
|
|
|
|
|
|
return new List<DatItem>();
|
|
|
|
|
|
|
|
|
|
|
|
// Create output list
|
|
|
|
|
|
List<DatItem> outfiles = new List<DatItem>();
|
|
|
|
|
|
|
|
|
|
|
|
// Then deduplicate them by checking to see if data matches previous saved roms
|
|
|
|
|
|
int nodumpCount = 0;
|
2020-07-19 13:42:07 -07:00
|
|
|
|
for (int f = 0; f < infiles.Count; f++)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-07-19 13:42:07 -07:00
|
|
|
|
DatItem file = infiles[f];
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
// If we don't have a Rom or a Disk, we skip checking for duplicates
|
|
|
|
|
|
if (file.ItemType != ItemType.Rom && file.ItemType != ItemType.Disk)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// If it's a nodump, add and skip
|
2020-08-17 17:28:32 -07:00
|
|
|
|
if (file.ItemType == ItemType.Rom && (file as Rom).ItemStatus == ItemStatus.Nodump)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
outfiles.Add(file);
|
|
|
|
|
|
nodumpCount++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
2020-08-17 17:28:32 -07:00
|
|
|
|
else if (file.ItemType == ItemType.Disk && (file as Disk).ItemStatus == ItemStatus.Nodump)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
outfiles.Add(file);
|
|
|
|
|
|
nodumpCount++;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
// If it's the first non-nodump rom in the list, don't touch it
|
|
|
|
|
|
else if (outfiles.Count == 0 || outfiles.Count == nodumpCount)
|
|
|
|
|
|
{
|
|
|
|
|
|
outfiles.Add(file);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the rom is a duplicate
|
|
|
|
|
|
DupeType dupetype = 0x00;
|
2020-08-17 17:28:32 -07:00
|
|
|
|
DatItem saveditem = new Blank();
|
2019-01-08 12:11:55 -08:00
|
|
|
|
int pos = -1;
|
|
|
|
|
|
for (int i = 0; i < outfiles.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DatItem lastrom = outfiles[i];
|
|
|
|
|
|
|
|
|
|
|
|
// Get the duplicate status
|
|
|
|
|
|
dupetype = file.GetDuplicateStatus(lastrom);
|
|
|
|
|
|
|
|
|
|
|
|
// If it's a duplicate, skip adding it to the output but add any missing information
|
|
|
|
|
|
if (dupetype != 0x00)
|
|
|
|
|
|
{
|
|
|
|
|
|
saveditem = lastrom;
|
|
|
|
|
|
pos = i;
|
|
|
|
|
|
|
2020-08-17 17:28:32 -07:00
|
|
|
|
// Disks and Roms have more information to fill
|
|
|
|
|
|
if (file.ItemType == ItemType.Disk)
|
|
|
|
|
|
(saveditem as Disk).FillMissingInformation(file as Disk);
|
|
|
|
|
|
else if (file.ItemType == ItemType.Rom)
|
|
|
|
|
|
(saveditem as Rom).FillMissingInformation(file as Rom);
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
|
|
|
|
|
saveditem.DupeType = dupetype;
|
|
|
|
|
|
|
|
|
|
|
|
// If the current system has a lower ID than the previous, set the system accordingly
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (file.Source.Index < saveditem.Source.Index)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
saveditem.Source = file.Source.Clone() as Source;
|
2019-01-08 12:11:55 -08:00
|
|
|
|
saveditem.CopyMachineInformation(file);
|
|
|
|
|
|
saveditem.Name = file.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the current machine is a child of the new machine, use the new machine instead
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (saveditem.Machine.CloneOf == file.Machine.Name || saveditem.Machine.RomOf == file.Machine.Name)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
saveditem.CopyMachineInformation(file);
|
|
|
|
|
|
saveditem.Name = file.Name;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If no duplicate is found, add it to the list
|
|
|
|
|
|
if (dupetype == 0x00)
|
|
|
|
|
|
{
|
|
|
|
|
|
outfiles.Add(file);
|
|
|
|
|
|
}
|
|
|
|
|
|
// Otherwise, if a new rom information is found, add that
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
outfiles.RemoveAt(pos);
|
|
|
|
|
|
outfiles.Insert(pos, saveditem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Then return the result
|
|
|
|
|
|
return outfiles;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Resolve name duplicates in an arbitrary set of ROMs based on the supplied information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="infiles">List of File objects representing the roms to be merged</param>
|
|
|
|
|
|
/// <returns>A List of DatItem objects representing the renamed roms</returns>
|
|
|
|
|
|
public static List<DatItem> ResolveNames(List<DatItem> infiles)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Create the output list
|
|
|
|
|
|
List<DatItem> output = new List<DatItem>();
|
|
|
|
|
|
|
|
|
|
|
|
// First we want to make sure the list is in alphabetical order
|
|
|
|
|
|
Sort(ref infiles, true);
|
|
|
|
|
|
|
|
|
|
|
|
// Now we want to loop through and check names
|
|
|
|
|
|
DatItem lastItem = null;
|
|
|
|
|
|
string lastrenamed = null;
|
|
|
|
|
|
int lastid = 0;
|
|
|
|
|
|
for (int i = 0; i < infiles.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DatItem datItem = infiles[i];
|
|
|
|
|
|
|
|
|
|
|
|
// If we have the first item, we automatically add it
|
|
|
|
|
|
if (lastItem == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
output.Add(datItem);
|
|
|
|
|
|
lastItem = datItem;
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the current item exactly matches the last item, then we don't add it
|
2020-07-15 09:41:59 -07:00
|
|
|
|
if (datItem.GetDuplicateStatus(lastItem).HasFlag(DupeType.All))
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
Globals.Logger.Verbose($"Exact duplicate found for '{datItem.Name}'");
|
2019-01-08 12:11:55 -08:00
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the current name matches the previous name, rename the current item
|
|
|
|
|
|
else if (datItem.Name == lastItem.Name)
|
|
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
Globals.Logger.Verbose($"Name duplicate found for '{datItem.Name}'");
|
2019-01-08 12:11:55 -08:00
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
if (datItem.ItemType == ItemType.Disk || datItem.ItemType == ItemType.Rom)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-06-10 22:37:19 -07:00
|
|
|
|
datItem.Name += GetDuplicateSuffix(datItem);
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#if NET_FRAMEWORK
|
2019-01-08 12:11:55 -08:00
|
|
|
|
lastrenamed = lastrenamed ?? datItem.Name;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
#else
|
|
|
|
|
|
lastrenamed ??= datItem.Name;
|
|
|
|
|
|
#endif
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If we have a conflict with the last renamed item, do the right thing
|
|
|
|
|
|
if (datItem.Name == lastrenamed)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastrenamed = datItem.Name;
|
2020-06-10 22:37:19 -07:00
|
|
|
|
datItem.Name += (lastid == 0 ? string.Empty : "_" + lastid);
|
2019-01-08 12:11:55 -08:00
|
|
|
|
lastid++;
|
|
|
|
|
|
}
|
|
|
|
|
|
// If we have no conflict, then we want to reset the lastrenamed and id
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
lastrenamed = null;
|
|
|
|
|
|
lastid = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
output.Add(datItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Otherwise, we say that we have a valid named file
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
output.Add(datItem);
|
|
|
|
|
|
lastItem = datItem;
|
|
|
|
|
|
lastrenamed = null;
|
|
|
|
|
|
lastid = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// One last sort to make sure this is ordered
|
|
|
|
|
|
Sort(ref output, true);
|
|
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-10 22:37:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get duplicate suffix based on the item type
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private static string GetDuplicateSuffix(DatItem datItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (datItem.ItemType == ItemType.Disk)
|
2020-08-17 17:28:32 -07:00
|
|
|
|
return (datItem as Disk).GetDuplicateSuffix();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
else if (datItem.ItemType == ItemType.Rom)
|
2020-08-17 17:28:32 -07:00
|
|
|
|
return (datItem as Rom).GetDuplicateSuffix();
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
|
|
|
|
|
return "_1";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sort a list of File objects by SystemID, SourceID, Game, and Name (in order)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="roms">List of File objects representing the roms to be sorted</param>
|
|
|
|
|
|
/// <param name="norename">True if files are not renamed, false otherwise</param>
|
|
|
|
|
|
/// <returns>True if it sorted correctly, false otherwise</returns>
|
|
|
|
|
|
public static bool Sort(ref List<DatItem> roms, bool norename)
|
|
|
|
|
|
{
|
|
|
|
|
|
roms.Sort(delegate (DatItem x, DatItem y)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
NaturalComparer nc = new NaturalComparer();
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (x.Source.Index == y.Source.Index)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-08-20 13:17:14 -07:00
|
|
|
|
if (x.Machine.Name == y.Machine.Name)
|
2019-01-08 12:11:55 -08:00
|
|
|
|
{
|
2020-08-17 17:28:32 -07:00
|
|
|
|
// Special case for comparing a Disk or Rom to another item type
|
|
|
|
|
|
if ((x.ItemType == ItemType.Disk || x.ItemType == ItemType.Rom) ^ (y.ItemType == ItemType.Disk || y.ItemType == ItemType.Rom))
|
2020-07-15 09:41:59 -07:00
|
|
|
|
{
|
2020-08-17 17:28:32 -07:00
|
|
|
|
if (x.ItemType == ItemType.Disk || x.ItemType == ItemType.Rom)
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
else
|
|
|
|
|
|
return 1;
|
2020-07-15 09:41:59 -07:00
|
|
|
|
}
|
2020-08-17 17:28:32 -07:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, we compare names naturally
|
2020-07-15 09:41:59 -07:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-08-17 17:28:32 -07:00
|
|
|
|
if (Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)) == Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)))
|
|
|
|
|
|
return nc.Compare(Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-17 17:28:32 -07:00
|
|
|
|
return nc.Compare(Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
return nc.Compare(x.Machine.Name, y.Machine.Name);
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
2020-06-10 22:37:19 -07:00
|
|
|
|
|
2020-08-20 13:17:14 -07:00
|
|
|
|
return (norename ? nc.Compare(x.Machine.Name, y.Machine.Name) : x.Source.Index - y.Source.Index);
|
2019-01-08 12:11:55 -08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Absorb the error
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2019-09-20 10:30:16 -07:00
|
|
|
|
|
2019-01-08 12:11:55 -08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion // Static Methods
|
|
|
|
|
|
}
|
2016-09-19 20:52:55 -07:00
|
|
|
|
}
|