mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile, Machine] Fix description-to-name
This commit is contained in:
@@ -5,7 +5,7 @@ using SabreTools.Library.Data;
|
|||||||
|
|
||||||
namespace SabreTools.Library.Dats
|
namespace SabreTools.Library.Dats
|
||||||
{
|
{
|
||||||
public struct Machine
|
public class Machine
|
||||||
{
|
{
|
||||||
#region Protected instance variables
|
#region Protected instance variables
|
||||||
|
|
||||||
@@ -35,6 +35,28 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new Machine object
|
||||||
|
/// </summary>
|
||||||
|
public Machine()
|
||||||
|
{
|
||||||
|
Name = null;
|
||||||
|
Comment = null;
|
||||||
|
Description = null;
|
||||||
|
Year = null;
|
||||||
|
Manufacturer = null;
|
||||||
|
RomOf = null;
|
||||||
|
CloneOf = null;
|
||||||
|
SampleOf = null;
|
||||||
|
SourceFile = null;
|
||||||
|
Runnable = null;
|
||||||
|
Board = null;
|
||||||
|
RebuildTo = null;
|
||||||
|
Devices = null;
|
||||||
|
MachineType = MachineType.NULL;
|
||||||
|
_guid = new Guid();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new Machine object with the included information
|
/// Create a new Machine object with the included information
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -63,54 +85,40 @@ namespace SabreTools.Library.Dats
|
|||||||
|
|
||||||
#region Equality comparerers
|
#region Equality comparerers
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Override the equality comparer
|
|
||||||
/// </summary>
|
|
||||||
public static bool operator ==(Machine a, Machine b)
|
|
||||||
{
|
|
||||||
return (a.Name == b.Name
|
|
||||||
&& a.Comment == b.Comment
|
|
||||||
&& a.Description == b.Description
|
|
||||||
&& a.Year == b.Year
|
|
||||||
&& a.Manufacturer == b.Manufacturer
|
|
||||||
&& a.RomOf == b.RomOf
|
|
||||||
&& a.CloneOf == b.CloneOf
|
|
||||||
&& a.SampleOf == b.SampleOf
|
|
||||||
&& a.SourceFile == b.SourceFile
|
|
||||||
&& a.Runnable == b.Runnable
|
|
||||||
&& a.Board == b.Board
|
|
||||||
&& a.RebuildTo == b.RebuildTo
|
|
||||||
&& a.Devices == b.Devices
|
|
||||||
&& a.MachineType == b.MachineType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Override the inequality comparer
|
|
||||||
/// </summary>
|
|
||||||
public static bool operator !=(Machine a, Machine b)
|
|
||||||
{
|
|
||||||
return !(a == b);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Override the Equals method
|
/// Override the Equals method
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public override bool Equals(object o)
|
public override bool Equals(object o)
|
||||||
{
|
{
|
||||||
if (o.GetType() != typeof(Machine))
|
if (this == null && o == null)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (this == null || o == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (o.GetType() != typeof(Machine))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this == (Machine)o;
|
Machine b = (Machine)o;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
return (this.Name == b.Name
|
||||||
/// Override the GetHashCode method
|
&& this.Comment == b.Comment
|
||||||
/// </summary>
|
&& this.Description == b.Description
|
||||||
public override int GetHashCode()
|
&& this.Year == b.Year
|
||||||
{
|
&& this.Manufacturer == b.Manufacturer
|
||||||
return OCRC.OptimizedCRC.Compute(_guid.ToByteArray());
|
&& this.RomOf == b.RomOf
|
||||||
|
&& this.CloneOf == b.CloneOf
|
||||||
|
&& this.SampleOf == b.SampleOf
|
||||||
|
&& this.SourceFile == b.SourceFile
|
||||||
|
&& this.Runnable == b.Runnable
|
||||||
|
&& this.Board == b.Board
|
||||||
|
&& this.RebuildTo == b.RebuildTo
|
||||||
|
&& this.Devices == b.Devices
|
||||||
|
&& this.MachineType == b.MachineType);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -604,7 +604,7 @@ namespace SabreTools.Library.Dats
|
|||||||
innerDatdata.Filter(filter, trim, single, root);
|
innerDatdata.Filter(filter, trim, single, root);
|
||||||
|
|
||||||
// Try to output the file
|
// Try to output the file
|
||||||
innerDatdata.WriteToFile((realOutDir == Environment.CurrentDirectory ? Path.GetDirectoryName(inputFileName) : realOutDir), overwrite: (realOutDir != Environment.CurrentDirectory));
|
innerDatdata.WriteToFile((realOutDir == Environment.CurrentDirectory ? Path.GetDirectoryName(inputFileName) : realOutDir), overwrite: (realOutDir != Environment.CurrentDirectory));
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(inputFileName))
|
else if (Directory.Exists(inputFileName))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -181,48 +181,55 @@ namespace SabreTools.Library.Dats
|
|||||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||||
public void Filter(Filter filter, bool single, bool trim, string root)
|
public void Filter(Filter filter, bool single, bool trim, string root)
|
||||||
{
|
{
|
||||||
// Loop over every key in the dictionary
|
try
|
||||||
List<string> keys = Keys.ToList();
|
|
||||||
Parallel.ForEach(keys, key =>
|
|
||||||
{
|
{
|
||||||
// For every item in the current key
|
// Loop over every key in the dictionary
|
||||||
List<DatItem> items = this[key];
|
List<string> keys = Keys.ToList();
|
||||||
List<DatItem> newitems = new List<DatItem>();
|
foreach (string key in keys)
|
||||||
foreach (DatItem item in items)
|
|
||||||
{
|
{
|
||||||
// If the rom passes the filter, include it
|
// For every item in the current key
|
||||||
if (filter.ItemPasses(item))
|
List<DatItem> items = this[key];
|
||||||
|
List<DatItem> newitems = new List<DatItem>();
|
||||||
|
foreach (DatItem item in items)
|
||||||
{
|
{
|
||||||
// If we are in single game mode, rename all games
|
// If the rom passes the filter, include it
|
||||||
if (single)
|
if (filter.ItemPasses(item))
|
||||||
{
|
{
|
||||||
item.Machine.UpdateName("!");
|
// If we are in single game mode, rename all games
|
||||||
}
|
if (single)
|
||||||
|
|
||||||
// If we are in NTFS trim mode, trim the game name
|
|
||||||
if (trim)
|
|
||||||
{
|
|
||||||
// Windows max name length is 260
|
|
||||||
int usableLength = 260 - item.Machine.Name.Length - root.Length;
|
|
||||||
if (item.Name.Length > usableLength)
|
|
||||||
{
|
{
|
||||||
string ext = Path.GetExtension(item.Name);
|
item.Machine.UpdateName("!");
|
||||||
item.Name = item.Name.Substring(0, usableLength - ext.Length);
|
}
|
||||||
item.Name += ext;
|
|
||||||
|
// If we are in NTFS trim mode, trim the game name
|
||||||
|
if (trim)
|
||||||
|
{
|
||||||
|
// Windows max name length is 260
|
||||||
|
int usableLength = 260 - item.Machine.Name.Length - root.Length;
|
||||||
|
if (item.Name.Length > usableLength)
|
||||||
|
{
|
||||||
|
string ext = Path.GetExtension(item.Name);
|
||||||
|
item.Name = item.Name.Substring(0, usableLength - ext.Length);
|
||||||
|
item.Name += ext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock the list and add the item back
|
||||||
|
lock (newitems)
|
||||||
|
{
|
||||||
|
newitems.Add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock the list and add the item back
|
|
||||||
lock (newitems)
|
|
||||||
{
|
|
||||||
newitems.Add(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Remove(key);
|
Remove(key);
|
||||||
AddRange(key, newitems);
|
AddRange(key, newitems);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Globals.Logger.Error(ex.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -281,7 +288,7 @@ namespace SabreTools.Library.Dats
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the new item to the output list
|
// Add the new item to the output list
|
||||||
items.Add(item);
|
newItems.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace the old list of roms with the new one
|
// Replace the old list of roms with the new one
|
||||||
|
|||||||
Reference in New Issue
Block a user