ryujinx/Ryujinx/OsHle/Objects/FspSrv/IFileSystem.cs

79 lines
2 KiB
C#
Raw Normal View History

2018-02-04 18:08:20 -05:00
using ChocolArm64.Memory;
using Ryujinx.OsHle.Ipc;
using System.Collections.Generic;
2018-02-04 18:08:20 -05:00
using System.IO;
using static Ryujinx.OsHle.Objects.ObjHelper;
namespace Ryujinx.OsHle.Objects.FspSrv
2018-02-04 18:08:20 -05:00
{
class IFileSystem : IIpcInterface
2018-02-04 18:08:20 -05:00
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
2018-02-04 18:08:20 -05:00
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private string Path;
public IFileSystem(string Path)
2018-02-04 18:08:20 -05:00
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 7, GetEntryType },
{ 8, OpenFile },
{ 10, Commit }
};
this.Path = Path;
2018-02-04 18:08:20 -05:00
}
public long GetEntryType(ServiceCtx Context)
2018-02-04 18:08:20 -05:00
{
long Position = Context.Request.PtrBuff[0].Position;
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
2018-02-04 18:08:20 -05:00
if (FileName == null)
{
//TODO: Correct error code.
return -1;
}
bool IsFile = File.Exists(FileName);
Context.ResponseData.Write(IsFile ? 1 : 0);
return 0;
}
public long OpenFile(ServiceCtx Context)
2018-02-04 18:08:20 -05:00
{
long Position = Context.Request.PtrBuff[0].Position;
int FilterFlags = Context.RequestData.ReadInt32();
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
2018-02-04 18:08:20 -05:00
if (FileName == null)
{
//TODO: Correct error code.
return -1;
}
FileStream Stream = new FileStream(FileName, FileMode.OpenOrCreate);
MakeObject(Context, new IFile(Stream));
2018-02-04 18:08:20 -05:00
return 0;
}
public long Commit(ServiceCtx Context)
2018-02-04 18:08:20 -05:00
{
return 0;
}
}
}