mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
Improve external file reading
This commit is contained in:
parent
ee6c050330
commit
351228e45c
@ -93,8 +93,6 @@ namespace Unity_Studio
|
|||||||
m_3D = m_Legacy3D;
|
m_3D = m_Legacy3D;
|
||||||
|
|
||||||
m_Source = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
|
m_Source = a_Stream.ReadAlignedString(a_Stream.ReadInt32());
|
||||||
if (m_Source != "")
|
|
||||||
m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), m_Source.Replace("archive:/", ""));
|
|
||||||
m_Offset = a_Stream.ReadInt64();
|
m_Offset = a_Stream.ReadInt64();
|
||||||
m_Size = a_Stream.ReadInt64();
|
m_Size = a_Stream.ReadInt64();
|
||||||
m_CompressionFormat = (AudioCompressionFormat)a_Stream.ReadInt32();
|
m_CompressionFormat = (AudioCompressionFormat)a_Stream.ReadInt32();
|
||||||
@ -102,31 +100,41 @@ namespace Unity_Studio
|
|||||||
|
|
||||||
if (readSwitch)
|
if (readSwitch)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(m_Source))
|
if (!string.IsNullOrEmpty(m_Source))
|
||||||
{
|
{
|
||||||
if (m_Size > 0)
|
var resourceFileName = Path.GetFileName(m_Source);
|
||||||
m_AudioData = a_Stream.ReadBytes((int)m_Size);
|
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
|
||||||
}
|
if (!File.Exists(resourceFilePath))
|
||||||
else if (File.Exists(m_Source) ||
|
|
||||||
File.Exists(m_Source = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(m_Source))))
|
|
||||||
{
|
|
||||||
BinaryReader reader = new BinaryReader(File.OpenRead(m_Source));
|
|
||||||
reader.BaseStream.Position = m_Offset;
|
|
||||||
m_AudioData = reader.ReadBytes((int)m_Size);
|
|
||||||
reader.Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(m_Source), out var estream))
|
|
||||||
{
|
{
|
||||||
estream.Position = m_Offset;
|
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
|
||||||
m_AudioData = estream.ReadBytes((int)m_Size);
|
if (findFiles.Length > 0) { resourceFilePath = findFiles[0]; }
|
||||||
|
}
|
||||||
|
if (File.Exists(resourceFilePath))
|
||||||
|
{
|
||||||
|
using (var reader = new BinaryReader(File.OpenRead(resourceFilePath)))
|
||||||
|
{
|
||||||
|
reader.BaseStream.Position = m_Offset;
|
||||||
|
m_AudioData = reader.ReadBytes((int)m_Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show($"can't find the resource file {Path.GetFileName(m_Source)}");
|
if (UnityStudio.assetsfileandstream.TryGetValue(resourceFileName, out var reader))
|
||||||
|
{
|
||||||
|
reader.Position = m_Offset;
|
||||||
|
m_AudioData = reader.ReadBytes((int)m_Size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show($"can't find the resource file {resourceFileName}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_Size > 0)
|
||||||
|
m_AudioData = a_Stream.ReadBytes((int)m_Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -166,25 +166,31 @@ namespace Unity_Studio
|
|||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(path))
|
if (!string.IsNullOrEmpty(path))
|
||||||
{
|
{
|
||||||
path = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), path.Replace("archive:/", ""));
|
var resourceFileName = Path.GetFileName(path);
|
||||||
if (File.Exists(path) ||
|
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
|
||||||
File.Exists(path = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(path))))
|
if (!File.Exists(resourceFilePath))
|
||||||
{
|
{
|
||||||
BinaryReader reader = new BinaryReader(File.OpenRead(path));
|
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
|
||||||
reader.BaseStream.Position = offset;
|
if (findFiles.Length > 0) { resourceFilePath = findFiles[0]; }
|
||||||
image_data = reader.ReadBytes(image_data_size);
|
}
|
||||||
reader.Close();
|
if (File.Exists(resourceFilePath))
|
||||||
|
{
|
||||||
|
using (var reader = new BinaryReader(File.OpenRead(resourceFilePath)))
|
||||||
|
{
|
||||||
|
reader.BaseStream.Position = offset;
|
||||||
|
image_data = reader.ReadBytes(image_data_size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(path), out var estream))
|
if (UnityStudio.assetsfileandstream.TryGetValue(resourceFileName, out var reader))
|
||||||
{
|
{
|
||||||
estream.Position = offset;
|
reader.Position = offset;
|
||||||
image_data = estream.ReadBytes(image_data_size);
|
image_data = reader.ReadBytes(image_data_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show($"can't find the resource file {Path.GetFileName(path)}");
|
MessageBox.Show($"can't find the resource file {resourceFileName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ namespace Unity_Studio
|
|||||||
public Dictionary<long, Transform> TransformList = new Dictionary<long, Transform>();
|
public Dictionary<long, Transform> TransformList = new Dictionary<long, Transform>();
|
||||||
|
|
||||||
public List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>();
|
public List<AssetPreloadData> exportableAssets = new List<AssetPreloadData>();
|
||||||
public List<UnityShared> sharedAssetsList = new List<UnityShared>() { new UnityShared() };
|
public List<UnityShared> sharedAssetsList = new List<UnityShared> { new UnityShared() };
|
||||||
|
|
||||||
public SortedDictionary<int, ClassStruct> ClassStructures = new SortedDictionary<int, ClassStruct>();
|
public SortedDictionary<int, ClassStruct> ClassStructures = new SortedDictionary<int, ClassStruct>();
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ namespace Unity_Studio
|
|||||||
public static string[] buildTypeSplit = { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
public static string[] buildTypeSplit = { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||||
|
|
||||||
#region cmmon string
|
#region cmmon string
|
||||||
private static Dictionary<int, string> baseStrings = new Dictionary<int, string>()
|
private static Dictionary<int, string> baseStrings = new Dictionary<int, string>
|
||||||
{
|
{
|
||||||
{0, "AABB"},
|
{0, "AABB"},
|
||||||
{5, "AnimationClip"},
|
{5, "AnimationClip"},
|
||||||
@ -284,7 +284,7 @@ namespace Unity_Studio
|
|||||||
readBase(cb, 1);
|
readBase(cb, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var aClass = new ClassStruct() { ID = classID, Text = (baseType + " " + baseName), members = cb };
|
var aClass = new ClassStruct { ID = classID, Text = (baseType + " " + baseName), members = cb };
|
||||||
aClass.SubItems.Add(classID.ToString());
|
aClass.SubItems.Add(classID.ToString());
|
||||||
ClassStructures.Add(classID, aClass);
|
ClassStructures.Add(classID, aClass);
|
||||||
}
|
}
|
||||||
@ -392,11 +392,11 @@ namespace Unity_Studio
|
|||||||
int sharedFileCount = a_Stream.ReadInt32();
|
int sharedFileCount = a_Stream.ReadInt32();
|
||||||
for (int i = 0; i < sharedFileCount; i++)
|
for (int i = 0; i < sharedFileCount; i++)
|
||||||
{
|
{
|
||||||
UnityShared shared = new UnityShared();
|
var shared = new UnityShared();
|
||||||
shared.aName = a_Stream.ReadStringToNull();
|
shared.aName = a_Stream.ReadStringToNull();
|
||||||
a_Stream.Position += 20;
|
a_Stream.Position += 20;
|
||||||
string sharedFileName = a_Stream.ReadStringToNull(); //relative path
|
var sharedFilePath = a_Stream.ReadStringToNull(); //relative path
|
||||||
shared.fileName = sharedFileName.Replace("/", "\\");
|
shared.fileName = Path.GetFileName(sharedFilePath);
|
||||||
sharedAssetsList.Add(shared);
|
sharedAssetsList.Add(shared);
|
||||||
}
|
}
|
||||||
valid = true;
|
valid = true;
|
||||||
@ -417,7 +417,7 @@ namespace Unity_Studio
|
|||||||
int flag = a_Stream.ReadInt32();
|
int flag = a_Stream.ReadInt32();
|
||||||
int childrenCount = a_Stream.ReadInt32();
|
int childrenCount = a_Stream.ReadInt32();
|
||||||
|
|
||||||
cb.Add(new ClassMember()
|
cb.Add(new ClassMember
|
||||||
{
|
{
|
||||||
Level = level - 1,
|
Level = level - 1,
|
||||||
Type = varType,
|
Type = varType,
|
||||||
@ -506,7 +506,7 @@ namespace Unity_Studio
|
|||||||
if (index == 0) { className = varTypeStr + " " + varNameStr; }
|
if (index == 0) { className = varTypeStr + " " + varNameStr; }
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
classVar.Add(new ClassMember()
|
classVar.Add(new ClassMember
|
||||||
{
|
{
|
||||||
Level = level - 1,
|
Level = level - 1,
|
||||||
Type = varTypeStr,
|
Type = varTypeStr,
|
||||||
@ -519,7 +519,7 @@ namespace Unity_Studio
|
|||||||
stringReader.Dispose();
|
stringReader.Dispose();
|
||||||
a_Stream.Position += stringSize;
|
a_Stream.Position += stringSize;
|
||||||
|
|
||||||
var aClass = new ClassStruct() { ID = classID, Text = className, members = classVar };
|
var aClass = new ClassStruct { ID = classID, Text = className, members = classVar };
|
||||||
aClass.SubItems.Add(classID.ToString());
|
aClass.SubItems.Add(classID.ToString());
|
||||||
ClassStructures[classID] = aClass;
|
ClassStructures[classID] = aClass;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ namespace Unity_Studio
|
|||||||
foreach (var sharedFile in assetsFile.sharedAssetsList)
|
foreach (var sharedFile in assetsFile.sharedAssetsList)
|
||||||
{
|
{
|
||||||
string sharedFilePath = Path.GetDirectoryName(fileName) + "\\" + sharedFile.fileName;
|
string sharedFilePath = Path.GetDirectoryName(fileName) + "\\" + sharedFile.fileName;
|
||||||
string sharedFileName = Path.GetFileName(sharedFile.fileName);
|
string sharedFileName = sharedFile.fileName;
|
||||||
if (!unityFilesHash.Contains(sharedFileName))
|
if (!unityFilesHash.Contains(sharedFileName))
|
||||||
{
|
{
|
||||||
if (!File.Exists(sharedFilePath))
|
if (!File.Exists(sharedFilePath))
|
||||||
|
Loading…
Reference in New Issue
Block a user