mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-26 13:50:21 -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_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_Size = a_Stream.ReadInt64();
|
||||
m_CompressionFormat = (AudioCompressionFormat)a_Stream.ReadInt32();
|
||||
@ -102,31 +100,41 @@ namespace Unity_Studio
|
||||
|
||||
if (readSwitch)
|
||||
{
|
||||
if (string.IsNullOrEmpty(m_Source))
|
||||
if (!string.IsNullOrEmpty(m_Source))
|
||||
{
|
||||
if (m_Size > 0)
|
||||
m_AudioData = a_Stream.ReadBytes((int)m_Size);
|
||||
}
|
||||
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))
|
||||
var resourceFileName = Path.GetFileName(m_Source);
|
||||
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
|
||||
if (!File.Exists(resourceFilePath))
|
||||
{
|
||||
estream.Position = m_Offset;
|
||||
m_AudioData = estream.ReadBytes((int)m_Size);
|
||||
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
|
||||
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
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@ -166,25 +166,31 @@ namespace Unity_Studio
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
path = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), path.Replace("archive:/", ""));
|
||||
if (File.Exists(path) ||
|
||||
File.Exists(path = Path.Combine(Path.GetDirectoryName(sourceFile.filePath), Path.GetFileName(path))))
|
||||
var resourceFileName = Path.GetFileName(path);
|
||||
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
|
||||
if (!File.Exists(resourceFilePath))
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(File.OpenRead(path));
|
||||
reader.BaseStream.Position = offset;
|
||||
image_data = reader.ReadBytes(image_data_size);
|
||||
reader.Close();
|
||||
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
|
||||
if (findFiles.Length > 0) { resourceFilePath = findFiles[0]; }
|
||||
}
|
||||
if (File.Exists(resourceFilePath))
|
||||
{
|
||||
using (var reader = new BinaryReader(File.OpenRead(resourceFilePath)))
|
||||
{
|
||||
reader.BaseStream.Position = offset;
|
||||
image_data = reader.ReadBytes(image_data_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UnityStudio.assetsfileandstream.TryGetValue(Path.GetFileName(path), out var estream))
|
||||
if (UnityStudio.assetsfileandstream.TryGetValue(resourceFileName, out var reader))
|
||||
{
|
||||
estream.Position = offset;
|
||||
image_data = estream.ReadBytes(image_data_size);
|
||||
reader.Position = offset;
|
||||
image_data = reader.ReadBytes(image_data_size);
|
||||
}
|
||||
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 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>();
|
||||
|
||||
@ -36,7 +36,7 @@ namespace Unity_Studio
|
||||
public static string[] buildTypeSplit = { ".", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
|
||||
#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"},
|
||||
{5, "AnimationClip"},
|
||||
@ -284,7 +284,7 @@ namespace Unity_Studio
|
||||
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());
|
||||
ClassStructures.Add(classID, aClass);
|
||||
}
|
||||
@ -392,11 +392,11 @@ namespace Unity_Studio
|
||||
int sharedFileCount = a_Stream.ReadInt32();
|
||||
for (int i = 0; i < sharedFileCount; i++)
|
||||
{
|
||||
UnityShared shared = new UnityShared();
|
||||
var shared = new UnityShared();
|
||||
shared.aName = a_Stream.ReadStringToNull();
|
||||
a_Stream.Position += 20;
|
||||
string sharedFileName = a_Stream.ReadStringToNull(); //relative path
|
||||
shared.fileName = sharedFileName.Replace("/", "\\");
|
||||
var sharedFilePath = a_Stream.ReadStringToNull(); //relative path
|
||||
shared.fileName = Path.GetFileName(sharedFilePath);
|
||||
sharedAssetsList.Add(shared);
|
||||
}
|
||||
valid = true;
|
||||
@ -417,7 +417,7 @@ namespace Unity_Studio
|
||||
int flag = a_Stream.ReadInt32();
|
||||
int childrenCount = a_Stream.ReadInt32();
|
||||
|
||||
cb.Add(new ClassMember()
|
||||
cb.Add(new ClassMember
|
||||
{
|
||||
Level = level - 1,
|
||||
Type = varType,
|
||||
@ -506,7 +506,7 @@ namespace Unity_Studio
|
||||
if (index == 0) { className = varTypeStr + " " + varNameStr; }
|
||||
else
|
||||
{
|
||||
classVar.Add(new ClassMember()
|
||||
classVar.Add(new ClassMember
|
||||
{
|
||||
Level = level - 1,
|
||||
Type = varTypeStr,
|
||||
@ -519,7 +519,7 @@ namespace Unity_Studio
|
||||
stringReader.Dispose();
|
||||
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());
|
||||
ClassStructures[classID] = aClass;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ namespace Unity_Studio
|
||||
foreach (var sharedFile in assetsFile.sharedAssetsList)
|
||||
{
|
||||
string sharedFilePath = Path.GetDirectoryName(fileName) + "\\" + sharedFile.fileName;
|
||||
string sharedFileName = Path.GetFileName(sharedFile.fileName);
|
||||
string sharedFileName = sharedFile.fileName;
|
||||
if (!unityFilesHash.Contains(sharedFileName))
|
||||
{
|
||||
if (!File.Exists(sharedFilePath))
|
||||
|
Loading…
Reference in New Issue
Block a user