Fix filename trimming and other path related issues in OpenFileSystemFromInternalFile

This commit is contained in:
TSR Berry 2024-07-11 00:39:28 +02:00
commit eab85667e1
No known key found for this signature in database
GPG key ID: 52353C0A4CCA15E2

View file

@ -10,6 +10,7 @@ using LibHac.Tools.Es;
using LibHac.Tools.Fs; using LibHac.Tools.Fs;
using LibHac.Tools.FsSystem; using LibHac.Tools.FsSystem;
using LibHac.Tools.FsSystem.NcaUtils; using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Common.Utilities;
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -78,17 +79,21 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
DirectoryInfo archivePath = new DirectoryInfo(fullPath).Parent; DirectoryInfo archivePath = new DirectoryInfo(fullPath).Parent;
while (string.IsNullOrWhiteSpace(archivePath.Extension)) while (archivePath != null && string.IsNullOrWhiteSpace(archivePath.Extension))
{ {
archivePath = archivePath.Parent; archivePath = archivePath.Parent;
} }
if (archivePath.Extension == ".nsp" && File.Exists(archivePath.FullName)) if (archivePath == null)
{ {
FileStream pfsFile = new( return ResultCode.PathDoesNotExist;
archivePath.FullName.TrimEnd(Path.DirectorySeparatorChar), }
FileMode.Open,
FileAccess.Read); FileInfo archiveInfo = FileSystemUtils.GetActualFileInfo(Path.TrimEndingDirectorySeparator(archivePath.FullName));
if (archivePath.Extension.ToLower() == ".nsp" && archiveInfo.Exists)
{
FileStream pfsFile = archiveInfo.Open(FileMode.Open, FileAccess.Read);
try try
{ {
@ -97,7 +102,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet); ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet);
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\'); string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart(Path.DirectorySeparatorChar);
using var ncaFile = new UniqueRef<LibHac.Fs.Fsa.IFile>(); using var ncaFile = new UniqueRef<LibHac.Fs.Fsa.IFile>();