2018-11-18 14:37:41 -05:00
|
|
|
using LibHac;
|
2019-05-31 20:31:10 -04:00
|
|
|
using LibHac.Fs;
|
|
|
|
using LibHac.Fs.NcaUtils;
|
2019-07-04 11:14:17 -04:00
|
|
|
using Ryujinx.Common;
|
2019-06-15 21:31:18 -04:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-09-08 18:04:26 -04:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2018-10-07 09:13:46 -04:00
|
|
|
using Ryujinx.HLE.Utilities;
|
2018-11-18 14:37:41 -05:00
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using static Ryujinx.HLE.FileSystem.VirtualFileSystem;
|
|
|
|
using static Ryujinx.HLE.Utilities.StringUtils;
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.FspSrv
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-07-10 11:59:54 -04:00
|
|
|
[Service("fsp-srv")]
|
2018-04-06 00:01:52 -04:00
|
|
|
class IFileSystemProxy : IpcService
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-07-11 21:13:43 -04:00
|
|
|
public IFileSystemProxy(ServiceCtx context) { }
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(1)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// Initialize(u64, pid)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(8)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenFileSystemWithId(nn::fssrv::sf::FileSystemType filesystem_type, nn::ApplicationId tid, buffer<bytes<0x301>, 0x19, 0x301> path)
|
|
|
|
// -> object<nn::fssrv::sf::IFileSystem> contentFs
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenFileSystemWithId(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
FileSystemType fileSystemType = (FileSystemType)context.RequestData.ReadInt32();
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
|
|
|
string switchPath = ReadUtf8String(context);
|
|
|
|
string fullPath = context.Device.FileSystem.SwitchPathToSystemPath(switchPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (!File.Exists(fullPath))
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
if (fullPath.Contains("."))
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
return OpenFileSystemFromInternalFile(context, fullPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.PathDoesNotExist;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
|
|
|
|
string extension = Path.GetExtension(fullPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (extension == ".nca")
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-01-04 19:41:49 -05:00
|
|
|
return OpenNcaFs(context, fullPath, fileStream.AsStorage());
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
2018-12-06 06:16:24 -05:00
|
|
|
else if (extension == ".nsp")
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
return OpenNsp(context, fullPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.InvalidInput;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(11)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenBisFileSystem(nn::fssrv::sf::Partition partitionID, buffer<bytes<0x301>, 0x19, 0x301>) -> object<nn::fssrv::sf::IFileSystem> Bis
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenBisFileSystem(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-05-31 20:31:10 -04:00
|
|
|
int bisPartitionId = context.RequestData.ReadInt32();
|
|
|
|
string partitionString = ReadUtf8String(context);
|
|
|
|
string bisPartitionPath = string.Empty;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
switch (bisPartitionId)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
|
|
|
case 29:
|
2019-05-31 20:31:10 -04:00
|
|
|
bisPartitionPath = SafeNandPath;
|
2018-11-18 14:37:41 -05:00
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
case 31:
|
2019-05-31 20:31:10 -04:00
|
|
|
bisPartitionPath = SystemNandPath;
|
2018-11-18 14:37:41 -05:00
|
|
|
break;
|
|
|
|
case 32:
|
2019-05-31 20:31:10 -04:00
|
|
|
bisPartitionPath = UserNandPath;
|
2018-11-18 14:37:41 -05:00
|
|
|
break;
|
|
|
|
default:
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.InvalidInput;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
string fullPath = context.Device.FileSystem.GetFullPartitionPath(bisPartitionPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
LocalFileSystem fileSystem = new LocalFileSystem(fullPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
MakeObject(context, new IFileSystem(fileSystem));
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(18)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenSdCardFileSystem() -> object<nn::fssrv::sf::IFileSystem>
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenSdCardFileSystem(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
string sdCardPath = context.Device.FileSystem.GetSdCardPath();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
LocalFileSystem fileSystem = new LocalFileSystem(sdCardPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
MakeObject(context, new IFileSystem(fileSystem));
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(51)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenSaveDataFileSystem(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> saveDataFs
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenSaveDataFileSystem(ServiceCtx context)
|
2018-06-02 18:46:09 -04:00
|
|
|
{
|
2019-07-10 13:20:01 -04:00
|
|
|
return LoadSaveDataFileSystem(context);
|
2018-06-02 18:46:09 -04:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(52)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenSaveDataFileSystemBySystemSaveDataId(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> systemSaveDataFs
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenSaveDataFileSystemBySystemSaveDataId(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-07-10 13:20:01 -04:00
|
|
|
return LoadSaveDataFileSystem(context);
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(200)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage> dataStorage
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenDataStorageByCurrentProcess(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-05-31 20:31:10 -04:00
|
|
|
MakeObject(context, new IStorage(context.Device.FileSystem.RomFs.AsStorage()));
|
2018-02-24 23:34:16 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(202)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenDataStorageByDataId(ServiceCtx context)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
StorageId storageId = (StorageId)context.RequestData.ReadByte();
|
|
|
|
byte[] padding = context.RequestData.ReadBytes(7);
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-30 08:36:35 -05:00
|
|
|
ContentType contentType = ContentType.Data;
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
StorageId installedStorage =
|
2018-12-30 08:36:35 -05:00
|
|
|
context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (installedStorage == StorageId.None)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-05-31 20:31:10 -04:00
|
|
|
contentType = ContentType.PublicData;
|
2018-12-30 08:36:35 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
installedStorage =
|
2018-12-30 08:36:35 -05:00
|
|
|
context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId);
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (installedStorage != StorageId.None)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-30 08:36:35 -05:00
|
|
|
string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, contentType);
|
2018-12-06 06:16:24 -05:00
|
|
|
string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (!string.IsNullOrWhiteSpace(installPath))
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
string ncaPath = installPath;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (File.Exists(ncaPath))
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-07-10 13:20:01 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
LibHac.Fs.IStorage ncaStorage = new LocalStorage(ncaPath, FileAccess.Read, FileMode.Open);
|
|
|
|
Nca nca = new Nca(context.Device.System.KeySet, ncaStorage);
|
|
|
|
LibHac.Fs.IStorage romfsStorage = nca.OpenStorage(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel);
|
|
|
|
|
|
|
|
MakeObject(context, new IStorage(romfsStorage));
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
2019-07-14 15:04:38 -04:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2019-07-10 13:20:01 -04:00
|
|
|
}
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
throw new FileNotFoundException($"No Nca found in Path `{ncaPath}`.");
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
throw new DirectoryNotFoundException($"Path for title id {titleId:x16} on Storage {storageId} was not found in Path {installPath}.");
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
throw new FileNotFoundException($"System archive with titleid {titleId:x16} was not found on Storage {storageId}. Found in {installedStorage}.");
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(203)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenPatchDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage>
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenPatchDataStorageByCurrentProcess(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-05-31 20:31:10 -04:00
|
|
|
MakeObject(context, new IStorage(context.Device.FileSystem.RomFs.AsStorage()));
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(1005)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// GetGlobalAccessLogMode() -> u32 logMode
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetGlobalAccessLogMode(ServiceCtx context)
|
2018-02-24 23:34:16 -05:00
|
|
|
{
|
2019-06-15 21:31:18 -04:00
|
|
|
int mode = context.Device.System.GlobalAccessLogMode;
|
|
|
|
|
|
|
|
context.ResponseData.Write(mode);
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2019-06-15 21:31:18 -04:00
|
|
|
}
|
|
|
|
|
2019-07-11 21:13:43 -04:00
|
|
|
[Command(1006)]
|
2019-06-15 21:31:18 -04:00
|
|
|
// OutputAccessLogToSdCard(buffer<bytes, 5> log_text)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OutputAccessLogToSdCard(ServiceCtx context)
|
2019-06-15 21:31:18 -04:00
|
|
|
{
|
|
|
|
string message = ReadUtf8StringSend(context);
|
|
|
|
|
|
|
|
// FS ends each line with a newline. Remove it because Ryujinx logging adds its own newline
|
|
|
|
Logger.PrintAccessLog(LogClass.ServiceFs, message.TrimEnd('\n'));
|
2018-02-24 23:34:16 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-04-06 00:01:52 -04:00
|
|
|
}
|
2018-09-08 18:04:26 -04:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode LoadSaveDataFileSystem(ServiceCtx context)
|
2018-09-08 18:04:26 -04:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64();
|
2018-09-08 18:04:26 -04:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-09-08 18:04:26 -04:00
|
|
|
|
2019-07-04 11:14:17 -04:00
|
|
|
UInt128 userId = context.RequestData.ReadStruct<UInt128>();
|
2018-09-08 18:04:26 -04:00
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
long saveId = context.RequestData.ReadInt64();
|
|
|
|
SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte();
|
|
|
|
SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, userId, saveSpaceId);
|
|
|
|
string savePath = context.Device.FileSystem.GetGameSavePath(saveInfo, context);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
LocalFileSystem fileSystem = new LocalFileSystem(savePath);
|
|
|
|
DirectorySaveDataFileSystem saveFileSystem = new DirectorySaveDataFileSystem(fileSystem);
|
|
|
|
|
|
|
|
MakeObject(context, new IFileSystem(saveFileSystem));
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
2019-07-14 15:04:38 -04:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2019-07-10 13:20:01 -04:00
|
|
|
}
|
2019-05-31 20:31:10 -04:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
private ResultCode OpenNsp(ServiceCtx context, string pfsPath)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-07-10 13:20:01 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
LocalStorage storage = new LocalStorage(pfsPath, FileAccess.Read, FileMode.Open);
|
|
|
|
PartitionFileSystem nsp = new PartitionFileSystem(storage);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet);
|
|
|
|
|
|
|
|
IFileSystem nspFileSystem = new IFileSystem(nsp);
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
MakeObject(context, nspFileSystem);
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
2019-07-14 15:04:38 -04:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2019-07-10 13:20:01 -04:00
|
|
|
}
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
private ResultCode OpenNcaFs(ServiceCtx context, string ncaPath, LibHac.Fs.IStorage ncaStorage)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-07-10 13:20:01 -04:00
|
|
|
try
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-07-10 13:20:01 -04:00
|
|
|
Nca nca = new Nca(context.Device.System.KeySet, ncaStorage);
|
|
|
|
|
|
|
|
if (!nca.SectionExists(NcaSectionType.Data))
|
|
|
|
{
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.PartitionNotFound;
|
2019-07-10 13:20:01 -04:00
|
|
|
}
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
LibHac.Fs.IFileSystem fileSystem = nca.OpenFileSystem(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel);
|
2019-05-31 20:31:10 -04:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
MakeObject(context, new IFileSystem(fileSystem));
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
2019-07-14 15:04:38 -04:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2019-07-10 13:20:01 -04:00
|
|
|
}
|
2019-05-31 20:31:10 -04:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.Success;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
private ResultCode OpenFileSystemFromInternalFile(ServiceCtx context, string fullPath)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
DirectoryInfo archivePath = new DirectoryInfo(fullPath).Parent;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
while (string.IsNullOrWhiteSpace(archivePath.Extension))
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
archivePath = archivePath.Parent;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
if (archivePath.Extension == ".nsp" && File.Exists(archivePath.FullName))
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
FileStream pfsFile = new FileStream(
|
|
|
|
archivePath.FullName.TrimEnd(Path.DirectorySeparatorChar),
|
2018-11-18 14:37:41 -05:00
|
|
|
FileMode.Open,
|
|
|
|
FileAccess.Read);
|
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
PartitionFileSystem nsp = new PartitionFileSystem(pfsFile.AsStorage());
|
2018-09-08 18:04:26 -04:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet);
|
|
|
|
|
|
|
|
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\');
|
2018-09-08 18:04:26 -04:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
if (nsp.FileExists(filename))
|
|
|
|
{
|
|
|
|
return OpenNcaFs(context, fullPath, nsp.OpenFile(filename, OpenMode.Read).AsStorage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
2018-11-18 14:37:41 -05:00
|
|
|
{
|
2019-07-14 15:04:38 -04:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2018-11-18 14:37:41 -05:00
|
|
|
}
|
|
|
|
}
|
2018-09-08 18:04:26 -04:00
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
return ResultCode.PathDoesNotExist;
|
2018-09-08 18:04:26 -04:00
|
|
|
}
|
2019-01-04 19:41:49 -05:00
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
private void ImportTitleKeysFromNsp(LibHac.Fs.IFileSystem nsp, Keyset keySet)
|
2019-01-04 19:41:49 -05:00
|
|
|
{
|
2019-07-01 22:39:22 -04:00
|
|
|
foreach (DirectoryEntry ticketEntry in nsp.EnumerateEntries("*.tik"))
|
2019-01-04 19:41:49 -05:00
|
|
|
{
|
2019-05-31 20:31:10 -04:00
|
|
|
Ticket ticket = new Ticket(nsp.OpenFile(ticketEntry.FullPath, OpenMode.Read).AsStream());
|
2019-01-04 19:41:49 -05:00
|
|
|
|
|
|
|
if (!keySet.TitleKeys.ContainsKey(ticket.RightsId))
|
|
|
|
{
|
|
|
|
keySet.TitleKeys.Add(ticket.RightsId, ticket.GetTitleKey(keySet));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-24 23:34:16 -05:00
|
|
|
}
|
|
|
|
}
|