FspSrvIFileSystem.cs 1.8 KB

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