mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Promote Info
This commit is contained in:
@@ -15,38 +15,8 @@ namespace SabreTools.Library.DatItems
|
||||
{
|
||||
#region Machine
|
||||
|
||||
#region OpenMSX
|
||||
|
||||
/// <summary>
|
||||
/// Represents the OpenMSX original value
|
||||
/// </summary>
|
||||
[JsonObject("original")]
|
||||
public class Original
|
||||
{
|
||||
[JsonProperty("value")]
|
||||
public bool? Value { get; set; }
|
||||
|
||||
[JsonProperty("content")]
|
||||
public string Content { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
/// <summary>
|
||||
/// Represents one SoftwareList info
|
||||
/// </summary>
|
||||
[JsonObject("info")]
|
||||
public class Info
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("value")]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents one SoftwareList shared feature object
|
||||
/// </summary>
|
||||
@@ -66,6 +36,23 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
#region DatItem
|
||||
|
||||
#region OpenMSX
|
||||
|
||||
/// <summary>
|
||||
/// Represents the OpenMSX original value
|
||||
/// </summary>
|
||||
[JsonObject("original")]
|
||||
public class Original
|
||||
{
|
||||
[JsonProperty("value")]
|
||||
public bool? Value { get; set; }
|
||||
|
||||
[JsonProperty("content")]
|
||||
public string Content { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SoftwareList
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -326,7 +326,6 @@ namespace SabreTools.Library.DatItems
|
||||
// ListXML
|
||||
Field.Machine_SourceFile,
|
||||
Field.Machine_Runnable,
|
||||
Field.Machine_Infos,
|
||||
|
||||
// Logiqx
|
||||
Field.Machine_Board,
|
||||
@@ -506,6 +505,9 @@ namespace SabreTools.Library.DatItems
|
||||
case ItemType.Feature:
|
||||
return new Feature();
|
||||
|
||||
case ItemType.Info:
|
||||
return new Info();
|
||||
|
||||
case ItemType.Input:
|
||||
return new Input();
|
||||
|
||||
@@ -570,6 +572,7 @@ namespace SabreTools.Library.DatItems
|
||||
ItemType.Driver => new Driver(),
|
||||
ItemType.Extension => new Extension(),
|
||||
ItemType.Feature => new Feature(),
|
||||
ItemType.Info => new Info(),
|
||||
ItemType.Instance => new Instance(),
|
||||
ItemType.Location => new Location(),
|
||||
ItemType.Media => new Media(),
|
||||
|
||||
@@ -221,11 +221,6 @@ namespace SabreTools.Library.DatItems
|
||||
|
||||
Machine_Supported,
|
||||
|
||||
// Infos
|
||||
Machine_Infos, // TODO: Fix usage of Infos
|
||||
Machine_Info_Name,
|
||||
Machine_Info_Value,
|
||||
|
||||
// SharedFeatures
|
||||
Machine_SharedFeatures, // TODO: Fix usage of SharedFeatures
|
||||
Machine_SharedFeature_Name,
|
||||
@@ -396,6 +391,9 @@ namespace SabreTools.Library.DatItems
|
||||
DatItem_FeatureStatus,
|
||||
DatItem_FeatureOverall,
|
||||
|
||||
// Info
|
||||
DatItem_InfoValue,
|
||||
|
||||
// Inputs
|
||||
DatItem_Service,
|
||||
DatItem_Tilt,
|
||||
@@ -491,6 +489,7 @@ namespace SabreTools.Library.DatItems
|
||||
Driver,
|
||||
Extension,
|
||||
Feature,
|
||||
Info,
|
||||
Input,
|
||||
Instance,
|
||||
Location,
|
||||
|
||||
243
SabreTools.Library/DatItems/Info.cs
Normal file
243
SabreTools.Library/DatItems/Info.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SabreTools.Library.Filtering;
|
||||
using Newtonsoft.Json;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Library.DatItems
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents special information about a machine
|
||||
/// </summary>
|
||||
[JsonObject("info")]
|
||||
public class Info : DatItem
|
||||
{
|
||||
#region Fields
|
||||
|
||||
/// <summary>
|
||||
/// Name of the item
|
||||
/// </summary>
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Information value
|
||||
/// </summary>
|
||||
[JsonProperty("value")]
|
||||
public string InfoValue { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name to use for a DatItem
|
||||
/// </summary>
|
||||
/// <returns>Name if available, null otherwise</returns>
|
||||
public override string GetName()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set fields with given values
|
||||
/// </summary>
|
||||
/// <param name="mappings">Mappings dictionary</param>
|
||||
public override void SetFields(Dictionary<Field, string> mappings)
|
||||
{
|
||||
// Set base fields
|
||||
base.SetFields(mappings);
|
||||
|
||||
// Handle Info-specific fields
|
||||
if (mappings.Keys.Contains(Field.DatItem_Name))
|
||||
Name = mappings[Field.DatItem_Name];
|
||||
|
||||
if (mappings.Keys.Contains(Field.DatItem_InfoValue))
|
||||
InfoValue = mappings[Field.DatItem_InfoValue];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Info object
|
||||
/// </summary>
|
||||
public Info()
|
||||
{
|
||||
Name = string.Empty;
|
||||
ItemType = ItemType.Info;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public override object Clone()
|
||||
{
|
||||
return new Info()
|
||||
{
|
||||
Name = this.Name,
|
||||
ItemType = this.ItemType,
|
||||
DupeType = this.DupeType,
|
||||
|
||||
AltName = this.AltName,
|
||||
AltTitle = this.AltTitle,
|
||||
|
||||
Original = this.Original,
|
||||
OpenMSXSubType = this.OpenMSXSubType,
|
||||
OpenMSXType = this.OpenMSXType,
|
||||
Remark = this.Remark,
|
||||
Boot = this.Boot,
|
||||
|
||||
Part = this.Part,
|
||||
Features = this.Features,
|
||||
AreaName = this.AreaName,
|
||||
AreaSize = this.AreaSize,
|
||||
AreaWidth = this.AreaWidth,
|
||||
AreaEndianness = this.AreaEndianness,
|
||||
Value = this.Value,
|
||||
LoadFlag = this.LoadFlag,
|
||||
|
||||
Machine = this.Machine.Clone() as Machine,
|
||||
Source = this.Source.Clone() as Source,
|
||||
Remove = this.Remove,
|
||||
|
||||
InfoValue = this.InfoValue,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Comparision Methods
|
||||
|
||||
public override bool Equals(DatItem other)
|
||||
{
|
||||
// If we don't have a sample, return false
|
||||
if (ItemType != other.ItemType)
|
||||
return false;
|
||||
|
||||
// Otherwise, treat it as a Info
|
||||
Info newOther = other as Info;
|
||||
|
||||
// If the archive information matches
|
||||
return (Name == newOther.Name && InfoValue == newOther.InfoValue);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Filtering
|
||||
|
||||
/// <summary>
|
||||
/// Clean a DatItem according to the cleaner
|
||||
/// </summary>
|
||||
/// <param name="cleaner">Cleaner to implement</param>
|
||||
public override void Clean(Cleaner cleaner)
|
||||
{
|
||||
// Clean common items first
|
||||
base.Clean(cleaner);
|
||||
|
||||
// If we're stripping unicode characters, strip item name
|
||||
if (cleaner?.RemoveUnicode == true)
|
||||
Name = Sanitizer.RemoveUnicodeCharacters(Name);
|
||||
|
||||
// If we are in NTFS trim mode, trim the game name
|
||||
if (cleaner?.Trim == true)
|
||||
{
|
||||
// Windows max name length is 260
|
||||
int usableLength = 260 - Machine.Name.Length - (cleaner.Root?.Length ?? 0);
|
||||
if (Name.Length > usableLength)
|
||||
{
|
||||
string ext = Path.GetExtension(Name);
|
||||
Name = Name.Substring(0, usableLength - ext.Length);
|
||||
Name += ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 override bool PassesFilter(Filter filter)
|
||||
{
|
||||
// Check common fields first
|
||||
if (!base.PassesFilter(filter))
|
||||
return false;
|
||||
|
||||
// Filter on item name
|
||||
if (filter.DatItem_Name.MatchesPositiveSet(Name) == false)
|
||||
return false;
|
||||
if (filter.DatItem_Name.MatchesNegativeSet(Name) == true)
|
||||
return false;
|
||||
|
||||
// Filter on info value
|
||||
if (filter.DatItem_InfoValue.MatchesPositiveSet(InfoValue) == false)
|
||||
return false;
|
||||
if (filter.DatItem_InfoValue.MatchesNegativeSet(InfoValue) == true)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove fields from the DatItem
|
||||
/// </summary>
|
||||
/// <param name="fields">List of Fields to remove</param>
|
||||
public override void RemoveFields(List<Field> fields)
|
||||
{
|
||||
// Remove common fields first
|
||||
base.RemoveFields(fields);
|
||||
|
||||
// Remove the fields
|
||||
if (fields.Contains(Field.DatItem_Name))
|
||||
Name = null;
|
||||
|
||||
if (fields.Contains(Field.DatItem_InfoValue))
|
||||
InfoValue = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set internal names to match One Rom Per Game (ORPG) logic
|
||||
/// </summary>
|
||||
public override void SetOneRomPerGame()
|
||||
{
|
||||
string[] splitname = Name.Split('.');
|
||||
Machine.Name += $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}";
|
||||
Name = Path.GetFileName(Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Replace fields from another item
|
||||
/// </summary>
|
||||
/// <param name="item">DatItem to pull new information from</param>
|
||||
/// <param name="fields">List of Fields representing what should be updated</param>
|
||||
public override void ReplaceFields(DatItem item, List<Field> fields)
|
||||
{
|
||||
// Replace common fields first
|
||||
base.ReplaceFields(item, fields);
|
||||
|
||||
// If we don't have a Info to replace from, ignore specific fields
|
||||
if (item.ItemType != ItemType.Info)
|
||||
return;
|
||||
|
||||
// Cast for easier access
|
||||
Info newItem = item as Info;
|
||||
|
||||
// Replace the fields
|
||||
if (fields.Contains(Field.DatItem_Name))
|
||||
Name = newItem.Name;
|
||||
|
||||
if (fields.Contains(Field.DatItem_InfoValue))
|
||||
InfoValue = newItem.InfoValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -259,13 +259,6 @@ namespace SabreTools.Library.DatItems
|
||||
[JsonProperty("supported", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public Supported Supported { get; set; } = Supported.NULL;
|
||||
|
||||
/// <summary>
|
||||
/// List of info items
|
||||
/// </summary>
|
||||
/// <remarks>Also in SoftwareList</remarks>
|
||||
[JsonProperty("infos", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public List<Info> Infos { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// List of shared feature items
|
||||
/// </summary>
|
||||
@@ -522,7 +515,6 @@ namespace SabreTools.Library.DatItems
|
||||
#region SoftwareList
|
||||
|
||||
Supported = this.Supported,
|
||||
Infos = this.Infos,
|
||||
SharedFeatures = this.SharedFeatures,
|
||||
|
||||
#endregion
|
||||
@@ -790,54 +782,6 @@ namespace SabreTools.Library.DatItems
|
||||
if (filter.Machine_Supported.MatchesNegative(Supported.NULL, Supported) == true)
|
||||
return false;
|
||||
|
||||
#region Infos
|
||||
|
||||
// Machine_Infos
|
||||
if (filter.Machine_Infos.MatchesNeutral(null, Infos?.Any() ?? null) == false)
|
||||
return false;
|
||||
|
||||
// Machine_Info_Name
|
||||
if (Infos?.Any() == true)
|
||||
{
|
||||
bool anyPositive = false;
|
||||
bool anyNegative = false;
|
||||
|
||||
foreach (var info in Infos)
|
||||
{
|
||||
if (filter.Machine_Info_Name.MatchesPositiveSet(info?.Name) != false)
|
||||
anyPositive = true;
|
||||
if (filter.Machine_Info_Name.MatchesNegativeSet(info?.Name) == true)
|
||||
anyNegative = true;
|
||||
}
|
||||
|
||||
if (!anyPositive)
|
||||
return false;
|
||||
if (anyNegative)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Machine_Info_Value
|
||||
if (Infos?.Any() == true)
|
||||
{
|
||||
bool anyPositive = false;
|
||||
bool anyNegative = false;
|
||||
|
||||
foreach (var info in Infos)
|
||||
{
|
||||
if (filter.Machine_Info_Value.MatchesPositiveSet(info?.Value) != false)
|
||||
anyPositive = true;
|
||||
if (filter.Machine_Info_Value.MatchesNegativeSet(info?.Value) == true)
|
||||
anyNegative = true;
|
||||
}
|
||||
|
||||
if (!anyPositive)
|
||||
return false;
|
||||
if (anyNegative)
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SharedFeatures
|
||||
|
||||
// Machine_SharedFeatures
|
||||
@@ -968,9 +912,6 @@ namespace SabreTools.Library.DatItems
|
||||
if (fields.Contains(Field.Machine_Runnable))
|
||||
Runnable = Runnable.NULL;
|
||||
|
||||
if (fields.Contains(Field.Machine_Infos))
|
||||
Infos = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logiqx
|
||||
@@ -1124,9 +1065,6 @@ namespace SabreTools.Library.DatItems
|
||||
if (fields.Contains(Field.Machine_Runnable))
|
||||
Runnable = machine.Runnable;
|
||||
|
||||
if (fields.Contains(Field.Machine_Infos))
|
||||
Infos = machine.Infos;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Logiqx
|
||||
|
||||
Reference in New Issue
Block a user