Name is not guaranteed

This commit is contained in:
Matt Nadareski
2020-09-02 12:19:12 -07:00
parent c77bcca9ad
commit bd92f8993a
20 changed files with 1397 additions and 164 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
@@ -15,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Determine whether the value is default
/// </summary>
@@ -31,6 +38,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -41,6 +57,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Adjuster-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Default))
Default = mappings[Field.DatItem_Default].AsYesNo();
@@ -120,6 +139,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -131,6 +177,12 @@ namespace SabreTools.Library.DatItems
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 default
if (filter.DatItem_Default.MatchesNeutral(null, Default) == false)
return false;
@@ -150,6 +202,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Default))
Default = null;
@@ -159,6 +214,16 @@ namespace SabreTools.Library.DatItems
// TODO: Handle DatItem_Condition*
}
/// <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
@@ -181,6 +246,9 @@ namespace SabreTools.Library.DatItems
Adjuster newItem = item as Adjuster;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Default))
Default = newItem.Default;

View File

@@ -1,4 +1,10 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
@@ -8,6 +14,43 @@ namespace SabreTools.Library.DatItems
[JsonObject("archive")]
public class Archive : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { 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 Archive-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
}
#endregion
#region Constructors
/// <summary>
@@ -73,5 +116,106 @@ namespace SabreTools.Library.DatItems
}
#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;
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;
}
/// <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 Archive to replace from, ignore specific fields
if (item.ItemType != ItemType.Archive)
return;
// Cast for easier access
Archive newItem = item as Archive;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
}
#endregion
}
}

View File

@@ -24,7 +24,7 @@ namespace SabreTools.Library.DatItems
/// <summary>
/// Represents one ListXML condition
/// </summary>
/// TODO: Promote to DatItem level? (Both used at ListXML level AND under a lot of stuff)
/// TODO: Promote to DatItem level? (doesn't have "name" field?) (Both used at ListXML level AND under a lot of stuff)
[JsonObject("condition")]
public class Condition
{

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
@@ -15,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Description of the BIOS
/// </summary>
@@ -31,6 +38,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -41,6 +57,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle BiosSet-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Default))
Default = mappings[Field.DatItem_Default].AsYesNo();
@@ -121,6 +140,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -132,6 +178,12 @@ namespace SabreTools.Library.DatItems
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 description
if (filter.DatItem_Description.MatchesPositiveSet(Description) == false)
return false;
@@ -155,6 +207,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Description))
Description = null;
@@ -162,6 +217,16 @@ namespace SabreTools.Library.DatItems
Default = 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
@@ -184,6 +249,9 @@ namespace SabreTools.Library.DatItems
BiosSet newItem = item as BiosSet;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Description))
Description = newItem.Description;

View File

