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
This commit is contained in:
VaDiM
2026-02-22 00:40:19 +03:00
parent ab5b81d01e
commit 0ae33f995f
13 changed files with 866 additions and 160 deletions
+15 -11
View File
@@ -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" +
@@ -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<T>(string option, T value)
private static T SetOption<T>(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;
}
}
+2 -2
View File
@@ -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)