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

View File

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