holopy3/Assets/UniGLTF/UniJSON/Scripts/IFileSystemAccessor.cs
Lena Biresch 490ef558ef CleanUp
2021-01-28 13:07:52 +01:00

53 lines
1.3 KiB
C#

using System.IO;
using System.Text;
namespace UniJSON
{
public interface IFileSystemAccessor
{
string ReadAllText();
string ReadAllText(string relativePath);
IFileSystemAccessor Get(string relativePath);
}
public class FileSystemAccessor : IFileSystemAccessor
{
string m_path;
string m_baseDir;
public FileSystemAccessor(string path)
{
m_path = path;
if (Directory.Exists(path))
{
m_baseDir = path;
}
else
{
m_baseDir = Path.GetDirectoryName(path);
}
}
public override string ToString()
{
return "<" + Path.GetFileName(m_path) + ">";
}
public string ReadAllText()
{
return File.ReadAllText(m_path, Encoding.UTF8);
}
public string ReadAllText(string relativePath)
{
var path = Path.Combine(m_baseDir, relativePath);
return File.ReadAllText(path, Encoding.UTF8);
}
public IFileSystemAccessor Get(string relativePath)
{
var path = Path.Combine(m_baseDir, relativePath);
return new FileSystemAccessor(path);
}
}
}