@@ -15,7 +15,6 @@ namespace SabreTools.Library.DatItems
/// </summary>
public Blank()
{
Name = string.Empty;
ItemType = ItemType.Blank;
}
@@ -27,7 +26,6 @@ namespace SabreTools.Library.DatItems
{
return new Blank()
{
Name = this.Name,
ItemType = this.ItemType,
DupeType = this.DupeType,

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
@@ -15,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Internal tag
/// </summary>
@@ -37,6 +44,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -47,6 +63,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Chip-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Tag))
Tag = mappings[Field.DatItem_Tag];
@@ -134,6 +153,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -145,6 +191,12 @@ namespace SabreTools.Library.DatItems
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;
// DatItem_Tag
if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false)
return false;
@@ -176,6 +228,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Tag))
Tag = null;
@@ -186,6 +241,16 @@ namespace SabreTools.Library.DatItems
Clock = 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
@@ -208,6 +273,9 @@ namespace SabreTools.Library.DatItems
Chip newItem = item as Chip;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Tag))
Tag = newItem.Tag;

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
@@ -14,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Tag associated with the configuration
/// </summary>
@@ -48,6 +56,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -58,6 +75,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Configuration-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Tag))
Tag = mappings[Field.DatItem_Tag];
@@ -149,6 +169,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -160,6 +207,12 @@ namespace SabreTools.Library.DatItems
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 tag
if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false)
return false;
@@ -189,6 +242,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Tag))
Tag = null;
@@ -209,6 +265,16 @@ namespace SabreTools.Library.DatItems
// TODO: Handle DatItem_Setting*
}
/// <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
@@ -231,6 +297,9 @@ namespace SabreTools.Library.DatItems
Configuration newItem = item as Configuration;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Tag))
Tag = newItem.Tag;

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using SabreTools.Library.Data;
using SabreTools.Library.FileTypes;
@@ -26,12 +25,6 @@ namespace SabreTools.Library.DatItems
#region Common Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Item type for outputting
/// </summary>
@@ -368,6 +361,15 @@ namespace SabreTools.Library.DatItems
#region Accessors
/// <summary>
/// Gets the name to use for a DatItem
/// </summary>
/// <returns>Name if available, null otherwise</returns>
public virtual string GetName()
{
return null;
}
/// <summary>
/// Set fields with given values
/// </summary>
@@ -380,13 +382,6 @@ namespace SabreTools.Library.DatItems
Machine.SetFields(mappings);
#region Common
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
#endregion
#region AttractMode
if (mappings.Keys.Contains(Field.DatItem_AltName))
@@ -514,13 +509,22 @@ namespace SabreTools.Library.DatItems
#else
return itemType switch
{
ItemType.Adjuster => new Adjuster(),
ItemType.Archive => new Archive(),
ItemType.BiosSet => new BiosSet(),
ItemType.Blank => new Blank(),
ItemType.Chip => new Chip(),
ItemType.Configuration => new Configuration(),
ItemType.DeviceReference => new DeviceReference(),
ItemType.DipSwitch => new DipSwitch(),
ItemType.Disk => new Disk(),
ItemType.Media => new Media(),
ItemType.RamOption => new RamOption(),
ItemType.Release => new Release(),
ItemType.Rom => new Rom(),
ItemType.Sample => new Sample(),
ItemType.Slot => new Slot(),
ItemType.SoftwareList => new SoftwareList(),
_ => new Rom(),
};
#endif
@@ -596,10 +600,7 @@ namespace SabreTools.Library.DatItems
{
try
{
if (Name == other.Name)
return Equals(other) ? 0 : 1;
return string.Compare(Name, other.Name);
return ItemType - other.ItemType;
}
catch
{
@@ -630,7 +631,7 @@ namespace SabreTools.Library.DatItems
// If the duplicate is external already or should be, set it
if (lastItem.DupeType.HasFlag(DupeType.External) || lastItem.Source.Index != Source.Index)
{
if (lastItem.Machine.Name == Machine.Name && lastItem.Name == Name)
if (lastItem.Machine.Name == Machine.Name)
output = DupeType.External | DupeType.All;
else
output = DupeType.External | DupeType.Hash;
@@ -639,7 +640,7 @@ namespace SabreTools.Library.DatItems
// Otherwise, it's considered an internal dupe
else
{
if (lastItem.Machine.Name == Machine.Name && lastItem.Name == Name)
if (lastItem.Machine.Name == Machine.Name)
output = DupeType.Internal | DupeType.All;
else
output = DupeType.Internal | DupeType.Hash;
@@ -652,6 +653,31 @@ namespace SabreTools.Library.DatItems
#region Filtering
/// <summary>
/// Clean a DatItem according to the cleaner
/// </summary>
/// <param name="cleaner">Cleaner to implement</param>
public virtual void Clean(Cleaner cleaner)
{
// If we're stripping unicode characters, strip machine name and description
if (cleaner?.RemoveUnicode == true)
{
Machine.Name = Sanitizer.RemoveUnicodeCharacters(Machine.Name);
Machine.Description = Sanitizer.RemoveUnicodeCharacters(Machine.Description);
}
// If we're in cleaning mode, sanitize machine name and description
if (cleaner?.Clean == true)
{
Machine.Name = Sanitizer.CleanGameName(Machine.Name);
Machine.Description = Sanitizer.CleanGameName(Machine.Description);
}
// If we are in single game mode, rename the machine
if (cleaner?.Single == true)
Machine.Name = "!";
}
/// <summary>
/// Check to see if a DatItem passes the filter
/// </summary>
@@ -665,12 +691,6 @@ namespace SabreTools.Library.DatItems
#region Common
// Filter on item name
if (filter.DatItem_Name.MatchesPositiveSet(Name) == false)
return false;
if (filter.DatItem_Name.MatchesNegativeSet(Name) == true)
return false;
// Filter on item type
if (filter.DatItem_Type.MatchesPositiveSet(ItemType.ToString()) == false)
return false;
@@ -795,13 +815,6 @@ namespace SabreTools.Library.DatItems
// Remove machine fields
Machine.RemoveFields(fields);
#region Common
if (fields.Contains(Field.DatItem_Name))
Name = null;
#endregion
#region AttractMode
if (fields.Contains(Field.DatItem_AltName))
@@ -863,6 +876,13 @@ namespace SabreTools.Library.DatItems
#endregion
}
/// <summary>
/// Set internal names to match One Rom Per Game (ORPG) logic
/// </summary>
public virtual void SetOneRomPerGame()
{
}
#endregion
#region Sorting and Merging
@@ -943,13 +963,6 @@ namespace SabreTools.Library.DatItems
/// <param name="fields">List of Fields representing what should be updated</param>
public virtual void ReplaceFields(DatItem item, List<Field> fields)
{
#region Common
if (fields.Contains(Field.DatItem_Name))
Name = item.Name;
#endregion
#region AttractMode
if (fields.Contains(Field.DatItem_AltName))
@@ -1125,14 +1138,14 @@ namespace SabreTools.Library.DatItems
{
saveditem.Source = file.Source.Clone() as Source;
saveditem.CopyMachineInformation(file);
saveditem.Name = file.Name;
saveditem.SetFields(new Dictionary<Field, string> { [Field.DatItem_Name] = file.GetName() });
}
// If the current machine is a child of the new machine, use the new machine instead
if (saveditem.Machine.CloneOf == file.Machine.Name || saveditem.Machine.RomOf == file.Machine.Name)
{
saveditem.CopyMachineInformation(file);
saveditem.Name = file.Name;
saveditem.SetFields(new Dictionary<Field, string> { [Field.DatItem_Name] = file.GetName() });
}
break;
@@ -1185,33 +1198,39 @@ namespace SabreTools.Library.DatItems
continue;
}
// Get the last item name, if applicable
string lastItemName = lastItem.GetName() ?? lastItem.ItemType.ToString();
// Get the current item name, if applicable
string datItemName = datItem.GetName() ?? datItem.ItemType.ToString();
// If the current item exactly matches the last item, then we don't add it
if (datItem.GetDuplicateStatus(lastItem).HasFlag(DupeType.All))
{
Globals.Logger.Verbose($"Exact duplicate found for '{datItem.Name}'");
Globals.Logger.Verbose($"Exact duplicate found for '{datItemName}'");
continue;
}
// If the current name matches the previous name, rename the current item
else if (datItem.Name == lastItem.Name)
else if (datItemName == lastItemName)
{
Globals.Logger.Verbose($"Name duplicate found for '{datItem.Name}'");
Globals.Logger.Verbose($"Name duplicate found for '{datItemName}'");
if (datItem.ItemType == ItemType.Disk || datItem.ItemType == ItemType.Media || datItem.ItemType == ItemType.Rom)
{
datItem.Name += GetDuplicateSuffix(datItem);
datItemName += GetDuplicateSuffix(datItem);
#if NET_FRAMEWORK
lastrenamed = lastrenamed ?? datItem.Name;
lastrenamed = lastrenamed ?? datItemName;
#else
lastrenamed ??= datItem.Name;
lastrenamed ??= datItemName;
#endif
}
// If we have a conflict with the last renamed item, do the right thing
if (datItem.Name == lastrenamed)
if (datItemName == lastrenamed)
{
lastrenamed = datItem.Name;
datItem.Name += (lastid == 0 ? string.Empty : "_" + lastid);
lastrenamed = datItemName;
datItemName += (lastid == 0 ? string.Empty : "_" + lastid);
lastid++;
}
// If we have no conflict, then we want to reset the lastrenamed and id
@@ -1221,6 +1240,9 @@ namespace SabreTools.Library.DatItems
lastid = 0;
}
// Set the item name back to the datItem
datItem.SetFields(new Dictionary<Field, string> { [Field.DatItem_Name] = datItemName });
output.Add(datItem);
}
@@ -1274,10 +1296,10 @@ namespace SabreTools.Library.DatItems
{
if (x.ItemType == y.ItemType)
{
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)));
if (Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty)) == Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty)))
return nc.Compare(Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty)), Path.GetFileName(Sanitizer.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty)));
return nc.Compare(Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.Name)), Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.Name)));
return nc.Compare(Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(x.GetName() ?? string.Empty)), Path.GetDirectoryName(Sanitizer.RemovePathUnsafeCharacters(y.GetName() ?? string.Empty)));
}
return x.ItemType - y.ItemType;

