Move machine to same name model as DatItem

This commit is contained in:
Matt Nadareski
2025-05-02 16:05:08 -04:00
parent 90a7917ebe
commit 7754ca5bd7
34 changed files with 247 additions and 230 deletions

View File

@@ -220,7 +220,7 @@ namespace SabreTools.DatTools
internal void CleanDatItem(DatItem datItem, Machine machine)
{
// Get the fields for processing
string? machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
string? machineName = machine.GetName();
string? machineDesc = machine.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey);
string? datItemName = datItem.GetName();
@@ -259,7 +259,7 @@ namespace SabreTools.DatTools
}
// Set the fields back, if necessary
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machineName);
machine.SetName(machineName);
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machineDesc);
datItem.SetName(datItemName);
}

View File

@@ -302,7 +302,7 @@ namespace SabreTools.DatTools
#endif
{
var emptyMachine = new Machine();
emptyMachine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, item);
emptyMachine.SetName(item);
var emptyRom = new Rom();
emptyRom.SetName(Path.Combine(empty, "_"));
@@ -376,7 +376,7 @@ namespace SabreTools.DatTools
_staticLogger.Verbose($"Adding blank empty folder: {gamename}");
var blankMachine = new Machine();
blankMachine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, gamename);
blankMachine.SetName(gamename);
var blankRom = new Blank();
blankRom.SetName(romname);
@@ -510,7 +510,7 @@ namespace SabreTools.DatTools
// Update machine information
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machineName);
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machineName);
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(machineName);
// If we have a Disk, then the ".chd" extension needs to be removed
if (datItem is Disk && itemName!.EndsWith(".chd"))

View File

@@ -164,7 +164,7 @@ namespace SabreTools.DatTools
string? machineName = null;
var machine = disk.GetFieldValue<Machine>(DatItem.MachineKey);
if (machine != null)
machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
machineName = machine.GetName();
return new CHDFile()
{
@@ -187,7 +187,7 @@ namespace SabreTools.DatTools
string? machineName = null;
var machine = file.GetFieldValue<Machine>(DatItem.MachineKey);
if (machine != null)
machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
machineName = machine.GetName();
return new BaseFile()
{
@@ -209,7 +209,7 @@ namespace SabreTools.DatTools
string? machineName = null;
var machine = media.GetFieldValue<Machine>(DatItem.MachineKey);
if (machine != null)
machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
machineName = machine.GetName();
return new AaruFormat()
{
@@ -236,7 +236,7 @@ namespace SabreTools.DatTools
string? machineName = null;
var machine = rom.GetFieldValue<Machine>(DatItem.MachineKey);
if (machine != null)
machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
machineName = machine.GetName();
string? spamSum = rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey);
return new BaseFile()

View File

@@ -488,7 +488,7 @@ namespace SabreTools.DatTools
continue;
if (item.GetFieldValue<Source?>(DatItem.SourceKey) != null)
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName() + $" ({Path.GetFileNameWithoutExtension(inputs[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
dupeData.AddItem(newrom, statsOnly: false);
}
@@ -558,7 +558,7 @@ namespace SabreTools.DatTools
// Get the current source and machine
var currentSource = sources[sourceIndex];
string? currentMachineName = machines[machineIndex].GetStringFieldValue(Models.Metadata.Machine.NameKey);
string? currentMachineName = machines[machineIndex].GetName();
var currentMachine = datFile.ItemsDB.GetMachine(currentMachineName);
if (currentMachine.Value == null)
#if NET40_OR_GREATER || NETCOREAPP
@@ -573,7 +573,7 @@ namespace SabreTools.DatTools
if (renamedMachine.Value == null)
{
var newMachine = currentMachine.Value.Clone() as Machine;
newMachine!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, renamedMachineName);
newMachine!.SetName(renamedMachineName);
long newMachineIndex = dupeData.AddMachineDB(newMachine!);
renamedMachine = new KeyValuePair<long, Machine?>(newMachineIndex, newMachine);
}
@@ -887,7 +887,7 @@ namespace SabreTools.DatTools
if (item.Clone() is not DatItem newrom || newrom.GetFieldValue<Source?>(DatItem.SourceKey) == null)
continue;
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName() + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
outerDiffData.AddItem(newrom, statsOnly: false);
}
}
@@ -956,7 +956,7 @@ namespace SabreTools.DatTools
// Get the current source and machine
var currentSource = sources[sourceIndex];
string? currentMachineName = machines[machineIndex].GetStringFieldValue(Models.Metadata.Machine.NameKey);
string? currentMachineName = machines[machineIndex].GetName();
var currentMachine = datFile.ItemsDB.GetMachine(currentMachineName);
if (currentMachine.Value == null)
#if NET40_OR_GREATER || NETCOREAPP
@@ -971,7 +971,7 @@ namespace SabreTools.DatTools
if (renamedMachine.Value == null)
{
var newMachine = currentMachine.Value.Clone() as Machine;
newMachine!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, renamedMachineName);
newMachine!.SetName(renamedMachineName);
long newMachineIndex = outerDiffData.AddMachineDB(newMachine);
renamedMachine = new KeyValuePair<long, Machine?>(newMachineIndex, newMachine);
}

