IFileSystem.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using ChocolArm64.Memory;
  2. using Ryujinx.OsHle.Ipc;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using static Ryujinx.OsHle.Objects.ObjHelper;
  6. namespace Ryujinx.OsHle.Objects.FspSrv
  7. {
  8. class IFileSystem : IIpcInterface
  9. {
  10. private Dictionary<int, ServiceProcessRequest> m_Commands;
  11. public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  12. private string Path;
  13. public IFileSystem(string Path)
  14. {
  15. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  16. {
  17. { 7, GetEntryType },
  18. { 8, OpenFile },
  19. { 10, Commit }
  20. };
  21. this.Path = Path;
  22. }
  23. public long GetEntryType(ServiceCtx Context)
  24. {
  25. long Position = Context.Request.PtrBuff[0].Position;
  26. string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
  27. string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
  28. if (FileName == null)
  29. {
  30. //TODO: Correct error code.
  31. return -1;
  32. }
  33. bool IsFile = File.Exists(FileName);
  34. Context.ResponseData.Write(IsFile ? 1 : 0);
  35. return 0;
  36. }
  37. public long OpenFile(ServiceCtx Context)
  38. {
  39. long Position = Context.Request.PtrBuff[0].Position;
  40. int FilterFlags = Context.RequestData.ReadInt32();
  41. string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
  42. string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
  43. if (FileName == null)
  44. {
  45. //TODO: Correct error code.
  46. return -1;
  47. }
  48. FileStream Stream = new FileStream(FileName, FileMode.OpenOrCreate);
  49. MakeObject(Context, new IFile(Stream));
  50. return 0;
  51. }
  52. public long Commit(ServiceCtx Context)
  53. {
  54. return 0;
  55. }
  56. }
  57. }