Update to LibHac 0.2.0 (#549)

* Update to LibHac 0.2.0

* Changes based on feedback
This commit is contained in:
Alex Barney 2019-01-04 17:41:49 -07:00 committed by Ac_K
parent cf147f1e49
commit 290f5e812e
9 changed files with 110 additions and 120 deletions

View file

@ -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);
IStorage firmwareFile = firmwareRomFs.OpenFile("/file");
byte[] data = new byte[firmwareFile.Length];
firmwareFile.Read(data, 0);
return data;
}
firmwareContent.Dispose();
firmwareStream.Dispose();
return data;
}
}
}