View File

@@ -1,4 +1,10 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
@@ -8,6 +14,43 @@ namespace SabreTools.Library.DatItems
[JsonObject("device_ref")]
public class DeviceReference : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { 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 DeviceReference-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
}
#endregion
#region Constructors
/// <summary>
@@ -73,5 +116,106 @@ namespace SabreTools.Library.DatItems
}
#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;
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;
}
/// <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 DeviceReference to replace from, ignore specific fields
if (item.ItemType != ItemType.DeviceReference)
return;
// Cast for easier access
DeviceReference newItem = item as DeviceReference;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
}
#endregion
}
}

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
@@ -14,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Tag associated with the dipswitch
/// </summary>
@@ -48,6 +56,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -58,6 +75,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle DipSwitch-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Tag))
Tag = mappings[Field.DatItem_Tag];
@@ -149,6 +169,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -160,6 +207,12 @@ namespace SabreTools.Library.DatItems
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 tag
if (filter.DatItem_Tag.MatchesPositiveSet(Tag) == false)
return false;
@@ -189,6 +242,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Tag))
Tag = null;
@@ -209,6 +265,16 @@ namespace SabreTools.Library.DatItems
// TODO: Handle DatItem_Value*
}
/// <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
@@ -231,6 +297,9 @@ namespace SabreTools.Library.DatItems
DipSwitch newItem = item as DipSwitch;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Tag))
Tag = newItem.Tag;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.FileTypes;
@@ -24,6 +25,12 @@ namespace SabreTools.Library.DatItems
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Data MD5 hash
/// </summary>
@@ -85,6 +92,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -95,6 +111,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Disk-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_MD5))
MD5 = mappings[Field.DatItem_MD5];
@@ -345,6 +364,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -356,6 +402,12 @@ namespace SabreTools.Library.DatItems
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 MD5
if (filter.DatItem_MD5.MatchesPositiveSet(MD5) == false)
return false;
@@ -413,6 +465,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_MD5))
MD5 = null;
@@ -438,6 +493,16 @@ namespace SabreTools.Library.DatItems
Optional = 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
@@ -495,6 +560,9 @@ namespace SabreTools.Library.DatItems
Disk newItem = item as Disk;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_MD5))
{
if (string.IsNullOrEmpty(MD5) && !string.IsNullOrEmpty(newItem.MD5))

View File

@@ -1,12 +1,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
using SabreTools.Library.FileTypes;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace SabreTools.Library.DatItems
{
@@ -21,12 +20,18 @@ namespace SabreTools.Library.DatItems
private byte[] _md5; // 16 bytes
private byte[] _sha1; // 20 bytes
private byte[] _sha256; // 32 bytes
// TODO: Implement SpamSum
// TODO: Implement SpamSum
#endregion
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Data MD5 hash
/// </summary>
@@ -61,6 +66,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -71,6 +85,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Media-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_MD5))
MD5 = mappings[Field.DatItem_MD5];
@@ -294,6 +311,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -305,6 +349,12 @@ namespace SabreTools.Library.DatItems
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 MD5
if (filter.DatItem_MD5.MatchesPositiveSet(MD5) == false)
return false;
@@ -336,6 +386,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_MD5))
MD5 = null;
@@ -346,6 +399,16 @@ namespace SabreTools.Library.DatItems
SHA256 = 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
@@ -407,6 +470,9 @@ namespace SabreTools.Library.DatItems
Media newItem = item as Media;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_MD5))
{
if (string.IsNullOrEmpty(MD5) && !string.IsNullOrEmpty(newItem.MD5))

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
@@ -15,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Determine whether the RamOption is default
/// </summary>
@@ -31,6 +38,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -41,6 +57,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle BiosSet-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Default))
Default = mappings[Field.DatItem_Default].AsYesNo();
@@ -121,6 +140,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -132,6 +178,12 @@ namespace SabreTools.Library.DatItems
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 default
if (filter.DatItem_Default.MatchesNeutral(null, Default) == false)
return false;
@@ -155,6 +207,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Default))
Default = null;
@@ -162,6 +217,16 @@ namespace SabreTools.Library.DatItems
Content = 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
@@ -176,7 +241,7 @@ namespace SabreTools.Library.DatItems
// Replace common fields first
base.ReplaceFields(item, fields);
// If we don't have a BiosSet to replace from, ignore specific fields
// If we don't have a RamOption to replace from, ignore specific fields
if (item.ItemType != ItemType.RamOption)
return;
@@ -184,6 +249,9 @@ namespace SabreTools.Library.DatItems
RamOption newItem = item as RamOption;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Default))
Default = newItem.Default;

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using Newtonsoft.Json;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
@@ -15,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Release region(s)
/// </summary>
@@ -43,6 +50,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -53,6 +69,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Release-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Region))
Region = mappings[Field.DatItem_Region];
@@ -149,6 +168,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -160,6 +206,12 @@ namespace SabreTools.Library.DatItems
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 region
if (filter.DatItem_Region.MatchesPositiveSet(Region) == false)
return false;
@@ -195,6 +247,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Region))
Region = null;
@@ -208,6 +263,16 @@ namespace SabreTools.Library.DatItems
Default = 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
@@ -230,6 +295,9 @@ namespace SabreTools.Library.DatItems
Release newItem = item as Release;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Region))
Region = newItem.Region;

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Data;
@@ -33,6 +34,12 @@ namespace SabreTools.Library.DatItems
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// What BIOS is required for this rom
/// </summary>
@@ -164,6 +171,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -174,6 +190,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Rom-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_Bios))
Bios = mappings[Field.DatItem_Bios];
@@ -501,6 +520,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -512,6 +558,12 @@ namespace SabreTools.Library.DatItems
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 bios
if (filter.DatItem_Bios.MatchesPositiveSet(Bios) == false)
return false;
@@ -621,6 +673,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_Bios))
Bios = null;
@@ -672,6 +727,16 @@ namespace SabreTools.Library.DatItems
Inverted = 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
@@ -751,6 +816,9 @@ namespace SabreTools.Library.DatItems
Rom newItem = item as Rom;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_Bios))
Bios = newItem.Bios;

