aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services
diff options
context:
space:
mode:
authorAlex Barney <thealexbarney@gmail.com>2019-01-04 17:41:49 -0700
committerAc_K <Acoustik666@gmail.com>2019-01-05 01:41:49 +0100
commit290f5e812e68e47d95aba0cc3789a4bc6d04c7ce (patch)
treeffe7b55c31c913e002afe55db1f68107cd1da854 /Ryujinx.HLE/HOS/Services
parentcf147f1e4977a2dfe197d00341739b72a0e3a129 (diff)
Update to LibHac 0.2.0 (#549)
* Update to LibHac 0.2.0 * Changes based on feedback
Diffstat (limited to 'Ryujinx.HLE/HOS/Services')
-rw-r--r--Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs65
-rw-r--r--Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs40
2 files changed, 51 insertions, 54 deletions
diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs
index 9df7880c..878f2e4e 100644
--- a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs
+++ b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs
@@ -1,4 +1,5 @@
using LibHac;
+using LibHac.IO;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.Utilities;
@@ -65,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
if (extension == ".nca")
{
- return OpenNcaFs(context, fullPath, fileStream);
+ return OpenNcaFs(context, fullPath, fileStream.AsStorage());
}
else if (extension == ".nsp")
{
@@ -174,10 +175,10 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
if (File.Exists(ncaPath))
{
- 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);
+ LibHac.IO.IStorage ncaStorage = new FileStream(ncaPath, FileMode.Open, FileAccess.Read).AsStorage();
+ Nca nca = new Nca(context.Device.System.KeySet, ncaStorage, false);
+ NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
+ Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel, false).AsStream();
MakeObject(context, new IStorage(romfsStream));
@@ -234,17 +235,11 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
private long OpenNsp(ServiceCtx context, string pfsPath)
{
- FileStream pfsFile = new FileStream(pfsPath, FileMode.Open, FileAccess.Read);
- Pfs nsp = new Pfs(pfsFile);
- PfsFileEntry ticketFile = nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
+ FileStream pfsFile = new FileStream(pfsPath, FileMode.Open, FileAccess.Read);
+ Pfs nsp = new Pfs(pfsFile.AsStorage());
- if (ticketFile != null)
- {
- Ticket ticket = new Ticket(nsp.OpenFile(ticketFile));
+ ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet);
- context.Device.System.KeySet.TitleKeys[ticket.RightsId] =
- ticket.GetTitleKey(context.Device.System.KeySet);
- }
IFileSystem nspFileSystem = new IFileSystem(pfsPath, new PFsProvider(nsp));
@@ -253,25 +248,25 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
return 0;
}
- private long OpenNcaFs(ServiceCtx context,string ncaPath, Stream ncaStream)
+ private long OpenNcaFs(ServiceCtx context, string ncaPath, LibHac.IO.IStorage ncaStorage)
{
- Nca nca = new Nca(context.Device.System.KeySet, ncaStream, false);
+ Nca nca = new Nca(context.Device.System.KeySet, ncaStorage, false);
NcaSection romfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs);
NcaSection pfsSection = nca.Sections.FirstOrDefault(x => x?.Type == SectionType.Pfs0);
if (romfsSection != null)
{
- Stream romfsStream = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
- IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new RomFsProvider(romfsStream));
+ LibHac.IO.IStorage romfsStorage = nca.OpenSection(romfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel, false);
+ IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new RomFsProvider(romfsStorage));
MakeObject(context, ncaFileSystem);
}
- else if(pfsSection !=null)
+ else if(pfsSection != null)
{
- Stream pfsStream = nca.OpenSection(pfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel);
- Pfs pfs = new Pfs(pfsStream);
- IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new PFsProvider(pfs));
+ LibHac.IO.IStorage pfsStorage = nca.OpenSection(pfsSection.SectionNum, false, context.Device.System.FsIntegrityCheckLevel, false);
+ Pfs pfs = new Pfs(pfsStorage);
+ IFileSystem ncaFileSystem = new IFileSystem(ncaPath, new PFsProvider(pfs));
MakeObject(context, ncaFileSystem);
}
@@ -299,17 +294,10 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
FileMode.Open,
FileAccess.Read);
- Pfs nsp = new Pfs(pfsFile);
- PfsFileEntry ticketFile = nsp.Files.FirstOrDefault(x => x.Name.EndsWith(".tik"));
-
- if (ticketFile != null)
- {
- Ticket ticket = new Ticket(nsp.OpenFile(ticketFile));
-
- context.Device.System.KeySet.TitleKeys[ticket.RightsId] =
- ticket.GetTitleKey(context.Device.System.KeySet);
- }
+ Pfs nsp = new Pfs(pfsFile.AsStorage());
+ ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet);
+
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\');
if (nsp.FileExists(filename))
@@ -320,5 +308,18 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
}
+
+ private void ImportTitleKeysFromNsp(Pfs nsp, Keyset keySet)
+ {
+ foreach (PfsFileEntry ticketEntry in nsp.Files.Where(x => x.Name.EndsWith(".tik")))
+ {
+ Ticket ticket = new Ticket(nsp.OpenFile(ticketEntry).AsStream());
+
+ if (!keySet.TitleKeys.ContainsKey(ticket.RightsId))
+ {
+ keySet.TitleKeys.Add(ticket.RightsId, ticket.GetTitleKey(keySet));
+ }
+ }
+ }
}
} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs b/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs
index b4464b77..8eec31cf 100644
--- a/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs
+++ b/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs
@@ -1,12 +1,13 @@
+using LibHac;
+using LibHac.IO;
using Ryujinx.Common.Logging;
+using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.SystemState;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
-using LibHac;
-using Ryujinx.HLE.FileSystem;
namespace Ryujinx.HLE.HOS.Services.Set
{
@@ -173,7 +174,6 @@ namespace Ryujinx.HLE.HOS.Services.Set
public static byte[] GetFirmwareData(Switch device)
{
- byte[] data = null;
long titleId = 0x0100000000000809;
string contentPath = device.System.ContentManager.GetInstalledContentPath(titleId, StorageId.NandSystem, ContentType.Data);
@@ -182,32 +182,28 @@ namespace Ryujinx.HLE.HOS.Services.Set
return null;
}
- string firmwareTitlePath = device.FileSystem.SwitchPathToSystemPath(contentPath);
- FileStream firmwareStream = File.Open(firmwareTitlePath, FileMode.Open, FileAccess.Read);
- Nca firmwareContent = new Nca(device.System.KeySet, firmwareStream, false);
- Stream romFsStream = firmwareContent.OpenSection(0, false, device.System.FsIntegrityCheckLevel);
+ string firmwareTitlePath = device.FileSystem.SwitchPathToSystemPath(contentPath);
- if(romFsStream == null)
- {
- return null;
- }
+ using(FileStream firmwareStream = File.Open(firmwareTitlePath, FileMode.Open, FileAccess.Read))
+ {
+ Nca firmwareContent = new Nca(device.System.KeySet, firmwareStream.AsStorage(), false);
+ IStorage romFsStorage = firmwareContent.OpenSection(0, false, device.System.FsIntegrityCheckLevel, false);
- Romfs firmwareRomFs = new Romfs(romFsStream);
-
- using(MemoryStream memoryStream = new MemoryStream())
- {
- using (Stream firmwareFile = firmwareRomFs.OpenFile("/file"))
+ if(romFsStorage == null)
{
- firmwareFile.CopyTo(memoryStream);
+ return null;
}
- data = memoryStream.ToArray();
- }
+ Romfs firmwareRomFs = new Romfs(romFsStorage);
- firmwareContent.Dispose();
- firmwareStream.Dispose();
+ IStorage firmwareFile = firmwareRomFs.OpenFile("/file");
- return data;
+ byte[] data = new byte[firmwareFile.Length];
+
+ firmwareFile.Read(data, 0);
+
+ return data;
+ }
}
}
}