using System; using SabreTools.Core.Tools; using SabreTools.DatFiles; using SabreTools.IO.Logging; namespace SabreTools.DatTools { public class MergeSplit { #region Fields /// /// Splitting mode to apply /// public MergingFlag SplitType { get; set; } #endregion #region Logging /// /// Logging object /// private static readonly Logger _staticLogger = new(); #endregion #region Running /// /// Apply splitting on the DatFile /// /// Current DatFile object to run operations on /// True if DatFile tags override splitting, false otherwise /// True if the error that is thrown should be thrown back to the caller, false otherwise /// True if the DatFile was split, false on error public bool ApplySplitting(DatFile datFile, bool useTags, bool throwOnError = false) { InternalStopwatch watch = new("Applying splitting to DAT"); 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(); // 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) { _staticLogger.Error(ex); return false; } finally { watch.Stop(); } return true; } #endregion } }