diff options
| author | Lordmau5 <mail@lordmau5.com> | 2018-06-11 06:03:37 +0200 |
|---|---|---|
| committer | Lordmau5 <mail@lordmau5.com> | 2018-06-11 06:03:37 +0200 |
| commit | c636c74dd2a54a9c0ece6cd31b03512f8c41fc43 (patch) | |
| tree | e7b5089e4d873e51337752b8819c71c9f6257e93 /Ryujinx.HLE/VirtualFileSystem.cs | |
| parent | 851f2ded9a369633bb18a5fc97c123b3ef94c24e (diff) | |
| parent | 76f3b1b3a4637ec72abfbb8cbc0679f2e0ca838f (diff) | |
Merge branch 'master' into ICommonStateGetter
Diffstat (limited to 'Ryujinx.HLE/VirtualFileSystem.cs')
| -rw-r--r-- | Ryujinx.HLE/VirtualFileSystem.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/Ryujinx.HLE/VirtualFileSystem.cs b/Ryujinx.HLE/VirtualFileSystem.cs new file mode 100644 index 00000000..8b71caa9 --- /dev/null +++ b/Ryujinx.HLE/VirtualFileSystem.cs @@ -0,0 +1,85 @@ +using System; +using System.IO; + +namespace Ryujinx.HLE +{ + class VirtualFileSystem : IDisposable + { + private const string BasePath = "RyuFs"; + private const string NandPath = "nand"; + private const string SdCardPath = "sdmc"; + + public Stream RomFs { get; private set; } + + public void LoadRomFs(string FileName) + { + RomFs = new FileStream(FileName, FileMode.Open, FileAccess.Read); + } + + public string GetFullPath(string BasePath, string FileName) + { + if (FileName.StartsWith("//")) + { + FileName = FileName.Substring(2); + } + else if (FileName.StartsWith('/')) + { + FileName = FileName.Substring(1); + } + else + { + return null; + } + + string FullPath = Path.GetFullPath(Path.Combine(BasePath, FileName)); + + if (!FullPath.StartsWith(GetBasePath())) + { + return null; + } + + return FullPath; + } + + public string GetSdCardPath() => MakeDirAndGetFullPath(SdCardPath); + + public string GetGameSavesPath() => MakeDirAndGetFullPath(NandPath); + + private string MakeDirAndGetFullPath(string Dir) + { + string FullPath = Path.Combine(GetBasePath(), Dir); + + if (!Directory.Exists(FullPath)) + { + Directory.CreateDirectory(FullPath); + } + + return FullPath; + } + + public DriveInfo GetDrive() + { + return new DriveInfo(Path.GetPathRoot(GetBasePath())); + } + + public string GetBasePath() + { + string AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + + return Path.Combine(AppDataPath, BasePath); + } + + public void Dispose() + { + Dispose(true); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + RomFs?.Dispose(); + } + } + } +}
\ No newline at end of file |
