VirtualFs.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.IO;
  3. namespace Ryujinx
  4. {
  5. class VirtualFs : IDisposable
  6. {
  7. private const string BasePath = "Fs";
  8. private const string SavesPath = "Saves";
  9. public Stream RomFs { get; private set; }
  10. public void LoadRomFs(string FileName)
  11. {
  12. RomFs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
  13. }
  14. internal string GetFullPath(string BasePath, string FileName)
  15. {
  16. if (FileName.StartsWith('/'))
  17. {
  18. FileName = FileName.Substring(1);
  19. }
  20. string FullPath = Path.GetFullPath(Path.Combine(BasePath, FileName));
  21. if (!FullPath.StartsWith(GetBasePath()))
  22. {
  23. return null;
  24. }
  25. return FullPath;
  26. }
  27. internal string GetGameSavesPath()
  28. {
  29. string SavesDir = Path.Combine(GetBasePath(), SavesPath);
  30. if (!Directory.Exists(SavesDir))
  31. {
  32. Directory.CreateDirectory(SavesDir);
  33. }
  34. return SavesDir;
  35. }
  36. internal string GetBasePath()
  37. {
  38. return Path.Combine(Directory.GetCurrentDirectory(), BasePath);
  39. }
  40. public void Dispose()
  41. {
  42. Dispose(true);
  43. }
  44. protected virtual void Dispose(bool disposing)
  45. {
  46. if (disposing && RomFs != null)
  47. {
  48. RomFs.Dispose();
  49. }
  50. }
  51. }
  52. }