From daf3e18bd60ad2857abdb4ab836b49554358f7bd Mon Sep 17 00:00:00 2001 From: VaDiM Date: Mon, 26 Jan 2026 17:59:39 +0300 Subject: [PATCH] Some refactor for customBundleOptions --- AssetStudio/AssetsManager.cs | 4 +- AssetStudio/BundleFile.cs | 14 ++--- .../CustomOptions/CustomBundleOptions.cs | 58 +++++++++---------- AssetStudio/CustomOptions/ImportOptions.cs | 4 +- AssetStudioCLI/Studio.cs | 4 +- AssetStudioGUI/Studio.cs | 4 +- 6 files changed, 43 insertions(+), 45 deletions(-) diff --git a/AssetStudio/AssetsManager.cs b/AssetStudio/AssetsManager.cs index b21f2ef..94c65fa 100644 --- a/AssetStudio/AssetsManager.cs +++ b/AssetStudio/AssetsManager.cs @@ -310,7 +310,7 @@ namespace AssetStudio try { - var bundleFile = new BundleFile(bundleReader, Options.BundleOptions); + var bundleFile = new BundleFile(bundleReader, Options); isLoaded = LoadBundleFiles(bundleReader, bundleFile, originalPath); if (!isLoaded) return false; @@ -331,7 +331,7 @@ namespace AssetStudio bundleReader.FileName = $"{reader.FileName}_0x{bundleStream.Offset:X}"; } Logger.Info($"[MultiBundle] Loading \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}"); - bundleFile = new BundleFile(bundleReader, Options.BundleOptions, isMultiBundle: true); + bundleFile = new BundleFile(bundleReader, Options, isMultiBundle: true); isLoaded = LoadBundleFiles(bundleReader, bundleFile, originalPath ?? reader.FullPath); } return isLoaded; diff --git a/AssetStudio/BundleFile.cs b/AssetStudio/BundleFile.cs index fed0323..de0cc1f 100644 --- a/AssetStudio/BundleFile.cs +++ b/AssetStudio/BundleFile.cs @@ -1,8 +1,8 @@ -using System; +using AssetStudio.CustomOptions; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; -using System.Collections.Generic; -using AssetStudio.CustomOptions; namespace AssetStudio { @@ -45,7 +45,7 @@ namespace AssetStudio public class BundleFile { public readonly bool IsDataAfterBundle; - private readonly CustomBundleOptions _bundleOptions; + private readonly ImportOptions.CustomBundleOptions _bundleOptions; public class Header { @@ -80,9 +80,9 @@ namespace AssetStudio public List fileList; - public BundleFile(FileReader reader, CustomBundleOptions bundleOptions, bool isMultiBundle = false) + public BundleFile(FileReader reader, ImportOptions importOptions, bool isMultiBundle = false) { - _bundleOptions = bundleOptions; + _bundleOptions = importOptions.BundleOptions; m_Header = new Header(); m_Header.signature = reader.ReadStringToNull(); m_Header.version = reader.ReadUInt32(); @@ -115,7 +115,7 @@ namespace AssetStudio IsDataAfterBundle = streamSize - bundleSize > 200; var unityVer = m_Header.unityRevision; - var customUnityVer = _bundleOptions.Options.CustomUnityVersion; + var customUnityVer = importOptions.CustomUnityVersion; if (customUnityVer != null) { if (!unityVer.IsStripped && customUnityVer != unityVer) diff --git a/AssetStudio/CustomOptions/CustomBundleOptions.cs b/AssetStudio/CustomOptions/CustomBundleOptions.cs index 8c974a5..cb48643 100644 --- a/AssetStudio/CustomOptions/CustomBundleOptions.cs +++ b/AssetStudio/CustomOptions/CustomBundleOptions.cs @@ -1,40 +1,38 @@ namespace AssetStudio.CustomOptions { - public class CustomBundleOptions + public partial class ImportOptions { - private CompressionType _customBlockCompression = CompressionType.Auto; - private CompressionType _customBlockInfoCompression = CompressionType.Auto; - private bool _decompressToDisk; - - public ImportOptions Options; - - public CompressionType CustomBlockCompression + public sealed class CustomBundleOptions { - get => _customBlockCompression; - set => _customBlockCompression = SetOption(nameof(CustomBlockCompression), value); - } - public CompressionType CustomBlockInfoCompression - { - get => _customBlockInfoCompression; - set => _customBlockInfoCompression = SetOption(nameof(CustomBlockInfoCompression), value); - } - public bool DecompressToDisk - { - get => _decompressToDisk; - set => _decompressToDisk = SetOption(nameof(DecompressToDisk), value); - } + private CompressionType _customBlockCompression = CompressionType.Auto; + private CompressionType _customBlockInfoCompression = CompressionType.Auto; + private bool _decompressToDisk; - public CustomBundleOptions() { } + public CompressionType CustomBlockCompression + { + get => _customBlockCompression; + set => _customBlockCompression = SetOption(nameof(CustomBlockCompression), value); + } - public CustomBundleOptions(ImportOptions importOptions) - { - Options = importOptions; - } + public CompressionType CustomBlockInfoCompression + { + get => _customBlockInfoCompression; + set => _customBlockInfoCompression = SetOption(nameof(CustomBlockInfoCompression), value); + } - private static T SetOption(string option, T value) - { - Logger.Info($"- {option}: {value}"); - return value; + public bool DecompressToDisk + { + get => _decompressToDisk; + set => _decompressToDisk = SetOption(nameof(DecompressToDisk), value); + } + + public CustomBundleOptions() { } + + private static T SetOption(string option, T value) + { + Logger.Info($"- {option}: {value}"); + return value; + } } } } diff --git a/AssetStudio/CustomOptions/ImportOptions.cs b/AssetStudio/CustomOptions/ImportOptions.cs index 452904f..f01e6fb 100644 --- a/AssetStudio/CustomOptions/ImportOptions.cs +++ b/AssetStudio/CustomOptions/ImportOptions.cs @@ -8,7 +8,7 @@ using System.Text.Json.Serialization; namespace AssetStudio.CustomOptions { - public class ImportOptions + public partial class ImportOptions { private static JsonSerializerOptions jsonOptions; private static string fileName = "ImportOptions"; @@ -28,7 +28,7 @@ namespace AssetStudio.CustomOptions public ImportOptions() { - BundleOptions = new CustomBundleOptions(this); + BundleOptions = new CustomBundleOptions(); CustomUnityVersion = null; } diff --git a/AssetStudioCLI/Studio.cs b/AssetStudioCLI/Studio.cs index 98986b4..fba3852 100644 --- a/AssetStudioCLI/Studio.cs +++ b/AssetStudioCLI/Studio.cs @@ -100,7 +100,7 @@ namespace AssetStudioCLI var count = 0; var bundleStream = new OffsetStream(reader); var bundleReader = new FileReader(reader.FullPath, bundleStream); - var bundleFile = new BundleFile(bundleReader, assetsManager.Options.BundleOptions); + var bundleFile = new BundleFile(bundleReader, assetsManager.Options); var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); if (bundleFile.fileList.Count > 0) { @@ -119,7 +119,7 @@ namespace AssetStudioCLI bundleReader.FileName = $"{reader.FileName}_0x{bundleStream.Offset:X}"; } Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}.."); - bundleFile = new BundleFile(bundleReader, assetsManager.Options.BundleOptions, isMultiBundle: true); + bundleFile = new BundleFile(bundleReader, assetsManager.Options, isMultiBundle: true); if (bundleFile.fileList.Count > 0) { count += ExtractStreamFile(extractPath, bundleFile.fileList); diff --git a/AssetStudioGUI/Studio.cs b/AssetStudioGUI/Studio.cs index c056b8f..6fe50f4 100644 --- a/AssetStudioGUI/Studio.cs +++ b/AssetStudioGUI/Studio.cs @@ -140,7 +140,7 @@ namespace AssetStudioGUI var count = 0; var bundleStream = new OffsetStream(reader); var bundleReader = new FileReader(reader.FullPath, bundleStream); - var bundleFile = new BundleFile(bundleReader, assetsManager.Options.BundleOptions); + var bundleFile = new BundleFile(bundleReader, assetsManager.Options); var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked"); if (bundleFile.fileList.Count > 0) { @@ -159,7 +159,7 @@ namespace AssetStudioGUI bundleReader.FileName = $"{reader.FileName}_0x{bundleStream.Offset:X}"; } Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}.."); - bundleFile = new BundleFile(bundleReader, assetsManager.Options.BundleOptions, isMultiBundle: true); + bundleFile = new BundleFile(bundleReader, assetsManager.Options, isMultiBundle: true); if (bundleFile.fileList.Count > 0) { count += ExtractStreamFile(extractPath, bundleFile.fileList);