From 0ae33f995f9bbceb0d78b73cbc2e131de6c199c8 Mon Sep 17 00:00:00 2001 From: VaDiM Date: Sat, 21 Feb 2026 03:21:37 +0300 Subject: [PATCH] Improve Import options - Added Import options window - Changed cache logic: - single cache file instead of separate cache files for each bundle - program folder as a default cache folder - added an option to specify a custom cache folder --- AssetStudio/BundleFile.cs | 26 +- .../CustomOptions/CustomBundleOptions.cs | 23 +- AssetStudio/OffsetStream.cs | 4 +- AssetStudioCLI/Options/CLIOptions.cs | 89 ++-- AssetStudioCLI/Studio.cs | 1 + AssetStudioGUI/AssetStudioGUIForm.Designer.cs | 94 ++-- AssetStudioGUI/AssetStudioGUIForm.cs | 71 ++- AssetStudioGUI/AssetStudioGUIForm.resx | 6 +- AssetStudioGUI/ImportOptionsForm.Designer.cs | 432 ++++++++++++++++++ AssetStudioGUI/ImportOptionsForm.cs | 142 ++++++ AssetStudioGUI/ImportOptionsForm.resx | 123 +++++ .../Properties/Settings.Designer.cs | 12 + AssetStudioGUI/Properties/Settings.settings | 3 + 13 files changed, 866 insertions(+), 160 deletions(-) create mode 100644 AssetStudioGUI/ImportOptionsForm.Designer.cs create mode 100644 AssetStudioGUI/ImportOptionsForm.cs create mode 100644 AssetStudioGUI/ImportOptionsForm.resx diff --git a/AssetStudio/BundleFile.cs b/AssetStudio/BundleFile.cs index de0cc1f..79d44b1 100644 --- a/AssetStudio/BundleFile.cs +++ b/AssetStudio/BundleFile.cs @@ -45,6 +45,7 @@ namespace AssetStudio public class BundleFile { public readonly bool IsDataAfterBundle; + private static TempFileStream _sharedTempFileStream; private readonly ImportOptions.CustomBundleOptions _bundleOptions; public class Header @@ -180,26 +181,29 @@ namespace AssetStudio reader.Position = m_Header.size; } - private Stream CreateBlocksStream(string path) + private Stream CreateBlocksStream() { var uncompressedSizeSum = m_BlocksInfo.Sum(x => x.uncompressedSize); - if (uncompressedSizeSum < int.MaxValue && !_bundleOptions.DecompressToDisk) + if (uncompressedSizeSum < int.MaxValue && !_bundleOptions.DecompressToDisk) return new MemoryStream((int)uncompressedSizeSum); - if (!Directory.Exists(Path.GetDirectoryName(path))) + if (_sharedTempFileStream == null || !_sharedTempFileStream.CanRead) { - var tempDir = Path.Combine(Directory.GetCurrentDirectory(), "Studio_temp"); - Directory.CreateDirectory(tempDir); - var filename = Path.GetFileName(path); - var hash = path.GetHashCode(); - path = Path.Combine(tempDir, $"{filename}_{hash:X}"); + var cachePath = _bundleOptions.CustomCachePath; + if (string.IsNullOrEmpty(cachePath) || !Directory.Exists(cachePath)) + { + throw new NotSupportedException("Cache directory wasn't found. Make sure that the specified path is correct."); + } + var filename = $"studio_{DateTimeOffset.UtcNow.ToUnixTimeSeconds():X}.temp"; + _sharedTempFileStream = new TempFileStream(Path.Combine(cachePath, filename), FileMode.Create); } - return new TempFileStream(path + ".temp", FileMode.Create); + + return new OffsetStream(_sharedTempFileStream, _sharedTempFileStream.Length, uncompressedSizeSum); } private Stream ReadBlocksAndDirectory(FileReader reader) { - var blocksStream = CreateBlocksStream(reader.FullPath); + var blocksStream = CreateBlocksStream(); var isCompressed = m_Header.signature == "UnityWeb"; foreach (var blockInfo in m_BlocksInfo) { @@ -408,7 +412,7 @@ namespace AssetStudio private Stream ReadBlocks(FileReader reader) { var customBlockCompression = _bundleOptions.CustomBlockCompression; - var blocksStream = CreateBlocksStream(reader.FullPath); + var blocksStream = CreateBlocksStream(); var blocksCompression = m_BlocksInfo.Max(x => (CompressionType)(x.flags & StorageBlockFlags.CompressionTypeMask)); var blockSize = (int)m_BlocksInfo.Max(x => x.uncompressedSize); Logger.Debug($"BlockData compression: {blocksCompression}\n" + diff --git a/AssetStudio/CustomOptions/CustomBundleOptions.cs b/AssetStudio/CustomOptions/CustomBundleOptions.cs index cb48643..5e0329e 100644 --- a/AssetStudio/CustomOptions/CustomBundleOptions.cs +++ b/AssetStudio/CustomOptions/CustomBundleOptions.cs @@ -6,31 +6,44 @@ { private CompressionType _customBlockCompression = CompressionType.Auto; private CompressionType _customBlockInfoCompression = CompressionType.Auto; + private string _customCachePath; private bool _decompressToDisk; public CompressionType CustomBlockCompression { get => _customBlockCompression; - set => _customBlockCompression = SetOption(nameof(CustomBlockCompression), value); + set => _customBlockCompression = SetOption(nameof(CustomBlockCompression), value, _customBlockCompression); } public CompressionType CustomBlockInfoCompression { get => _customBlockInfoCompression; - set => _customBlockInfoCompression = SetOption(nameof(CustomBlockInfoCompression), value); + set => _customBlockInfoCompression = SetOption(nameof(CustomBlockInfoCompression), value, _customBlockInfoCompression); + } + + public string CustomCachePath + { + get => _customCachePath; + set => _customCachePath = SetOption(nameof(CustomCachePath), value, _customCachePath); } public bool DecompressToDisk { get => _decompressToDisk; - set => _decompressToDisk = SetOption(nameof(DecompressToDisk), value); + set => _decompressToDisk = SetOption(nameof(DecompressToDisk), value, _decompressToDisk); } public CustomBundleOptions() { } - private static T SetOption(string option, T value) + private static T SetOption(string option, T value, T curValue) { - Logger.Info($"- {option}: {value}"); + if (value.Equals(curValue)) + return curValue; + + var val = string.IsNullOrEmpty(value.ToString()) + ? "None" + : value.ToString(); + Logger.Info($"- {option}: {val}"); return value; } } diff --git a/AssetStudio/OffsetStream.cs b/AssetStudio/OffsetStream.cs index 3a89d94..9446a28 100644 --- a/AssetStudio/OffsetStream.cs +++ b/AssetStudio/OffsetStream.cs @@ -10,7 +10,7 @@ namespace AssetStudio public override bool CanRead => _baseStream.CanRead; public override bool CanSeek => _baseStream.CanSeek; - public override bool CanWrite => false; + public override bool CanWrite => _baseStream.CanWrite; public override long Length => _length > 0 ? _length : _baseStream.Length - _offset; @@ -86,7 +86,7 @@ namespace AssetStudio public override void Write(byte[] buffer, int offset, int count) { - throw new System.NotImplementedException(); + _baseStream.Write(buffer, offset, count); } protected override void Dispose(bool disposing) diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index 37cd044..3f138b3 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -15,6 +15,7 @@ namespace AssetStudioCLI.Options Live2D, FBX, Filter, + Import, Advanced, } @@ -118,14 +119,16 @@ namespace AssetStudioCLI.Options public static Option> o_filterByPathID; public static Option> o_filterByText; public static Option f_filterWithRegex; - //advanced + //import + public static Option o_unityVersion; + public static Option o_cachePath; public static Option o_bundleBlockInfoCompression; public static Option o_bundleBlockCompression; + public static Option f_decompressToDisk; + //advanced public static Option o_maxParallelExportTasks; public static Option o_exportAssetList; public static Option o_assemblyPath; - public static Option o_unityVersion; - public static Option f_decompressToDisk; public static Option f_notRestoreExtensionName; public static Option f_avoidLoadingViaTypetree; public static Option f_rawByteArrayFromMono; @@ -463,12 +466,28 @@ namespace AssetStudioCLI.Options ); #endregion - #region Init Advanced Options + #region Init Import Options + o_unityVersion = new GroupedOption + ( + optionDefaultValue: null, + optionName: "--unity-version ", + optionDescription: "Specify Unity version\n", + optionExample: "Example: \"--unity-version 2017.4.39f1\"\n", + optionHelpGroup: HelpGroups.Import + ); + o_cachePath = new GroupedOption + ( + optionDefaultValue: "temp", + optionName: "--cache-dir ", + optionDescription: "Specify a directory for storing temporary files. Default: .\n", + optionExample: "", + optionHelpGroup: HelpGroups.Import + ); o_bundleBlockInfoCompression = new GroupedOption ( optionDefaultValue: CompressionType.Auto, optionName: "--blockinfo-comp ", - optionDescription: "Specify the compression type of bundle's blockInfo data\n" + + optionDescription: "Specify the compression type of bundle's blockInfo data\n" + "\n" + "Auto - Use compression type specified in an asset bundle\n" + "Zstd - Try to decompress as zstd archive\n" + @@ -476,9 +495,8 @@ namespace AssetStudioCLI.Options "Lz4 - Try to decompress as lz4/lz4hc archive\n" + "Lzma - Try to decompress as lzma archive\n", optionExample: "Example: \"--blockinfo-comp lz4\"\n", - optionHelpGroup: HelpGroups.Advanced + optionHelpGroup: HelpGroups.Import ); - o_bundleBlockCompression = new GroupedOption ( optionDefaultValue: CompressionType.Auto, @@ -491,9 +509,20 @@ namespace AssetStudioCLI.Options "Lz4 - Try to decompress as lz4/lz4hc archive\n" + "Lzma - Try to decompress as lzma archive\n", optionExample: "Example: \"--block-comp zstd\"\n", - optionHelpGroup: HelpGroups.Advanced + optionHelpGroup: HelpGroups.Import ); + f_decompressToDisk = new GroupedOption + ( + optionDefaultValue: false, + optionName: "--decompress-to-disk", + optionDescription: "(Flag) If not specified, only bundles larger than 2GB will be decompressed to disk\ninstead of RAM", + optionExample: "", + optionHelpGroup: HelpGroups.Import, + isFlag: true + ); + #endregion + #region Init Advanced Options o_maxParallelExportTasks = new GroupedOption ( optionDefaultValue: Environment.ProcessorCount - 1, @@ -504,7 +533,6 @@ namespace AssetStudioCLI.Options optionExample: "Example: \"--max-export-tasks 8\"\n", optionHelpGroup: HelpGroups.Advanced ); - o_exportAssetList = new GroupedOption ( optionDefaultValue: ExportListType.None, @@ -523,23 +551,6 @@ namespace AssetStudioCLI.Options optionExample: "", optionHelpGroup: HelpGroups.Advanced ); - o_unityVersion = new GroupedOption - ( - optionDefaultValue: null, - optionName: "--unity-version ", - optionDescription: "Specify Unity version\n", - optionExample: "Example: \"--unity-version 2017.4.39f1\"\n", - optionHelpGroup: HelpGroups.Advanced - ); - f_decompressToDisk = new GroupedOption - ( - optionDefaultValue: false, - optionName: "--decompress-to-disk", - optionDescription: "(Flag) If not specified, only bundles larger than 2GB will be decompressed to disk\ninstead of RAM\n", - optionExample: "", - optionHelpGroup: HelpGroups.Advanced, - isFlag: true - ); f_notRestoreExtensionName = new GroupedOption ( optionDefaultValue: false, @@ -1242,6 +1253,18 @@ namespace AssetStudioCLI.Options return; } break; + case "--cache-dir": + value = Path.GetFullPath(value); + if (Directory.Exists(value)) + { + o_cachePath.Value = value; + } + else + { + Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{option.Color(brightYellow)}] option. Cache folder [{value.Color(brightRed)}] was not found."); + return; + } + break; default: Console.WriteLine($"{"Error:".Color(brightRed)} Unknown option [{option.Color(brightRed)}].\n"); if (!TryFindOptionDescription(option, optionsDict)) @@ -1295,6 +1318,15 @@ namespace AssetStudioCLI.Options } o_outputFolder.Value = fullPath; } + if (o_cachePath.Value == o_cachePath.DefaultValue) + { + var defaultCachePath = Path.Combine(Directory.GetCurrentDirectory(), o_cachePath.DefaultValue + Path.DirectorySeparatorChar); + if (!Directory.Exists(defaultCachePath)) + { + Directory.CreateDirectory(defaultCachePath); + } + o_cachePath.Value = defaultCachePath; + } isParsed = true; } @@ -1416,6 +1448,11 @@ namespace AssetStudioCLI.Options { sb.AppendLine($"# Output Path: \"{o_outputFolder}\""); } + if (f_decompressToDisk.Value || o_cachePath.Value != o_cachePath.DefaultValue) + { + var driveInfo = new DriveInfo(Directory.GetDirectoryRoot(o_cachePath.Value)); + sb.AppendLine($"# Cache Folder: \"{o_cachePath}\" (Free space: {driveInfo.AvailableFreeSpace * 1.0f / 0x40000000:.00}GB)"); + } sb.AppendLine($"# Log Level: {o_logLevel}"); sb.AppendLine($"# Log Output: {o_logOutput}"); sb.AppendLine($"# Bundle BlockInfo Compression Type: {o_bundleBlockInfoCompression}"); diff --git a/AssetStudioCLI/Studio.cs b/AssetStudioCLI/Studio.cs index fba3852..5849680 100644 --- a/AssetStudioCLI/Studio.cs +++ b/AssetStudioCLI/Studio.cs @@ -34,6 +34,7 @@ namespace AssetStudioCLI assetsManager.Options.CustomUnityVersion = CLIOptions.o_unityVersion.Value; assetsManager.Options.BundleOptions.CustomBlockInfoCompression = CLIOptions.o_bundleBlockInfoCompression.Value; assetsManager.Options.BundleOptions.CustomBlockCompression = CLIOptions.o_bundleBlockCompression.Value; + assetsManager.Options.BundleOptions.CustomCachePath = CLIOptions.o_cachePath.Value; assetsManager.Options.BundleOptions.DecompressToDisk = CLIOptions.f_decompressToDisk.Value; assetsManager.OptionLoaders.Clear(); } diff --git a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs index 2f607a9..9c65618 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.Designer.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.Designer.cs @@ -52,12 +52,10 @@ this.specifyUnityVersionTextBox = new System.Windows.Forms.ToolStripTextBox(); this.bundleDecompressionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.alwaysDecompressToDiskToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.blockInfoCompressionTypeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.customBlockInfoCompressionComboBox = new System.Windows.Forms.ToolStripComboBox(); - this.blockCompressionTypeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.customBlockCompressionComboBox = new System.Windows.Forms.ToolStripComboBox(); this.importOptionsToolStripSeparator = new System.Windows.Forms.ToolStripSeparator(); this.saveOptionsToDiskToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.importOptionsToolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.moreOptionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.showExpOpt = new System.Windows.Forms.ToolStripMenuItem(); this.modelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exportAllObjectssplitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); @@ -384,12 +382,10 @@ this.specifyUnityVersionTextBox, this.bundleDecompressionToolStripMenuItem, this.alwaysDecompressToDiskToolStripMenuItem, - this.blockInfoCompressionTypeToolStripMenuItem, - this.customBlockInfoCompressionComboBox, - this.blockCompressionTypeToolStripMenuItem, - this.customBlockCompressionComboBox, this.importOptionsToolStripSeparator, - this.saveOptionsToDiskToolStripMenuItem}); + this.saveOptionsToDiskToolStripMenuItem, + this.importOptionsToolStripSeparator2, + this.moreOptionsToolStripMenuItem}); this.importOptionsToolStripMenuItem.Name = "importOptionsToolStripMenuItem"; this.importOptionsToolStripMenuItem.Size = new System.Drawing.Size(243, 22); this.importOptionsToolStripMenuItem.Text = "Import options"; @@ -401,7 +397,7 @@ this.customUnityVersionToolStripMenuItem.Enabled = false; this.customUnityVersionToolStripMenuItem.Name = "customUnityVersionToolStripMenuItem"; this.customUnityVersionToolStripMenuItem.ShowShortcutKeys = false; - this.customUnityVersionToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.customUnityVersionToolStripMenuItem.Size = new System.Drawing.Size(213, 22); this.customUnityVersionToolStripMenuItem.Text = "Custom Unity version"; // // specifyUnityVersionTextBox @@ -417,7 +413,7 @@ this.bundleDecompressionToolStripMenuItem.Enabled = false; this.bundleDecompressionToolStripMenuItem.Name = "bundleDecompressionToolStripMenuItem"; this.bundleDecompressionToolStripMenuItem.ShowShortcutKeys = false; - this.bundleDecompressionToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.bundleDecompressionToolStripMenuItem.Size = new System.Drawing.Size(213, 22); this.bundleDecompressionToolStripMenuItem.Text = "Bundle Decompression"; // // alwaysDecompressToDiskToolStripMenuItem @@ -425,72 +421,36 @@ this.alwaysDecompressToDiskToolStripMenuItem.CheckOnClick = true; this.alwaysDecompressToDiskToolStripMenuItem.Name = "alwaysDecompressToDiskToolStripMenuItem"; this.alwaysDecompressToDiskToolStripMenuItem.ShowShortcutKeys = false; - this.alwaysDecompressToDiskToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.alwaysDecompressToDiskToolStripMenuItem.Size = new System.Drawing.Size(213, 22); this.alwaysDecompressToDiskToolStripMenuItem.Text = "Always decompress to disk"; this.alwaysDecompressToDiskToolStripMenuItem.ToolTipText = "If not selected, any bundles less than 2GB will be decompressed to RAM"; this.alwaysDecompressToDiskToolStripMenuItem.Click += new System.EventHandler(this.alwaysDecompressToDiskToolStripMenuItem_Click); // - // blockInfoCompressionTypeToolStripMenuItem - // - this.blockInfoCompressionTypeToolStripMenuItem.Enabled = false; - this.blockInfoCompressionTypeToolStripMenuItem.Name = "blockInfoCompressionTypeToolStripMenuItem"; - this.blockInfoCompressionTypeToolStripMenuItem.ShowShortcutKeys = false; - this.blockInfoCompressionTypeToolStripMenuItem.Size = new System.Drawing.Size(217, 22); - this.blockInfoCompressionTypeToolStripMenuItem.Text = "BlockInfo Compression Type"; - // - // customBlockInfoCompressionComboBox - // - this.customBlockInfoCompressionComboBox.DropDownHeight = 80; - this.customBlockInfoCompressionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.customBlockInfoCompressionComboBox.IntegralHeight = false; - this.customBlockInfoCompressionComboBox.Items.AddRange(new object[] { - "Auto", - "Zstd", - "Oodle", - "Lz4/Lz4HC", - "Lzma"}); - this.customBlockInfoCompressionComboBox.Name = "customBlockInfoCompressionComboBox"; - this.customBlockInfoCompressionComboBox.Size = new System.Drawing.Size(121, 23); - this.customBlockInfoCompressionComboBox.ToolTipText = "Selected compression type will override detected type from asset bundle"; - this.customBlockInfoCompressionComboBox.SelectedIndexChanged += new System.EventHandler(this.customBlockInfoCompressionComboBox_SelectedIndexChanged); - // - // blockCompressionTypeToolStripMenuItem - // - this.blockCompressionTypeToolStripMenuItem.Enabled = false; - this.blockCompressionTypeToolStripMenuItem.Name = "blockCompressionTypeToolStripMenuItem"; - this.blockCompressionTypeToolStripMenuItem.ShowShortcutKeys = false; - this.blockCompressionTypeToolStripMenuItem.Size = new System.Drawing.Size(217, 22); - this.blockCompressionTypeToolStripMenuItem.Text = "Block Compression Type"; - // - // customBlockCompressionComboBox - // - this.customBlockCompressionComboBox.DropDownHeight = 80; - this.customBlockCompressionComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.customBlockCompressionComboBox.IntegralHeight = false; - this.customBlockCompressionComboBox.Items.AddRange(new object[] { - "Auto", - "Zstd", - "Oodle", - "Lz4/Lz4HC", - "Lzma"}); - this.customBlockCompressionComboBox.Name = "customBlockCompressionComboBox"; - this.customBlockCompressionComboBox.Size = new System.Drawing.Size(121, 23); - this.customBlockCompressionComboBox.ToolTipText = "Selected compression type will override detected type from asset bundle"; - this.customBlockCompressionComboBox.SelectedIndexChanged += new System.EventHandler(this.customBlockCompressionComboBox_SelectedIndexChanged); - // // importOptionsToolStripSeparator // this.importOptionsToolStripSeparator.Name = "importOptionsToolStripSeparator"; - this.importOptionsToolStripSeparator.Size = new System.Drawing.Size(214, 6); + this.importOptionsToolStripSeparator.Size = new System.Drawing.Size(210, 6); // // saveOptionsToDiskToolStripMenuItem // this.saveOptionsToDiskToolStripMenuItem.Name = "saveOptionsToDiskToolStripMenuItem"; this.saveOptionsToDiskToolStripMenuItem.ShowShortcutKeys = false; - this.saveOptionsToDiskToolStripMenuItem.Size = new System.Drawing.Size(217, 22); - this.saveOptionsToDiskToolStripMenuItem.Text = "Save options to disk"; + this.saveOptionsToDiskToolStripMenuItem.Size = new System.Drawing.Size(213, 22); + this.saveOptionsToDiskToolStripMenuItem.Text = "Save current options to disk"; this.saveOptionsToDiskToolStripMenuItem.Click += new System.EventHandler(this.saveOptionsToDiskToolStripMenuItem_Click); // + // importOptionsToolStripSeparator2 + // + this.importOptionsToolStripSeparator2.Name = "importOptionsToolStripSeparator2"; + this.importOptionsToolStripSeparator2.Size = new System.Drawing.Size(210, 6); + // + // moreOptionsToolStripMenuItem + // + this.moreOptionsToolStripMenuItem.Name = "moreOptionsToolStripMenuItem"; + this.moreOptionsToolStripMenuItem.Size = new System.Drawing.Size(213, 22); + this.moreOptionsToolStripMenuItem.Text = "More options..."; + this.moreOptionsToolStripMenuItem.Click += new System.EventHandler(this.moreOptionsToolStripMenuItem_Click); + // // showExpOpt // this.showExpOpt.Name = "showExpOpt"; @@ -1892,15 +1852,13 @@ private System.Windows.Forms.ToolStripTextBox specifyUnityVersionTextBox; private System.Windows.Forms.ToolStripMenuItem bundleDecompressionToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem alwaysDecompressToDiskToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem blockInfoCompressionTypeToolStripMenuItem; - private System.Windows.Forms.ToolStripComboBox customBlockInfoCompressionComboBox; - private System.Windows.Forms.ToolStripMenuItem blockCompressionTypeToolStripMenuItem; - private System.Windows.Forms.ToolStripComboBox customBlockCompressionComboBox; private System.Windows.Forms.ToolStripMenuItem saveOptionsToDiskToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator importOptionsToolStripSeparator; + private System.Windows.Forms.ToolStripSeparator importOptionsToolStripSeparator2; private System.Windows.Forms.ToolStripMenuItem meshLazyLoadToolStripMenuItem; private System.Windows.Forms.Panel panel2; private System.Windows.Forms.ToolStripMenuItem tvCopyNameToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator importOptionsToolStripSeparator; + private System.Windows.Forms.ToolStripMenuItem moreOptionsToolStripMenuItem; } } diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index e4054af..5eb2adb 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -38,6 +38,7 @@ namespace AssetStudioGUI private DirectBitmap imageTexture; private string tempClipboard; private bool isDarkMode; + private ImportOptionsForm importOptionsForm; #region FMODControl private FMOD.System system; @@ -150,9 +151,8 @@ namespace AssetStudioGUI useDumpTreeViewToolStripMenuItem.Checked = Properties.Settings.Default.useDumpTreeView; autoPlayAudioAssetsToolStripMenuItem.Checked = Properties.Settings.Default.autoplayAudio; meshLazyLoadToolStripMenuItem.Checked = Properties.Settings.Default.meshLazyLoad; - customBlockCompressionComboBox.SelectedIndex = 0; - customBlockInfoCompressionComboBox.SelectedIndex = 0; assetsManager.Options.BundleOptions.DecompressToDisk = Properties.Settings.Default.decompressToDisk; + assetsManager.Options.BundleOptions.CustomCachePath = GetCachePath(); FMODinit(); listSearchFilterMode.SelectedIndex = 0; FbxInitOptions(Properties.Settings.Default.fbxSettings); @@ -174,6 +174,17 @@ namespace AssetStudioGUI Studio.StatusStripUpdate = StatusStripUpdate; } + private static string GetCachePath() + { + var path = Properties.Settings.Default.cachePath; + if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) + { + path = Path.Combine(Directory.GetCurrentDirectory(), "temp"); + Directory.CreateDirectory(path); + } + return path; + } + private void AssetStudioGUIForm_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) @@ -2476,53 +2487,10 @@ namespace AssetStudioGUI specifyUnityVersionTextBox.Text = assetsManager.Options.CustomUnityVersion.FullVersion; } alwaysDecompressToDiskToolStripMenuItem.Checked = assetsManager.Options.BundleOptions.DecompressToDisk; - customBlockInfoCompressionComboBox.SelectedIndex = SetComboBoxIndex(assetsManager.Options.BundleOptions.CustomBlockInfoCompression); - customBlockCompressionComboBox.SelectedIndex = SetComboBoxIndex(assetsManager.Options.BundleOptions.CustomBlockCompression); //highDpi workaround var font = customUnityVersionToolStripMenuItem.Font; specifyUnityVersionTextBox.Font = font; - customBlockInfoCompressionComboBox.Font = font; - customBlockCompressionComboBox.Font = font; - } - - private static int SetComboBoxIndex(CompressionType compressionType) - { - switch (compressionType) - { - case CompressionType.Auto: return 0; - case CompressionType.Lzma: return 4; - case CompressionType.Lz4: - case CompressionType.Lz4HC: return 3; - case CompressionType.Zstd: return 1; - case CompressionType.Oodle: return 2; - default: throw new NotSupportedException(); - } - } - - private void customBlockCompressionComboBox_SelectedIndexChanged(object sender, EventArgs e) - { - var selectedTypeIndex = customBlockCompressionComboBox.SelectedIndex; - assetsManager.Options.BundleOptions.CustomBlockCompression = GetCustomCompressionTypes(selectedTypeIndex); - } - - private void customBlockInfoCompressionComboBox_SelectedIndexChanged(object sender, EventArgs e) - { - var selectedTypeIndex = customBlockInfoCompressionComboBox.SelectedIndex; - assetsManager.Options.BundleOptions.CustomBlockInfoCompression = GetCustomCompressionTypes(selectedTypeIndex); - } - - private static CompressionType GetCustomCompressionTypes(int index) - { - switch (index) - { - case 0: return CompressionType.Auto; - case 1: return CompressionType.Zstd; - case 2: return CompressionType.Oodle; - case 3: return CompressionType.Lz4HC; - case 4: return CompressionType.Lzma; - default: throw new NotSupportedException(); - } } private void alwaysDecompressToDiskToolStripMenuItem_Click(object sender, EventArgs e) @@ -2745,6 +2713,19 @@ namespace AssetStudioGUI } } + private void moreOptionsToolStripMenuItem_Click(object sender, EventArgs e) + { + if (importOptionsForm == null || importOptionsForm.IsDisposed) + { + importOptionsForm = new ImportOptionsForm(assetsManager); + importOptionsForm.Show(this); + } + else + { + importOptionsForm.Focus(); + } + } + #region FMOD private void FMODinit() { diff --git a/AssetStudioGUI/AssetStudioGUIForm.resx b/AssetStudioGUI/AssetStudioGUIForm.resx index cd1b776..fa337eb 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.resx +++ b/AssetStudioGUI/AssetStudioGUIForm.resx @@ -120,6 +120,9 @@ 312, 17 + + 432, 17 + abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWYZ 1234567890.:,;'\"(!?)+-*/= @@ -138,9 +141,6 @@ The quick brown fox jumps over the lazy dog. 1234567890 The quick brown fox jumps over the lazy dog. 1234567890 - - 432, 17 - 775, 21 diff --git a/AssetStudioGUI/ImportOptionsForm.Designer.cs b/AssetStudioGUI/ImportOptionsForm.Designer.cs new file mode 100644 index 0000000..a75e554 --- /dev/null +++ b/AssetStudioGUI/ImportOptionsForm.Designer.cs @@ -0,0 +1,432 @@ +namespace AssetStudioGUI +{ + partial class ImportOptionsForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.cachePathLabel = new System.Windows.Forms.Label(); + this.cachePathSelectButton = new System.Windows.Forms.Button(); + this.cachePathResetButton = new System.Windows.Forms.Button(); + this.unityVersionGroupBox = new System.Windows.Forms.GroupBox(); + this.customUnityVersionTextBox = new System.Windows.Forms.TextBox(); + this.customUnityVersionLabel = new System.Windows.Forms.Label(); + this.unityVerDetectionModePanel = new System.Windows.Forms.Panel(); + this.unityVerAutoRadioButton = new System.Windows.Forms.RadioButton(); + this.unityVerLegacy2RadioButton = new System.Windows.Forms.RadioButton(); + this.unityVerLegacyRadioButton = new System.Windows.Forms.RadioButton(); + this.unityVerDetectionModeLabel = new System.Windows.Forms.Label(); + this.decompressionGroupBox = new System.Windows.Forms.GroupBox(); + this.customBlockCompressionComboBox = new System.Windows.Forms.ComboBox(); + this.customBlockCompressionLabel = new System.Windows.Forms.Label(); + this.customBlockInfoCompressionComboBox = new System.Windows.Forms.ComboBox(); + this.customBlockInfoCompressionLabel = new System.Windows.Forms.Label(); + this.cacheFreeSpaceLabel = new System.Windows.Forms.Label(); + this.alwaysDecompressToDiskCheckBox = new System.Windows.Forms.CheckBox(); + this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.closeButton = new System.Windows.Forms.Button(); + this.saveToDiskButton = new System.Windows.Forms.Button(); + this.applyButton = new System.Windows.Forms.Button(); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.tabPage2 = new System.Windows.Forms.TabPage(); + this.cacheGroupBox = new System.Windows.Forms.GroupBox(); + this.unityVersionGroupBox.SuspendLayout(); + this.unityVerDetectionModePanel.SuspendLayout(); + this.decompressionGroupBox.SuspendLayout(); + this.tabControl1.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.tabPage2.SuspendLayout(); + this.cacheGroupBox.SuspendLayout(); + this.SuspendLayout(); + // + // cachePathLabel + // + this.cachePathLabel.AutoEllipsis = true; + this.cachePathLabel.Location = new System.Drawing.Point(6, 19); + this.cachePathLabel.Name = "cachePathLabel"; + this.cachePathLabel.Size = new System.Drawing.Size(348, 20); + this.cachePathLabel.TabIndex = 0; + this.cachePathLabel.Text = "Cache directory: "; + // + // cachePathSelectButton + // + this.cachePathSelectButton.Location = new System.Drawing.Point(9, 42); + this.cachePathSelectButton.Name = "cachePathSelectButton"; + this.cachePathSelectButton.Size = new System.Drawing.Size(60, 25); + this.cachePathSelectButton.TabIndex = 1; + this.cachePathSelectButton.Text = "Select"; + this.cachePathSelectButton.UseVisualStyleBackColor = false; + this.cachePathSelectButton.Click += new System.EventHandler(this.cachePathSelectButton_Click); + // + // cachePathResetButton + // + this.cachePathResetButton.Location = new System.Drawing.Point(75, 42); + this.cachePathResetButton.Name = "cachePathResetButton"; + this.cachePathResetButton.Size = new System.Drawing.Size(60, 25); + this.cachePathResetButton.TabIndex = 2; + this.cachePathResetButton.Text = "Reset"; + this.cachePathResetButton.UseVisualStyleBackColor = false; + this.cachePathResetButton.Click += new System.EventHandler(this.cachePathResetButton_Click); + // + // unityVersionGroupBox + // + this.unityVersionGroupBox.Controls.Add(this.customUnityVersionTextBox); + this.unityVersionGroupBox.Controls.Add(this.customUnityVersionLabel); + this.unityVersionGroupBox.Controls.Add(this.unityVerDetectionModePanel); + this.unityVersionGroupBox.Controls.Add(this.unityVerDetectionModeLabel); + this.unityVersionGroupBox.Dock = System.Windows.Forms.DockStyle.Top; + this.unityVersionGroupBox.Location = new System.Drawing.Point(3, 3); + this.unityVersionGroupBox.Name = "unityVersionGroupBox"; + this.unityVersionGroupBox.Size = new System.Drawing.Size(357, 126); + this.unityVersionGroupBox.TabIndex = 0; + this.unityVersionGroupBox.TabStop = false; + this.unityVersionGroupBox.Text = "Unity version"; + // + // customUnityVersionTextBox + // + this.customUnityVersionTextBox.Location = new System.Drawing.Point(137, 20); + this.customUnityVersionTextBox.Name = "customUnityVersionTextBox"; + this.customUnityVersionTextBox.Size = new System.Drawing.Size(121, 23); + this.customUnityVersionTextBox.TabIndex = 1; + this.toolTip1.SetToolTip(this.customUnityVersionTextBox, "Specify full Unity version, including letters at the end\r\nExample: 2017.4.39f1\r\n"); + // + // customUnityVersionLabel + // + this.customUnityVersionLabel.AutoSize = true; + this.customUnityVersionLabel.Location = new System.Drawing.Point(6, 23); + this.customUnityVersionLabel.Name = "customUnityVersionLabel"; + this.customUnityVersionLabel.Size = new System.Drawing.Size(124, 15); + this.customUnityVersionLabel.TabIndex = 0; + this.customUnityVersionLabel.Text = "Custom Unity version:"; + this.toolTip1.SetToolTip(this.customUnityVersionLabel, "Specify full Unity version, including letters at the end\r\nExample: 2017.4.39f1\r\n"); + // + // unityVerDetectionModePanel + // + this.unityVerDetectionModePanel.Controls.Add(this.unityVerAutoRadioButton); + this.unityVerDetectionModePanel.Controls.Add(this.unityVerLegacy2RadioButton); + this.unityVerDetectionModePanel.Controls.Add(this.unityVerLegacyRadioButton); + this.unityVerDetectionModePanel.Location = new System.Drawing.Point(35, 75); + this.unityVerDetectionModePanel.Name = "unityVerDetectionModePanel"; + this.unityVerDetectionModePanel.Size = new System.Drawing.Size(289, 34); + this.unityVerDetectionModePanel.TabIndex = 3; + // + // unityVerAutoRadioButton + // + this.unityVerAutoRadioButton.AutoSize = true; + this.unityVerAutoRadioButton.Dock = System.Windows.Forms.DockStyle.Left; + this.unityVerAutoRadioButton.Location = new System.Drawing.Point(152, 0); + this.unityVerAutoRadioButton.Name = "unityVerAutoRadioButton"; + this.unityVerAutoRadioButton.Padding = new System.Windows.Forms.Padding(0, 0, 5, 0); + this.unityVerAutoRadioButton.Size = new System.Drawing.Size(103, 34); + this.unityVerAutoRadioButton.TabIndex = 2; + this.unityVerAutoRadioButton.TabStop = true; + this.unityVerAutoRadioButton.Text = "Auto/Custom"; + this.unityVerAutoRadioButton.UseVisualStyleBackColor = true; + // + // unityVerLegacy2RadioButton + // + this.unityVerLegacy2RadioButton.AutoSize = true; + this.unityVerLegacy2RadioButton.Dock = System.Windows.Forms.DockStyle.Left; + this.unityVerLegacy2RadioButton.Enabled = false; + this.unityVerLegacy2RadioButton.Location = new System.Drawing.Point(76, 0); + this.unityVerLegacy2RadioButton.Name = "unityVerLegacy2RadioButton"; + this.unityVerLegacy2RadioButton.Padding = new System.Windows.Forms.Padding(0, 0, 5, 0); + this.unityVerLegacy2RadioButton.Size = new System.Drawing.Size(76, 34); + this.unityVerLegacy2RadioButton.TabIndex = 1; + this.unityVerLegacy2RadioButton.TabStop = true; + this.unityVerLegacy2RadioButton.Text = "Legacy 2"; + this.toolTip1.SetToolTip(this.unityVerLegacy2RadioButton, "WIP"); + this.unityVerLegacy2RadioButton.UseVisualStyleBackColor = true; + // + // unityVerLegacyRadioButton + // + this.unityVerLegacyRadioButton.AutoSize = true; + this.unityVerLegacyRadioButton.Dock = System.Windows.Forms.DockStyle.Left; + this.unityVerLegacyRadioButton.Enabled = false; + this.unityVerLegacyRadioButton.Location = new System.Drawing.Point(0, 0); + this.unityVerLegacyRadioButton.Name = "unityVerLegacyRadioButton"; + this.unityVerLegacyRadioButton.Padding = new System.Windows.Forms.Padding(0, 0, 5, 0); + this.unityVerLegacyRadioButton.Size = new System.Drawing.Size(76, 34); + this.unityVerLegacyRadioButton.TabIndex = 0; + this.unityVerLegacyRadioButton.TabStop = true; + this.unityVerLegacyRadioButton.Text = "Legacy 1"; + this.toolTip1.SetToolTip(this.unityVerLegacyRadioButton, "WIP"); + this.unityVerLegacyRadioButton.UseVisualStyleBackColor = true; + // + // unityVerDetectionModeLabel + // + this.unityVerDetectionModeLabel.AutoSize = true; + this.unityVerDetectionModeLabel.Location = new System.Drawing.Point(6, 57); + this.unityVerDetectionModeLabel.Name = "unityVerDetectionModeLabel"; + this.unityVerDetectionModeLabel.Size = new System.Drawing.Size(92, 15); + this.unityVerDetectionModeLabel.TabIndex = 2; + this.unityVerDetectionModeLabel.Text = "Detection mode"; + this.toolTip1.SetToolTip(this.unityVerDetectionModeLabel, "WIP"); + // + // decompressionGroupBox + // + this.decompressionGroupBox.Controls.Add(this.customBlockCompressionComboBox); + this.decompressionGroupBox.Controls.Add(this.customBlockCompressionLabel); + this.decompressionGroupBox.Controls.Add(this.customBlockInfoCompressionComboBox); + this.decompressionGroupBox.Controls.Add(this.customBlockInfoCompressionLabel); + this.decompressionGroupBox.Dock = System.Windows.Forms.DockStyle.Top; + this.decompressionGroupBox.Location = new System.Drawing.Point(3, 126); + this.decompressionGroupBox.Name = "decompressionGroupBox"; + this.decompressionGroupBox.Size = new System.Drawing.Size(357, 92); + this.decompressionGroupBox.TabIndex = 1; + this.decompressionGroupBox.TabStop = false; + this.decompressionGroupBox.Text = "Decompression options"; + // + // customBlockCompressionComboBox + // + this.customBlockCompressionComboBox.FormattingEnabled = true; + this.customBlockCompressionComboBox.Items.AddRange(new object[] { + "Auto", + "Zstd", + "Oodle", + "Lz4/Lz4HC", + "Lzma"}); + this.customBlockCompressionComboBox.Location = new System.Drawing.Point(166, 51); + this.customBlockCompressionComboBox.Name = "customBlockCompressionComboBox"; + this.customBlockCompressionComboBox.Size = new System.Drawing.Size(121, 23); + this.customBlockCompressionComboBox.TabIndex = 3; + this.toolTip1.SetToolTip(this.customBlockCompressionComboBox, "Selected compression type will override detected type from an asset bundle"); + // + // customBlockCompressionLabel + // + this.customBlockCompressionLabel.AutoSize = true; + this.customBlockCompressionLabel.Location = new System.Drawing.Point(6, 54); + this.customBlockCompressionLabel.Name = "customBlockCompressionLabel"; + this.customBlockCompressionLabel.Size = new System.Drawing.Size(133, 15); + this.customBlockCompressionLabel.TabIndex = 2; + this.customBlockCompressionLabel.Text = "Block compression type"; + // + // customBlockInfoCompressionComboBox + // + this.customBlockInfoCompressionComboBox.FormattingEnabled = true; + this.customBlockInfoCompressionComboBox.Items.AddRange(new object[] { + "Auto", + "Zstd", + "Oodle", + "Lz4/Lz4HC", + "Lzma"}); + this.customBlockInfoCompressionComboBox.Location = new System.Drawing.Point(166, 22); + this.customBlockInfoCompressionComboBox.Name = "customBlockInfoCompressionComboBox"; + this.customBlockInfoCompressionComboBox.Size = new System.Drawing.Size(121, 23); + this.customBlockInfoCompressionComboBox.TabIndex = 1; + this.toolTip1.SetToolTip(this.customBlockInfoCompressionComboBox, "Selected compression type will override detected type from an asset bundle"); + // + // customBlockInfoCompressionLabel + // + this.customBlockInfoCompressionLabel.AutoSize = true; + this.customBlockInfoCompressionLabel.Location = new System.Drawing.Point(6, 25); + this.customBlockInfoCompressionLabel.Name = "customBlockInfoCompressionLabel"; + this.customBlockInfoCompressionLabel.Size = new System.Drawing.Size(154, 15); + this.customBlockInfoCompressionLabel.TabIndex = 0; + this.customBlockInfoCompressionLabel.Text = "BlockInfo compression type"; + // + // cacheFreeSpaceLabel + // + this.cacheFreeSpaceLabel.AutoSize = true; + this.cacheFreeSpaceLabel.Location = new System.Drawing.Point(160, 47); + this.cacheFreeSpaceLabel.Name = "cacheFreeSpaceLabel"; + this.cacheFreeSpaceLabel.Size = new System.Drawing.Size(91, 15); + this.cacheFreeSpaceLabel.TabIndex = 3; + this.cacheFreeSpaceLabel.Text = "Available space:"; + // + // alwaysDecompressToDiskCheckBox + // + this.alwaysDecompressToDiskCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.alwaysDecompressToDiskCheckBox.Location = new System.Drawing.Point(9, 82); + this.alwaysDecompressToDiskCheckBox.Name = "alwaysDecompressToDiskCheckBox"; + this.alwaysDecompressToDiskCheckBox.Size = new System.Drawing.Size(345, 19); + this.alwaysDecompressToDiskCheckBox.TabIndex = 4; + this.alwaysDecompressToDiskCheckBox.Text = "Always decompress asset bundles to disk (cache dir)"; + this.toolTip1.SetToolTip(this.alwaysDecompressToDiskCheckBox, "If not selected, any bundles less than 2GB will be decompressed to RAM"); + this.alwaysDecompressToDiskCheckBox.UseVisualStyleBackColor = true; + // + // closeButton + // + this.closeButton.AutoSize = true; + this.closeButton.BackColor = System.Drawing.SystemColors.ButtonFace; + this.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.closeButton.Location = new System.Drawing.Point(294, 336); + this.closeButton.Margin = new System.Windows.Forms.Padding(3, 6, 3, 6); + this.closeButton.Name = "closeButton"; + this.closeButton.Size = new System.Drawing.Size(88, 27); + this.closeButton.TabIndex = 3; + this.closeButton.Text = "Close"; + this.closeButton.UseVisualStyleBackColor = false; + this.closeButton.Click += new System.EventHandler(this.closeButton_Click); + // + // saveToDiskButton + // + this.saveToDiskButton.AutoSize = true; + this.saveToDiskButton.BackColor = System.Drawing.SystemColors.ButtonFace; + this.saveToDiskButton.Location = new System.Drawing.Point(12, 336); + this.saveToDiskButton.Margin = new System.Windows.Forms.Padding(3, 6, 3, 6); + this.saveToDiskButton.Name = "saveToDiskButton"; + this.saveToDiskButton.Size = new System.Drawing.Size(89, 27); + this.saveToDiskButton.TabIndex = 1; + this.saveToDiskButton.Text = "Save to disk"; + this.saveToDiskButton.UseVisualStyleBackColor = false; + this.saveToDiskButton.Click += new System.EventHandler(this.saveToDiskButton_Click); + // + // applyButton + // + this.applyButton.AutoSize = true; + this.applyButton.BackColor = System.Drawing.SystemColors.ButtonFace; + this.applyButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.applyButton.Location = new System.Drawing.Point(200, 336); + this.applyButton.Margin = new System.Windows.Forms.Padding(3, 6, 3, 6); + this.applyButton.Name = "applyButton"; + this.applyButton.Size = new System.Drawing.Size(88, 27); + this.applyButton.TabIndex = 2; + this.applyButton.Text = "Apply"; + this.applyButton.UseVisualStyleBackColor = false; + this.applyButton.Click += new System.EventHandler(this.applyButton_Click); + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage2); + this.tabControl1.Location = new System.Drawing.Point(12, 12); + this.tabControl1.Margin = new System.Windows.Forms.Padding(12); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(371, 319); + this.tabControl1.TabIndex = 0; + // + // tabPage1 + // + this.tabPage1.BackColor = System.Drawing.SystemColors.Menu; + this.tabPage1.Controls.Add(this.unityVersionGroupBox); + this.tabPage1.Location = new System.Drawing.Point(4, 24); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(363, 291); + this.tabPage1.TabIndex = 0; + this.tabPage1.Text = "General"; + // + // tabPage2 + // + this.tabPage2.BackColor = System.Drawing.SystemColors.Menu; + this.tabPage2.Controls.Add(this.decompressionGroupBox); + this.tabPage2.Controls.Add(this.cacheGroupBox); + this.tabPage2.Location = new System.Drawing.Point(4, 24); + this.tabPage2.Name = "tabPage2"; + this.tabPage2.Padding = new System.Windows.Forms.Padding(3); + this.tabPage2.Size = new System.Drawing.Size(363, 291); + this.tabPage2.TabIndex = 1; + this.tabPage2.Text = "Asset Bundles"; + // + // cacheGroupBox + // + this.cacheGroupBox.AutoSize = true; + this.cacheGroupBox.Controls.Add(this.alwaysDecompressToDiskCheckBox); + this.cacheGroupBox.Controls.Add(this.cacheFreeSpaceLabel); + this.cacheGroupBox.Controls.Add(this.cachePathLabel); + this.cacheGroupBox.Controls.Add(this.cachePathSelectButton); + this.cacheGroupBox.Controls.Add(this.cachePathResetButton); + this.cacheGroupBox.Dock = System.Windows.Forms.DockStyle.Top; + this.cacheGroupBox.Location = new System.Drawing.Point(3, 3); + this.cacheGroupBox.Name = "cacheGroupBox"; + this.cacheGroupBox.Size = new System.Drawing.Size(357, 123); + this.cacheGroupBox.TabIndex = 0; + this.cacheGroupBox.TabStop = false; + this.cacheGroupBox.Text = "Disk cache"; + // + // ImportOptionsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.AutoSize = true; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.BackColor = System.Drawing.SystemColors.Menu; + this.CancelButton = this.closeButton; + this.ClientSize = new System.Drawing.Size(394, 372); + this.Controls.Add(this.tabControl1); + this.Controls.Add(this.applyButton); + this.Controls.Add(this.saveToDiskButton); + this.Controls.Add(this.closeButton); + this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.MaximizeBox = false; + this.Name = "ImportOptionsForm"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Import options"; + this.unityVersionGroupBox.ResumeLayout(false); + this.unityVersionGroupBox.PerformLayout(); + this.unityVerDetectionModePanel.ResumeLayout(false); + this.unityVerDetectionModePanel.PerformLayout(); + this.decompressionGroupBox.ResumeLayout(false); + this.decompressionGroupBox.PerformLayout(); + this.tabControl1.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.tabPage2.ResumeLayout(false); + this.tabPage2.PerformLayout(); + this.cacheGroupBox.ResumeLayout(false); + this.cacheGroupBox.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label cachePathLabel; + private System.Windows.Forms.Button cachePathSelectButton; + private System.Windows.Forms.Button cachePathResetButton; + private System.Windows.Forms.GroupBox unityVersionGroupBox; + private System.Windows.Forms.GroupBox decompressionGroupBox; + private System.Windows.Forms.ToolTip toolTip1; + private System.Windows.Forms.ComboBox customBlockInfoCompressionComboBox; + private System.Windows.Forms.Label customBlockInfoCompressionLabel; + private System.Windows.Forms.TextBox customUnityVersionTextBox; + private System.Windows.Forms.Label customUnityVersionLabel; + private System.Windows.Forms.ComboBox customBlockCompressionComboBox; + private System.Windows.Forms.Label customBlockCompressionLabel; + private System.Windows.Forms.CheckBox alwaysDecompressToDiskCheckBox; + private System.Windows.Forms.Button closeButton; + private System.Windows.Forms.Button saveToDiskButton; + private System.Windows.Forms.Button applyButton; + private System.Windows.Forms.Label cacheFreeSpaceLabel; + private System.Windows.Forms.Panel unityVerDetectionModePanel; + private System.Windows.Forms.RadioButton unityVerAutoRadioButton; + private System.Windows.Forms.RadioButton unityVerLegacy2RadioButton; + private System.Windows.Forms.RadioButton unityVerLegacyRadioButton; + private System.Windows.Forms.Label unityVerDetectionModeLabel; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage2; + private System.Windows.Forms.GroupBox cacheGroupBox; + } +} \ No newline at end of file diff --git a/AssetStudioGUI/ImportOptionsForm.cs b/AssetStudioGUI/ImportOptionsForm.cs new file mode 100644 index 0000000..82af90c --- /dev/null +++ b/AssetStudioGUI/ImportOptionsForm.cs @@ -0,0 +1,142 @@ +using AssetStudio; +using System; +using System.Diagnostics; +using System.IO; +using System.Windows.Forms; + +namespace AssetStudioGUI +{ + public partial class ImportOptionsForm : Form + { + private readonly AssetsManager _assetsManager; + private string _cachePath; + + public ImportOptionsForm(AssetsManager assetsManager) + { + InitializeComponent(); + _assetsManager = assetsManager; + if (assetsManager.Options.CustomUnityVersion != null) + { + customUnityVersionTextBox.Text = assetsManager.Options.CustomUnityVersion.FullVersion; + } + unityVerAutoRadioButton.Checked = true; + cachePathLabel.AutoSize = IsWine; //to disable AutoEllipsis in Wine + _cachePath = _assetsManager.Options.BundleOptions.CustomCachePath; + DisplayCachePath(); + alwaysDecompressToDiskCheckBox.Checked = assetsManager.Options.BundleOptions.DecompressToDisk; + customBlockInfoCompressionComboBox.SelectedIndex = SetComboBoxIndex(assetsManager.Options.BundleOptions.CustomBlockInfoCompression); + customBlockCompressionComboBox.SelectedIndex = SetComboBoxIndex(assetsManager.Options.BundleOptions.CustomBlockCompression); + } + + private void ApplyOptions() + { + if (string.IsNullOrEmpty(customUnityVersionTextBox.Text)) + { + _assetsManager.Options.CustomUnityVersion = null; + } + else + { + try + { + _assetsManager.Options.CustomUnityVersion = new UnityVersion(customUnityVersionTextBox.Text); + } + catch (Exception ex) + { + Logger.Error(ex.Message); + } + } + + _assetsManager.Options.BundleOptions.CustomCachePath = _cachePath; + Properties.Settings.Default.cachePath = _cachePath; + + var blockCompression = GetCustomCompressionTypes(customBlockCompressionComboBox.SelectedIndex); + _assetsManager.Options.BundleOptions.CustomBlockCompression = blockCompression; + var blockInfoCompression = GetCustomCompressionTypes(customBlockInfoCompressionComboBox.SelectedIndex); + _assetsManager.Options.BundleOptions.CustomBlockInfoCompression = blockInfoCompression; + + var decompressToDisk = alwaysDecompressToDiskCheckBox.Checked; + _assetsManager.Options.BundleOptions.DecompressToDisk = decompressToDisk; + Properties.Settings.Default.decompressToDisk = decompressToDisk; + + Properties.Settings.Default.Save(); + } + + private static CompressionType GetCustomCompressionTypes(int index) + { + switch (index) + { + case 0: return CompressionType.Auto; + case 1: return CompressionType.Zstd; + case 2: return CompressionType.Oodle; + case 3: return CompressionType.Lz4HC; + case 4: return CompressionType.Lzma; + default: throw new NotSupportedException(); + } + } + + private static int SetComboBoxIndex(CompressionType compressionType) + { + switch (compressionType) + { + case CompressionType.Auto: return 0; + case CompressionType.Lzma: return 4; + case CompressionType.Lz4: + case CompressionType.Lz4HC: return 3; + case CompressionType.Zstd: return 1; + case CompressionType.Oodle: return 2; + default: throw new NotSupportedException(); + } + } + + private void DisplayCachePath() + { + cachePathLabel.Text = $"Cache directory: {_cachePath}"; + toolTip1.SetToolTip(cachePathLabel, _cachePath); + var driveInfo = new DriveInfo(Directory.GetDirectoryRoot(_cachePath)); + cacheFreeSpaceLabel.Text = $"Available space: {driveInfo.AvailableFreeSpace * 1.0f / 0x40000000:.00}GB"; + } + + private void cachePathSelectButton_Click(object sender, EventArgs e) + { + var cachePathFolderDialog = new OpenFolderDialog(); + cachePathFolderDialog.Title = "Select the cache directory"; + if (cachePathFolderDialog.ShowDialog(this) != DialogResult.OK) + return; + + _cachePath = cachePathFolderDialog.Folder; + DisplayCachePath(); + } + + private void cachePathResetButton_Click(object sender, EventArgs e) + { + _cachePath = Path.Combine(Directory.GetCurrentDirectory(), "temp"); + if (!Directory.Exists(_cachePath)) + Directory.CreateDirectory(_cachePath); + DisplayCachePath(); + } + + private void saveToDiskButton_Click(object sender, EventArgs e) + { + ApplyOptions(); + var saveFolderDialog = new OpenFolderDialog(); + saveFolderDialog.Title = "Select the save folder"; + if (saveFolderDialog.ShowDialog(this) == DialogResult.OK) + { + var savePath = saveFolderDialog.Folder; + _assetsManager.Options.SaveToFile(savePath); + } + } + + private void closeButton_Click(object sender, EventArgs e) + { + Close(); + } + + private void applyButton_Click(object sender, EventArgs e) + { + ApplyOptions(); + } + + private static bool IsWine => Process.GetProcessesByName("winlogon").Length == 0; + } +} diff --git a/AssetStudioGUI/ImportOptionsForm.resx b/AssetStudioGUI/ImportOptionsForm.resx new file mode 100644 index 0000000..df8339b --- /dev/null +++ b/AssetStudioGUI/ImportOptionsForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/AssetStudioGUI/Properties/Settings.Designer.cs b/AssetStudioGUI/Properties/Settings.Designer.cs index a9a86b7..173e4fc 100644 --- a/AssetStudioGUI/Properties/Settings.Designer.cs +++ b/AssetStudioGUI/Properties/Settings.Designer.cs @@ -370,5 +370,17 @@ namespace AssetStudioGUI.Properties { this["rawByteArrayFromMono"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string cachePath { + get { + return ((string)(this["cachePath"])); + } + set { + this["cachePath"] = value; + } + } } } diff --git a/AssetStudioGUI/Properties/Settings.settings b/AssetStudioGUI/Properties/Settings.settings index cb25a17..c632f8f 100644 --- a/AssetStudioGUI/Properties/Settings.settings +++ b/AssetStudioGUI/Properties/Settings.settings @@ -89,5 +89,8 @@ False + + + \ No newline at end of file