diff --git a/Unity Studio/Unity Classes/AudioClip.cs b/Unity Studio/Unity Classes/AudioClip.cs index 5050048..351e337 100644 --- a/Unity Studio/Unity Classes/AudioClip.cs +++ b/Unity Studio/Unity Classes/AudioClip.cs @@ -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 { diff --git a/Unity Studio/Unity Classes/Texture2D.cs b/Unity Studio/Unity Classes/Texture2D.cs index 0e30f31..b4a6831 100644 --- a/Unity Studio/Unity Classes/Texture2D.cs +++ b/Unity Studio/Unity Classes/Texture2D.cs @@ -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}"); } } } diff --git a/Unity Studio/Unity Studio Classes/AssetsFile.cs b/Unity Studio/Unity Studio Classes/AssetsFile.cs index bd36c34..fb91b1a 100644 --- a/Unity Studio/Unity Studio Classes/AssetsFile.cs +++ b/Unity Studio/Unity Studio Classes/AssetsFile.cs @@ -26,7 +26,7 @@ namespace Unity_Studio public Dictionary TransformList = new Dictionary(); public List exportableAssets = new List(); - public List sharedAssetsList = new List() { new UnityShared() }; + public List sharedAssetsList = new List { new UnityShared() }; public SortedDictionary ClassStructures = new SortedDictionary(); @@ -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 baseStrings = new Dictionary() + private static Dictionary baseStrings = new Dictionary { {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; } diff --git a/Unity Studio/Unity Studio Classes/UnityStudio.cs b/Unity Studio/Unity Studio Classes/UnityStudio.cs index f8d0ba4..a4ee3b6 100644 --- a/Unity Studio/Unity Studio Classes/UnityStudio.cs +++ b/Unity Studio/Unity Studio Classes/UnityStudio.cs @@ -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))