Add ResourcesHelper

This commit is contained in:
Perfare 2018-07-13 01:08:28 +08:00
parent 54c2bdc728
commit dc6b9748a3
6 changed files with 52 additions and 93 deletions

View File

@ -169,6 +169,7 @@
<Compile Include="StudioClasses\FBXExporter.cs" />
<Compile Include="StudioClasses\BuildTarget.cs" />
<Compile Include="StudioClasses\ModelConverter.cs" />
<Compile Include="StudioClasses\ResourcesHelper.cs" />
<Compile Include="StudioClasses\ShaderResource.Designer.cs">
<DependentUpon>ShaderResource.resx</DependentUpon>
<AutoGen>True</AutoGen>

View File

@ -152,6 +152,7 @@
<Compile Include="StudioClasses\ClassIDReference.cs" />
<Compile Include="StudioClasses\ClassMember.cs" />
<Compile Include="StudioClasses\ClassStructHelper.cs" />
<Compile Include="StudioClasses\ResourcesHelper.cs" />
<Compile Include="StudioClasses\ShaderResource.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AssetStudio
{
@ -94,36 +93,7 @@ namespace AssetStudio
{
if (!string.IsNullOrEmpty(m_Source))
{
var resourceFileName = Path.GetFileName(m_Source);
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
if (!File.Exists(resourceFilePath))
{
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
if (findFiles.Length > 0)
{
resourceFilePath = findFiles[0];
}
}
if (File.Exists(resourceFilePath))
{
using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
{
resourceReader.BaseStream.Position = m_Offset;
m_AudioData = resourceReader.ReadBytes((int)m_Size);
}
}
else
{
if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
{
resourceReader.Position = m_Offset;
m_AudioData = resourceReader.ReadBytes((int)m_Size);
}
else
{
MessageBox.Show($"can't find the resource file {resourceFileName}");
}
}
m_AudioData = ResourcesHelper.GetData(m_Source, sourceFile.filePath, m_Offset, (int)m_Size);
}
else
{

View File

@ -4,7 +4,6 @@ using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace AssetStudio
{
@ -117,36 +116,7 @@ namespace AssetStudio
{
if (!string.IsNullOrEmpty(path))
{
var resourceFileName = Path.GetFileName(path);
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
if (!File.Exists(resourceFilePath))
{
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
if (findFiles.Length > 0)
{
resourceFilePath = findFiles[0];
}
}
if (File.Exists(resourceFilePath))
{
using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
{
resourceReader.BaseStream.Position = offset;
image_data = resourceReader.ReadBytes(image_data_size);
}
}
else
{
if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
{
resourceReader.Position = offset;
image_data = resourceReader.ReadBytes(image_data_size);
}
else
{
MessageBox.Show($"can't find the resource file {resourceFileName}");
}
}
image_data = ResourcesHelper.GetData(path, sourceFile.filePath, offset, image_data_size);
}
else
{

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AssetStudio
{
@ -54,36 +53,7 @@ namespace AssetStudio
{
if (!string.IsNullOrEmpty(m_Source))
{
var resourceFileName = Path.GetFileName(m_Source);
var resourceFilePath = Path.GetDirectoryName(sourceFile.filePath) + "\\" + resourceFileName;
if (!File.Exists(resourceFilePath))
{
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFile.filePath), resourceFileName, SearchOption.AllDirectories);
if (findFiles.Length > 0)
{
resourceFilePath = findFiles[0];
}
}
if (File.Exists(resourceFilePath))
{
using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
{
resourceReader.BaseStream.Position = (long)m_Offset;
m_VideoData = resourceReader.ReadBytes((int)m_Size);
}
}
else
{
if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
{
resourceReader.Position = (long)m_Offset;
m_VideoData = resourceReader.ReadBytes((int)m_Size);
}
else
{
MessageBox.Show($"can't find the resource file {resourceFileName}");
}
}
m_VideoData = ResourcesHelper.GetData(m_Source, sourceFile.filePath, (long)m_Offset, (int)m_Size);
}
else
{

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AssetStudio
{
public static class ResourcesHelper
{
public static byte[] GetData(string path, string sourceFilePath, long offset, int size)
{
var resourceFileName = Path.GetFileName(path);
var resourceFilePath = Path.GetDirectoryName(sourceFilePath) + "\\" + resourceFileName;
if (!File.Exists(resourceFilePath))
{
var findFiles = Directory.GetFiles(Path.GetDirectoryName(sourceFilePath), resourceFileName, SearchOption.AllDirectories);
if (findFiles.Length > 0)
{
resourceFilePath = findFiles[0];
}
}
if (File.Exists(resourceFilePath))
{
using (var resourceReader = new BinaryReader(File.OpenRead(resourceFilePath)))
{
resourceReader.BaseStream.Position = offset;
return resourceReader.ReadBytes(size);
}
}
else
{
if (Studio.resourceFileReaders.TryGetValue(resourceFileName.ToUpper(), out var resourceReader))
{
resourceReader.Position = offset;
return resourceReader.ReadBytes(size);
}
else
{
MessageBox.Show($"can't find the resource file {resourceFileName}");
return null;
}
}
}
}
}