From 3f0ab45b9c4efe13964ec858f9c84a6d0462e99f Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Wed, 31 Jul 2024 19:01:31 +0200 Subject: [PATCH] Resolve symlinks for TryGetRealPath() as well --- .../Utilities/FileSystemUtils.cs | 23 +++++++++++++++++++ src/Ryujinx.HLE/FileSystem/ContentPath.cs | 12 +++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Common/Utilities/FileSystemUtils.cs b/src/Ryujinx.Common/Utilities/FileSystemUtils.cs index 2628efc74..50c2a2b87 100644 --- a/src/Ryujinx.Common/Utilities/FileSystemUtils.cs +++ b/src/Ryujinx.Common/Utilities/FileSystemUtils.cs @@ -65,6 +65,29 @@ namespace Ryujinx.Common.Utilities return pathInfo.FullName; } + // TODO: This is bad. Resolve all data paths on startup instead. + public static string CombineAndResolveFullPath(bool isDirectory, params string[] paths) + { + if (paths.Length == 0) + { + return null; + } + + if (paths.Length == 1) + { + return ResolveFullPath(paths[0], isDirectory); + } + + string fullPath = ResolveFullPath(paths[0], true); + + for (int i = 1; i < paths.Length - 1; i++) + { + fullPath = ResolveFullPath(Path.Combine(fullPath, paths[i]), true); + } + + return ResolveFullPath(Path.Combine(fullPath, paths[^1]), isDirectory); + } + public static FileInfo GetActualFileInfo(this FileInfo fileInfo) { if (fileInfo.Exists) diff --git a/src/Ryujinx.HLE/FileSystem/ContentPath.cs b/src/Ryujinx.HLE/FileSystem/ContentPath.cs index ffc212f77..5e612eb1f 100644 --- a/src/Ryujinx.HLE/FileSystem/ContentPath.cs +++ b/src/Ryujinx.HLE/FileSystem/ContentPath.cs @@ -1,9 +1,9 @@ using LibHac.Fs; using LibHac.Ncm; using Ryujinx.Common.Configuration; +using Ryujinx.Common.Utilities; using System; using static Ryujinx.HLE.FileSystem.VirtualFileSystem; -using Path = System.IO.Path; namespace Ryujinx.HLE.FileSystem { @@ -30,11 +30,11 @@ namespace Ryujinx.HLE.FileSystem { realPath = switchContentPath switch { - SystemContent => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath, Contents), - UserContent => Path.Combine(AppDataManager.BaseDirPath, UserNandPath, Contents), - SdCardContent => Path.Combine(GetSdCardPath(), Nintendo, Contents), - System => Path.Combine(AppDataManager.BaseDirPath, SystemNandPath), - User => Path.Combine(AppDataManager.BaseDirPath, UserNandPath), + SystemContent => FileSystemUtils.CombineAndResolveFullPath(true, AppDataManager.BaseDirPath, SystemNandPath, Contents), + UserContent => FileSystemUtils.CombineAndResolveFullPath(true, AppDataManager.BaseDirPath, UserNandPath, Contents), + SdCardContent => FileSystemUtils.CombineAndResolveFullPath(true, GetSdCardPath(), Nintendo, Contents), + System => FileSystemUtils.CombineAndResolveFullPath(true, AppDataManager.BaseDirPath, SystemNandPath), + User => FileSystemUtils.CombineAndResolveFullPath(true, AppDataManager.BaseDirPath, UserNandPath), _ => null, };