Files
SabreTools/SabreTools.DatTools/MergeSplit.cs

92 lines
2.9 KiB
C#
Raw Normal View History

using System;
using SabreTools.Core.Tools;
2020-12-10 23:24:09 -08:00
using SabreTools.DatFiles;
2024-10-24 00:36:44 -04:00
using SabreTools.IO.Logging;
2024-10-30 11:26:56 -04:00
namespace SabreTools.DatTools
{
2024-10-30 11:26:56 -04:00
public class MergeSplit
{
#region Fields
2020-12-10 14:11:35 -08:00
/// <summary>
/// Splitting mode to apply
2020-12-10 14:11:35 -08:00
/// </summary>
public MergingFlag SplitType { get; set; }
2020-12-10 14:11:35 -08:00
#endregion
#region Logging
/// <summary>
/// Logging object
/// </summary>
2025-01-08 16:59:44 -05:00
private static readonly Logger _staticLogger = new();
#endregion
#region Running
/// <summary>
/// Apply splitting on the DatFile
/// </summary>
2020-12-10 13:13:54 -08:00
/// <param name="datFile">Current DatFile object to run operations on</param>
/// <param name="useTags">True if DatFile tags override splitting, false otherwise</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 DatFile was split, false on error</returns>
public bool ApplySplitting(DatFile datFile, bool useTags, bool throwOnError = false)
{
InternalStopwatch watch = new("Applying splitting to DAT");
2021-02-02 14:09:49 -08:00
try
{
// If we are using tags from the DAT, set the proper input for split type unless overridden
if (useTags && SplitType == MergingFlag.None)
SplitType = datFile.Header.GetStringFieldValue(Models.Metadata.Header.ForceMergingKey).AsEnumValue<MergingFlag>();
// Run internal splitting
switch (SplitType)
{
// Standard
case MergingFlag.None:
// No-op
break;
case MergingFlag.Split:
datFile.ApplySplit();
break;
case MergingFlag.Merged:
datFile.ApplyMerged();
break;
case MergingFlag.NonMerged:
datFile.ApplyNonMerged();
break;
// Nonstandard
case MergingFlag.FullMerged:
datFile.ApplyFullyMerged();
break;
case MergingFlag.DeviceNonMerged:
datFile.ApplyDeviceNonMerged();
break;
case MergingFlag.FullNonMerged:
datFile.ApplyFullyNonMerged();
break;
}
}
catch (Exception ex) when (!throwOnError)
{
2025-01-08 16:59:44 -05:00
_staticLogger.Error(ex);
return false;
}
2021-02-02 14:09:49 -08:00
finally
{
watch.Stop();
}
return true;
}
#endregion
}
}