2018-11-18 20:37:41 +01:00
|
|
|
using LibHac;
|
2018-09-09 00:04:26 +02:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2018-08-17 01:47:36 +02:00
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-10-07 15:13:46 +02:00
|
|
|
using Ryujinx.HLE.Utilities;
|
2018-02-25 05:34:16 +01:00
|
|
|
using System.Collections.Generic;
|
2018-11-18 20:37:41 +01:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using static Ryujinx.HLE.FileSystem.VirtualFileSystem;
|
|
|
|
using static Ryujinx.HLE.HOS.ErrorCode;
|
|
|
|
using static Ryujinx.HLE.Utilities.StringUtils;
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.FspSrv
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-04-06 06:01:52 +02:00
|
|
|
class IFileSystemProxy : IpcService
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2018-04-06 06:01:52 +02:00
|
|
|
public IFileSystemProxy()
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-11-18 20:37:41 +01:00
|
|
|
{ 1, Initialize },
|
|
|
|
{ 8, OpenFileSystemWithId },
|
|
|
|
{ 11, OpenBisFileSystem },
|
2018-09-09 00:04:26 +02:00
|
|
|
{ 18, OpenSdCardFileSystem },
|
|
|
|
{ 51, OpenSaveDataFileSystem },
|
|
|
|
{ 52, OpenSaveDataFileSystemBySystemSaveDataId },
|
|
|
|
{ 200, OpenDataStorageByCurrentProcess },
|
2018-11-18 20:37:41 +01:00
|
|
|
{ 202, OpenDataStorageByDataId },
|
2018-09-09 00:04:26 +02:00
|
|
|
{ 203, OpenPatchDataStorageByCurrentProcess },
|
|
|
|
{ 1005, GetGlobalAccessLogMode }
|
2018-02-25 05:34:16 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// Initialize(u64, pid)
|
2018-12-05 01:52:39 +01:00
|
|
|
public long Initialize(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenFileSystemWithId(nn::fssrv::sf::FileSystemType filesystem_type, nn::ApplicationId tid, buffer<bytes<0x301>, 0x19, 0x301> path)
|
|
|
|
// -> object<nn::fssrv::sf::IFileSystem> contentFs
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenFileSystemWithId(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01: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 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (!File.Exists(FullPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (FullPath.Contains("."))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return OpenFileSystemFromInternalFile(Context, FullPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
FileStream FileStream = new FileStream(FullPath, FileMode.Open, FileAccess.Read);
|
|
|
|
string Extension = Path.GetExtension(FullPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Extension == ".nca")
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return OpenNcaFs(Context, FullPath, FileStream);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-12-05 01:52:39 +01:00
|
|
|
else if (Extension == ".nsp")
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return OpenNsp(Context, FullPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.InvalidInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenBisFileSystem(nn::fssrv::sf::Partition partitionID, buffer<bytes<0x301>, 0x19, 0x301>) -> object<nn::fssrv::sf::IFileSystem> Bis
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenBisFileSystem(ServiceCtx Context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
int BisPartitionId = Context.RequestData.ReadInt32();
|
|
|
|
string PartitionString = ReadUtf8String(Context);
|
|
|
|
string BisPartitonPath = string.Empty;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
switch (BisPartitionId)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
|
|
|
case 29:
|
2018-12-05 01:52:39 +01:00
|
|
|
BisPartitonPath = SafeNandPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
case 31:
|
2018-12-05 01:52:39 +01:00
|
|
|
BisPartitonPath = SystemNandPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2018-12-05 01:52:39 +01:00
|
|
|
BisPartitonPath = UserNandPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.InvalidInput);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string FullPath = Context.Device.FileSystem.GetFullPartitionPath(BisPartitonPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
FileSystemProvider FileSystemProvider = new FileSystemProvider(FullPath, Context.Device.FileSystem.GetBasePath());
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, new IFileSystem(FullPath, FileSystemProvider));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-02-25 05:34:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenSdCardFileSystem() -> object<nn::fssrv::sf::IFileSystem>
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenSdCardFileSystem(ServiceCtx Context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string SdCardPath = Context.Device.FileSystem.GetSdCardPath();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
FileSystemProvider FileSystemProvider = new FileSystemProvider(SdCardPath, Context.Device.FileSystem.GetBasePath());
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, new IFileSystem(SdCardPath, FileSystemProvider));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenSaveDataFileSystem(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> saveDataFs
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenSaveDataFileSystem(ServiceCtx Context)
|
2018-06-03 00:46:09 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
LoadSaveDataFileSystem(Context);
|
2018-06-03 00:46:09 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenSaveDataFileSystemBySystemSaveDataId(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> systemSaveDataFs
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenSaveDataFileSystemBySystemSaveDataId(ServiceCtx Context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
LoadSaveDataFileSystem(Context);
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage> dataStorage
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenDataStorageByCurrentProcess(ServiceCtx Context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, new IStorage(Context.Device.FileSystem.RomFs));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenDataStorageByDataId(ServiceCtx Context)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
StorageId StorageId = (StorageId)Context.RequestData.ReadByte();
|
|
|
|
byte[] Padding = Context.RequestData.ReadBytes(7);
|
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
StorageId InstalledStorage =
|
|
|
|
Context.Device.System.ContentManager.GetInstalledStorage(TitleId, ContentType.Data, StorageId);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (InstalledStorage == StorageId.None)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
InstalledStorage =
|
|
|
|
Context.Device.System.ContentManager.GetInstalledStorage(TitleId, ContentType.AocData, StorageId);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (InstalledStorage != StorageId.None)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (string.IsNullOrWhiteSpace(ContentPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
ContentPath = Context.Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId, ContentType.AocData);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string InstallPath = Context.Device.FileSystem.SwitchPathToSystemPath(ContentPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (!string.IsNullOrWhiteSpace(InstallPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string NcaPath = InstallPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (File.Exists(NcaPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
FileStream NcaStream = new FileStream(NcaPath, FileMode.Open, FileAccess.Read);
|
|
|
|
Nca Nca = new Nca(Context.Device.System.KeySet, NcaStream, false);
|
|
|
|
NcaSection RomfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
|
|
|
Stream RomfsStream = Nca.OpenSection(RomfsSection.SectionNum, false, Context.Device.System.FsIntegrityCheckLevel);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, new IStorage(RomfsStream));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
throw new FileNotFoundException($"No Nca found in Path `{NcaPath}`.");
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
throw new DirectoryNotFoundException($"Path for title id {TitleId:x16} on Storage {StorageId} was not found in Path {InstallPath}.");
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
throw new FileNotFoundException($"System archive with titleid {TitleId:x16} was not found on Storage {StorageId}. Found in {InstalledStorage}.");
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// OpenPatchDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage>
|
2018-12-05 01:52:39 +01:00
|
|
|
public long OpenPatchDataStorageByCurrentProcess(ServiceCtx Context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, new IStorage(Context.Device.FileSystem.RomFs));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// GetGlobalAccessLogMode() -> u32 logMode
|
2018-12-05 01:52:39 +01:00
|
|
|
public long GetGlobalAccessLogMode(ServiceCtx Context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Context.ResponseData.Write(0);
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
2018-04-06 06:01:52 +02:00
|
|
|
}
|
2018-09-09 00:04:26 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public void LoadSaveDataFileSystem(ServiceCtx Context)
|
2018-09-09 00:04:26 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
SaveSpaceId SaveSpaceId = (SaveSpaceId)Context.RequestData.ReadInt64();
|
2018-09-09 00:04:26 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long TitleId = Context.RequestData.ReadInt64();
|
2018-09-09 00:04:26 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
UInt128 UserId = new UInt128(
|
|
|
|
Context.RequestData.ReadInt64(),
|
|
|
|
Context.RequestData.ReadInt64());
|
2018-09-09 00:04:26 +02:00
|
|
|
|
2018-12-05 01:52:39 +01: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);
|
|
|
|
FileSystemProvider FileSystemProvider = new FileSystemProvider(SavePath, Context.Device.FileSystem.GetBasePath());
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, new IFileSystem(SavePath, FileSystemProvider));
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private long OpenNsp(ServiceCtx Context, string PfsPath)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
FileStream PfsFile = new FileStream(PfsPath, FileMode.Open, FileAccess.Read);
|
|
|
|
Pfs Nsp = new Pfs(PfsFile);
|
|
|
|
PfsFileEntry TicketFile = Nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (TicketFile != null)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Ticket Ticket = new Ticket(Nsp.OpenFile(TicketFile));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Context.Device.System.KeySet.TitleKeys[Ticket.RightsId] =
|
|
|
|
Ticket.GetTitleKey(Context.Device.System.KeySet);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
IFileSystem NspFileSystem = new IFileSystem(PfsPath, new PFsProvider(Nsp));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, NspFileSystem);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private long OpenNcaFs(ServiceCtx Context,string NcaPath, Stream NcaStream)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Nca Nca = new Nca(Context.Device.System.KeySet, NcaStream, false);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
NcaSection RomfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
|
|
|
|
NcaSection PfsSection = Nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Pfs0);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (RomfsSection != null)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Stream RomfsStream = Nca.OpenSection(RomfsSection.SectionNum, false, Context.Device.System.FsIntegrityCheckLevel);
|
|
|
|
IFileSystem NcaFileSystem = new IFileSystem(NcaPath, new RomFsProvider(RomfsStream));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, NcaFileSystem);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-12-05 01:52:39 +01:00
|
|
|
else if(PfsSection !=null)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Stream PfsStream = Nca.OpenSection(PfsSection.SectionNum, false, Context.Device.System.FsIntegrityCheckLevel);
|
|
|
|
Pfs Pfs = new Pfs(PfsStream);
|
|
|
|
IFileSystem NcaFileSystem = new IFileSystem(NcaPath, new PFsProvider(Pfs));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, NcaFileSystem);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PartitionNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private long OpenFileSystemFromInternalFile(ServiceCtx Context, string FullPath)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
DirectoryInfo ArchivePath = new DirectoryInfo(FullPath).Parent;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
while (string.IsNullOrWhiteSpace(ArchivePath.Extension))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
ArchivePath = ArchivePath.Parent;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (ArchivePath.Extension == ".nsp" && File.Exists(ArchivePath.FullName))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
FileStream PfsFile = new FileStream(
|
|
|
|
ArchivePath.FullName.TrimEnd(Path.DirectorySeparatorChar),
|
2018-11-18 20:37:41 +01:00
|
|
|
FileMode.Open,
|
|
|
|
FileAccess.Read);
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Pfs Nsp = new Pfs(PfsFile);
|
|
|
|
PfsFileEntry TicketFile = Nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (TicketFile != null)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Ticket Ticket = new Ticket(Nsp.OpenFile(TicketFile));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
Context.Device.System.KeySet.TitleKeys[Ticket.RightsId] =
|
|
|
|
Ticket.GetTitleKey(Context.Device.System.KeySet);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-09-09 00:04:26 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string Filename = FullPath.Replace(ArchivePath.FullName, string.Empty).TrimStart('\\');
|
2018-09-09 00:04:26 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Nsp.FileExists(Filename))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return OpenNcaFs(Context, FullPath, Nsp.OpenFile(Filename));
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
}
|
2018-09-09 00:04:26 +02:00
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
2018-09-09 00:04:26 +02:00
|
|
|
}
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
|
|
|
}
|