aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2022-03-22 20:46:16 +0100
committerGitHub <noreply@github.com>2022-03-22 20:46:16 +0100
commite3b36db71c62a34a26b30683dd5ad5410c97cc9c (patch)
tree18feea12db46ad2ddcdc207e9fd0e805fd98b7da /Ryujinx.HLE/FileSystem/VirtualFileSystem.cs
parentba0171d05464201c1513386b7d0b69b5ea956426 (diff)
hle: Some cleanup (#3210)1.1.83
* hle: Some cleanup This PR cleaned up a bit the HLE folder and the VirtualFileSystem one, since we use LibHac, we can use some class of it directly instead of duplicate things. The "Content" of VFS folder is removed since it should be handled in the NCM service directly. A larger cleanup should be done later since there is still be duplicated code here and there. * Fix Headless.SDL2 * Addresses gdkchan feedback
Diffstat (limited to 'Ryujinx.HLE/FileSystem/VirtualFileSystem.cs')
-rw-r--r--Ryujinx.HLE/FileSystem/VirtualFileSystem.cs88
1 files changed, 31 insertions, 57 deletions
diff --git a/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs b/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs
index 9359b03c..001a1f5f 100644
--- a/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs
+++ b/Ryujinx.HLE/FileSystem/VirtualFileSystem.cs
@@ -13,7 +13,6 @@ using LibHac.Tools.Fs;
using LibHac.Tools.FsSystem;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
-using Ryujinx.HLE.FileSystem.Content;
using Ryujinx.HLE.HOS;
using System;
using System.Buffers.Text;
@@ -28,20 +27,29 @@ namespace Ryujinx.HLE.FileSystem
{
public class VirtualFileSystem : IDisposable
{
- public const string NandPath = AppDataManager.DefaultNandDir;
- public const string SdCardPath = AppDataManager.DefaultSdcardDir;
+ public static string SafeNandPath = Path.Combine(AppDataManager.DefaultNandDir, "safe");
+ public static string SystemNandPath = Path.Combine(AppDataManager.DefaultNandDir, "system");
+ public static string UserNandPath = Path.Combine(AppDataManager.DefaultNandDir, "user");
- public static string SafeNandPath = Path.Combine(NandPath, "safe");
- public static string SystemNandPath = Path.Combine(NandPath, "system");
- public static string UserNandPath = Path.Combine(NandPath, "user");
+ public KeySet KeySet { get; private set; }
+ public EmulatedGameCard GameCard { get; private set; }
+ public EmulatedSdCard SdCard { get; private set; }
+ public ModLoader ModLoader { get; private set; }
+ public Stream RomFs { get; private set; }
private static bool _isInitialized = false;
- public KeySet KeySet { get; private set; }
- public EmulatedGameCard GameCard { get; private set; }
- public EmulatedSdCard SdCard { get; private set; }
+ public static VirtualFileSystem CreateInstance()
+ {
+ if (_isInitialized)
+ {
+ throw new InvalidOperationException("VirtualFileSystem can only be instantiated once!");
+ }
- public ModLoader ModLoader { get; private set; }
+ _isInitialized = true;
+
+ return new VirtualFileSystem();
+ }
private VirtualFileSystem()
{
@@ -49,8 +57,6 @@ namespace Ryujinx.HLE.FileSystem
ModLoader = new ModLoader(); // Should only be created once
}
- public Stream RomFs { get; private set; }
-
public void LoadRomFs(string fileName)
{
RomFs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
@@ -79,7 +85,7 @@ namespace Ryujinx.HLE.FileSystem
string fullPath = Path.GetFullPath(Path.Combine(basePath, fileName));
- if (!fullPath.StartsWith(GetBasePath()))
+ if (!fullPath.StartsWith(AppDataManager.BaseDirPath))
{
return null;
}
@@ -87,14 +93,8 @@ namespace Ryujinx.HLE.FileSystem
return fullPath;
}
- internal string GetBasePath() => AppDataManager.BaseDirPath;
- internal string GetSdCardPath() => MakeFullPath(SdCardPath);
- public string GetNandPath() => MakeFullPath(NandPath);
-
- public string GetFullPartitionPath(string partitionPath)
- {
- return MakeFullPath(partitionPath);
- }
+ internal string GetSdCardPath() => MakeFullPath(AppDataManager.DefaultSdcardDir);
+ public string GetNandPath() => MakeFullPath(AppDataManager.DefaultNandDir);
public string SwitchPathToSystemPath(string switchPath)
{
@@ -110,7 +110,7 @@ namespace Ryujinx.HLE.FileSystem
public string SystemPathToSwitchPath(string systemPath)
{
- string baseSystemPath = GetBasePath() + Path.DirectorySeparatorChar;
+ string baseSystemPath = AppDataManager.BaseDirPath + Path.DirectorySeparatorChar;
if (systemPath.StartsWith(baseSystemPath))
{
@@ -136,8 +136,7 @@ namespace Ryujinx.HLE.FileSystem
switch (path)
{
case ContentPath.SdCard:
- case "@Sdcard":
- path = SdCardPath;
+ path = AppDataManager.DefaultSdcardDir;
break;
case ContentPath.User:
path = UserNandPath;
@@ -146,7 +145,7 @@ namespace Ryujinx.HLE.FileSystem
path = SystemNandPath;
break;
case ContentPath.SdCardContent:
- path = Path.Combine(SdCardPath, "Nintendo", "Contents");
+ path = Path.Combine(AppDataManager.DefaultSdcardDir, "Nintendo", "Contents");
break;
case ContentPath.UserContent:
path = Path.Combine(UserNandPath, "Contents");
@@ -156,27 +155,19 @@ namespace Ryujinx.HLE.FileSystem
break;
}
- string fullPath = Path.Combine(GetBasePath(), path);
+ string fullPath = Path.Combine(AppDataManager.BaseDirPath, path);
- if (isDirectory)
+ if (isDirectory && !Directory.Exists(fullPath))
{
- if (!Directory.Exists(fullPath))
- {
- Directory.CreateDirectory(fullPath);
- }
+ Directory.CreateDirectory(fullPath);
}
return fullPath;
}
- public DriveInfo GetDrive()
- {
- return new DriveInfo(Path.GetPathRoot(GetBasePath()));
- }
-
public void InitializeFsServer(LibHac.Horizon horizon, out HorizonClient fsServerClient)
{
- LocalFileSystem serverBaseFs = new LocalFileSystem(GetBasePath());
+ LocalFileSystem serverBaseFs = new LocalFileSystem(AppDataManager.BaseDirPath);
fsServerClient = horizon.CreatePrivilegedHorizonClient();
var fsServer = new FileSystemServer(fsServerClient);
@@ -505,7 +496,7 @@ namespace Ryujinx.HLE.FileSystem
bool canFixBySaveDataId = extraData.Attribute.StaticSaveDataId == 0 && info.StaticSaveDataId != 0;
- bool hasEmptyOwnerId = extraData.OwnerId == 0 && info.Type != LibHac.Fs.SaveDataType.System;
+ bool hasEmptyOwnerId = extraData.OwnerId == 0 && info.Type != SaveDataType.System;
if (!canFixByProgramId && !canFixBySaveDataId && !hasEmptyOwnerId)
{
@@ -523,7 +514,7 @@ namespace Ryujinx.HLE.FileSystem
// The rest of the extra data can't be created from the save data info.
// On user saves the owner ID will almost certainly be the same as the program ID.
- if (info.Type != LibHac.Fs.SaveDataType.System)
+ if (info.Type != SaveDataType.System)
{
extraData.OwnerId = info.ProgramId.Value;
}
@@ -580,11 +571,6 @@ namespace Ryujinx.HLE.FileSystem
}
};
- public void Unload()
- {
- RomFs?.Dispose();
- }
-
public void Dispose()
{
Dispose(true);
@@ -594,20 +580,8 @@ namespace Ryujinx.HLE.FileSystem
{
if (disposing)
{
- Unload();
+ RomFs?.Dispose();
}
}
-
- public static VirtualFileSystem CreateInstance()
- {
- if (_isInitialized)
- {
- throw new InvalidOperationException("VirtualFileSystem can only be instantiated once!");
- }
-
- _isInitialized = true;
-
- return new VirtualFileSystem();
- }
}
} \ No newline at end of file