Fix issues found during compilation and testing

This commit is contained in:
Matt Nadareski
2025-01-12 23:23:23 -05:00
parent f4743e859e
commit 10b4046c5d
2 changed files with 27 additions and 22 deletions

View File

@@ -46,7 +46,7 @@ namespace SabreTools.DatFiles
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
private readonly ConcurrentDictionary<string, List<DatItem>?> _items = []; private readonly ConcurrentDictionary<string, List<DatItem>?> _items = [];
#else #else
private readonly Dictionary<string, List<DatItem>?> items = []; private readonly Dictionary<string, List<DatItem>?> _items = [];
#endif #endif
/// <summary> /// <summary>
@@ -318,16 +318,16 @@ namespace SabreTools.DatFiles
_items.TryRemove(key, out _); _items.TryRemove(key, out _);
#else #else
// If the key doesn't exist, skip // If the key doesn't exist, skip
if (!items.ContainsKey(key)) if (!_items.ContainsKey(key))
continue; continue;
// If the value is null, remove // If the value is null, remove
else if (items[key] == null) else if (_items[key] == null)
items.Remove(key); _items.Remove(key);
// If there are no non-blank items, remove // If there are no non-blank items, remove
else if (items[key]!.FindIndex(i => i != null && i is not Blank) == -1) else if (_items[key]!.FindIndex(i => i != null && i is not Blank) == -1)
items.Remove(key); _items.Remove(key);
#endif #endif
} }
} }
@@ -389,8 +389,8 @@ namespace SabreTools.DatFiles
if (_items.TryGetValue(key, out var list) && list != null) if (_items.TryGetValue(key, out var list) && list != null)
return list.Contains(value); return list.Contains(value);
#else #else
if (items.ContainsKey(key) && items[key] != null) if (_items.ContainsKey(key) && _items[key] != null)
return items[key]!.Contains(value); return _items[key]!.Contains(value);
#endif #endif
} }
@@ -408,7 +408,7 @@ namespace SabreTools.DatFiles
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
_items.TryAdd(key, []); _items.TryAdd(key, []);
#else #else
items[key] = []; _items[key] = [];
#endif #endif
} }
@@ -457,7 +457,7 @@ namespace SabreTools.DatFiles
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
return _items.TryRemove(key, out _); return _items.TryRemove(key, out _);
#else #else
return items.Remove(key); return _items.Remove(key);
#endif #endif
} }
} }
@@ -1110,24 +1110,29 @@ namespace SabreTools.DatFiles
/// <param name="datItem">DatItem to run logic on</param> /// <param name="datItem">DatItem to run logic on</param>
private static void SetOneRomPerGame(DatItem datItem) private static void SetOneRomPerGame(DatItem datItem)
{ {
if (datItem.GetName() == null) // If the item name is null
string? machineName = datItem.GetName();
if (machineName == null)
return;
// Get the current machine
var machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey);
if (machine == null)
return; return;
// Remove extensions from Rom items // Remove extensions from Rom items
string machine = datItem.GetName()!;
if (datItem is Rom) if (datItem is Rom)
{ {
string[] splitname = machine.Split('.'); string[] splitname = machineName.Split('.');
machine = datItem.GetFieldValue<Machine>(DatItem.MachineKey)! machineName = machine.GetStringFieldValue(Models.Metadata.Machine.NameKey)
.GetStringFieldValue(Models.Metadata.Machine.NameKey)
+ $"/{string.Join(".", splitname, 0, splitname.Length > 1 ? splitname.Length - 1 : 1)}"; + $"/{string.Join(".", splitname, 0, splitname.Length > 1 ? splitname.Length - 1 : 1)}";
} }
// Strip off "Default" prefix only for ORPG // Strip off "Default" prefix only for ORPG
if (machine.StartsWith("Default")) if (machineName.StartsWith("Default"))
machine = machine.Substring("Default".Length + 1); machineName = machineName.Substring("Default".Length + 1);
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machine); datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, machineName);
datItem.SetName(Path.GetFileName(datItem.GetName())); datItem.SetName(Path.GetFileName(datItem.GetName()));
} }

View File

@@ -1514,7 +1514,9 @@ namespace SabreTools.DatFiles
/// <param name="datItem">DatItem to run logic on</param> /// <param name="datItem">DatItem to run logic on</param>
private void SetOneRomPerGame(KeyValuePair<long, DatItem> datItem) private void SetOneRomPerGame(KeyValuePair<long, DatItem> datItem)
{ {
if (datItem.Key < 0 || datItem.Value.GetName() == null) // If the item name is null
string? machineName = datItem.Value.GetName();
if (datItem.Key < 0 || machineName == null)
return; return;
// Get the current machine // Get the current machine
@@ -1523,12 +1525,10 @@ namespace SabreTools.DatFiles
return; return;
// Remove extensions from Rom items // Remove extensions from Rom items
string machineName = datItem.Value.GetName()!;
if (datItem.Value is Rom) if (datItem.Value is Rom)
{ {
string[] splitname = machineName.Split('.'); string[] splitname = machineName.Split('.');
machineName = datItem.Value.GetFieldValue<Machine>(DatItem.MachineKey)! machineName = machine.Value.GetStringFieldValue(Models.Metadata.Machine.NameKey)
.GetStringFieldValue(Models.Metadata.Machine.NameKey)
+ $"/{string.Join(".", splitname, 0, splitname.Length > 1 ? splitname.Length - 1 : 1)}"; + $"/{string.Join(".", splitname, 0, splitname.Length > 1 ? splitname.Length - 1 : 1)}";
} }