Fix return/continue issues

This commit is contained in:
Matt Nadareski
2024-03-05 02:52:53 -05:00
parent 2b2aa5aff8
commit 05900cf818
10 changed files with 123 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ using SabreTools.Core.Tools;
using SabreTools.DatFiles.Formats;
using SabreTools.DatItems;
using SabreTools.DatItems.Formats;
using SabreTools.Filter;
using SabreTools.Hashing;
using SabreTools.Logging;
@@ -146,6 +147,41 @@ namespace SabreTools.DatFiles
#endregion
#region Filtering
/// <summary>
/// Execute all filters in a filter runner on the items in the dictionary
/// </summary>
/// <param name="filterRunner">Preconfigured filter runner to use</param>
public void ExecuteFilters(FilterRunner filterRunner)
{
List<string> keys = [.. Items.Keys];
#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
{
ConcurrentList<DatItem>? items = Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// TODO: Implement filtering
#if NET40_OR_GREATER || NETCOREAPP
});
#else
}
#endif
}
#endregion
#region Parsing
/// <summary>

View File

@@ -818,7 +818,11 @@ namespace SabreTools.DatFiles
// Get the possibly unsorted list
ConcurrentList<DatItem>? sortedlist = this[key]?.ToConcurrentList();
if (sortedlist == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// Sort the list of items to be consistent
DatItem.Sort(ref sortedlist, false);

View File

@@ -946,7 +946,11 @@ CREATE TABLE IF NOT EXISTS groups (
{
string key = oldkeys[k];
if (this[key] == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// Now add each of the roms to their respective keys
for (int i = 0; i < this[key]!.Count; i++)

View File

@@ -43,7 +43,11 @@ namespace SabreTools.DatTools
{
ConcurrentList<DatItem>? items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
ConcurrentList<DatItem> newItems = [];
foreach (DatItem item in items)
@@ -119,7 +123,11 @@ namespace SabreTools.DatTools
{
ConcurrentList<DatItem>? datItems = intDat.Items[key];
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
ConcurrentList<DatItem> newDatItems = [];
foreach (DatItem datItem in datItems)
@@ -163,7 +171,11 @@ namespace SabreTools.DatTools
{
ConcurrentList<DatItem>? datItems = intDat.Items[key];
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
ConcurrentList<DatItem> newDatItems = [];
foreach (DatItem datItem in datItems)
@@ -230,15 +242,27 @@ namespace SabreTools.DatTools
{
// If the key is null, keep it
if (!intDat.Items.TryGetValue(key, out var intList) || intList == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// If the base DAT doesn't contain the key, keep it
if (!datFile.Items.TryGetValue(key, out var list) || list == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// If the number of items is different, then keep it
if (list.Count != intList.Count)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
// Otherwise, compare by name and hash the remaining files
bool exactMatch = true;
@@ -262,7 +286,11 @@ namespace SabreTools.DatTools
{
ConcurrentList<DatItem>? datItems = intDat.Items[key];
if (datItems == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
ConcurrentList<DatItem> keepDatItems = [];
foreach (DatItem datItem in datItems)

View File

@@ -255,7 +255,11 @@ namespace SabreTools.DatTools
{
DatItem? datItem = DatItem.Create(baseFile);
if (datItem == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
ProcessFileHelper(datFile, item, datItem, basePath, parent);
#if NET40_OR_GREATER || NETCOREAPP

View File

@@ -597,7 +597,11 @@ namespace SabreTools.DatTools
// If the rom list is empty or null, just skip it
if (items == null || items.Count == 0)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (DatItem item in items)
{

View File

@@ -249,7 +249,11 @@ namespace SabreTools.Filtering
{
var items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
foreach (DatItem item in items)
{
@@ -277,7 +281,11 @@ namespace SabreTools.Filtering
{
var items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
ConcurrentList<DatItem> newItems = [];
foreach (DatItem item in items)
@@ -420,7 +428,11 @@ namespace SabreTools.Filtering
{
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++)
{
@@ -474,7 +486,11 @@ namespace SabreTools.Filtering
{
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++)
{

View File

@@ -121,7 +121,11 @@ namespace SabreTools.Filtering
{
ConcurrentList<DatItem>? items = datFile.Items[key];
if (items == null)
#if NET40_OR_GREATER || NETCOREAPP
return;
#else
continue;
#endif
for (int j = 0; j < items.Count; j++)
{

View File

@@ -1786,6 +1786,11 @@ Some special strings that can be used:
/// </summary>
protected Filtering.Filter Filter { get; set; }
/// <summary>
/// Preonfigured FilterRunner
/// </summary>
protected Filter.FilterRunner FilterRunner { get; set; }
/// <summary>
/// Pre-configured DatHeader
/// </summary>
@@ -1894,6 +1899,7 @@ Some special strings that can be used:
Cleaner = GetCleaner(features);
Extras = GetExtras(features);
Filter = GetFilter(features);
FilterRunner = GetFilterRunner(features);
Header = GetDatHeader(features);
LogLevel = GetString(features, LogLevelStringValue).AsLogLevel();
OutputDir = GetString(features, OutputDirStringValue)?.Trim('"');
@@ -2243,6 +2249,22 @@ Some special strings that can be used:
return filter;
}
/// <summary>
/// Get FilterRunner from feature list
/// </summary>
private static Filter.FilterRunner GetFilterRunner(Dictionary<string, Feature> features)
{
// Populate filters
List<string> filterPairs = GetList(features, FilterListValue);
var filterRunner = new Filter.FilterRunner(filterPairs.ToArray());
// TODO: Support this use case somehow
// Include 'of" in game filters
//filter.MachineFilter.IncludeOfInGame = GetBoolean(features, MatchOfTagsValue);
return filterRunner;
}
/// <summary>
/// Get Remover from feature list
/// </summary>

View File

@@ -101,6 +101,7 @@ namespace SabreTools.Features
Extras.ApplyExtras(datdata);
Splitter.ApplySplitting(datdata, useTags: false);
Filter.ApplyFilters(datdata);
//FilterRunner.Run(datdata); // TODO: Create helper method to run over entire DAT
Cleaner.ApplyCleaning(datdata);
Remover.ApplyRemovals(datdata);