Merge branch 'Perfare_master' into AssetStudio-mod

This commit is contained in:
VaDiM 2021-12-28 02:36:50 +02:00
commit 74f2c3190b
4 changed files with 68 additions and 13 deletions

View File

@ -12,6 +12,7 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'net472' ">
<PackageReference Include="System.Memory" Version="4.5.4" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.1.11" />
</ItemGroup>

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using static AssetStudio.ImportHelper;
@ -84,6 +85,9 @@ namespace AssetStudio
case FileType.BrotliFile:
LoadFile(DecompressBrotli(reader));
break;
case FileType.ZipFile:
LoadZipFile(reader);
break;
}
}
@ -91,7 +95,7 @@ namespace AssetStudio
{
if (!assetsFileListHash.Contains(reader.FileName))
{
Logger.Info($"Loading {reader.FileName}");
Logger.Info($"Loading {reader.FullPath}");
try
{
var assetsFile = new SerializedFile(reader, this);
@ -125,12 +129,13 @@ namespace AssetStudio
}
catch (Exception e)
{
Logger.Error($"Error while reading assets file {reader.FileName}", e);
Logger.Error($"Error while reading assets file {reader.FullPath}", e);
reader.Dispose();
}
}
else
{
Logger.Info($"Skipping {reader.FullPath}");
reader.Dispose();
}
}
@ -153,15 +158,17 @@ namespace AssetStudio
}
catch (Exception e)
{
Logger.Error($"Error while reading assets file {reader.FileName} from {Path.GetFileName(originalPath)}", e);
Logger.Error($"Error while reading assets file {reader.FullPath} from {Path.GetFileName(originalPath)}", e);
resourceFileReaders.Add(reader.FileName, reader);
}
}
else
Logger.Info($"Skipping {originalPath} ({reader.FileName})");
}
private void LoadBundleFile(FileReader reader, string originalPath = null)
{
Logger.Info("Loading " + reader.FileName);
Logger.Info("Loading " + reader.FullPath);
try
{
var bundleFile = new BundleFile(reader);
@ -181,7 +188,7 @@ namespace AssetStudio
}
catch (Exception e)
{
var str = $"Error while reading bundle file {reader.FileName}";
var str = $"Error while reading bundle file {reader.FullPath}";
if (originalPath != null)
{
str += $" from {Path.GetFileName(originalPath)}";
@ -196,7 +203,7 @@ namespace AssetStudio
private void LoadWebFile(FileReader reader)
{
Logger.Info("Loading " + reader.FileName);
Logger.Info("Loading " + reader.FullPath);
try
{
var webFile = new WebFile(reader);
@ -223,7 +230,49 @@ namespace AssetStudio
}
catch (Exception e)
{
Logger.Error($"Error while reading web file {reader.FileName}", e);
Logger.Error($"Error while reading web file {reader.FullPath}", e);
}
finally
{
reader.Dispose();
}
}
private void LoadZipFile(FileReader reader)
{
Logger.Info("Loading " + reader.FileName);
try
{
using (ZipArchive archive = new ZipArchive(reader.BaseStream, ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
try
{
string dummyPath = Path.Combine(Path.GetDirectoryName(reader.FullPath), reader.FileName, entry.FullName);
// create a new stream
// - to store the deflated stream in
// - to keep the data for later extraction
Stream streamReader = new MemoryStream();
using (Stream entryStream = entry.Open())
{
entryStream.CopyTo(streamReader);
}
streamReader.Position = 0;
FileReader entryReader = new FileReader(dummyPath, streamReader);
LoadFile(entryReader);
}
catch (Exception e)
{
Logger.Error($"Error while reading zip entry {entry.FullName}", e);
}
}
}
}
catch (Exception e)
{
Logger.Error($"Error while reading zip file {reader.FileName}", e);
}
finally
{
@ -373,6 +422,7 @@ namespace AssetStudio
var sb = new StringBuilder();
sb.AppendLine("Unable to load object")
.AppendLine($"Assets {assetsFile.fileName}")
.AppendLine($"Path {assetsFile.originalPath}")
.AppendLine($"Type {objectReader.type}")
.AppendLine($"PathID {objectInfo.m_PathID}")
.Append(e);

View File

@ -11,6 +11,8 @@ namespace AssetStudio
private static readonly byte[] gzipMagic = { 0x1f, 0x8b };
private static readonly byte[] brotliMagic = { 0x62, 0x72, 0x6F, 0x74, 0x6C, 0x69 };
private static readonly byte[] zipMagic = { 0x50, 0x4B, 0x03, 0x04 };
private static readonly byte[] zipSpannedMagic = { 0x50, 0x4B, 0x07, 0x08 };
public FileReader(string path) : this(path, File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { }
@ -36,7 +38,7 @@ namespace AssetStudio
return FileType.WebFile;
default:
{
var magic = ReadBytes(2);
byte[] magic = ReadBytes(2);
Position = 0;
if (gzipMagic.SequenceEqual(magic))
{
@ -53,10 +55,11 @@ namespace AssetStudio
{
return FileType.AssetsFile;
}
else
{
return FileType.ResourceFile;
}
magic = ReadBytes(4);
Position = 0;
if (zipMagic.SequenceEqual(magic) || zipSpannedMagic.SequenceEqual(magic))
return FileType.ZipFile;
return FileType.ResourceFile;
}
}
}

View File

@ -13,6 +13,7 @@ namespace AssetStudio
WebFile,
ResourceFile,
GZipFile,
BrotliFile
BrotliFile,
ZipFile
}
}