mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Handle some inefficiencies found via messages
This commit is contained in:
@@ -320,7 +320,7 @@ namespace SabreTools.DatFiles
|
|||||||
private void ConvertMachines(Models.Metadata.Machine[]? items, string filename, int indexId, bool statsOnly)
|
private void ConvertMachines(Models.Metadata.Machine[]? items, string filename, int indexId, bool statsOnly)
|
||||||
{
|
{
|
||||||
// If the array is invalid, we can't do anything
|
// If the array is invalid, we can't do anything
|
||||||
if (items == null || !items.Any())
|
if (items == null || items.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Loop through the machines and add
|
// Loop through the machines and add
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using SabreTools.Core.Tools;
|
using SabreTools.Core.Tools;
|
||||||
@@ -15,7 +16,7 @@ namespace SabreTools.DatFiles
|
|||||||
public Models.Metadata.MetadataFile? ConvertMetadata(bool ignoreblanks = false)
|
public Models.Metadata.MetadataFile? ConvertMetadata(bool ignoreblanks = false)
|
||||||
{
|
{
|
||||||
// If we don't have items, we can't do anything
|
// If we don't have items, we can't do anything
|
||||||
if (this.Items == null || !this.Items.Any())
|
if (Items == null || Items.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Create an object to hold the data
|
// Create an object to hold the data
|
||||||
@@ -212,7 +213,7 @@ namespace SabreTools.DatFiles
|
|||||||
foreach (string key in Items.SortedKeys)
|
foreach (string key in Items.SortedKeys)
|
||||||
{
|
{
|
||||||
var items = Items.FilteredItems(key);
|
var items = Items.FilteredItems(key);
|
||||||
if (items == null || !items.Any())
|
if (items == null || items.Count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Create a machine to hold everything
|
// Create a machine to hold everything
|
||||||
@@ -436,7 +437,7 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle Part, DiskItem, and DatItem mappings, if they exist
|
// Handle Part, DiskItem, and DatItem mappings, if they exist
|
||||||
if (partMappings.Any())
|
if (partMappings.Count != 0)
|
||||||
{
|
{
|
||||||
// Create a collection to hold the inverted Parts
|
// Create a collection to hold the inverted Parts
|
||||||
Dictionary<string, Models.Metadata.Part> partItems = [];
|
Dictionary<string, Models.Metadata.Part> partItems = [];
|
||||||
@@ -948,7 +949,11 @@ namespace SabreTools.DatFiles
|
|||||||
private static void EnsureMachineKey<T>(Models.Metadata.Machine machine, string key)
|
private static void EnsureMachineKey<T>(Models.Metadata.Machine machine, string key)
|
||||||
{
|
{
|
||||||
if (machine.Read<T[]?>(key) == null)
|
if (machine.Read<T[]?>(key) == null)
|
||||||
|
#if NET20 || NET35 || NET40 || NET452
|
||||||
machine[key] = new T[0];
|
machine[key] = new T[0];
|
||||||
|
#else
|
||||||
|
machine[key] = Array.Empty<T>();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -395,11 +395,11 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
DatItem datItem = datItems[index];
|
DatItem datItem = datItems[index];
|
||||||
|
|
||||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
if (lastgame != null && !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||||
SabreJSON.WriteEndGame(jtw);
|
SabreJSON.WriteEndGame(jtw);
|
||||||
|
|
||||||
// If we have a new game, output the beginning of the new item
|
// If we have a new game, output the beginning of the new item
|
||||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||||
SabreJSON.WriteStartGame(jtw, datItem);
|
SabreJSON.WriteStartGame(jtw, datItem);
|
||||||
|
|
||||||
// Check for a "null" item
|
// Check for a "null" item
|
||||||
|
|||||||
@@ -227,11 +227,11 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
DatItem datItem = datItems[index];
|
DatItem datItem = datItems[index];
|
||||||
|
|
||||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
if (lastgame != null && !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||||
WriteEndGame(xtw);
|
WriteEndGame(xtw);
|
||||||
|
|
||||||
// If we have a new game, output the beginning of the new item
|
// If we have a new game, output the beginning of the new item
|
||||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)?.ToLowerInvariant())
|
if (lastgame == null || !string.Equals(lastgame, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey), StringComparison.OrdinalIgnoreCase))
|
||||||
WriteStartGame(xtw, datItem);
|
WriteStartGame(xtw, datItem);
|
||||||
|
|
||||||
// Check for a "null" item
|
// Check for a "null" item
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ namespace SabreTools.DatFiles
|
|||||||
lock (key)
|
lock (key)
|
||||||
{
|
{
|
||||||
// If the value is null or empty, just return
|
// If the value is null or empty, just return
|
||||||
if (value == null || !value.Any())
|
if (value == null || value.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Ensure the key exists
|
// Ensure the key exists
|
||||||
|
|||||||
@@ -430,7 +430,7 @@ namespace SabreTools.DatFiles
|
|||||||
private List<(long, DatItem)> Deduplicate(List<(long, DatItem)> itemMappings)
|
private List<(long, DatItem)> Deduplicate(List<(long, DatItem)> itemMappings)
|
||||||
{
|
{
|
||||||
// Check for null or blank roms first
|
// Check for null or blank roms first
|
||||||
if (itemMappings == null || !itemMappings.Any())
|
if (itemMappings == null || itemMappings.Count == 0)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
// Create output list
|
// Create output list
|
||||||
@@ -717,7 +717,7 @@ namespace SabreTools.DatFiles
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var itemIndices = _buckets[bucketKeys[i]];
|
var itemIndices = _buckets[bucketKeys[i]];
|
||||||
if (itemIndices == null || !itemIndices.Any())
|
if (itemIndices == null || itemIndices.Count == 0)
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
@@ -760,7 +760,7 @@ namespace SabreTools.DatFiles
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
var itemIndices = _buckets[bucketKeys[i]];
|
var itemIndices = _buckets[bucketKeys[i]];
|
||||||
if (itemIndices == null || !itemIndices.Any())
|
if (itemIndices == null || itemIndices.Count == 0)
|
||||||
{
|
{
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
_buckets.TryRemove(bucketKeys[i], out _);
|
_buckets.TryRemove(bucketKeys[i], out _);
|
||||||
@@ -902,7 +902,7 @@ namespace SabreTools.DatFiles
|
|||||||
DatStatistics.ResetStatistics();
|
DatStatistics.ResetStatistics();
|
||||||
|
|
||||||
// If there are no items
|
// If there are no items
|
||||||
if (_items == null || !_items.Any())
|
if (_items == null || _items.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Loop through and add
|
// Loop through and add
|
||||||
|
|||||||
Reference in New Issue
Block a user