Add setters and getters for Machine

This commit is contained in:
Matt Nadareski
2024-03-09 23:43:43 -05:00
parent f37e3a07da
commit c2e30138db
55 changed files with 534 additions and 890 deletions

View File

@@ -74,9 +74,9 @@ namespace SabreTools.DatTools
}
filename = filename.Remove(0, rootpath?.Length ?? 0);
newItem.Machine.Name = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar
newItem.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar
+ Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar
+ newItem.Machine.Name;
+ newItem.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey));
newItems.Add(newItem);
}
@@ -430,7 +430,7 @@ namespace SabreTools.DatTools
continue;
if (item.Source != null)
newrom.Machine.Name += $" ({Path.GetFileNameWithoutExtension(inputs[item.Source.Index].CurrentPath)})";
newrom.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[item.Source.Index].CurrentPath)})");
dupeData.Items.Add(key, newrom);
}
@@ -622,7 +622,7 @@ namespace SabreTools.DatTools
if (item.Clone() is not DatItem newrom || newrom.Source == null)
continue;
newrom.Machine.Name += $" ({Path.GetFileNameWithoutExtension(inputs[newrom.Source.Index].CurrentPath)})";
newrom.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.Source.Index].CurrentPath)})");
outerDiffData.Items.Add(key, newrom);
}
}

View File

@@ -493,8 +493,8 @@ namespace SabreTools.DatTools
}
// Update machine information
datItem.Machine.Name = machineName;
datItem.Machine.Description = machineName;
datItem.Machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machineName);
datItem.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machineName);
// If we have a Disk, then the ".chd" extension needs to be removed
if (datItem.ItemType == ItemType.Disk && itemName!.EndsWith(".chd"))

View File

@@ -437,11 +437,11 @@ namespace SabreTools.DatTools
foreach (DatItem item in dupes)
{
// If we don't have a proper machine
if (item.Machine?.Name == null || !datFile.Items.ContainsKey(item.Machine.Name))
if (item.Machine?.GetFieldValue<string?>(Models.Metadata.Machine.NameKey) == null || !datFile.Items.ContainsKey(item.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)!))
continue;
// If we should check for the items in the machine
var items = datFile.Items[item.Machine.Name];
var items = datFile.Items[item.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey)!];
if (shouldCheck && items!.Count > 1)
outputFormat = OutputFormat.Folder;
else if (shouldCheck && items!.Count == 1)
@@ -547,14 +547,14 @@ namespace SabreTools.DatTools
// Get the item from the current file
Rom item = new(BaseFile.GetInfo(stream, keepReadOpen: true));
item.Machine.Name = Path.GetFileNameWithoutExtension(item.GetName());
item.Machine.Description = Path.GetFileNameWithoutExtension(item.GetName());
item.Machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileNameWithoutExtension(item.GetName()));
item.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetFileNameWithoutExtension(item.GetName()));
// If we are coming from an archive, set the correct machine name
if (machinename != null)
{
item.Machine.Name = machinename;
item.Machine.Description = machinename;
item.Machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, machinename);
item.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machinename);
}
dupes.Add(item);

View File

@@ -295,8 +295,8 @@ namespace SabreTools.DatTools
#else
continue;
#endif
items.ForEach(item => item.Machine.Name = Path.GetFileName(item.Machine.Name));
items.ForEach(item => item.Machine.Description = Path.GetFileName(item.Machine.Description));
items.ForEach(item => item.Machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetFileName(item.Machine.GetFieldValue<string?>(Models.Metadata.Machine.NameKey))));
items.ForEach(item => item.Machine.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Path.GetFileName(item.Machine.GetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey))));
// Now add the game to the output DAT
tempDat.Items.AddRange(key, items);