DotRecastNetSim/src/DotRecast.Core/Loader.cs

33 lines
872 B
C#
Raw Normal View History

2023-03-14 08:02:43 +03:00
using System.IO;
2023-03-16 19:09:10 +03:00
namespace DotRecast.Core
{
2023-03-16 19:48:49 +03:00
public static class Loader
2023-03-14 08:02:43 +03:00
{
2023-03-16 19:48:49 +03:00
public static byte[] ToBytes(string filename)
{
var filepath = ToRPath(filename);
2023-03-27 05:00:19 +03:00
using var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
2023-03-16 19:48:49 +03:00
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
2023-03-14 08:02:43 +03:00
2023-03-16 19:48:49 +03:00
return buffer;
}
public static string ToRPath(string filename)
2023-03-14 08:02:43 +03:00
{
2023-03-16 19:48:49 +03:00
string filePath = Path.Combine("resources", filename);
for (int i = 0; i < 10; ++i)
2023-03-14 08:02:43 +03:00
{
2023-03-16 19:48:49 +03:00
if (File.Exists(filePath))
{
return Path.GetFullPath(filePath);
}
filePath = Path.Combine("..", filePath);
2023-03-14 08:02:43 +03:00
}
2023-03-18 18:09:36 +03:00
return Path.GetFullPath(filename);
2023-03-14 08:02:43 +03:00
}
}
}