View File

@@ -149,11 +149,11 @@ namespace SabreTools.DatTools
+ Path.DirectorySeparatorChar
+ Path.GetFileNameWithoutExtension(filename)
+ Path.DirectorySeparatorChar
+ machine.GetStringFieldValue(Models.Metadata.Machine.NameKey);
+ machine.GetName();
if (machineName.Length == 0)
machineName = "Default";
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machineName);
machine.SetName(machineName);
newItems.Add(newItem);
}
@@ -222,11 +222,11 @@ namespace SabreTools.DatTools
+ Path.DirectorySeparatorChar
+ Path.GetFileNameWithoutExtension(filename)
+ Path.DirectorySeparatorChar
+ machine.Value.GetStringFieldValue(Models.Metadata.Machine.NameKey);
+ machine.Value.GetName();
if (machineName.Length == 0)
machineName = "Default";
machine.Value.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machineName);
machine.Value.SetName(machineName);
}
#if NET40_OR_GREATER || NETCOREAPP
});

View File

@@ -458,11 +458,11 @@ namespace SabreTools.DatTools
{
// If we don't have a proper machine
var machine = item.GetFieldValue<Machine>(DatItem.MachineKey);
if (machine?.GetStringFieldValue(Models.Metadata.Machine.NameKey) == null)
if (machine?.GetName() == null)
continue;
// If we should check for the items in the machine
var items = datFile.GetItemsForBucket(machine.GetStringFieldValue(Models.Metadata.Machine.NameKey));
var items = datFile.GetItemsForBucket(machine.GetName());
if (shouldCheck && items!.Count > 1)
outputFormat = OutputFormat.Folder;
else if (shouldCheck && items!.Count == 1)
@@ -576,13 +576,13 @@ namespace SabreTools.DatTools
HashType[] hashes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
Rom item = FileTypeTool.GetInfo(stream, hashes).ConvertToRom();
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileNameWithoutExtension(item.GetName()));
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetFileNameWithoutExtension(item.GetName()));
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(Path.GetFileNameWithoutExtension(item.GetName()));
// If we are coming from an archive, set the correct machine name
if (machinename != null)
{
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machinename);
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machinename);
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(machinename);
}
dupes.Add(item);
@@ -637,14 +637,14 @@ namespace SabreTools.DatTools
// Create a machine for the current item
var machine = new Machine();
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileNameWithoutExtension(item.GetName()));
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetFileNameWithoutExtension(item.GetName()));
machine.SetName(Path.GetFileNameWithoutExtension(item.GetName()));
long machineIndex = datFile.AddMachineDB(machine);
// If we are coming from an archive, set the correct machine name
if (machinename != null)
{
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machinename);
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machinename);
machine.SetName(machinename);
}
long index = datFile.AddItemDB(item, machineIndex, -1, false);

View File

@@ -300,7 +300,7 @@ namespace SabreTools.DatTools
// Special case for description
if (machineFieldNames.Contains(Models.Metadata.Machine.DescriptionKey))
{
if (!onlySame || (onlySame && machine.GetStringFieldValue(Models.Metadata.Machine.NameKey) == machine.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)))
if (!onlySame || (onlySame && machine.GetName() == machine.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)))
machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, repMachine.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey));
continue;

View File

@@ -526,7 +526,7 @@ namespace SabreTools.DatTools
#else
continue;
#endif
items.ForEach(item => item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetFileName(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey))));
items.ForEach(item => item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(Path.GetFileName(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName())));
items.ForEach(item => item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileName(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey))));
// Now add the game to the output DAT