mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-15 19:28:48 -05:00
Extract fileList to a separate class
This commit is contained in:
@@ -360,7 +360,7 @@ namespace AssetStudio
|
|||||||
|
|
||||||
private bool LoadBundleFiles(FileReader reader, BundleFile bundleFile, string originalPath = null)
|
private bool LoadBundleFiles(FileReader reader, BundleFile bundleFile, string originalPath = null)
|
||||||
{
|
{
|
||||||
foreach (var file in bundleFile.fileList)
|
foreach (var file in bundleFile.FileList)
|
||||||
{
|
{
|
||||||
if (file.stream == null)
|
if (file.stream == null)
|
||||||
continue;
|
continue;
|
||||||
@@ -386,7 +386,7 @@ namespace AssetStudio
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var webFile = new WebFile(reader);
|
var webFile = new WebFile(reader);
|
||||||
foreach (var file in webFile.fileList)
|
foreach (var file in webFile.FileList)
|
||||||
{
|
{
|
||||||
var dummyPath = Path.Combine(Path.GetDirectoryName(reader.FullPath), file.fileName);
|
var dummyPath = Path.Combine(Path.GetDirectoryName(reader.FullPath), file.fileName);
|
||||||
var subReader = new FileReader(dummyPath, file.stream);
|
var subReader = new FileReader(dummyPath, file.stream);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using AssetStudio.CustomOptions;
|
using AssetStudio.CustomOptions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -42,7 +41,7 @@ namespace AssetStudio
|
|||||||
Oodle, //custom
|
Oodle, //custom
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BundleFile
|
public class BundleFile : FileArchive
|
||||||
{
|
{
|
||||||
public readonly bool IsDataAfterBundle;
|
public readonly bool IsDataAfterBundle;
|
||||||
private static TempFileStream _sharedTempFileStream;
|
private static TempFileStream _sharedTempFileStream;
|
||||||
@@ -79,8 +78,6 @@ namespace AssetStudio
|
|||||||
private StorageBlock[] m_BlocksInfo;
|
private StorageBlock[] m_BlocksInfo;
|
||||||
private Node[] m_DirectoryInfo;
|
private Node[] m_DirectoryInfo;
|
||||||
|
|
||||||
public List<StreamFile> fileList;
|
|
||||||
|
|
||||||
public BundleFile(FileReader reader, ImportOptions importOptions, bool isMultiBundle = false)
|
public BundleFile(FileReader reader, ImportOptions importOptions, bool isMultiBundle = false)
|
||||||
{
|
{
|
||||||
_bundleOptions = importOptions.BundleOptions;
|
_bundleOptions = importOptions.BundleOptions;
|
||||||
@@ -240,11 +237,10 @@ namespace AssetStudio
|
|||||||
|
|
||||||
private void ReadFiles(Stream inputStream, long blocksOffset = 0)
|
private void ReadFiles(Stream inputStream, long blocksOffset = 0)
|
||||||
{
|
{
|
||||||
fileList = new List<StreamFile>(m_DirectoryInfo.Length);
|
|
||||||
foreach (var node in m_DirectoryInfo)
|
foreach (var node in m_DirectoryInfo)
|
||||||
{
|
{
|
||||||
var file = new StreamFile();
|
var file = new StreamFile();
|
||||||
fileList.Add(file);
|
this.FileList.Add(file);
|
||||||
file.path = node.path;
|
file.path = node.path;
|
||||||
file.fileName = Path.GetFileName(node.path);
|
file.fileName = Path.GetFileName(node.path);
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AssetStudio
|
||||||
|
{
|
||||||
|
public abstract class FileArchive
|
||||||
|
{
|
||||||
|
public readonly List<StreamFile> FileList = new List<StreamFile>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,8 @@ using System.Text;
|
|||||||
|
|
||||||
namespace AssetStudio
|
namespace AssetStudio
|
||||||
{
|
{
|
||||||
public class WebFile
|
public class WebFile : FileArchive
|
||||||
{
|
{
|
||||||
public List<StreamFile> fileList;
|
|
||||||
|
|
||||||
private class WebData
|
private class WebData
|
||||||
{
|
{
|
||||||
public int dataOffset;
|
public int dataOffset;
|
||||||
@@ -30,15 +28,14 @@ namespace AssetStudio
|
|||||||
data.path = Encoding.UTF8.GetString(reader.ReadBytes(pathLength));
|
data.path = Encoding.UTF8.GetString(reader.ReadBytes(pathLength));
|
||||||
dataList.Add(data);
|
dataList.Add(data);
|
||||||
}
|
}
|
||||||
fileList = new List<StreamFile>(dataList.Count);
|
|
||||||
foreach (var data in dataList)
|
foreach (var data in dataList)
|
||||||
{
|
{
|
||||||
var file = new StreamFile();
|
var file = new StreamFile();
|
||||||
|
this.FileList.Add(file);
|
||||||
file.path = data.path;
|
file.path = data.path;
|
||||||
file.fileName = Path.GetFileName(data.path);
|
file.fileName = Path.GetFileName(data.path);
|
||||||
reader.BaseStream.Position = data.dataOffset;
|
reader.BaseStream.Position = data.dataOffset;
|
||||||
file.stream = new MemoryStream(reader.ReadBytes(data.dataLength));
|
file.stream = new MemoryStream(reader.ReadBytes(data.dataLength));
|
||||||
fileList.Add(file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-11
@@ -103,9 +103,9 @@ namespace AssetStudioCLI
|
|||||||
var bundleReader = new FileReader(reader.FullPath, bundleStream);
|
var bundleReader = new FileReader(reader.FullPath, bundleStream);
|
||||||
var bundleFile = new BundleFile(bundleReader, assetsManager.Options);
|
var bundleFile = new BundleFile(bundleReader, assetsManager.Options);
|
||||||
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
||||||
if (bundleFile.fileList.Count > 0)
|
if (bundleFile.FileList.Count > 0)
|
||||||
{
|
{
|
||||||
count += ExtractStreamFile(extractPath, bundleFile.fileList);
|
count += ExtractStreamFile(extractPath, bundleFile);
|
||||||
}
|
}
|
||||||
while (bundleFile.IsDataAfterBundle)
|
while (bundleFile.IsDataAfterBundle)
|
||||||
{
|
{
|
||||||
@@ -121,9 +121,9 @@ namespace AssetStudioCLI
|
|||||||
}
|
}
|
||||||
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
|
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
|
||||||
bundleFile = new BundleFile(bundleReader, assetsManager.Options, isMultiBundle: true);
|
bundleFile = new BundleFile(bundleReader, assetsManager.Options, isMultiBundle: true);
|
||||||
if (bundleFile.fileList.Count > 0)
|
if (bundleFile.FileList.Count > 0)
|
||||||
{
|
{
|
||||||
count += ExtractStreamFile(extractPath, bundleFile.fileList);
|
count += ExtractStreamFile(extractPath, bundleFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bundleStream.Dispose();
|
bundleStream.Dispose();
|
||||||
@@ -135,21 +135,23 @@ namespace AssetStudioCLI
|
|||||||
Logger.Info($"Decompressing {reader.FileName} ...");
|
Logger.Info($"Decompressing {reader.FileName} ...");
|
||||||
var webFile = new WebFile(reader);
|
var webFile = new WebFile(reader);
|
||||||
reader.Dispose();
|
reader.Dispose();
|
||||||
if (webFile.fileList.Count > 0)
|
if (webFile.FileList.Count > 0)
|
||||||
{
|
{
|
||||||
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
||||||
return ExtractStreamFile(extractPath, webFile.fileList, isOffsetStream: false);
|
return ExtractStreamFile(extractPath, webFile);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ExtractStreamFile(string extractPath, List<StreamFile> fileList, bool isOffsetStream = true)
|
private static int ExtractStreamFile(string extractPath, FileArchive fileArchive)
|
||||||
{
|
{
|
||||||
var extractedCount = 0;
|
var extractedCount = 0;
|
||||||
foreach (var file in fileList)
|
var isWebFile = fileArchive is WebFile;
|
||||||
|
foreach (var file in fileArchive.FileList)
|
||||||
{
|
{
|
||||||
if (file.stream == null)
|
if (file.stream == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var filePath = Path.Combine(extractPath, file.path);
|
var filePath = Path.Combine(extractPath, file.path);
|
||||||
var fileDirectory = Path.GetDirectoryName(filePath);
|
var fileDirectory = Path.GetDirectoryName(filePath);
|
||||||
if (!Directory.Exists(fileDirectory))
|
if (!Directory.Exists(fileDirectory))
|
||||||
@@ -165,11 +167,11 @@ namespace AssetStudioCLI
|
|||||||
}
|
}
|
||||||
extractedCount++;
|
extractedCount++;
|
||||||
}
|
}
|
||||||
if (!isOffsetStream) file.stream.Dispose();
|
if (isWebFile) file.stream.Dispose();
|
||||||
}
|
}
|
||||||
if (isOffsetStream && fileList.Count > 0)
|
if (!isWebFile)
|
||||||
{
|
{
|
||||||
fileList[0].stream?.Dispose();
|
fileArchive.FileList.FirstOrDefault(x => x.stream != null)?.stream.Dispose();
|
||||||
}
|
}
|
||||||
return extractedCount;
|
return extractedCount;
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-11
@@ -142,9 +142,9 @@ namespace AssetStudioGUI
|
|||||||
var bundleReader = new FileReader(reader.FullPath, bundleStream);
|
var bundleReader = new FileReader(reader.FullPath, bundleStream);
|
||||||
var bundleFile = new BundleFile(bundleReader, assetsManager.Options);
|
var bundleFile = new BundleFile(bundleReader, assetsManager.Options);
|
||||||
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
||||||
if (bundleFile.fileList.Count > 0)
|
if (bundleFile.FileList.Count > 0)
|
||||||
{
|
{
|
||||||
count += ExtractStreamFile(extractPath, bundleFile.fileList);
|
count += ExtractStreamFile(extractPath, bundleFile);
|
||||||
}
|
}
|
||||||
while (bundleFile.IsDataAfterBundle)
|
while (bundleFile.IsDataAfterBundle)
|
||||||
{
|
{
|
||||||
@@ -160,9 +160,9 @@ namespace AssetStudioGUI
|
|||||||
}
|
}
|
||||||
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
|
Logger.Info($"[MultiBundle] Decompressing \"{reader.FileName}\" from offset: 0x{bundleStream.Offset:X}..");
|
||||||
bundleFile = new BundleFile(bundleReader, assetsManager.Options, isMultiBundle: true);
|
bundleFile = new BundleFile(bundleReader, assetsManager.Options, isMultiBundle: true);
|
||||||
if (bundleFile.fileList.Count > 0)
|
if (bundleFile.FileList.Count > 0)
|
||||||
{
|
{
|
||||||
count += ExtractStreamFile(extractPath, bundleFile.fileList);
|
count += ExtractStreamFile(extractPath, bundleFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bundleStream.Dispose();
|
bundleStream.Dispose();
|
||||||
@@ -174,21 +174,23 @@ namespace AssetStudioGUI
|
|||||||
Logger.Info($"Decompressing {reader.FileName} ...");
|
Logger.Info($"Decompressing {reader.FileName} ...");
|
||||||
var webFile = new WebFile(reader);
|
var webFile = new WebFile(reader);
|
||||||
reader.Dispose();
|
reader.Dispose();
|
||||||
if (webFile.fileList.Count > 0)
|
if (webFile.FileList.Count > 0)
|
||||||
{
|
{
|
||||||
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
var extractPath = Path.Combine(savePath, reader.FileName + "_unpacked");
|
||||||
return ExtractStreamFile(extractPath, webFile.fileList, isOffsetStream: false);
|
return ExtractStreamFile(extractPath, webFile);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ExtractStreamFile(string extractPath, List<StreamFile> fileList, bool isOffsetStream = true)
|
private static int ExtractStreamFile(string extractPath, FileArchive fileArchive)
|
||||||
{
|
{
|
||||||
var extractedCount = 0;
|
var extractedCount = 0;
|
||||||
foreach (var file in fileList)
|
var isWebFile = fileArchive is WebFile;
|
||||||
|
foreach (var file in fileArchive.FileList)
|
||||||
{
|
{
|
||||||
if (file.stream == null)
|
if (file.stream == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var filePath = Path.Combine(extractPath, file.path);
|
var filePath = Path.Combine(extractPath, file.path);
|
||||||
var fileDirectory = Path.GetDirectoryName(filePath);
|
var fileDirectory = Path.GetDirectoryName(filePath);
|
||||||
if (!Directory.Exists(fileDirectory))
|
if (!Directory.Exists(fileDirectory))
|
||||||
@@ -204,11 +206,11 @@ namespace AssetStudioGUI
|
|||||||
}
|
}
|
||||||
extractedCount++;
|
extractedCount++;
|
||||||
}
|
}
|
||||||
if (!isOffsetStream) file.stream.Dispose();
|
if (isWebFile) file.stream.Dispose();
|
||||||
}
|
}
|
||||||
if (isOffsetStream && fileList.Count > 0)
|
if (!isWebFile)
|
||||||
{
|
{
|
||||||
fileList[0].stream?.Dispose();
|
fileArchive.FileList.FirstOrDefault(x => x.stream != null)?.stream.Dispose();
|
||||||
}
|
}
|
||||||
return extractedCount;
|
return extractedCount;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user