mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move StripSceneDatesFromItems to dictionaries
This commit is contained in:
@@ -6,6 +6,8 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
#endif
|
||||||
@@ -988,11 +990,57 @@ namespace SabreTools.DatFiles
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Strip the dates from the beginning of scene-style set names
|
||||||
|
/// </summary>
|
||||||
|
public void StripSceneDatesFromItems()
|
||||||
|
{
|
||||||
|
// Set the regex pattern to use
|
||||||
|
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
||||||
|
|
||||||
|
// Now process all of the roms
|
||||||
|
#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 j = 0; j < items.Count; j++)
|
||||||
|
{
|
||||||
|
DatItem item = items[j];
|
||||||
|
if (Regex.IsMatch(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!, pattern))
|
||||||
|
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Regex.Replace(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!, pattern, "$2"));
|
||||||
|
|
||||||
|
if (Regex.IsMatch(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)!, pattern))
|
||||||
|
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Regex.Replace(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)!, pattern, "$2"));
|
||||||
|
|
||||||
|
items[j] = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
Remove(key);
|
||||||
|
AddRange(key, items);
|
||||||
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
|
});
|
||||||
|
#else
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set internal names to match One Rom Per Game (ORPG) logic
|
/// Set internal names to match One Rom Per Game (ORPG) logic
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datItem">DatItem to run logic on</param>
|
/// <param name="datItem">DatItem to run logic on</param>
|
||||||
internal static void SetOneRomPerGame(DatItem datItem)
|
private void SetOneRomPerGame(DatItem datItem)
|
||||||
{
|
{
|
||||||
if (datItem.GetName() == null)
|
if (datItem.GetName() == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
#endif
|
#endif
|
||||||
@@ -1050,6 +1052,51 @@ namespace SabreTools.DatFiles
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Strip the dates from the beginning of scene-style set names
|
||||||
|
/// </summary>
|
||||||
|
public void StripSceneDatesFromItems()
|
||||||
|
{
|
||||||
|
// Set the regex pattern to use
|
||||||
|
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
||||||
|
|
||||||
|
// Now process all of the roms
|
||||||
|
#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 j = 0; j < items.Length; j++)
|
||||||
|
{
|
||||||
|
(long, DatItem) item = items[j];
|
||||||
|
if (Regex.IsMatch(item.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!, pattern))
|
||||||
|
item.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Regex.Replace(item.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!, pattern, "$2"));
|
||||||
|
|
||||||
|
if (Regex.IsMatch(item.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)!, pattern))
|
||||||
|
item.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Regex.Replace(item.Item2.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)!, pattern, "$2"));
|
||||||
|
|
||||||
|
items[j] = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
_buckets[key] = items.Select(i => i.Item1).ToConcurrentList();
|
||||||
|
#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>
|
||||||
@@ -1077,7 +1124,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// Set internal names to match One Rom Per Game (ORPG) logic
|
/// Set internal names to match One Rom Per Game (ORPG) logic
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datItem">DatItem to run logic on</param>
|
/// <param name="datItem">DatItem to run logic on</param>
|
||||||
internal static void SetOneRomPerGame((long, DatItem) datItem)
|
private void SetOneRomPerGame((long, DatItem) datItem)
|
||||||
{
|
{
|
||||||
if (datItem.Item1 < 0 || datItem.Item2.GetName() == null)
|
if (datItem.Item1 < 0 || datItem.Item2.GetName() == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -354,45 +354,8 @@ namespace SabreTools.Filtering
|
|||||||
// Output the logging statement
|
// Output the logging statement
|
||||||
logger.User("Stripping scene-style dates");
|
logger.User("Stripping scene-style dates");
|
||||||
|
|
||||||
// Set the regex pattern to use
|
datFile.Items.StripSceneDatesFromItems();
|
||||||
string pattern = @"([0-9]{2}\.[0-9]{2}\.[0-9]{2}-)(.*?-.*?)";
|
datFile.ItemsDB.StripSceneDatesFromItems();
|
||||||
|
|
||||||
// Now process all of the roms
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
|
||||||
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 j = 0; j < items.Count; j++)
|
|
||||||
{
|
|
||||||
DatItem item = items[j];
|
|
||||||
if (Regex.IsMatch(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!, pattern))
|
|
||||||
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Regex.Replace(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)!, pattern, "$2"));
|
|
||||||
|
|
||||||
if (Regex.IsMatch(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)!, pattern))
|
|
||||||
item.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.DescriptionKey, Regex.Replace(item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.DescriptionKey)!, pattern, "$2"));
|
|
||||||
|
|
||||||
items[j] = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
datFile.Items.Remove(key);
|
|
||||||
datFile.Items.AddRange(key, items);
|
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
|
||||||
});
|
|
||||||
#else
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user