mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make IDDB version of ApplyExtras
This commit is contained in:
@@ -144,6 +144,68 @@ namespace SabreTools.Filtering
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Apply a set of Extra INIs on the DatFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="datFile">Current DatFile object to run operations on</param>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
/// <returns>True if the extras were applied, false on error</returns>
|
||||||
|
public bool ApplyExtrasDB(DatFile datFile, bool throwOnError = false)
|
||||||
|
{
|
||||||
|
// If we have no extras, don't attempt to apply and just return true
|
||||||
|
if (Items == null || !Items.Any())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var watch = new InternalStopwatch("Applying extra mappings to DAT");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Bucket by game first
|
||||||
|
datFile.ItemsDB.BucketBy(ItemKey.Machine, DedupeType.None);
|
||||||
|
|
||||||
|
// Create mappings based on the extra items
|
||||||
|
var combinedMaps = CombineExtras();
|
||||||
|
var games = combinedMaps.Keys;
|
||||||
|
|
||||||
|
// Apply the mappings
|
||||||
|
foreach (string game in games)
|
||||||
|
{
|
||||||
|
// Get the list of DatItems for the machine
|
||||||
|
var datItems = datFile.ItemsDB.GetDatItemsForBucket(game);
|
||||||
|
if (datItems == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Try to get the map values, if possible
|
||||||
|
combinedMaps.TryGetValue(game, out var mappings);
|
||||||
|
|
||||||
|
// Create a setter with the new mappings
|
||||||
|
var setter = new Setter();
|
||||||
|
setter.PopulateSettersFromDictionary(mappings);
|
||||||
|
|
||||||
|
// Loop through and set the fields accordingly
|
||||||
|
foreach (var datItem in datItems)
|
||||||
|
{
|
||||||
|
var machine = datFile.ItemsDB.GetMachineForItem(datItem.Item1);
|
||||||
|
if (machine.Item2 != null)
|
||||||
|
setter.SetFields(machine.Item2);
|
||||||
|
|
||||||
|
setter.SetFields(datItem.Item2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (!throwOnError)
|
||||||
|
{
|
||||||
|
logger.Error(ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
watch.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Combine ExtraIni fields
|
/// Combine ExtraIni fields
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -350,6 +350,7 @@ Reset the internal state: reset();";
|
|||||||
|
|
||||||
// Apply the extra INI blindly
|
// Apply the extra INI blindly
|
||||||
extraIni.ApplyExtras(batchState.DatFile);
|
extraIni.ApplyExtras(batchState.DatFile);
|
||||||
|
extraIni.ApplyExtrasDB(batchState.DatFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ namespace SabreTools.Features
|
|||||||
{
|
{
|
||||||
// Perform additional processing steps
|
// Perform additional processing steps
|
||||||
Extras!.ApplyExtras(datdata);
|
Extras!.ApplyExtras(datdata);
|
||||||
|
Extras!.ApplyExtrasDB(datdata);
|
||||||
Splitter!.ApplySplitting(datdata, useTags: false);
|
Splitter!.ApplySplitting(datdata, useTags: false);
|
||||||
datdata.ExecuteFilters(FilterRunner!);
|
datdata.ExecuteFilters(FilterRunner!);
|
||||||
Cleaner!.ApplyCleaning(datdata);
|
Cleaner!.ApplyCleaning(datdata);
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ namespace SabreTools.Features
|
|||||||
|
|
||||||
// Perform additional processing steps
|
// Perform additional processing steps
|
||||||
Extras!.ApplyExtras(datFile);
|
Extras!.ApplyExtras(datFile);
|
||||||
|
Extras!.ApplyExtrasDB(datFile);
|
||||||
Splitter!.ApplySplitting(datFile, useTags: false);
|
Splitter!.ApplySplitting(datFile, useTags: false);
|
||||||
datFile.ExecuteFilters(FilterRunner!);
|
datFile.ExecuteFilters(FilterRunner!);
|
||||||
Cleaner!.ApplyCleaning(datFile);
|
Cleaner!.ApplyCleaning(datFile);
|
||||||
@@ -216,6 +217,7 @@ namespace SabreTools.Features
|
|||||||
|
|
||||||
// Perform additional processing steps
|
// Perform additional processing steps
|
||||||
Extras!.ApplyExtras(userInputDat);
|
Extras!.ApplyExtras(userInputDat);
|
||||||
|
Extras!.ApplyExtrasDB(userInputDat);
|
||||||
Splitter!.ApplySplitting(userInputDat, useTags: false);
|
Splitter!.ApplySplitting(userInputDat, useTags: false);
|
||||||
userInputDat.ExecuteFilters(FilterRunner!);
|
userInputDat.ExecuteFilters(FilterRunner!);
|
||||||
Cleaner!.ApplyCleaning(userInputDat);
|
Cleaner!.ApplyCleaning(userInputDat);
|
||||||
@@ -345,6 +347,7 @@ namespace SabreTools.Features
|
|||||||
|
|
||||||
// Perform additional processing steps
|
// Perform additional processing steps
|
||||||
Extras.ApplyExtras(repDat);
|
Extras.ApplyExtras(repDat);
|
||||||
|
Extras.ApplyExtrasDB(repDat);
|
||||||
Splitter.ApplySplitting(repDat, useTags: false);
|
Splitter.ApplySplitting(repDat, useTags: false);
|
||||||
repDat.ExecuteFilters(FilterRunner!);
|
repDat.ExecuteFilters(FilterRunner!);
|
||||||
Cleaner.ApplyCleaning(repDat);
|
Cleaner.ApplyCleaning(repDat);
|
||||||
@@ -381,6 +384,7 @@ namespace SabreTools.Features
|
|||||||
|
|
||||||
// Perform additional processing steps
|
// Perform additional processing steps
|
||||||
Extras.ApplyExtras(repDat);
|
Extras.ApplyExtras(repDat);
|
||||||
|
Extras.ApplyExtrasDB(repDat);
|
||||||
Splitter.ApplySplitting(repDat, useTags: false);
|
Splitter.ApplySplitting(repDat, useTags: false);
|
||||||
repDat.ExecuteFilters(FilterRunner!);
|
repDat.ExecuteFilters(FilterRunner!);
|
||||||
Cleaner.ApplyCleaning(repDat);
|
Cleaner.ApplyCleaning(repDat);
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ namespace SabreTools.Features
|
|||||||
|
|
||||||
// Perform additional processing steps
|
// Perform additional processing steps
|
||||||
Extras!.ApplyExtras(datdata);
|
Extras!.ApplyExtras(datdata);
|
||||||
|
Extras!.ApplyExtrasDB(datdata);
|
||||||
Splitter!.ApplySplitting(datdata, useTags: true);
|
Splitter!.ApplySplitting(datdata, useTags: true);
|
||||||
datdata.ExecuteFilters(FilterRunner!);
|
datdata.ExecuteFilters(FilterRunner!);
|
||||||
Cleaner!.ApplyCleaning(datdata);
|
Cleaner!.ApplyCleaning(datdata);
|
||||||
@@ -114,6 +115,7 @@ namespace SabreTools.Features
|
|||||||
|
|
||||||
// Perform additional processing steps
|
// Perform additional processing steps
|
||||||
Extras!.ApplyExtras(datdata);
|
Extras!.ApplyExtras(datdata);
|
||||||
|
Extras!.ApplyExtrasDB(datdata);
|
||||||
Splitter!.ApplySplitting(datdata, useTags: true);
|
Splitter!.ApplySplitting(datdata, useTags: true);
|
||||||
datdata.ExecuteFilters(FilterRunner!);
|
datdata.ExecuteFilters(FilterRunner!);
|
||||||
Cleaner!.ApplyCleaning(datdata);
|
Cleaner!.ApplyCleaning(datdata);
|
||||||
|
|||||||
Reference in New Issue
Block a user