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