aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Core/VirtualFs.cs
diff options
context:
space:
mode:
authoremmauss <emmausssss@gmail.com>2018-02-20 22:09:23 +0200
committergdkchan <gab.dark.100@gmail.com>2018-02-20 17:09:23 -0300
commit62b827f474f0aa2152dd339fcc7cf31084e16a0b (patch)
tree0e5c55b341aee4db0ccb841a084f253ec5e05657 /Ryujinx.Core/VirtualFs.cs
parentcb665bb715834526d73c9469d16114b287faaecd (diff)
Split main project into core,graphics and chocolarm4 subproject (#29)
Diffstat (limited to 'Ryujinx.Core/VirtualFs.cs')
-rw-r--r--Ryujinx.Core/VirtualFs.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/Ryujinx.Core/VirtualFs.cs b/Ryujinx.Core/VirtualFs.cs
new file mode 100644
index 00000000..23c7285c
--- /dev/null
+++ b/Ryujinx.Core/VirtualFs.cs
@@ -0,0 +1,70 @@
+using System;
+using System.IO;
+
+namespace Ryujinx.Core
+{
+ class VirtualFs : IDisposable
+ {
+ private const string BasePath = "Fs";
+ private const string SavesPath = "Saves";
+ private const string SdCardPath = "SdCard";
+
+ 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(1);
+ }
+
+ 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(SavesPath);
+
+ private static string MakeDirAndGetFullPath(string Dir)
+ {
+ string FullPath = Path.Combine(GetBasePath(), Dir);
+
+ if (!Directory.Exists(FullPath))
+ {
+ Directory.CreateDirectory(FullPath);
+ }
+
+ return FullPath;
+ }
+
+ public static string GetBasePath()
+ {
+ return Path.Combine(Directory.GetCurrentDirectory(), BasePath);
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ RomFs?.Dispose();
+ }
+ }
+ }
+} \ No newline at end of file