mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move SuperDAT out of DatFileTool
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
using System.Threading.Tasks;
|
||||
#endif
|
||||
@@ -194,142 +193,6 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#endregion
|
||||
|
||||
#region SuperDAT
|
||||
|
||||
/// <summary>
|
||||
/// Apply SuperDAT naming logic to a merged DatFile
|
||||
/// </summary>
|
||||
/// <param name="datFile">Current DatFile object to run operations on</param>
|
||||
/// <param name="inputs">List of inputs to use for renaming</param>
|
||||
public static void ApplySuperDAT(DatFile datFile, List<ParentablePath> inputs)
|
||||
{
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
|
||||
List<DatItem> newItems = [];
|
||||
foreach (DatItem item in items)
|
||||
{
|
||||
DatItem newItem = item;
|
||||
var source = newItem.GetFieldValue<Source?>(DatItem.SourceKey);
|
||||
if (source == null)
|
||||
continue;
|
||||
|
||||
string filename = inputs[source.Index].CurrentPath;
|
||||
string rootpath = inputs[source.Index].ParentPath ?? string.Empty;
|
||||
|
||||
if (rootpath.Length > 0
|
||||
#if NETFRAMEWORK
|
||||
&& !rootpath.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
&& !rootpath.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
|
||||
#else
|
||||
&& !rootpath.EndsWith(Path.DirectorySeparatorChar)
|
||||
&& !rootpath.EndsWith(Path.AltDirectorySeparatorChar))
|
||||
#endif
|
||||
{
|
||||
rootpath += Path.DirectorySeparatorChar.ToString();
|
||||
}
|
||||
|
||||
filename = filename.Remove(0, rootpath.Length);
|
||||
|
||||
var machine = newItem.GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
if (machine == null)
|
||||
continue;
|
||||
|
||||
machine.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetDirectoryName(filename)
|
||||
+ Path.DirectorySeparatorChar
|
||||
+ Path.GetFileNameWithoutExtension(filename)
|
||||
+ Path.DirectorySeparatorChar
|
||||
+ machine.GetStringFieldValue(Models.Metadata.Machine.NameKey));
|
||||
|
||||
newItems.Add(newItem);
|
||||
}
|
||||
|
||||
datFile.RemoveBucket(key);
|
||||
newItems.ForEach(item => datFile.AddItem(item, statsOnly: false));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply SuperDAT naming logic to a merged DatFile
|
||||
/// </summary>
|
||||
/// <param name="datFile">Current DatFile object to run operations on</param>
|
||||
/// <param name="inputs">List of inputs to use for renaming</param>
|
||||
public static void ApplySuperDATDB(DatFile datFile, List<ParentablePath> inputs)
|
||||
{
|
||||
List<string> keys = [.. datFile.ItemsDB.SortedKeys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(keys, key =>
|
||||
#else
|
||||
foreach (var key in keys)
|
||||
#endif
|
||||
{
|
||||
var items = datFile.GetItemsForBucketDB(key);
|
||||
if (items == null)
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return;
|
||||
#else
|
||||
continue;
|
||||
#endif
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
var source = datFile.ItemsDB.GetSourceForItem(item.Key);
|
||||
if (source.Value == null)
|
||||
continue;
|
||||
|
||||
var machine = datFile.ItemsDB.GetMachineForItem(item.Key);
|
||||
if (machine.Value == null)
|
||||
continue;
|
||||
|
||||
string filename = inputs[source.Value.Index].CurrentPath;
|
||||
string rootpath = inputs[source.Value.Index].ParentPath ?? string.Empty;
|
||||
|
||||
if (rootpath.Length > 0
|
||||
#if NETFRAMEWORK
|
||||
&& !rootpath!.EndsWith(Path.DirectorySeparatorChar.ToString())
|
||||
&& !rootpath!.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
|
||||
#else
|
||||
&& !rootpath.EndsWith(Path.DirectorySeparatorChar)
|
||||
&& !rootpath.EndsWith(Path.AltDirectorySeparatorChar))
|
||||
#endif
|
||||
{
|
||||
rootpath += Path.DirectorySeparatorChar.ToString();
|
||||
}
|
||||
|
||||
filename = filename.Remove(0, rootpath.Length);
|
||||
|
||||
machine.Value.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar
|
||||
+ Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar
|
||||
+ machine.Value.GetStringFieldValue(Models.Metadata.Machine.NameKey));
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Population
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user