mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move SetOneRomPerGame to dictionaries
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Collections;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
#endif
|
#endif
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -954,6 +955,57 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure that all roms are in their own game (or at least try to ensure)
|
||||||
|
/// </summary>
|
||||||
|
public void SetOneRomPerGame()
|
||||||
|
{
|
||||||
|
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||||
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
|
Parallel.ForEach(Keys, Globals.ParallelOptions, key =>
|
||||||
|
#elif NET40_OR_GREATER
|
||||||
|
Parallel.ForEach(Keys, key =>
|
||||||
|
#else
|
||||||
|
foreach (var key in Keys)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
var items = this[key];
|
||||||
|
if (items == null)
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < items.Count; i++)
|
||||||
|
{
|
||||||
|
SetOneRomPerGame(items[i]);
|
||||||
|
}
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set internal names to match One Rom Per Game (ORPG) logic
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datItem">DatItem to run logic on</param>
|
||||||
|
internal static void SetOneRomPerGame(DatItem datItem)
|
||||||
|
{
|
||||||
|
if (datItem.GetName() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string[] splitname = datItem.GetName()!.Split('.');
|
||||||
|
#if NET20 || NET35
|
||||||
|
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1).ToArray())}");
|
||||||
|
#else
|
||||||
|
datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, datItem.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}");
|
||||||
|
#endif
|
||||||
|
datItem.SetName(Path.GetFileName(datItem.GetName()));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Statistics
|
#region Statistics
|
||||||
|
|||||||
@@ -1017,6 +1017,39 @@ namespace SabreTools.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure that all roms are in their own game (or at least try to ensure)
|
||||||
|
/// </summary>
|
||||||
|
public void SetOneRomPerGame()
|
||||||
|
{
|
||||||
|
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||||
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
|
Parallel.ForEach(SortedKeys, Globals.ParallelOptions, key =>
|
||||||
|
#elif NET40_OR_GREATER
|
||||||
|
Parallel.ForEach(SortedKeys, key =>
|
||||||
|
#else
|
||||||
|
foreach (var key in SortedKeys)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
var items = GetDatItemsForBucket(key);
|
||||||
|
if (items == null)
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
return;
|
||||||
|
#else
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (int i = 0; i < items.Length; i++)
|
||||||
|
{
|
||||||
|
SetOneRomPerGame(items[i]);
|
||||||
|
}
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Execute all filters in a filter runner on a single bucket
|
/// Execute all filters in a filter runner on a single bucket
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -1040,6 +1073,24 @@ namespace SabreTools.DatFiles
|
|||||||
_buckets[bucketName] = newItems.Select(i => i.Item1).ToConcurrentList();
|
_buckets[bucketName] = newItems.Select(i => i.Item1).ToConcurrentList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set internal names to match One Rom Per Game (ORPG) logic
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datItem">DatItem to run logic on</param>
|
||||||
|
internal static void SetOneRomPerGame((long, DatItem) datItem)
|
||||||
|
{
|
||||||
|
if (datItem.Item1 < 0 || datItem.Item2.GetName() == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string[] splitname = datItem.Item2.GetName()!.Split('.');
|
||||||
|
#if NET20 || NET35
|
||||||
|
datItem.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, datItem.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1).ToArray())}");
|
||||||
|
#else
|
||||||
|
datItem.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, datItem.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $"/{string.Join(".", splitname.Take(splitname.Length > 1 ? splitname.Length - 1 : 1))}");
|
||||||
|
#endif
|
||||||
|
datItem.Item2.SetName(Path.GetFileName(datItem.Item2.GetName()));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Statistics
|
#region Statistics
|
||||||
|
|||||||
@@ -323,32 +323,8 @@ namespace SabreTools.Filtering
|
|||||||
// Because this introduces subfolders, we need to set the SuperDAT type
|
// Because this introduces subfolders, we need to set the SuperDAT type
|
||||||
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.TypeKey, "SuperDAT");
|
datFile.Header.SetFieldValue<string?>(Models.Metadata.Header.TypeKey, "SuperDAT");
|
||||||
|
|
||||||
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
datFile.Items.SetOneRomPerGame();
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
datFile.ItemsDB.SetOneRomPerGame();
|
||||||
Parallel.ForEach(datFile.Items.Keys, Globals.ParallelOptions, key =>
|
|
||||||
#elif NET40_OR_GREATER
|
|
||||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
|
||||||
#else
|
|
||||||
foreach (var key in datFile.Items.Keys)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
var items = datFile.Items[key];
|
|
||||||
if (items == null)
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
|
||||||
return;
|
|
||||||
#else
|
|
||||||
continue;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (int i = 0; i < items.Count; i++)
|
|
||||||
{
|
|
||||||
SetOneRomPerGame(items[i]);
|
|
||||||
}
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
|
||||||
});
|
|
||||||
#else
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user