mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Increase readability of Machine access
This commit is contained in:
@@ -172,7 +172,7 @@ namespace SabreTools.DatTools
|
||||
continue;
|
||||
|
||||
// Get the machine associated with the item, if possible
|
||||
var machine = item.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = item.GetMachine();
|
||||
if (machine == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -509,8 +509,8 @@ namespace SabreTools.DatTools
|
||||
}
|
||||
|
||||
// Update machine information
|
||||
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machineName);
|
||||
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(machineName);
|
||||
datItem.GetMachine()!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machineName);
|
||||
datItem.GetMachine()!.SetName(machineName);
|
||||
|
||||
// If we have a Disk, then the ".chd" extension needs to be removed
|
||||
if (datItem is Disk && itemName!.EndsWith(".chd"))
|
||||
|
||||
@@ -162,7 +162,7 @@ namespace SabreTools.DatTools
|
||||
public static BaseFile ConvertToBaseFile(this Disk disk)
|
||||
{
|
||||
string? machineName = null;
|
||||
var machine = disk.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = disk.GetMachine();
|
||||
if (machine != null)
|
||||
machineName = machine.GetName();
|
||||
|
||||
@@ -185,7 +185,7 @@ namespace SabreTools.DatTools
|
||||
public static BaseFile ConvertToBaseFile(this DatItems.Formats.File file)
|
||||
{
|
||||
string? machineName = null;
|
||||
var machine = file.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = file.GetMachine();
|
||||
if (machine != null)
|
||||
machineName = machine.GetName();
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace SabreTools.DatTools
|
||||
public static BaseFile ConvertToBaseFile(this Media media)
|
||||
{
|
||||
string? machineName = null;
|
||||
var machine = media.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = media.GetMachine();
|
||||
if (machine != null)
|
||||
machineName = machine.GetName();
|
||||
|
||||
@@ -234,7 +234,7 @@ namespace SabreTools.DatTools
|
||||
public static BaseFile ConvertToBaseFile(this Rom rom)
|
||||
{
|
||||
string? machineName = null;
|
||||
var machine = rom.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = rom.GetMachine();
|
||||
if (machine != null)
|
||||
machineName = machine.GetName();
|
||||
|
||||
|
||||
@@ -488,7 +488,7 @@ namespace SabreTools.DatTools
|
||||
continue;
|
||||
|
||||
if (item.GetFieldValue<Source?>(DatItem.SourceKey) != null)
|
||||
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetName(newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName() + $" ({Path.GetFileNameWithoutExtension(inputs[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
|
||||
newrom.GetMachine()!.SetName(newrom.GetMachine()!.GetName() + $" ({Path.GetFileNameWithoutExtension(inputs[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
|
||||
|
||||
dupeData.AddItem(newrom, statsOnly: false);
|
||||
}
|
||||
@@ -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)!.SetName(newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetName() + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
|
||||
newrom.GetMachine()!.SetName(newrom.GetMachine()!.GetName() + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
|
||||
outerDiffData.AddItem(newrom, statsOnly: false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace SabreTools.DatTools
|
||||
// Loop through and set the fields accordingly
|
||||
foreach (var datItem in datItems)
|
||||
{
|
||||
setter.SetFields(datItem.GetFieldValue<Machine>(DatItem.MachineKey));
|
||||
setter.SetFields(datItem.GetMachine());
|
||||
setter.SetFields(datItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace SabreTools.DatTools
|
||||
|
||||
filename = filename.Remove(0, rootpath.Length);
|
||||
|
||||
var machine = newItem.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = newItem.GetMachine();
|
||||
if (machine == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -457,7 +457,7 @@ namespace SabreTools.DatTools
|
||||
foreach (DatItem item in dupes)
|
||||
{
|
||||
// If we don't have a proper machine
|
||||
var machine = item.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = item.GetMachine();
|
||||
if (machine?.GetName() == null)
|
||||
continue;
|
||||
|
||||
@@ -575,14 +575,14 @@ namespace SabreTools.DatTools
|
||||
// Get the item from the current file
|
||||
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)!.SetName(Path.GetFileNameWithoutExtension(item.GetName()));
|
||||
item.GetMachine()!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileNameWithoutExtension(item.GetName()));
|
||||
item.GetMachine()!.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)!.SetName(machinename);
|
||||
item.GetMachine()!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machinename);
|
||||
item.GetMachine()!.SetName(machinename);
|
||||
}
|
||||
|
||||
dupes.Add(item);
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace SabreTools.DatTools
|
||||
for (int j = 0; j < items.Count; j++)
|
||||
{
|
||||
// Handle machine removals
|
||||
var machine = items[j].GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
var machine = items[j].GetMachine();
|
||||
RemoveFields(machine);
|
||||
|
||||
// Handle item removals
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace SabreTools.DatTools
|
||||
|
||||
var list = datFile.GetItemsForBucket(key);
|
||||
if (list.Count > 0)
|
||||
ReplaceFields(newDatItem.GetFieldValue<Machine>(DatItem.MachineKey)!, list[index: 0].GetFieldValue<Machine>(DatItem.MachineKey)!, machineFieldNames, onlySame);
|
||||
ReplaceFields(newDatItem.GetMachine()!, list[index: 0].GetMachine()!, machineFieldNames, onlySame);
|
||||
|
||||
newDatItems.Add(newDatItem);
|
||||
}
|
||||
|
||||
@@ -172,8 +172,8 @@ namespace SabreTools.DatTools
|
||||
#region Common
|
||||
|
||||
// Handle Machine fields
|
||||
if (MachineFieldMappings.Count > 0 && datItem.GetFieldValue<Machine>(DatItem.MachineKey) != null)
|
||||
SetFields(datItem.GetFieldValue<Machine>(DatItem.MachineKey)!);
|
||||
if (MachineFieldMappings.Count > 0 && datItem.GetMachine() != null)
|
||||
SetFields(datItem.GetMachine()!);
|
||||
|
||||
// If there are no field names, return
|
||||
if (ItemFieldMappings == null || ItemFieldMappings.Count == 0)
|
||||
|
||||
@@ -526,8 +526,8 @@ namespace SabreTools.DatTools
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
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))));
|
||||
items.ForEach(item => item.GetMachine()!.SetName(Path.GetFileName(item.GetMachine()!.GetName())));
|
||||
items.ForEach(item => item.GetMachine()!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileName(item.GetMachine()!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey))));
|
||||
|
||||
// Now add the game to the output DAT
|
||||
items.ForEach(item => tempDat.AddItem(item, statsOnly: false));
|
||||
|
||||
Reference in New Issue
Block a user