2018-02-04 18:08:20 -05:00
|
|
|
using ChocolArm64.Memory;
|
2018-02-09 19:14:55 -05:00
|
|
|
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;
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
namespace Ryujinx.OsHle.Objects.FspSrv
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -05:00
|
|
|
class IFileSystem : IIpcInterface
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -05:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
|
|
|
|
|
|
|
private string Path;
|
|
|
|
|
|
|
|
public IFileSystem(string Path)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-02-09 19:14:55 -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
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -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);
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
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);
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
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);
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
MakeObject(Context, new IFile(Stream));
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 19:14:55 -05:00
|
|
|
public long Commit(ServiceCtx Context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|