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
@@ -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;
}
}
}
}
}