View File

@@ -1,4 +1,10 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
{
@@ -8,6 +14,43 @@ namespace SabreTools.Library.DatItems
[JsonObject("sample")]
public class Sample : DatItem
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { 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 Sample-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
}
#endregion
#region Constructors
/// <summary>
@@ -73,5 +116,106 @@ namespace SabreTools.Library.DatItems
}
#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;
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;
}
/// <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 Sample to replace from, ignore specific fields
if (item.ItemType != ItemType.Sample)
return;
// Cast for easier access
Sample newItem = item as Sample;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
}
#endregion
}
}

View File

@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
using SabreTools.Library.Tools;
using Newtonsoft.Json;
namespace SabreTools.Library.DatItems
@@ -13,6 +16,12 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Slot options associated with the slot
/// </summary>
@@ -23,6 +32,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -33,6 +51,8 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle Slot-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
// TODO: Handle DatItem_SlotOption*
}
@@ -109,6 +129,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -120,6 +167,12 @@ namespace SabreTools.Library.DatItems
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;
// TODO: Handle DatItem_SlotOption*
return true;
@@ -135,12 +188,25 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_SlotOptions))
SlotOptions = null;
// TODO: Handle DatItem_SlotOption*
}
/// <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
@@ -163,6 +229,9 @@ namespace SabreTools.Library.DatItems
Slot newItem = item as Slot;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_SlotOptions))
SlotOptions = newItem.SlotOptions;

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using SabreTools.Library.Filtering;
@@ -15,9 +16,21 @@ namespace SabreTools.Library.DatItems
{
#region Fields
/// <summary>
/// Name of the item
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }
/// <summary>
/// Status of the softare list according to the machine
/// </summary>
[JsonProperty("status", DefaultValueHandling = DefaultValueHandling.Ignore)]
public SoftwareListStatus Status { get; set; }
/// <summary>
/// Filter to apply to the software list
/// </summary>
[JsonProperty("filter", DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Filter { get; set; }
@@ -25,6 +38,15 @@ namespace SabreTools.Library.DatItems
#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>
@@ -35,6 +57,9 @@ namespace SabreTools.Library.DatItems
base.SetFields(mappings);
// Handle SoftwareList-specific fields
if (mappings.Keys.Contains(Field.DatItem_Name))
Name = mappings[Field.DatItem_Name];
if (mappings.Keys.Contains(Field.DatItem_SoftwareListStatus))
Status = mappings[Field.DatItem_Default].AsSoftwareListStatus();
@@ -117,6 +142,33 @@ namespace SabreTools.Library.DatItems
#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>
@@ -128,6 +180,12 @@ namespace SabreTools.Library.DatItems
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 status
if (filter.DatItem_SoftwareListStatus.MatchesPositive(SoftwareListStatus.NULL, Status) == false)
return false;
@@ -153,6 +211,9 @@ namespace SabreTools.Library.DatItems
base.RemoveFields(fields);
// Remove the fields
if (fields.Contains(Field.DatItem_Name))
Name = null;
if (fields.Contains(Field.DatItem_SoftwareListStatus))
Status = SoftwareListStatus.NULL;
@@ -160,6 +221,16 @@ namespace SabreTools.Library.DatItems
Filter = 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
@@ -182,6 +253,9 @@ namespace SabreTools.Library.DatItems
SoftwareList newItem = item as SoftwareList;
// Replace the fields
if (fields.Contains(Field.DatItem_Name))
Name = newItem.Name;
if (fields.Contains(Field.DatItem_SoftwareListStatus))
Status = newItem.Status;