Merge branch 'master' into aot
This commit is contained in:
commit
0b955b880c
21 changed files with 1195 additions and 188 deletions
|
@ -45,7 +45,7 @@ The latest automatic build for Windows, macOS, and Linux can be found on the [Of
|
||||||
|
|
||||||
- **System Titles**
|
- **System Titles**
|
||||||
|
|
||||||
Some of our System Module implementations, like `time`, require [System Data Archives](https://switchbrew.org/wiki/Title_list#System_Data_Archives). You can install them by mounting your nand partition using [HacDiskMount](https://switchtools.sshnuke.net/) and copying the content to `Ryujinx/nand/system`.
|
Some of our System Module implementations, like `time`, require [System Data Archives](https://switchbrew.org/wiki/Title_list#System_Data_Archives). You can install them by mounting your nand partition using [HacDiskMount](https://switchtools.sshnuke.net/) and copying the content to `Ryujinx/bis/system`.
|
||||||
|
|
||||||
- **Executables**
|
- **Executables**
|
||||||
|
|
||||||
|
|
|
@ -66,12 +66,13 @@ namespace Ryujinx.Graphics.Gpu.Memory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pa">CPU virtual address to map into</param>
|
/// <param name="pa">CPU virtual address to map into</param>
|
||||||
/// <param name="size">Size in bytes of the mapping</param>
|
/// <param name="size">Size in bytes of the mapping</param>
|
||||||
|
/// <param name="alignment">Required alignment of the GPU virtual address in bytes</param>
|
||||||
/// <returns>GPU virtual address where the range was mapped, or an all ones mask in case of failure</returns>
|
/// <returns>GPU virtual address where the range was mapped, or an all ones mask in case of failure</returns>
|
||||||
public ulong Map(ulong pa, ulong size)
|
public ulong MapAllocate(ulong pa, ulong size, ulong alignment)
|
||||||
{
|
{
|
||||||
lock (_pageTable)
|
lock (_pageTable)
|
||||||
{
|
{
|
||||||
ulong va = GetFreePosition(size);
|
ulong va = GetFreePosition(size, alignment);
|
||||||
|
|
||||||
if (va != PteUnmapped)
|
if (va != PteUnmapped)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Ryujinx.HLE.Exceptions
|
||||||
|
{
|
||||||
|
class InvalidFirmwarePackageException : Exception
|
||||||
|
{
|
||||||
|
public InvalidFirmwarePackageException(string message) : base(message) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,22 +1,30 @@
|
||||||
using LibHac.FsSystem;
|
using LibHac;
|
||||||
|
using LibHac.Fs;
|
||||||
|
using LibHac.FsSystem;
|
||||||
using LibHac.FsSystem.NcaUtils;
|
using LibHac.FsSystem.NcaUtils;
|
||||||
|
using LibHac.Ncm;
|
||||||
|
using Ryujinx.HLE.Exceptions;
|
||||||
using Ryujinx.HLE.HOS.Services.Time;
|
using Ryujinx.HLE.HOS.Services.Time;
|
||||||
using Ryujinx.HLE.Utilities;
|
using Ryujinx.HLE.Utilities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.FileSystem.Content
|
namespace Ryujinx.HLE.FileSystem.Content
|
||||||
{
|
{
|
||||||
internal class ContentManager
|
internal class ContentManager
|
||||||
{
|
{
|
||||||
|
private const ulong SystemVersionTitleId = 0x0100000000000809;
|
||||||
|
private const ulong SystemUpdateTitleId = 0x0100000000000816;
|
||||||
|
|
||||||
private Dictionary<StorageId, LinkedList<LocationEntry>> _locationEntries;
|
private Dictionary<StorageId, LinkedList<LocationEntry>> _locationEntries;
|
||||||
|
|
||||||
private Dictionary<string, long> _sharedFontTitleDictionary;
|
private Dictionary<string, long> _sharedFontTitleDictionary;
|
||||||
private Dictionary<string, string> _sharedFontFilenameDictionary;
|
private Dictionary<string, string> _sharedFontFilenameDictionary;
|
||||||
|
|
||||||
private SortedDictionary<(ulong, NcaContentType), string> _contentDictionary;
|
private SortedDictionary<(ulong titleId, NcaContentType type), string> _contentDictionary;
|
||||||
|
|
||||||
private Switch _device;
|
private Switch _device;
|
||||||
|
|
||||||
|
@ -48,9 +56,10 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
_device = device;
|
_device = device;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadEntries()
|
public void LoadEntries(bool ignoreMissingFonts = false)
|
||||||
{
|
{
|
||||||
_contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>();
|
_contentDictionary = new SortedDictionary<(ulong, NcaContentType), string>();
|
||||||
|
_locationEntries = new Dictionary<StorageId, LinkedList<LocationEntry>>();
|
||||||
|
|
||||||
foreach (StorageId storageId in Enum.GetValues(typeof(StorageId)))
|
foreach (StorageId storageId in Enum.GetValues(typeof(StorageId)))
|
||||||
{
|
{
|
||||||
|
@ -144,6 +153,8 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeManager.Instance.InitializeTimeZone(_device);
|
TimeManager.Instance.InitializeTimeZone(_device);
|
||||||
|
|
||||||
|
_device.System.Font.Initialize(this, ignoreMissingFonts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearEntry(long titleId, NcaContentType contentType, StorageId storageId)
|
public void ClearEntry(long titleId, NcaContentType contentType, StorageId storageId)
|
||||||
|
@ -153,7 +164,7 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
|
|
||||||
public void RefreshEntries(StorageId storageId, int flag)
|
public void RefreshEntries(StorageId storageId, int flag)
|
||||||
{
|
{
|
||||||
LinkedList<LocationEntry> locationList = _locationEntries[storageId];
|
LinkedList<LocationEntry> locationList = _locationEntries[storageId];
|
||||||
LinkedListNode<LocationEntry> locationEntry = locationList.First;
|
LinkedListNode<LocationEntry> locationEntry = locationList.First;
|
||||||
|
|
||||||
while (locationEntry != null)
|
while (locationEntry != null)
|
||||||
|
@ -173,9 +184,10 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
{
|
{
|
||||||
if (_contentDictionary.ContainsValue(ncaId))
|
if (_contentDictionary.ContainsValue(ncaId))
|
||||||
{
|
{
|
||||||
var content = _contentDictionary.FirstOrDefault(x => x.Value == ncaId);
|
var content = _contentDictionary.FirstOrDefault(x => x.Value == ncaId);
|
||||||
long titleId = (long)content.Key.Item1;
|
long titleId = (long)content.Key.Item1;
|
||||||
NcaContentType contentType = content.Key.Item2;
|
|
||||||
|
NcaContentType contentType = content.Key.type;
|
||||||
StorageId storage = GetInstalledStorage(titleId, contentType, storageId);
|
StorageId storage = GetInstalledStorage(titleId, contentType, storageId);
|
||||||
|
|
||||||
return storage == storageId;
|
return storage == storageId;
|
||||||
|
@ -186,9 +198,9 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
|
|
||||||
public UInt128 GetInstalledNcaId(long titleId, NcaContentType contentType)
|
public UInt128 GetInstalledNcaId(long titleId, NcaContentType contentType)
|
||||||
{
|
{
|
||||||
if (_contentDictionary.ContainsKey(((ulong)titleId,contentType)))
|
if (_contentDictionary.ContainsKey(((ulong)titleId, contentType)))
|
||||||
{
|
{
|
||||||
return new UInt128(_contentDictionary[((ulong)titleId,contentType)]);
|
return new UInt128(_contentDictionary[((ulong)titleId, contentType)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UInt128();
|
return new UInt128();
|
||||||
|
@ -232,9 +244,8 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageId storageId = LocationHelper.GetStorageId(locationEntry.ContentPath);
|
string installedPath = _device.FileSystem.SwitchPathToSystemPath(locationEntry.ContentPath);
|
||||||
string installedPath = _device.FileSystem.SwitchPathToSystemPath(locationEntry.ContentPath);
|
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(installedPath))
|
if (!string.IsNullOrWhiteSpace(installedPath))
|
||||||
{
|
{
|
||||||
|
@ -242,7 +253,7 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
{
|
{
|
||||||
using (FileStream file = new FileStream(installedPath, FileMode.Open, FileAccess.Read))
|
using (FileStream file = new FileStream(installedPath, FileMode.Open, FileAccess.Read))
|
||||||
{
|
{
|
||||||
Nca nca = new Nca(_device.System.KeySet, file.AsStorage());
|
Nca nca = new Nca(_device.System.KeySet, file.AsStorage());
|
||||||
bool contentCheck = nca.Header.ContentType == contentType;
|
bool contentCheck = nca.Header.ContentType == contentType;
|
||||||
|
|
||||||
return contentCheck;
|
return contentCheck;
|
||||||
|
@ -310,5 +321,539 @@ namespace Ryujinx.HLE.FileSystem.Content
|
||||||
|
|
||||||
return locationList.ToList().Find(x => x.TitleId == titleId && x.ContentType == contentType);
|
return locationList.ToList().Find(x => x.TitleId == titleId && x.ContentType == contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void InstallFirmware(string firmwareSource)
|
||||||
|
{
|
||||||
|
string contentPathString = LocationHelper.GetContentRoot(StorageId.NandSystem);
|
||||||
|
string contentDirectory = LocationHelper.GetRealPath(_device.FileSystem, contentPathString);
|
||||||
|
string registeredDirectory = Path.Combine(contentDirectory, "registered");
|
||||||
|
string temporaryDirectory = Path.Combine(contentDirectory, "temp");
|
||||||
|
|
||||||
|
if (Directory.Exists(temporaryDirectory))
|
||||||
|
{
|
||||||
|
Directory.Delete(temporaryDirectory, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Directory.Exists(firmwareSource))
|
||||||
|
{
|
||||||
|
InstallFromDirectory(firmwareSource, temporaryDirectory);
|
||||||
|
FinishInstallation(temporaryDirectory, registeredDirectory);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(firmwareSource))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Firmware file does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInfo info = new FileInfo(firmwareSource);
|
||||||
|
|
||||||
|
using (FileStream file = File.OpenRead(firmwareSource))
|
||||||
|
{
|
||||||
|
switch (info.Extension)
|
||||||
|
{
|
||||||
|
case ".zip":
|
||||||
|
using (ZipArchive archive = ZipFile.OpenRead(firmwareSource))
|
||||||
|
{
|
||||||
|
InstallFromZip(archive, temporaryDirectory);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ".xci":
|
||||||
|
Xci xci = new Xci(_device.System.KeySet, file.AsStorage());
|
||||||
|
InstallFromCart(xci, temporaryDirectory);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new InvalidFirmwarePackageException("Input file is not a valid firmware package");
|
||||||
|
}
|
||||||
|
|
||||||
|
FinishInstallation(temporaryDirectory, registeredDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FinishInstallation(string temporaryDirectory, string registeredDirectory)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(registeredDirectory))
|
||||||
|
{
|
||||||
|
new DirectoryInfo(registeredDirectory).Delete(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory.Move(temporaryDirectory, registeredDirectory);
|
||||||
|
|
||||||
|
LoadEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstallFromDirectory(string firmwareDirectory, string temporaryDirectory)
|
||||||
|
{
|
||||||
|
InstallFromPartition(new LocalFileSystem(firmwareDirectory), temporaryDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstallFromPartition(IFileSystem filesystem, string temporaryDirectory)
|
||||||
|
{
|
||||||
|
foreach (var entry in filesystem.EnumerateEntries("/", "*.nca"))
|
||||||
|
{
|
||||||
|
Nca nca = new Nca(_device.System.KeySet, OpenPossibleFragmentedFile(filesystem, entry.FullPath, OpenMode.Read).AsStorage());
|
||||||
|
|
||||||
|
SaveNca(nca, entry.Name.Remove(entry.Name.IndexOf('.')), temporaryDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstallFromCart(Xci gameCard, string temporaryDirectory)
|
||||||
|
{
|
||||||
|
if (gameCard.HasPartition(XciPartitionType.Update))
|
||||||
|
{
|
||||||
|
XciPartition partition = gameCard.OpenPartition(XciPartitionType.Update);
|
||||||
|
|
||||||
|
InstallFromPartition(partition, temporaryDirectory);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("Update not found in xci file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InstallFromZip(ZipArchive archive, string temporaryDirectory)
|
||||||
|
{
|
||||||
|
using (archive)
|
||||||
|
{
|
||||||
|
foreach (var entry in archive.Entries)
|
||||||
|
{
|
||||||
|
if (entry.FullName.EndsWith(".nca") || entry.FullName.EndsWith(".nca/00"))
|
||||||
|
{
|
||||||
|
// Clean up the name and get the NcaId
|
||||||
|
|
||||||
|
string[] pathComponents = entry.FullName.Replace(".cnmt", "").Split('/');
|
||||||
|
|
||||||
|
string ncaId = pathComponents[pathComponents.Length - 1];
|
||||||
|
|
||||||
|
// If this is a fragmented nca, we need to get the previous element.GetZip
|
||||||
|
if (ncaId.Equals("00"))
|
||||||
|
{
|
||||||
|
ncaId = pathComponents[pathComponents.Length - 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ncaId.Contains(".nca"))
|
||||||
|
{
|
||||||
|
string newPath = Path.Combine(temporaryDirectory, ncaId);
|
||||||
|
|
||||||
|
Directory.CreateDirectory(newPath);
|
||||||
|
|
||||||
|
entry.ExtractToFile(Path.Combine(newPath, "00"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveNca(Nca nca, string ncaId, string temporaryDirectory)
|
||||||
|
{
|
||||||
|
string newPath = Path.Combine(temporaryDirectory, ncaId + ".nca");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(newPath);
|
||||||
|
|
||||||
|
using (FileStream file = File.Create(Path.Combine(newPath, "00")))
|
||||||
|
{
|
||||||
|
nca.BaseStorage.AsStream().CopyTo(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IFile OpenPossibleFragmentedFile(IFileSystem filesystem, string path, OpenMode mode)
|
||||||
|
{
|
||||||
|
IFile file;
|
||||||
|
|
||||||
|
if (filesystem.FileExists($"{path}/00"))
|
||||||
|
{
|
||||||
|
filesystem.OpenFile(out file, $"{path}/00", mode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
filesystem.OpenFile(out file, path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stream GetZipStream(ZipArchiveEntry entry)
|
||||||
|
{
|
||||||
|
MemoryStream dest = new MemoryStream();
|
||||||
|
|
||||||
|
Stream src = entry.Open();
|
||||||
|
|
||||||
|
src.CopyTo(dest);
|
||||||
|
src.Dispose();
|
||||||
|
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemVersion VerifyFirmwarePackage(string firmwarePackage)
|
||||||
|
{
|
||||||
|
Dictionary<ulong, List<(NcaContentType type, string path)>> updateNcas = new Dictionary<ulong, List<(NcaContentType, string)>>();
|
||||||
|
|
||||||
|
if (Directory.Exists(firmwarePackage))
|
||||||
|
{
|
||||||
|
return VerifyAndGetVersionDirectory(firmwarePackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!File.Exists(firmwarePackage))
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("Firmware file does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInfo info = new FileInfo(firmwarePackage);
|
||||||
|
|
||||||
|
using (FileStream file = File.OpenRead(firmwarePackage))
|
||||||
|
{
|
||||||
|
switch (info.Extension)
|
||||||
|
{
|
||||||
|
case ".zip":
|
||||||
|
using (ZipArchive archive = ZipFile.OpenRead(firmwarePackage))
|
||||||
|
{
|
||||||
|
return VerifyAndGetVersionZip(archive);
|
||||||
|
}
|
||||||
|
case ".xci":
|
||||||
|
Xci xci = new Xci(_device.System.KeySet, file.AsStorage());
|
||||||
|
|
||||||
|
if (xci.HasPartition(XciPartitionType.Update))
|
||||||
|
{
|
||||||
|
XciPartition partition = xci.OpenPartition(XciPartitionType.Update);
|
||||||
|
|
||||||
|
return VerifyAndGetVersion(partition);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidFirmwarePackageException("Update not found in xci file.");
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemVersion VerifyAndGetVersionDirectory(string firmwareDirectory)
|
||||||
|
{
|
||||||
|
return VerifyAndGetVersion(new LocalFileSystem(firmwareDirectory));
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemVersion VerifyAndGetVersionZip(ZipArchive archive)
|
||||||
|
{
|
||||||
|
SystemVersion systemVersion = null;
|
||||||
|
|
||||||
|
foreach (var entry in archive.Entries)
|
||||||
|
{
|
||||||
|
if (entry.FullName.EndsWith(".nca") || entry.FullName.EndsWith(".nca/00"))
|
||||||
|
{
|
||||||
|
using (Stream ncaStream = GetZipStream(entry))
|
||||||
|
{
|
||||||
|
IStorage storage = ncaStream.AsStorage();
|
||||||
|
|
||||||
|
Nca nca = new Nca(_device.System.KeySet, storage);
|
||||||
|
|
||||||
|
if (updateNcas.ContainsKey(nca.Header.TitleId))
|
||||||
|
{
|
||||||
|
updateNcas[nca.Header.TitleId].Add((nca.Header.ContentType, entry.FullName));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateNcas.Add(nca.Header.TitleId, new List<(NcaContentType, string)>());
|
||||||
|
updateNcas[nca.Header.TitleId].Add((nca.Header.ContentType, entry.FullName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateNcas.ContainsKey(SystemUpdateTitleId))
|
||||||
|
{
|
||||||
|
var ncaEntry = updateNcas[SystemUpdateTitleId];
|
||||||
|
|
||||||
|
string metaPath = ncaEntry.Find(x => x.type == NcaContentType.Meta).path;
|
||||||
|
|
||||||
|
CnmtContentMetaEntry[] metaEntries = null;
|
||||||
|
|
||||||
|
var fileEntry = archive.GetEntry(metaPath);
|
||||||
|
|
||||||
|
using (Stream ncaStream = GetZipStream(fileEntry))
|
||||||
|
{
|
||||||
|
Nca metaNca = new Nca(_device.System.KeySet, ncaStream.AsStorage());
|
||||||
|
|
||||||
|
IFileSystem fs = metaNca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
|
||||||
|
|
||||||
|
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
|
||||||
|
|
||||||
|
if (fs.OpenFile(out IFile metaFile, cnmtPath, OpenMode.Read).IsSuccess())
|
||||||
|
{
|
||||||
|
var meta = new Cnmt(metaFile.AsStream());
|
||||||
|
|
||||||
|
if (meta.Type == ContentMetaType.SystemUpdate)
|
||||||
|
{
|
||||||
|
metaEntries = meta.MetaEntries;
|
||||||
|
|
||||||
|
updateNcas.Remove(SystemUpdateTitleId);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metaEntries == null)
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("System update title was not found in the firmware package.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateNcas.ContainsKey(SystemVersionTitleId))
|
||||||
|
{
|
||||||
|
string versionEntry = updateNcas[SystemVersionTitleId].Find(x => x.type != NcaContentType.Meta).path;
|
||||||
|
|
||||||
|
using (Stream ncaStream = GetZipStream(archive.GetEntry(versionEntry)))
|
||||||
|
{
|
||||||
|
Nca nca = new Nca(_device.System.KeySet, ncaStream.AsStorage());
|
||||||
|
|
||||||
|
var romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
|
||||||
|
|
||||||
|
if (romfs.OpenFile(out IFile systemVersionFile, "/file", OpenMode.Read).IsSuccess())
|
||||||
|
{
|
||||||
|
systemVersion = new SystemVersion(systemVersionFile.AsStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (CnmtContentMetaEntry metaEntry in metaEntries)
|
||||||
|
{
|
||||||
|
if (updateNcas.TryGetValue(metaEntry.TitleId, out ncaEntry))
|
||||||
|
{
|
||||||
|
metaPath = ncaEntry.Find(x => x.type == NcaContentType.Meta).path;
|
||||||
|
|
||||||
|
string contentPath = ncaEntry.Find(x => x.type != NcaContentType.Meta).path;
|
||||||
|
|
||||||
|
// Nintendo in 9.0.0, removed PPC and only kept the meta nca of it.
|
||||||
|
// This is a perfect valid case, so we should just ignore the missing content nca and continue.
|
||||||
|
if (contentPath == null)
|
||||||
|
{
|
||||||
|
updateNcas.Remove(metaEntry.TitleId);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipArchiveEntry metaZipEntry = archive.GetEntry(metaPath);
|
||||||
|
ZipArchiveEntry contentZipEntry = archive.GetEntry(contentPath);
|
||||||
|
|
||||||
|
using (Stream metaNcaStream = GetZipStream(metaZipEntry))
|
||||||
|
{
|
||||||
|
using (Stream contentNcaStream = GetZipStream(contentZipEntry))
|
||||||
|
{
|
||||||
|
Nca metaNca = new Nca(_device.System.KeySet, metaNcaStream.AsStorage());
|
||||||
|
|
||||||
|
IFileSystem fs = metaNca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
|
||||||
|
|
||||||
|
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
|
||||||
|
|
||||||
|
if (fs.OpenFile(out IFile metaFile, cnmtPath, OpenMode.Read).IsSuccess())
|
||||||
|
{
|
||||||
|
var meta = new Cnmt(metaFile.AsStream());
|
||||||
|
|
||||||
|
IStorage contentStorage = contentNcaStream.AsStorage();
|
||||||
|
if (contentStorage.GetSize(out long size).IsSuccess())
|
||||||
|
{
|
||||||
|
byte[] contentData = new byte[size];
|
||||||
|
|
||||||
|
Span<byte> content = new Span<byte>(contentData);
|
||||||
|
|
||||||
|
contentStorage.Read(0, content);
|
||||||
|
|
||||||
|
Span<byte> hash = new Span<byte>(new byte[32]);
|
||||||
|
|
||||||
|
LibHac.Crypto.Sha256.GenerateSha256Hash(content, hash);
|
||||||
|
|
||||||
|
if (LibHac.Util.ArraysEqual(hash.ToArray(), meta.ContentEntries[0].Hash))
|
||||||
|
{
|
||||||
|
updateNcas.Remove(metaEntry.TitleId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateNcas.Count > 0)
|
||||||
|
{
|
||||||
|
string extraNcas = string.Empty;
|
||||||
|
|
||||||
|
foreach (var entry in updateNcas)
|
||||||
|
{
|
||||||
|
foreach (var nca in entry.Value)
|
||||||
|
{
|
||||||
|
extraNcas += nca.path + Environment.NewLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidFirmwarePackageException($"Firmware package contains unrelated archives. Please remove these paths: {Environment.NewLine}{extraNcas}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("System update title was not found in the firmware package.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return systemVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemVersion VerifyAndGetVersion(IFileSystem filesystem)
|
||||||
|
{
|
||||||
|
SystemVersion systemVersion = null;
|
||||||
|
|
||||||
|
CnmtContentMetaEntry[] metaEntries = null;
|
||||||
|
|
||||||
|
foreach (var entry in filesystem.EnumerateEntries("/", "*.nca"))
|
||||||
|
{
|
||||||
|
IStorage ncaStorage = OpenPossibleFragmentedFile(filesystem, entry.FullPath, OpenMode.Read).AsStorage();
|
||||||
|
|
||||||
|
Nca nca = new Nca(_device.System.KeySet, ncaStorage);
|
||||||
|
|
||||||
|
if (nca.Header.TitleId == SystemUpdateTitleId && nca.Header.ContentType == NcaContentType.Meta)
|
||||||
|
{
|
||||||
|
IFileSystem fs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
|
||||||
|
|
||||||
|
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
|
||||||
|
|
||||||
|
if (fs.OpenFile(out IFile metaFile, cnmtPath, OpenMode.Read).IsSuccess())
|
||||||
|
{
|
||||||
|
var meta = new Cnmt(metaFile.AsStream());
|
||||||
|
|
||||||
|
if (meta.Type == ContentMetaType.SystemUpdate)
|
||||||
|
{
|
||||||
|
metaEntries = meta.MetaEntries;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (nca.Header.TitleId == SystemVersionTitleId && nca.Header.ContentType == NcaContentType.Data)
|
||||||
|
{
|
||||||
|
var romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
|
||||||
|
|
||||||
|
if (romfs.OpenFile(out IFile systemVersionFile, "/file", OpenMode.Read).IsSuccess())
|
||||||
|
{
|
||||||
|
systemVersion = new SystemVersion(systemVersionFile.AsStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateNcas.ContainsKey(nca.Header.TitleId))
|
||||||
|
{
|
||||||
|
updateNcas[nca.Header.TitleId].Add((nca.Header.ContentType, entry.FullPath));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
updateNcas.Add(nca.Header.TitleId, new List<(NcaContentType, string)>());
|
||||||
|
updateNcas[nca.Header.TitleId].Add((nca.Header.ContentType, entry.FullPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
ncaStorage.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metaEntries == null)
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException("System update title was not found in the firmware package.");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (CnmtContentMetaEntry metaEntry in metaEntries)
|
||||||
|
{
|
||||||
|
if (updateNcas.TryGetValue(metaEntry.TitleId, out var ncaEntry))
|
||||||
|
{
|
||||||
|
var metaNcaEntry = ncaEntry.Find(x => x.type == NcaContentType.Meta);
|
||||||
|
string contentPath = ncaEntry.Find(x => x.type != NcaContentType.Meta).path;
|
||||||
|
|
||||||
|
// Nintendo in 9.0.0, removed PPC and only kept the meta nca of it.
|
||||||
|
// This is a perfect valid case, so we should just ignore the missing content nca and continue.
|
||||||
|
if (contentPath == null)
|
||||||
|
{
|
||||||
|
updateNcas.Remove(metaEntry.TitleId);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
IStorage metaStorage = OpenPossibleFragmentedFile(filesystem, metaNcaEntry.path, OpenMode.Read).AsStorage();
|
||||||
|
IStorage contentStorage = OpenPossibleFragmentedFile(filesystem, contentPath, OpenMode.Read).AsStorage();
|
||||||
|
|
||||||
|
Nca metaNca = new Nca(_device.System.KeySet, metaStorage);
|
||||||
|
|
||||||
|
IFileSystem fs = metaNca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
|
||||||
|
|
||||||
|
string cnmtPath = fs.EnumerateEntries("/", "*.cnmt").Single().FullPath;
|
||||||
|
|
||||||
|
if (fs.OpenFile(out IFile metaFile, cnmtPath, OpenMode.Read).IsSuccess())
|
||||||
|
{
|
||||||
|
var meta = new Cnmt(metaFile.AsStream());
|
||||||
|
|
||||||
|
if (contentStorage.GetSize(out long size).IsSuccess())
|
||||||
|
{
|
||||||
|
byte[] contentData = new byte[size];
|
||||||
|
|
||||||
|
Span<byte> content = new Span<byte>(contentData);
|
||||||
|
|
||||||
|
contentStorage.Read(0, content);
|
||||||
|
|
||||||
|
Span<byte> hash = new Span<byte>(new byte[32]);
|
||||||
|
|
||||||
|
LibHac.Crypto.Sha256.GenerateSha256Hash(content, hash);
|
||||||
|
|
||||||
|
if (LibHac.Util.ArraysEqual(hash.ToArray(), meta.ContentEntries[0].Hash))
|
||||||
|
{
|
||||||
|
updateNcas.Remove(metaEntry.TitleId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updateNcas.Count > 0)
|
||||||
|
{
|
||||||
|
string extraNcas = string.Empty;
|
||||||
|
|
||||||
|
foreach (var entry in updateNcas)
|
||||||
|
{
|
||||||
|
foreach (var nca in entry.Value)
|
||||||
|
{
|
||||||
|
extraNcas += nca.path + Environment.NewLine;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidFirmwarePackageException($"Firmware package contains unrelated archives. Please remove these paths: {Environment.NewLine}{extraNcas}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return systemVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemVersion GetCurrentFirmwareVersion()
|
||||||
|
{
|
||||||
|
LoadEntries(true);
|
||||||
|
|
||||||
|
var locationEnties = _locationEntries[StorageId.NandSystem];
|
||||||
|
|
||||||
|
foreach (var entry in locationEnties)
|
||||||
|
{
|
||||||
|
if (entry.ContentType == NcaContentType.Data)
|
||||||
|
{
|
||||||
|
var path = _device.FileSystem.SwitchPathToSystemPath(entry.ContentPath);
|
||||||
|
|
||||||
|
using (IStorage ncaStorage = File.Open(path, FileMode.Open).AsStorage())
|
||||||
|
{
|
||||||
|
Nca nca = new Nca(_device.System.KeySet, ncaStorage);
|
||||||
|
|
||||||
|
if (nca.Header.TitleId == SystemVersionTitleId && nca.Header.ContentType == NcaContentType.Data)
|
||||||
|
{
|
||||||
|
var romfs = nca.OpenFileSystem(NcaSectionType.Data, _device.System.FsIntegrityCheckLevel);
|
||||||
|
|
||||||
|
if (romfs.OpenFile(out IFile systemVersionFile, "/file", OpenMode.Read).IsSuccess())
|
||||||
|
{
|
||||||
|
return new SystemVersion(systemVersionFile.AsStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
Ryujinx.HLE/FileSystem/Content/SystemVersion.cs
Normal file
41
Ryujinx.HLE/FileSystem/Content/SystemVersion.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Ryujinx.HLE.FileSystem.Content
|
||||||
|
{
|
||||||
|
public class SystemVersion
|
||||||
|
{
|
||||||
|
public byte Major { get; }
|
||||||
|
public byte Minor { get; }
|
||||||
|
public byte Micro { get; }
|
||||||
|
public byte RevisionMajor { get; }
|
||||||
|
public byte RevisionMinor { get; }
|
||||||
|
public string PlatformString { get; }
|
||||||
|
public string Hex { get; }
|
||||||
|
public string VersionString { get; }
|
||||||
|
public string VersionTitle { get; }
|
||||||
|
|
||||||
|
public SystemVersion(Stream systemVersionFile)
|
||||||
|
{
|
||||||
|
using (BinaryReader reader = new BinaryReader(systemVersionFile))
|
||||||
|
{
|
||||||
|
Major = reader.ReadByte();
|
||||||
|
Minor = reader.ReadByte();
|
||||||
|
Micro = reader.ReadByte();
|
||||||
|
|
||||||
|
reader.ReadByte(); // Padding
|
||||||
|
|
||||||
|
RevisionMajor = reader.ReadByte();
|
||||||
|
RevisionMinor = reader.ReadByte();
|
||||||
|
|
||||||
|
reader.ReadBytes(2); // Padding
|
||||||
|
|
||||||
|
PlatformString = Encoding.ASCII.GetString(reader.ReadBytes(0x20)).TrimEnd('\0');
|
||||||
|
Hex = Encoding.ASCII.GetString(reader.ReadBytes(0x40)).TrimEnd('\0');
|
||||||
|
VersionString = Encoding.ASCII.GetString(reader.ReadBytes(0x18)).TrimEnd('\0');
|
||||||
|
VersionTitle = Encoding.ASCII.GetString(reader.ReadBytes(0x80)).TrimEnd('\0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,7 +44,15 @@ namespace Ryujinx.HLE.HOS.Font
|
||||||
_fontsPath = Path.Combine(device.FileSystem.GetSystemPath(), "fonts");
|
_fontsPath = Path.Combine(device.FileSystem.GetSystemPath(), "fonts");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnsureInitialized(ContentManager contentManager)
|
public void Initialize(ContentManager contentManager, bool ignoreMissingFonts)
|
||||||
|
{
|
||||||
|
_fontData?.Clear();
|
||||||
|
_fontData = null;
|
||||||
|
|
||||||
|
EnsureInitialized(contentManager, ignoreMissingFonts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EnsureInitialized(ContentManager contentManager, bool ignoreMissingFonts)
|
||||||
{
|
{
|
||||||
if (_fontData == null)
|
if (_fontData == null)
|
||||||
{
|
{
|
||||||
|
@ -112,10 +120,12 @@ namespace Ryujinx.HLE.HOS.Font
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
else
|
else if (!ignoreMissingFonts)
|
||||||
{
|
{
|
||||||
throw new InvalidSystemResourceException($"Font \"{name}.ttf\" not found. Please provide it in \"{_fontsPath}\".");
|
throw new InvalidSystemResourceException($"Font \"{name}.ttf\" not found. Please provide it in \"{_fontsPath}\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new FontInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
_fontData = new Dictionary<SharedFontType, FontInfo>
|
_fontData = new Dictionary<SharedFontType, FontInfo>
|
||||||
|
@ -128,7 +138,7 @@ namespace Ryujinx.HLE.HOS.Font
|
||||||
{ SharedFontType.NintendoEx, CreateFont("FontNintendoExtended") }
|
{ SharedFontType.NintendoEx, CreateFont("FontNintendoExtended") }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (fontOffset > Horizon.FontSize)
|
if (fontOffset > Horizon.FontSize && !ignoreMissingFonts)
|
||||||
{
|
{
|
||||||
throw new InvalidSystemResourceException(
|
throw new InvalidSystemResourceException(
|
||||||
$"The sum of all fonts size exceed the shared memory size. " +
|
$"The sum of all fonts size exceed the shared memory size. " +
|
||||||
|
@ -151,14 +161,14 @@ namespace Ryujinx.HLE.HOS.Font
|
||||||
|
|
||||||
public int GetFontSize(SharedFontType fontType)
|
public int GetFontSize(SharedFontType fontType)
|
||||||
{
|
{
|
||||||
EnsureInitialized(_device.System.ContentManager);
|
EnsureInitialized(_device.System.ContentManager, false);
|
||||||
|
|
||||||
return _fontData[fontType].Size;
|
return _fontData[fontType].Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetSharedMemoryAddressOffset(SharedFontType fontType)
|
public int GetSharedMemoryAddressOffset(SharedFontType fontType)
|
||||||
{
|
{
|
||||||
EnsureInitialized(_device.System.ContentManager);
|
EnsureInitialized(_device.System.ContentManager, false);
|
||||||
|
|
||||||
return _fontData[fontType].Offset + 8;
|
return _fontData[fontType].Offset + 8;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
using ARMeilleure.Translation.AOT;
|
using ARMeilleure.Translation.AOT;
|
||||||
using LibHac;
|
using LibHac;
|
||||||
|
using LibHac.Account;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
using LibHac.Fs;
|
using LibHac.Fs;
|
||||||
using LibHac.FsService;
|
using LibHac.FsService;
|
||||||
using LibHac.FsSystem;
|
using LibHac.FsSystem;
|
||||||
using LibHac.FsSystem.NcaUtils;
|
using LibHac.FsSystem.NcaUtils;
|
||||||
|
using LibHac.Ncm;
|
||||||
using LibHac.Ns;
|
using LibHac.Ns;
|
||||||
using LibHac.Spl;
|
using LibHac.Spl;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
|
@ -33,6 +35,8 @@ using System.Threading;
|
||||||
using TimeServiceManager = Ryujinx.HLE.HOS.Services.Time.TimeManager;
|
using TimeServiceManager = Ryujinx.HLE.HOS.Services.Time.TimeManager;
|
||||||
using NxStaticObject = Ryujinx.HLE.Loaders.Executables.NxStaticObject;
|
using NxStaticObject = Ryujinx.HLE.Loaders.Executables.NxStaticObject;
|
||||||
|
|
||||||
|
using static LibHac.Fs.ApplicationSaveDataManagement;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.HOS
|
namespace Ryujinx.HLE.HOS
|
||||||
{
|
{
|
||||||
public class Horizon : IDisposable
|
public class Horizon : IDisposable
|
||||||
|
@ -110,7 +114,8 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
public string TitleName { get; private set; }
|
public string TitleName { get; private set; }
|
||||||
|
|
||||||
public string TitleId { get; private set; }
|
public ulong TitleId { get; private set; }
|
||||||
|
public string TitleIdText => TitleId.ToString("x16");
|
||||||
|
|
||||||
public IntegrityCheckLevel FsIntegrityCheckLevel { get; set; }
|
public IntegrityCheckLevel FsIntegrityCheckLevel { get; set; }
|
||||||
|
|
||||||
|
@ -514,7 +519,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
|
|
||||||
LoadExeFs(codeFs, out Npdm metaData);
|
LoadExeFs(codeFs, out Npdm metaData);
|
||||||
|
|
||||||
TitleId = metaData.Aci0.TitleId.ToString("x16");
|
TitleId = metaData.Aci0.TitleId;
|
||||||
|
|
||||||
if (controlNca != null)
|
if (controlNca != null)
|
||||||
{
|
{
|
||||||
|
@ -524,6 +529,11 @@ namespace Ryujinx.HLE.HOS
|
||||||
{
|
{
|
||||||
ControlData.ByteSpan.Clear();
|
ControlData.ByteSpan.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TitleId != 0)
|
||||||
|
{
|
||||||
|
EnsureSaveData(new TitleId(TitleId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadExeFs(IFileSystem codeFs, out Npdm metaData)
|
private void LoadExeFs(IFileSystem codeFs, out Npdm metaData)
|
||||||
|
@ -562,7 +572,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TitleId = metaData.Aci0.TitleId.ToString("x16");
|
TitleId = metaData.Aci0.TitleId;
|
||||||
|
|
||||||
LoadNso("rtld");
|
LoadNso("rtld");
|
||||||
LoadNso("main");
|
LoadNso("main");
|
||||||
|
@ -669,7 +679,7 @@ namespace Ryujinx.HLE.HOS
|
||||||
ContentManager.LoadEntries();
|
ContentManager.LoadEntries();
|
||||||
|
|
||||||
TitleName = metaData.TitleName;
|
TitleName = metaData.TitleName;
|
||||||
TitleId = metaData.Aci0.TitleId.ToString("x16");
|
TitleId = metaData.Aci0.TitleId;
|
||||||
|
|
||||||
ProgramLoader.LoadStaticObjects(this, metaData, new IExecutable[] { staticObject });
|
ProgramLoader.LoadStaticObjects(this, metaData, new IExecutable[] { staticObject });
|
||||||
}
|
}
|
||||||
|
@ -684,6 +694,39 @@ namespace Ryujinx.HLE.HOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Result EnsureSaveData(TitleId titleId)
|
||||||
|
{
|
||||||
|
Logger.PrintInfo(LogClass.Application, "Ensuring required savedata exists.");
|
||||||
|
|
||||||
|
UInt128 lastOpenedUser = State.Account.LastOpenedUser.UserId;
|
||||||
|
Uid user = new Uid((ulong)lastOpenedUser.Low, (ulong)lastOpenedUser.High);
|
||||||
|
|
||||||
|
ref ApplicationControlProperty control = ref ControlData.Value;
|
||||||
|
|
||||||
|
if (LibHac.Util.IsEmpty(ControlData.ByteSpan))
|
||||||
|
{
|
||||||
|
// If the current application doesn't have a loaded control property, create a dummy one
|
||||||
|
// and set the savedata sizes so a user savedata will be created.
|
||||||
|
control = ref new BlitStruct<ApplicationControlProperty>(1).Value;
|
||||||
|
|
||||||
|
// The set sizes don't actually matter as long as they're non-zero because we use directory savedata.
|
||||||
|
control.UserAccountSaveDataSize = 0x4000;
|
||||||
|
control.UserAccountSaveDataJournalSize = 0x4000;
|
||||||
|
|
||||||
|
Logger.PrintWarning(LogClass.Application,
|
||||||
|
"No control file was found for this game. Using a dummy one instead. This may cause inaccuracies in some games.");
|
||||||
|
}
|
||||||
|
|
||||||
|
Result rc = EnsureApplicationSaveData(FsClient, out _, titleId, ref ControlData.Value, ref user);
|
||||||
|
|
||||||
|
if (rc.IsFailure())
|
||||||
|
{
|
||||||
|
Logger.PrintError(LogClass.Application, $"Error calling EnsureApplicationSaveData. Result code {rc.ToStringWithName()}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
public void LoadKeySet()
|
public void LoadKeySet()
|
||||||
{
|
{
|
||||||
string keyFile = null;
|
string keyFile = null;
|
||||||
|
@ -720,6 +763,21 @@ namespace Ryujinx.HLE.HOS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SystemVersion VerifyFirmwarePackage(string firmwarePackage)
|
||||||
|
{
|
||||||
|
return ContentManager.VerifyFirmwarePackage(firmwarePackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemVersion GetCurrentFirmwareVersion()
|
||||||
|
{
|
||||||
|
return ContentManager.GetCurrentFirmwareVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void InstallFirmware(string firmwarePackage)
|
||||||
|
{
|
||||||
|
ContentManager.InstallFirmware(firmwarePackage);
|
||||||
|
}
|
||||||
|
|
||||||
public void SignalVsync()
|
public void SignalVsync()
|
||||||
{
|
{
|
||||||
VsyncEvent.ReadableEvent.Signal();
|
VsyncEvent.ReadableEvent.Signal();
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
using ARMeilleure.Memory;
|
using ARMeilleure.Memory;
|
||||||
|
using Ryujinx.Common;
|
||||||
using Ryujinx.HLE.HOS.Diagnostics.Demangler;
|
using Ryujinx.HLE.HOS.Diagnostics.Demangler;
|
||||||
using Ryujinx.HLE.HOS.Kernel.Memory;
|
using Ryujinx.HLE.HOS.Kernel.Memory;
|
||||||
using Ryujinx.HLE.Loaders.Elf;
|
using Ryujinx.HLE.Loaders.Elf;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
|
@ -72,25 +75,43 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ARM32.
|
|
||||||
long framePointer = (long)context.GetX(29);
|
|
||||||
|
|
||||||
trace.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}");
|
trace.AppendLine($"Process: {_owner.Name}, PID: {_owner.Pid}");
|
||||||
|
|
||||||
while (framePointer != 0)
|
if (context.IsAarch32)
|
||||||
{
|
{
|
||||||
if ((framePointer & 7) != 0 ||
|
long framePointer = (long)context.GetX(11);
|
||||||
!_owner.CpuMemory.IsMapped(framePointer) ||
|
|
||||||
!_owner.CpuMemory.IsMapped(framePointer + 8))
|
while (framePointer != 0)
|
||||||
{
|
{
|
||||||
break;
|
if ((framePointer & 3) != 0 ||
|
||||||
|
!_owner.CpuMemory.IsMapped(framePointer) ||
|
||||||
|
!_owner.CpuMemory.IsMapped(framePointer + 4))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppendTrace(_owner.CpuMemory.ReadInt32(framePointer + 4));
|
||||||
|
|
||||||
|
framePointer = _owner.CpuMemory.ReadInt32(framePointer);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
long framePointer = (long)context.GetX(29);
|
||||||
|
|
||||||
// Note: This is the return address, we need to subtract one instruction
|
while (framePointer != 0)
|
||||||
// worth of bytes to get the branch instruction address.
|
{
|
||||||
AppendTrace(_owner.CpuMemory.ReadInt64(framePointer + 8) - 4);
|
if ((framePointer & 7) != 0 ||
|
||||||
|
!_owner.CpuMemory.IsMapped(framePointer) ||
|
||||||
|
!_owner.CpuMemory.IsMapped(framePointer + 8))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
framePointer = _owner.CpuMemory.ReadInt64(framePointer);
|
AppendTrace(_owner.CpuMemory.ReadInt64(framePointer + 8));
|
||||||
|
|
||||||
|
framePointer = _owner.CpuMemory.ReadInt64(framePointer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return trace.ToString();
|
return trace.ToString();
|
||||||
|
@ -111,9 +132,9 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
|
|
||||||
ElfSymbol symbol = image.Symbols[middle];
|
ElfSymbol symbol = image.Symbols[middle];
|
||||||
|
|
||||||
long endAddr = symbol.Value + symbol.Size;
|
ulong endAddr = symbol.Value + symbol.Size;
|
||||||
|
|
||||||
if ((ulong)address >= (ulong)symbol.Value && (ulong)address < (ulong)endAddr)
|
if ((ulong)address >= symbol.Value && (ulong)address < endAddr)
|
||||||
{
|
{
|
||||||
name = symbol.Name;
|
name = symbol.Name;
|
||||||
|
|
||||||
|
@ -242,13 +263,28 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
long ehHdrEndOffset = memory.ReadInt32(mod0Offset + 0x14) + mod0Offset;
|
long ehHdrEndOffset = memory.ReadInt32(mod0Offset + 0x14) + mod0Offset;
|
||||||
long modObjOffset = memory.ReadInt32(mod0Offset + 0x18) + mod0Offset;
|
long modObjOffset = memory.ReadInt32(mod0Offset + 0x18) + mod0Offset;
|
||||||
|
|
||||||
// TODO: Elf32.
|
bool isAArch32 = memory.ReadUInt64(dynamicOffset) > 0xFFFFFFFF || memory.ReadUInt64(dynamicOffset + 0x10) > 0xFFFFFFFF;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
long tagVal = memory.ReadInt64(dynamicOffset + 0);
|
long tagVal;
|
||||||
long value = memory.ReadInt64(dynamicOffset + 8);
|
long value;
|
||||||
|
|
||||||
|
if (isAArch32)
|
||||||
|
{
|
||||||
|
tagVal = memory.ReadInt32(dynamicOffset + 0);
|
||||||
|
value = memory.ReadInt32(dynamicOffset + 4);
|
||||||
|
|
||||||
|
dynamicOffset += 0x8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tagVal = memory.ReadInt64(dynamicOffset + 0);
|
||||||
|
value = memory.ReadInt64(dynamicOffset + 8);
|
||||||
|
|
||||||
|
dynamicOffset += 0x10;
|
||||||
|
}
|
||||||
|
|
||||||
dynamicOffset += 0x10;
|
|
||||||
|
|
||||||
ElfDynamicTag tag = (ElfDynamicTag)tagVal;
|
ElfDynamicTag tag = (ElfDynamicTag)tagVal;
|
||||||
|
|
||||||
|
@ -274,7 +310,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
|
|
||||||
while ((ulong)symTblAddr < (ulong)strTblAddr)
|
while ((ulong)symTblAddr < (ulong)strTblAddr)
|
||||||
{
|
{
|
||||||
ElfSymbol sym = GetSymbol(memory, symTblAddr, strTblAddr);
|
ElfSymbol sym = isAArch32 ? GetSymbol32(memory, symTblAddr, strTblAddr) : GetSymbol64(memory, symTblAddr, strTblAddr);
|
||||||
|
|
||||||
symbols.Add(sym);
|
symbols.Add(sym);
|
||||||
|
|
||||||
|
@ -287,23 +323,42 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ElfSymbol GetSymbol(MemoryManager memory, long address, long strTblAddr)
|
private ElfSymbol GetSymbol64(MemoryManager memory, long address, long strTblAddr)
|
||||||
{
|
{
|
||||||
int nameIndex = memory.ReadInt32(address + 0);
|
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(memory.ReadBytes(address, Unsafe.SizeOf<ElfSymbol64>()))))
|
||||||
int info = memory.ReadByte (address + 4);
|
|
||||||
int other = memory.ReadByte (address + 5);
|
|
||||||
int shIdx = memory.ReadInt16(address + 6);
|
|
||||||
long value = memory.ReadInt64(address + 8);
|
|
||||||
long size = memory.ReadInt64(address + 16);
|
|
||||||
|
|
||||||
string name = string.Empty;
|
|
||||||
|
|
||||||
for (int chr; (chr = memory.ReadByte(strTblAddr + nameIndex++)) != 0;)
|
|
||||||
{
|
{
|
||||||
name += (char)chr;
|
ElfSymbol64 sym = inputStream.ReadStruct<ElfSymbol64>();
|
||||||
}
|
|
||||||
|
|
||||||
return new ElfSymbol(name, info, other, shIdx, value, size);
|
uint nameIndex = sym.NameOffset;
|
||||||
|
|
||||||
|
string name = string.Empty;
|
||||||
|
|
||||||
|
for (int chr; (chr = memory.ReadByte(strTblAddr + nameIndex++)) != 0;)
|
||||||
|
{
|
||||||
|
name += (char)chr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ElfSymbol GetSymbol32(MemoryManager memory, long address, long strTblAddr)
|
||||||
|
{
|
||||||
|
using (BinaryReader inputStream = new BinaryReader(new MemoryStream(memory.ReadBytes(address, Unsafe.SizeOf<ElfSymbol32>()))))
|
||||||
|
{
|
||||||
|
ElfSymbol32 sym = inputStream.ReadStruct<ElfSymbol32>();
|
||||||
|
|
||||||
|
uint nameIndex = sym.NameOffset;
|
||||||
|
|
||||||
|
string name = string.Empty;
|
||||||
|
|
||||||
|
for (int chr; (chr = memory.ReadByte(strTblAddr + nameIndex++)) != 0;)
|
||||||
|
{
|
||||||
|
name += (char)chr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ElfSymbol(name, sym.Info, sym.Other, sym.SectionIndex, sym.ValueAddress, sym.Size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,10 @@
|
||||||
using Ryujinx.HLE.FileSystem;
|
using Ryujinx.HLE.FileSystem;
|
||||||
using Ryujinx.HLE.Utilities;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Ryujinx.HLE.HOS.Services.Arp
|
namespace Ryujinx.HLE.HOS.Services.Arp
|
||||||
{
|
{
|
||||||
class ApplicationLaunchProperty
|
class ApplicationLaunchProperty
|
||||||
{
|
{
|
||||||
public long TitleId;
|
public ulong TitleId;
|
||||||
public int Version;
|
public int Version;
|
||||||
public byte BaseGameStorageId;
|
public byte BaseGameStorageId;
|
||||||
public byte UpdateGameStorageId;
|
public byte UpdateGameStorageId;
|
||||||
|
@ -33,7 +31,7 @@ namespace Ryujinx.HLE.HOS.Services.Arp
|
||||||
|
|
||||||
return new ApplicationLaunchProperty
|
return new ApplicationLaunchProperty
|
||||||
{
|
{
|
||||||
TitleId = BitConverter.ToInt64(StringUtils.HexToBytes(context.Device.System.TitleId), 0),
|
TitleId = context.Device.System.TitleId,
|
||||||
Version = 0x00,
|
Version = 0x00,
|
||||||
BaseGameStorageId = (byte)StorageId.NandSystem,
|
BaseGameStorageId = (byte)StorageId.NandSystem,
|
||||||
UpdateGameStorageId = (byte)StorageId.None
|
UpdateGameStorageId = (byte)StorageId.None
|
||||||
|
|
|
@ -133,6 +133,20 @@ namespace Ryujinx.HLE.HOS.Services.Fs
|
||||||
SaveDataCreateInfo createInfo = context.RequestData.ReadStruct<SaveDataCreateInfo>();
|
SaveDataCreateInfo createInfo = context.RequestData.ReadStruct<SaveDataCreateInfo>();
|
||||||
SaveMetaCreateInfo metaCreateInfo = context.RequestData.ReadStruct<SaveMetaCreateInfo>();
|
SaveMetaCreateInfo metaCreateInfo = context.RequestData.ReadStruct<SaveMetaCreateInfo>();
|
||||||
|
|
||||||
|
// TODO: There's currently no program registry for FS to reference.
|
||||||
|
// Workaround that by setting the application ID and owner ID if they're not already set
|
||||||
|
if (attribute.TitleId == TitleId.Zero)
|
||||||
|
{
|
||||||
|
attribute.TitleId = new TitleId(context.Process.TitleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createInfo.OwnerId == TitleId.Zero)
|
||||||
|
{
|
||||||
|
createInfo.OwnerId = new TitleId(context.Process.TitleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.PrintInfo(LogClass.ServiceFs, $"Creating save with title ID {attribute.TitleId.Value:x16}");
|
||||||
|
|
||||||
Result result = _baseFileSystemProxy.CreateSaveDataFileSystem(ref attribute, ref createInfo, ref metaCreateInfo);
|
Result result = _baseFileSystemProxy.CreateSaveDataFileSystem(ref attribute, ref createInfo, ref metaCreateInfo);
|
||||||
|
|
||||||
return (ResultCode)result.Value;
|
return (ResultCode)result.Value;
|
||||||
|
@ -196,6 +210,18 @@ namespace Ryujinx.HLE.HOS.Services.Fs
|
||||||
SaveMetaCreateInfo metaCreateInfo = context.RequestData.ReadStruct<SaveMetaCreateInfo>();
|
SaveMetaCreateInfo metaCreateInfo = context.RequestData.ReadStruct<SaveMetaCreateInfo>();
|
||||||
HashSalt hashSalt = context.RequestData.ReadStruct<HashSalt>();
|
HashSalt hashSalt = context.RequestData.ReadStruct<HashSalt>();
|
||||||
|
|
||||||
|
// TODO: There's currently no program registry for FS to reference.
|
||||||
|
// Workaround that by setting the application ID and owner ID if they're not already set
|
||||||
|
if (attribute.TitleId == TitleId.Zero)
|
||||||
|
{
|
||||||
|
attribute.TitleId = new TitleId(context.Process.TitleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createInfo.OwnerId == TitleId.Zero)
|
||||||
|
{
|
||||||
|
createInfo.OwnerId = new TitleId(context.Process.TitleId);
|
||||||
|
}
|
||||||
|
|
||||||
Result result = _baseFileSystemProxy.CreateSaveDataFileSystemWithHashSalt(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSalt);
|
Result result = _baseFileSystemProxy.CreateSaveDataFileSystemWithHashSalt(ref attribute, ref createInfo, ref metaCreateInfo, ref hashSalt);
|
||||||
|
|
||||||
return (ResultCode)result.Value;
|
return (ResultCode)result.Value;
|
||||||
|
@ -208,6 +234,8 @@ namespace Ryujinx.HLE.HOS.Services.Fs
|
||||||
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
|
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
|
||||||
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
|
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
|
||||||
|
|
||||||
|
// TODO: There's currently no program registry for FS to reference.
|
||||||
|
// Workaround that by setting the application ID if it's not already set
|
||||||
if (attribute.TitleId == TitleId.Zero)
|
if (attribute.TitleId == TitleId.Zero)
|
||||||
{
|
{
|
||||||
attribute.TitleId = new TitleId(context.Process.TitleId);
|
attribute.TitleId = new TitleId(context.Process.TitleId);
|
||||||
|
@ -247,6 +275,8 @@ namespace Ryujinx.HLE.HOS.Services.Fs
|
||||||
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
|
SaveDataSpaceId spaceId = (SaveDataSpaceId)context.RequestData.ReadInt64();
|
||||||
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
|
SaveDataAttribute attribute = context.RequestData.ReadStruct<SaveDataAttribute>();
|
||||||
|
|
||||||
|
// TODO: There's currently no program registry for FS to reference.
|
||||||
|
// Workaround that by setting the application ID if it's not already set
|
||||||
if (attribute.TitleId == TitleId.Zero)
|
if (attribute.TitleId == TitleId.Zero)
|
||||||
{
|
{
|
||||||
attribute.TitleId = new TitleId(context.Process.TitleId);
|
attribute.TitleId = new TitleId(context.Process.TitleId);
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common;
|
||||||
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Graphics.Gpu.Memory;
|
using Ryujinx.Graphics.Gpu.Memory;
|
||||||
using Ryujinx.HLE.HOS.Kernel.Process;
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
||||||
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types;
|
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types;
|
||||||
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap;
|
using Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
||||||
{
|
{
|
||||||
|
@ -165,7 +167,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
||||||
|
|
||||||
private NvInternalResult MapBufferEx(ref MapBufferExArguments arguments)
|
private NvInternalResult MapBufferEx(ref MapBufferExArguments arguments)
|
||||||
{
|
{
|
||||||
const string mapErrorMsg = "Failed to map fixed buffer with offset 0x{0:x16} and size 0x{1:x16}!";
|
const string mapErrorMsg = "Failed to map fixed buffer with offset 0x{0:x16}, size 0x{1:x16} and alignment 0x{2:x16}!";
|
||||||
|
|
||||||
AddressSpaceContext addressSpaceContext = GetAddressSpaceContext(Context);
|
AddressSpaceContext addressSpaceContext = GetAddressSpaceContext(Context);
|
||||||
|
|
||||||
|
@ -178,6 +180,13 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
||||||
return NvInternalResult.InvalidInput;
|
return NvInternalResult.InvalidInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ulong pageSize = (ulong)arguments.PageSize;
|
||||||
|
|
||||||
|
if (pageSize == 0)
|
||||||
|
{
|
||||||
|
pageSize = (ulong)map.Align;
|
||||||
|
}
|
||||||
|
|
||||||
long physicalAddress;
|
long physicalAddress;
|
||||||
|
|
||||||
if ((arguments.Flags & AddressSpaceFlags.RemapSubRange) != 0)
|
if ((arguments.Flags & AddressSpaceFlags.RemapSubRange) != 0)
|
||||||
|
@ -192,7 +201,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
||||||
|
|
||||||
if ((long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)virtualAddress, (ulong)arguments.MappingSize) < 0)
|
if ((long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)virtualAddress, (ulong)arguments.MappingSize) < 0)
|
||||||
{
|
{
|
||||||
string message = string.Format(mapErrorMsg, virtualAddress, arguments.MappingSize);
|
string message = string.Format(mapErrorMsg, virtualAddress, arguments.MappingSize, pageSize);
|
||||||
|
|
||||||
Logger.PrintWarning(LogClass.ServiceNv, message);
|
Logger.PrintWarning(LogClass.ServiceNv, message);
|
||||||
|
|
||||||
|
@ -229,13 +238,13 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
||||||
|
|
||||||
if (!virtualAddressAllocated)
|
if (!virtualAddressAllocated)
|
||||||
{
|
{
|
||||||
if (addressSpaceContext.ValidateFixedBuffer(arguments.Offset, size))
|
if (addressSpaceContext.ValidateFixedBuffer(arguments.Offset, size, pageSize))
|
||||||
{
|
{
|
||||||
arguments.Offset = (long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)arguments.Offset, (ulong)size);
|
arguments.Offset = (long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)arguments.Offset, (ulong)size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string message = string.Format(mapErrorMsg, arguments.Offset, size);
|
string message = string.Format(mapErrorMsg, arguments.Offset, size, pageSize);
|
||||||
|
|
||||||
Logger.PrintWarning(LogClass.ServiceNv, message);
|
Logger.PrintWarning(LogClass.ServiceNv, message);
|
||||||
|
|
||||||
|
@ -244,7 +253,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
arguments.Offset = (long)addressSpaceContext.Gmm.Map((ulong)physicalAddress, (ulong)size);
|
arguments.Offset = (long)addressSpaceContext.Gmm.MapAllocate((ulong)physicalAddress, (ulong)size, pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.Offset < 0)
|
if (arguments.Offset < 0)
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
||||||
_reservations = new SortedList<long, Range>();
|
_reservations = new SortedList<long, Range>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ValidateFixedBuffer(long position, long size)
|
public bool ValidateFixedBuffer(long position, long size, ulong alignment)
|
||||||
{
|
{
|
||||||
long mapEnd = position + size;
|
long mapEnd = position + size;
|
||||||
|
|
||||||
|
@ -58,8 +58,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu.Types
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if address is page aligned.
|
// Check if address is aligned.
|
||||||
if ((position & (long)MemoryManager.PageMask) != 0)
|
if ((position & (long)(alignment - 1)) != 0)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ namespace Ryujinx.HLE.HOS.Services.Sdb.Pl
|
||||||
// GetSharedMemoryNativeHandle() -> handle<copy>
|
// GetSharedMemoryNativeHandle() -> handle<copy>
|
||||||
public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
|
public ResultCode GetSharedMemoryNativeHandle(ServiceCtx context)
|
||||||
{
|
{
|
||||||
context.Device.System.Font.EnsureInitialized(context.Device.System.ContentManager);
|
context.Device.System.Font.EnsureInitialized(context.Device.System.ContentManager, false);
|
||||||
|
|
||||||
if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out int handle) != KernelResult.Success)
|
if (context.Process.HandleTable.GenerateHandle(context.Device.System.FontSharedMem, out int handle) != KernelResult.Success)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,16 +17,16 @@ namespace Ryujinx.HLE.Loaders.Elf
|
||||||
Binding == ElfSymbolBinding.StbWeak;
|
Binding == ElfSymbolBinding.StbWeak;
|
||||||
|
|
||||||
public int ShIdx { get; private set; }
|
public int ShIdx { get; private set; }
|
||||||
public long Value { get; private set; }
|
public ulong Value { get; private set; }
|
||||||
public long Size { get; private set; }
|
public ulong Size { get; private set; }
|
||||||
|
|
||||||
public ElfSymbol(
|
public ElfSymbol(
|
||||||
string name,
|
string name,
|
||||||
int info,
|
int info,
|
||||||
int other,
|
int other,
|
||||||
int shIdx,
|
int shIdx,
|
||||||
long value,
|
ulong value,
|
||||||
long size)
|
ulong size)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Type = (ElfSymbolType)(info & 0xf);
|
Type = (ElfSymbolType)(info & 0xf);
|
||||||
|
|
12
Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs
Normal file
12
Ryujinx.HLE/Loaders/Elf/ElfSymbol32.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
namespace Ryujinx.HLE.Loaders.Elf
|
||||||
|
{
|
||||||
|
struct ElfSymbol32
|
||||||
|
{
|
||||||
|
public uint NameOffset;
|
||||||
|
public uint ValueAddress;
|
||||||
|
public uint Size;
|
||||||
|
public char Info;
|
||||||
|
public char Other;
|
||||||
|
public ushort SectionIndex;
|
||||||
|
}
|
||||||
|
}
|
12
Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs
Normal file
12
Ryujinx.HLE/Loaders/Elf/ElfSymbol64.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
namespace Ryujinx.HLE.Loaders.Elf
|
||||||
|
{
|
||||||
|
struct ElfSymbol64
|
||||||
|
{
|
||||||
|
public uint NameOffset;
|
||||||
|
public char Info;
|
||||||
|
public char Other;
|
||||||
|
public ushort SectionIndex;
|
||||||
|
public ulong ValueAddress;
|
||||||
|
public ulong Size;
|
||||||
|
}
|
||||||
|
}
|
|
@ -34,9 +34,8 @@ namespace Ryujinx.Ui
|
||||||
private static readonly byte[] _nroIcon = GetResourceBytes("Ryujinx.Ui.assets.NROIcon.png");
|
private static readonly byte[] _nroIcon = GetResourceBytes("Ryujinx.Ui.assets.NROIcon.png");
|
||||||
private static readonly byte[] _nsoIcon = GetResourceBytes("Ryujinx.Ui.assets.NSOIcon.png");
|
private static readonly byte[] _nsoIcon = GetResourceBytes("Ryujinx.Ui.assets.NSOIcon.png");
|
||||||
|
|
||||||
private static Keyset _keySet;
|
private static Keyset _keySet;
|
||||||
private static TitleLanguage _desiredTitleLanguage;
|
private static TitleLanguage _desiredTitleLanguage;
|
||||||
private static ApplicationMetadata _appMetadata;
|
|
||||||
|
|
||||||
public static void LoadApplications(List<string> appDirs, Keyset keySet, TitleLanguage desiredTitleLanguage, FileSystemClient fsClient = null, VirtualFileSystem vfs = null)
|
public static void LoadApplications(List<string> appDirs, Keyset keySet, TitleLanguage desiredTitleLanguage, FileSystemClient fsClient = null, VirtualFileSystem vfs = null)
|
||||||
{
|
{
|
||||||
|
@ -339,7 +338,7 @@ namespace Ryujinx.Ui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(bool favorite, string timePlayed, string lastPlayed) = GetMetadata(titleId);
|
ApplicationMetadata appMetadata = LoadAndSaveMetaData(titleId);
|
||||||
|
|
||||||
if (ulong.TryParse(titleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong titleIdNum))
|
if (ulong.TryParse(titleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out ulong titleIdNum))
|
||||||
{
|
{
|
||||||
|
@ -357,14 +356,14 @@ namespace Ryujinx.Ui
|
||||||
|
|
||||||
ApplicationData data = new ApplicationData()
|
ApplicationData data = new ApplicationData()
|
||||||
{
|
{
|
||||||
Favorite = favorite,
|
Favorite = appMetadata.Favorite,
|
||||||
Icon = applicationIcon,
|
Icon = applicationIcon,
|
||||||
TitleName = titleName,
|
TitleName = titleName,
|
||||||
TitleId = titleId,
|
TitleId = titleId,
|
||||||
Developer = developer,
|
Developer = developer,
|
||||||
Version = version,
|
Version = version,
|
||||||
TimePlayed = timePlayed,
|
TimePlayed = ConvertSecondsToReadableString(appMetadata.TimePlayed),
|
||||||
LastPlayed = lastPlayed,
|
LastPlayed = appMetadata.LastPlayed,
|
||||||
FileExtension = Path.GetExtension(applicationPath).ToUpper().Remove(0 ,1),
|
FileExtension = Path.GetExtension(applicationPath).ToUpper().Remove(0 ,1),
|
||||||
FileSize = (fileSize < 1) ? (fileSize * 1024).ToString("0.##") + "MB" : fileSize.ToString("0.##") + "GB",
|
FileSize = (fileSize < 1) ? (fileSize * 1024).ToString("0.##") + "MB" : fileSize.ToString("0.##") + "GB",
|
||||||
Path = applicationPath,
|
Path = applicationPath,
|
||||||
|
@ -431,34 +430,44 @@ namespace Ryujinx.Ui
|
||||||
return controlNca?.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None);
|
return controlNca?.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static (bool favorite, string timePlayed, string lastPlayed) GetMetadata(string titleId)
|
internal static ApplicationMetadata LoadAndSaveMetaData(string titleId, Action<ApplicationMetadata> modifyFunction = null)
|
||||||
{
|
{
|
||||||
string metadataFolder = Path.Combine(new VirtualFileSystem().GetBasePath(), "games", titleId, "gui");
|
string metadataFolder = Path.Combine(new VirtualFileSystem().GetBasePath(), "games", titleId, "gui");
|
||||||
string metadataFile = Path.Combine(metadataFolder, "metadata.json");
|
string metadataFile = Path.Combine(metadataFolder, "metadata.json");
|
||||||
|
|
||||||
IJsonFormatterResolver resolver = CompositeResolver.Create(StandardResolver.AllowPrivateSnakeCase);
|
IJsonFormatterResolver resolver = CompositeResolver.Create(new[] { StandardResolver.AllowPrivateSnakeCase });
|
||||||
|
|
||||||
|
ApplicationMetadata appMetadata;
|
||||||
|
|
||||||
if (!File.Exists(metadataFile))
|
if (!File.Exists(metadataFile))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(metadataFolder);
|
Directory.CreateDirectory(metadataFolder);
|
||||||
|
|
||||||
_appMetadata = new ApplicationMetadata
|
appMetadata = new ApplicationMetadata
|
||||||
{
|
{
|
||||||
Favorite = false,
|
Favorite = false,
|
||||||
TimePlayed = 0,
|
TimePlayed = 0,
|
||||||
LastPlayed = "Never"
|
LastPlayed = "Never"
|
||||||
};
|
};
|
||||||
|
|
||||||
byte[] saveData = JsonSerializer.Serialize(_appMetadata, resolver);
|
byte[] data = JsonSerializer.Serialize(appMetadata, resolver);
|
||||||
File.WriteAllText(metadataFile, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
|
File.WriteAllText(metadataFile, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
using (Stream stream = File.OpenRead(metadataFile))
|
using (Stream stream = File.OpenRead(metadataFile))
|
||||||
{
|
{
|
||||||
_appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
|
appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (_appMetadata.Favorite, ConvertSecondsToReadableString(_appMetadata.TimePlayed), _appMetadata.LastPlayed);
|
if (modifyFunction != null)
|
||||||
|
{
|
||||||
|
modifyFunction(appMetadata);
|
||||||
|
|
||||||
|
byte[] saveData = JsonSerializer.Serialize(appMetadata, resolver);
|
||||||
|
File.WriteAllText(metadataFile, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
return appMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ConvertSecondsToReadableString(double seconds)
|
private static string ConvertSecondsToReadableString(double seconds)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace Ryujinx.Ui
|
namespace Ryujinx.Ui
|
||||||
{
|
{
|
||||||
internal struct ApplicationMetadata
|
internal class ApplicationMetadata
|
||||||
{
|
{
|
||||||
public bool Favorite { get; set; }
|
public bool Favorite { get; set; }
|
||||||
public double TimePlayed { get; set; }
|
public double TimePlayed { get; set; }
|
||||||
|
|
|
@ -307,10 +307,10 @@ namespace Ryujinx.Ui
|
||||||
string titleNameSection = string.IsNullOrWhiteSpace(_device.System.TitleName) ? string.Empty
|
string titleNameSection = string.IsNullOrWhiteSpace(_device.System.TitleName) ? string.Empty
|
||||||
: " | " + _device.System.TitleName;
|
: " | " + _device.System.TitleName;
|
||||||
|
|
||||||
string titleIDSection = string.IsNullOrWhiteSpace(_device.System.TitleId) ? string.Empty
|
string titleIdSection = string.IsNullOrWhiteSpace(_device.System.TitleIdText) ? string.Empty
|
||||||
: " | " + _device.System.TitleId.ToUpper();
|
: " | " + _device.System.TitleIdText.ToUpper();
|
||||||
|
|
||||||
_newTitle = $"Ryujinx{titleNameSection}{titleIDSection} | Host FPS: {hostFps:0.0} | Game FPS: {gameFps:0.0} | " +
|
_newTitle = $"Ryujinx{titleNameSection}{titleIdSection} | Host FPS: {hostFps:0.0} | Game FPS: {gameFps:0.0} | " +
|
||||||
$"Game Vsync: {(_device.EnableDeviceVsync ? "On" : "Off")}";
|
$"Game Vsync: {(_device.EnableDeviceVsync ? "On" : "Off")}";
|
||||||
|
|
||||||
_titleEvent = true;
|
_titleEvent = true;
|
||||||
|
|
|
@ -45,6 +45,8 @@ namespace Ryujinx.Ui
|
||||||
[GUI] CheckMenuItem _fullScreen;
|
[GUI] CheckMenuItem _fullScreen;
|
||||||
[GUI] MenuItem _stopEmulation;
|
[GUI] MenuItem _stopEmulation;
|
||||||
[GUI] CheckMenuItem _favToggle;
|
[GUI] CheckMenuItem _favToggle;
|
||||||
|
[GUI] MenuItem _firmwareInstallFile;
|
||||||
|
[GUI] MenuItem _firmwareInstallDirectory;
|
||||||
[GUI] CheckMenuItem _iconToggle;
|
[GUI] CheckMenuItem _iconToggle;
|
||||||
[GUI] CheckMenuItem _appToggle;
|
[GUI] CheckMenuItem _appToggle;
|
||||||
[GUI] CheckMenuItem _developerToggle;
|
[GUI] CheckMenuItem _developerToggle;
|
||||||
|
@ -57,6 +59,7 @@ namespace Ryujinx.Ui
|
||||||
[GUI] TreeView _gameTable;
|
[GUI] TreeView _gameTable;
|
||||||
[GUI] TreeSelection _gameTableSelection;
|
[GUI] TreeSelection _gameTableSelection;
|
||||||
[GUI] Label _progressLabel;
|
[GUI] Label _progressLabel;
|
||||||
|
[GUI] Label _firmwareVersionLabel;
|
||||||
[GUI] LevelBar _progressBar;
|
[GUI] LevelBar _progressBar;
|
||||||
#pragma warning restore CS0649
|
#pragma warning restore CS0649
|
||||||
#pragma warning restore IDE0044
|
#pragma warning restore IDE0044
|
||||||
|
@ -135,6 +138,8 @@ namespace Ryujinx.Ui
|
||||||
#pragma warning disable CS4014
|
#pragma warning disable CS4014
|
||||||
UpdateGameTable();
|
UpdateGameTable();
|
||||||
#pragma warning restore CS4014
|
#pragma warning restore CS4014
|
||||||
|
|
||||||
|
Task.Run(RefreshFirmwareLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void ApplyTheme()
|
internal static void ApplyTheme()
|
||||||
|
@ -298,39 +303,15 @@ namespace Ryujinx.Ui
|
||||||
_gameLoaded = true;
|
_gameLoaded = true;
|
||||||
_stopEmulation.Sensitive = true;
|
_stopEmulation.Sensitive = true;
|
||||||
|
|
||||||
DiscordIntegrationModule.SwitchToPlayingState(_device.System.TitleId, _device.System.TitleName);
|
_firmwareInstallFile.Sensitive = false;
|
||||||
|
_firmwareInstallDirectory.Sensitive = false;
|
||||||
|
|
||||||
string metadataFolder = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "games", _device.System.TitleId, "gui");
|
DiscordIntegrationModule.SwitchToPlayingState(_device.System.TitleIdText, _device.System.TitleName);
|
||||||
string metadataFile = System.IO.Path.Combine(metadataFolder, "metadata.json");
|
|
||||||
|
|
||||||
IJsonFormatterResolver resolver = CompositeResolver.Create(new[] { StandardResolver.AllowPrivateSnakeCase });
|
ApplicationLibrary.LoadAndSaveMetaData(_device.System.TitleIdText, appMetadata =>
|
||||||
|
|
||||||
ApplicationMetadata appMetadata;
|
|
||||||
|
|
||||||
if (!File.Exists(metadataFile))
|
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(metadataFolder);
|
appMetadata.LastPlayed = DateTime.UtcNow.ToString();
|
||||||
|
});
|
||||||
appMetadata = new ApplicationMetadata
|
|
||||||
{
|
|
||||||
Favorite = false,
|
|
||||||
TimePlayed = 0,
|
|
||||||
LastPlayed = "Never"
|
|
||||||
};
|
|
||||||
|
|
||||||
byte[] data = JsonSerializer.Serialize(appMetadata, resolver);
|
|
||||||
File.WriteAllText(metadataFile, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
using (Stream stream = File.OpenRead(metadataFile))
|
|
||||||
{
|
|
||||||
appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
|
|
||||||
}
|
|
||||||
|
|
||||||
appMetadata.LastPlayed = DateTime.UtcNow.ToString();
|
|
||||||
|
|
||||||
byte[] saveData = JsonSerializer.Serialize(appMetadata, resolver);
|
|
||||||
File.WriteAllText(metadataFile, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,40 +338,13 @@ namespace Ryujinx.Ui
|
||||||
|
|
||||||
if (_gameLoaded)
|
if (_gameLoaded)
|
||||||
{
|
{
|
||||||
string metadataFolder = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "games", _device.System.TitleId, "gui");
|
ApplicationLibrary.LoadAndSaveMetaData(_device.System.TitleIdText, appMetadata =>
|
||||||
string metadataFile = System.IO.Path.Combine(metadataFolder, "metadata.json");
|
|
||||||
|
|
||||||
IJsonFormatterResolver resolver = CompositeResolver.Create(new[] { StandardResolver.AllowPrivateSnakeCase });
|
|
||||||
|
|
||||||
ApplicationMetadata appMetadata;
|
|
||||||
|
|
||||||
if (!File.Exists(metadataFile))
|
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(metadataFolder);
|
DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
|
||||||
|
double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
|
||||||
|
|
||||||
appMetadata = new ApplicationMetadata
|
appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
|
||||||
{
|
});
|
||||||
Favorite = false,
|
|
||||||
TimePlayed = 0,
|
|
||||||
LastPlayed = "Never"
|
|
||||||
};
|
|
||||||
|
|
||||||
byte[] data = JsonSerializer.Serialize(appMetadata, resolver);
|
|
||||||
File.WriteAllText(metadataFile, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
|
|
||||||
}
|
|
||||||
|
|
||||||
using (Stream stream = File.OpenRead(metadataFile))
|
|
||||||
{
|
|
||||||
appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
|
|
||||||
}
|
|
||||||
|
|
||||||
DateTime lastPlayedDateTime = DateTime.Parse(appMetadata.LastPlayed);
|
|
||||||
double sessionTimePlayed = DateTime.UtcNow.Subtract(lastPlayedDateTime).TotalSeconds;
|
|
||||||
|
|
||||||
appMetadata.TimePlayed += Math.Round(sessionTimePlayed, MidpointRounding.AwayFromZero);
|
|
||||||
|
|
||||||
byte[] saveData = JsonSerializer.Serialize(appMetadata, resolver);
|
|
||||||
File.WriteAllText(metadataFile, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Profile.FinishProfiling();
|
Profile.FinishProfiling();
|
||||||
|
@ -448,33 +402,16 @@ namespace Ryujinx.Ui
|
||||||
{
|
{
|
||||||
_tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
|
_tableStore.GetIter(out TreeIter treeIter, new TreePath(args.Path));
|
||||||
|
|
||||||
string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
|
string titleId = _tableStore.GetValue(treeIter, 2).ToString().Split("\n")[1].ToLower();
|
||||||
string metadataPath = System.IO.Path.Combine(new VirtualFileSystem().GetBasePath(), "games", titleId, "gui", "metadata.json");
|
|
||||||
|
|
||||||
IJsonFormatterResolver resolver = CompositeResolver.Create(new[] { StandardResolver.AllowPrivateSnakeCase });
|
bool newToggleValue = !(bool)_tableStore.GetValue(treeIter, 0);
|
||||||
|
|
||||||
ApplicationMetadata appMetadata;
|
_tableStore.SetValue(treeIter, 0, newToggleValue);
|
||||||
|
|
||||||
using (Stream stream = File.OpenRead(metadataPath))
|
ApplicationLibrary.LoadAndSaveMetaData(titleId, appMetadata =>
|
||||||
{
|
{
|
||||||
appMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(stream, resolver);
|
appMetadata.Favorite = newToggleValue;
|
||||||
}
|
});
|
||||||
|
|
||||||
if ((bool)_tableStore.GetValue(treeIter, 0))
|
|
||||||
{
|
|
||||||
_tableStore.SetValue(treeIter, 0, false);
|
|
||||||
|
|
||||||
appMetadata.Favorite = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_tableStore.SetValue(treeIter, 0, true);
|
|
||||||
|
|
||||||
appMetadata.Favorite = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] saveData = JsonSerializer.Serialize(appMetadata, resolver);
|
|
||||||
File.WriteAllText(metadataPath, Encoding.UTF8.GetString(saveData, 0, saveData.Length).PrettyPrintJson());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Row_Activated(object sender, RowActivatedArgs args)
|
private void Row_Activated(object sender, RowActivatedArgs args)
|
||||||
|
@ -559,7 +496,199 @@ namespace Ryujinx.Ui
|
||||||
_gameLoaded = false;
|
_gameLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FullScreen_Toggled(object sender, EventArgs args)
|
private void Installer_File_Pressed(object o, EventArgs args)
|
||||||
|
{
|
||||||
|
FileChooserDialog fileChooser = new FileChooserDialog("Choose the firmware file to open",
|
||||||
|
this,
|
||||||
|
FileChooserAction.Open,
|
||||||
|
"Cancel",
|
||||||
|
ResponseType.Cancel,
|
||||||
|
"Open",
|
||||||
|
ResponseType.Accept);
|
||||||
|
|
||||||
|
fileChooser.Filter = new FileFilter();
|
||||||
|
fileChooser.Filter.AddPattern("*.zip");
|
||||||
|
fileChooser.Filter.AddPattern("*.xci");
|
||||||
|
|
||||||
|
HandleInstallerDialog(fileChooser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Installer_Directory_Pressed(object o, EventArgs args)
|
||||||
|
{
|
||||||
|
FileChooserDialog directoryChooser = new FileChooserDialog("Choose the firmware directory to open",
|
||||||
|
this,
|
||||||
|
FileChooserAction.SelectFolder,
|
||||||
|
"Cancel",
|
||||||
|
ResponseType.Cancel,
|
||||||
|
"Open",
|
||||||
|
ResponseType.Accept);
|
||||||
|
|
||||||
|
HandleInstallerDialog(directoryChooser);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshFirmwareLabel()
|
||||||
|
{
|
||||||
|
var currentFirmware = _device.System.GetCurrentFirmwareVersion();
|
||||||
|
|
||||||
|
GLib.Idle.Add(new GLib.IdleHandler(() =>
|
||||||
|
{
|
||||||
|
_firmwareVersionLabel.Text = currentFirmware != null ? currentFirmware.VersionString : "0.0.0";
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleInstallerDialog(FileChooserDialog fileChooser)
|
||||||
|
{
|
||||||
|
if (fileChooser.Run() == (int)ResponseType.Accept)
|
||||||
|
{
|
||||||
|
MessageDialog dialog = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string filename = fileChooser.Filename;
|
||||||
|
|
||||||
|
fileChooser.Dispose();
|
||||||
|
|
||||||
|
var firmwareVersion = _device.System.VerifyFirmwarePackage(filename);
|
||||||
|
|
||||||
|
if (firmwareVersion == null)
|
||||||
|
{
|
||||||
|
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
|
||||||
|
|
||||||
|
dialog.Text = "Firmware not found.";
|
||||||
|
|
||||||
|
dialog.SecondaryText = $"A valid system firmware was not found in {filename}.";
|
||||||
|
|
||||||
|
Logger.PrintError(LogClass.Application, $"A valid system firmware was not found in {filename}.");
|
||||||
|
|
||||||
|
dialog.Run();
|
||||||
|
dialog.Hide();
|
||||||
|
dialog.Dispose();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentVersion = _device.System.GetCurrentFirmwareVersion();
|
||||||
|
|
||||||
|
string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";
|
||||||
|
|
||||||
|
if (currentVersion != null)
|
||||||
|
{
|
||||||
|
dialogMessage += $"This will replace the current system version {currentVersion.VersionString}. ";
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogMessage += "Do you want to continue?";
|
||||||
|
|
||||||
|
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, false, "");
|
||||||
|
|
||||||
|
dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
|
||||||
|
dialog.SecondaryText = dialogMessage;
|
||||||
|
|
||||||
|
int response = dialog.Run();
|
||||||
|
|
||||||
|
dialog.Dispose();
|
||||||
|
|
||||||
|
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.None, false, "");
|
||||||
|
|
||||||
|
dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
|
||||||
|
|
||||||
|
dialog.SecondaryText = "Installing firmware...";
|
||||||
|
|
||||||
|
if (response == (int)ResponseType.Yes)
|
||||||
|
{
|
||||||
|
Logger.PrintInfo(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");
|
||||||
|
|
||||||
|
Thread thread = new Thread(() =>
|
||||||
|
{
|
||||||
|
GLib.Idle.Add(new GLib.IdleHandler(() =>
|
||||||
|
{
|
||||||
|
dialog.Run();
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_device.System.InstallFirmware(filename);
|
||||||
|
|
||||||
|
GLib.Idle.Add(new GLib.IdleHandler(() =>
|
||||||
|
{
|
||||||
|
dialog.Dispose();
|
||||||
|
|
||||||
|
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
|
||||||
|
|
||||||
|
dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";
|
||||||
|
|
||||||
|
dialog.SecondaryText = $"System version {firmwareVersion.VersionString} successfully installed.";
|
||||||
|
|
||||||
|
Logger.PrintInfo(LogClass.Application, $"System version {firmwareVersion.VersionString} successfully installed.");
|
||||||
|
|
||||||
|
dialog.Run();
|
||||||
|
dialog.Dispose();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
GLib.Idle.Add(new GLib.IdleHandler(() =>
|
||||||
|
{
|
||||||
|
dialog.Dispose();
|
||||||
|
|
||||||
|
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
|
||||||
|
|
||||||
|
dialog.Text = $"Install Firmware {firmwareVersion.VersionString} Failed.";
|
||||||
|
|
||||||
|
dialog.SecondaryText = $"An error occured while installing system version {firmwareVersion.VersionString}." +
|
||||||
|
" Please check logs for more info.";
|
||||||
|
|
||||||
|
Logger.PrintError(LogClass.Application, ex.Message);
|
||||||
|
|
||||||
|
dialog.Run();
|
||||||
|
dialog.Dispose();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
RefreshFirmwareLabel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
thread.Start();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dialog.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (dialog != null)
|
||||||
|
{
|
||||||
|
dialog.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");
|
||||||
|
|
||||||
|
dialog.Text = "Parsing Firmware Failed.";
|
||||||
|
|
||||||
|
dialog.SecondaryText = "An error occured while parsing firmware. Please check the logs for more info.";
|
||||||
|
|
||||||
|
Logger.PrintError(LogClass.Application, ex.Message);
|
||||||
|
|
||||||
|
dialog.Run();
|
||||||
|
dialog.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fileChooser.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FullScreen_Toggled(object o, EventArgs args)
|
||||||
{
|
{
|
||||||
if (_fullScreen.Active)
|
if (_fullScreen.Active)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.22.1 -->
|
<!-- Generated with glade 3.21.0 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
<object class="GtkApplicationWindow" id="_mainWin">
|
<object class="GtkApplicationWindow" id="_mainWin">
|
||||||
|
@ -8,9 +8,6 @@
|
||||||
<property name="window_position">center</property>
|
<property name="window_position">center</property>
|
||||||
<property name="default_width">1280</property>
|
<property name="default_width">1280</property>
|
||||||
<property name="default_height">750</property>
|
<property name="default_height">750</property>
|
||||||
<child>
|
|
||||||
<placeholder/>
|
|
||||||
</child>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="_box">
|
<object class="GtkBox" id="_box">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -263,6 +260,44 @@
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="label" translatable="yes">Tools</property>
|
<property name="label" translatable="yes">Tools</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
|
<child type="submenu">
|
||||||
|
<object class="GtkMenu">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkMenuItem" id="FirmwareSubMenu">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Install Firmware</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<child type="submenu">
|
||||||
|
<object class="GtkMenu">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkMenuItem" id="_firmwareInstallFile">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Install a firmware from XCI or ZIP</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<signal name="activate" handler="Installer_File_Pressed" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkMenuItem" id="_firmwareInstallDirectory">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Install a firmware from a directory</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<signal name="activate" handler="Installer_Directory_Pressed" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
@ -370,7 +405,7 @@
|
||||||
<object class="GtkLabel" id="_progressLabel">
|
<object class="GtkLabel" id="_progressLabel">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="margin_left">5</property>
|
<property name="margin_left">10</property>
|
||||||
<property name="margin_right">5</property>
|
<property name="margin_right">5</property>
|
||||||
<property name="margin_top">2</property>
|
<property name="margin_top">2</property>
|
||||||
<property name="margin_bottom">2</property>
|
<property name="margin_bottom">2</property>
|
||||||
|
@ -388,7 +423,7 @@
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="halign">start</property>
|
<property name="halign">start</property>
|
||||||
<property name="margin_left">5</property>
|
<property name="margin_left">10</property>
|
||||||
<property name="margin_right">5</property>
|
<property name="margin_right">5</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
@ -397,6 +432,57 @@
|
||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSeparator">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">System Version</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="_firmwareVersionLabel">
|
||||||
|
<property name="width_request">50</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">4</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
@ -413,5 +499,8 @@
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child type="titlebar">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue