Archived
1
0
Fork 0
forked from Mirror/Ryujinx

Implement update loader and log loaded application info (#1023)

* Implement update loader

* Add title version to titlebar and log loaded application info

* nits

* requested changes
This commit is contained in:
Xpl0itR 2020-04-12 22:02:37 +01:00 committed by GitHub
parent 6052aa17f2
commit ad3d2fb5a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 605 additions and 39 deletions

View file

@ -200,7 +200,7 @@ namespace Ryujinx.Configuration
File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson()); File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
} }
private class ConfigurationEnumFormatter<T> : IJsonFormatter<T> public class ConfigurationEnumFormatter<T> : IJsonFormatter<T>
where T : struct where T : struct
{ {
public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver) public void Serialize(ref JsonWriter writer, T value, IJsonFormatterResolver formatterResolver)

View file

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace Ryujinx.Common.Configuration
{
public struct TitleUpdateMetadata
{
public string Selected { get; set; }
public List<string> Paths { get; set; }
}
}

View file

@ -7,6 +7,7 @@ using LibHac.FsSystem.NcaUtils;
using LibHac.Ncm; using LibHac.Ncm;
using LibHac.Ns; using LibHac.Ns;
using LibHac.Spl; using LibHac.Spl;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.HLE.FileSystem.Content; using Ryujinx.HLE.FileSystem.Content;
using Ryujinx.HLE.HOS.Font; using Ryujinx.HLE.HOS.Font;
@ -30,6 +31,8 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using Utf8Json;
using Utf8Json.Resolvers;
using TimeServiceManager = Ryujinx.HLE.HOS.Services.Time.TimeManager; using TimeServiceManager = Ryujinx.HLE.HOS.Services.Time.TimeManager;
using NsoExecutable = Ryujinx.HLE.Loaders.Executables.NsoExecutable; using NsoExecutable = Ryujinx.HLE.Loaders.Executables.NsoExecutable;
@ -117,6 +120,10 @@ namespace Ryujinx.HLE.HOS
public ulong TitleId { get; private set; } public ulong TitleId { get; private set; }
public string TitleIdText => TitleId.ToString("x16"); public string TitleIdText => TitleId.ToString("x16");
public string TitleVersionString { get; private set; }
public bool TitleIs64Bit { get; private set; }
public IntegrityCheckLevel FsIntegrityCheckLevel { get; set; } public IntegrityCheckLevel FsIntegrityCheckLevel { get; set; }
public int GlobalAccessLogMode { get; set; } public int GlobalAccessLogMode { get; set; }
@ -368,6 +375,8 @@ namespace Ryujinx.HLE.HOS
TitleName = ControlData.Value.Titles.ToArray() TitleName = ControlData.Value.Titles.ToArray()
.FirstOrDefault(x => x.Name[0] != 0).Name.ToString(); .FirstOrDefault(x => x.Name[0] != 0).Name.ToString();
} }
TitleVersionString = ControlData.Value.DisplayVersion.ToString();
} }
} }
else else
@ -455,6 +464,54 @@ namespace Ryujinx.HLE.HOS
IStorage dataStorage = null; IStorage dataStorage = null;
IFileSystem codeFs = null; IFileSystem codeFs = null;
if (File.Exists(Path.Combine(Device.FileSystem.GetBasePath(), "games", mainNca.Header.TitleId.ToString("x16"), "updates.json")))
{
using (Stream stream = File.OpenRead(Path.Combine(Device.FileSystem.GetBasePath(), "games", mainNca.Header.TitleId.ToString("x16"), "updates.json")))
{
IJsonFormatterResolver resolver = CompositeResolver.Create(StandardResolver.AllowPrivateSnakeCase);
string updatePath = JsonSerializer.Deserialize<TitleUpdateMetadata>(stream, resolver).Selected;
if (File.Exists(updatePath))
{
FileStream file = new FileStream(updatePath, FileMode.Open, FileAccess.Read);
PartitionFileSystem nsp = new PartitionFileSystem(file.AsStorage());
foreach (DirectoryEntryEx ticketEntry in nsp.EnumerateEntries("/", "*.tik"))
{
Result result = nsp.OpenFile(out IFile ticketFile, ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
if (result.IsSuccess())
{
Ticket ticket = new Ticket(ticketFile.AsStream());
KeySet.ExternalKeySet.Add(new RightsId(ticket.RightsId), new AccessKey(ticket.GetTitleKey(KeySet)));
}
}
foreach (DirectoryEntryEx fileEntry in nsp.EnumerateEntries("/", "*.nca"))
{
nsp.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(KeySet, ncaFile.AsStorage());
if ($"{nca.Header.TitleId.ToString("x16")[..^3]}000" != mainNca.Header.TitleId.ToString("x16"))
{
break;
}
if (nca.Header.ContentType == NcaContentType.Program)
{
patchNca = nca;
}
else if (nca.Header.ContentType == NcaContentType.Control)
{
controlNca = nca;
}
}
}
}
}
if (patchNca == null) if (patchNca == null)
{ {
if (mainNca.CanOpenSection(NcaSectionType.Data)) if (mainNca.CanOpenSection(NcaSectionType.Data))
@ -499,6 +556,7 @@ namespace Ryujinx.HLE.HOS
LoadExeFs(codeFs, out Npdm metaData); LoadExeFs(codeFs, out Npdm metaData);
TitleId = metaData.Aci0.TitleId; TitleId = metaData.Aci0.TitleId;
TitleIs64Bit = metaData.Is64Bit;
if (controlNca != null) if (controlNca != null)
{ {
@ -513,6 +571,8 @@ namespace Ryujinx.HLE.HOS
{ {
EnsureSaveData(new TitleId(TitleId)); EnsureSaveData(new TitleId(TitleId));
} }
Logger.PrintInfo(LogClass.Loader, $"Application Loaded: {TitleName} v{TitleVersionString} [{TitleIdText}] [{(TitleIs64Bit ? "64-bit" : "32-bit")}]");
} }
private void LoadExeFs(IFileSystem codeFs, out Npdm metaData) private void LoadExeFs(IFileSystem codeFs, out Npdm metaData)
@ -552,6 +612,7 @@ namespace Ryujinx.HLE.HOS
} }
TitleId = metaData.Aci0.TitleId; TitleId = metaData.Aci0.TitleId;
TitleIs64Bit = metaData.Is64Bit;
LoadNso("rtld"); LoadNso("rtld");
LoadNso("main"); LoadNso("main");
@ -655,6 +716,7 @@ namespace Ryujinx.HLE.HOS
TitleName = metaData.TitleName; TitleName = metaData.TitleName;
TitleId = metaData.Aci0.TitleId; TitleId = metaData.Aci0.TitleId;
TitleIs64Bit = metaData.Is64Bit;
ProgramLoader.LoadStaticObjects(this, metaData, new IExecutable[] { staticObject }); ProgramLoader.LoadStaticObjects(this, metaData, new IExecutable[] { staticObject });
} }

View file

@ -126,14 +126,9 @@ namespace Ryujinx.HLE.HOS
IExecutable[] staticObjects, IExecutable[] staticObjects,
byte[] arguments = null) byte[] arguments = null)
{ {
if (!metaData.Is64Bits)
{
Logger.PrintWarning(LogClass.Loader, "32-bits application detected.");
}
ulong argsStart = 0; ulong argsStart = 0;
int argsSize = 0; int argsSize = 0;
ulong codeStart = metaData.Is64Bits ? 0x8000000UL : 0x200000UL; ulong codeStart = metaData.Is64Bit ? 0x8000000UL : 0x200000UL;
int codeSize = 0; int codeSize = 0;
ulong[] nsoBase = new ulong[staticObjects.Length]; ulong[] nsoBase = new ulong[staticObjects.Length];

View file

@ -12,7 +12,7 @@ namespace Ryujinx.HLE.Loaders.Npdm
private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24; private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24;
public byte MmuFlags { get; private set; } public byte MmuFlags { get; private set; }
public bool Is64Bits { get; private set; } public bool Is64Bit { get; private set; }
public byte MainThreadPriority { get; private set; } public byte MainThreadPriority { get; private set; }
public byte DefaultCpuId { get; private set; } public byte DefaultCpuId { get; private set; }
public int PersonalMmHeapSize { get; private set; } public int PersonalMmHeapSize { get; private set; }
@ -37,7 +37,7 @@ namespace Ryujinx.HLE.Loaders.Npdm
MmuFlags = reader.ReadByte(); MmuFlags = reader.ReadByte();
Is64Bits = (MmuFlags & 1) != 0; Is64Bit = (MmuFlags & 1) != 0;
reader.ReadByte(); reader.ReadByte();

View file

@ -48,6 +48,7 @@
<None Remove="Ui\GameTableContextMenu.glade" /> <None Remove="Ui\GameTableContextMenu.glade" />
<None Remove="Ui\MainWindow.glade" /> <None Remove="Ui\MainWindow.glade" />
<None Remove="Ui\SwitchSettings.glade" /> <None Remove="Ui\SwitchSettings.glade" />
<None Remove="Ui\TitleUpdateWindow.glade" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -69,6 +70,7 @@
<EmbeddedResource Include="Ui\GameTableContextMenu.glade" /> <EmbeddedResource Include="Ui\GameTableContextMenu.glade" />
<EmbeddedResource Include="Ui\MainWindow.glade" /> <EmbeddedResource Include="Ui\MainWindow.glade" />
<EmbeddedResource Include="Ui\SwitchSettings.glade" /> <EmbeddedResource Include="Ui\SwitchSettings.glade" />
<EmbeddedResource Include="Ui\TitleUpdateWindow.glade" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -9,6 +9,7 @@ using LibHac.Ncm;
using LibHac.Ns; using LibHac.Ns;
using LibHac.Spl; using LibHac.Spl;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.Configuration;
using Ryujinx.Configuration.System; using Ryujinx.Configuration.System;
using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.Loaders.Npdm; using Ryujinx.HLE.Loaders.Npdm;
@ -218,7 +219,7 @@ namespace Ryujinx.Ui
controlFs.OpenFile(out IFile controlNacpFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure(); controlFs.OpenFile(out IFile controlNacpFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
// Get the title name, title ID, developer name and version number from the NACP // Get the title name, title ID, developer name and version number from the NACP
version = controlHolder.Value.DisplayVersion.ToString(); version = IsUpdateApplied(titleId, out string updateVersion) ? updateVersion : controlHolder.Value.DisplayVersion.ToString();
GetNameIdDeveloper(ref controlHolder.Value, out titleName, out _, out developer); GetNameIdDeveloper(ref controlHolder.Value, out titleName, out _, out developer);
@ -400,11 +401,11 @@ namespace Ryujinx.Ui
if (result.IsSuccess()) if (result.IsSuccess())
{ {
saveDataPath = Path.Combine(virtualFileSystem.GetNandPath(), $"user/save/{saveDataInfo.SaveDataId:x16}"); saveDataPath = Path.Combine(virtualFileSystem.GetNandPath(), "user", "save", saveDataInfo.SaveDataId.ToString("x16"));
} }
} }
ApplicationData data = new ApplicationData() ApplicationData data = new ApplicationData
{ {
Favorite = appMetadata.Favorite, Favorite = appMetadata.Favorite,
Icon = applicationIcon, Icon = applicationIcon,
@ -629,5 +630,72 @@ namespace Ryujinx.Ui
titleId = "0000000000000000"; titleId = "0000000000000000";
} }
} }
private static bool IsUpdateApplied(string titleId, out string version)
{
string jsonPath = Path.Combine(_virtualFileSystem.GetBasePath(), "games", titleId, "updates.json");
if (File.Exists(jsonPath))
{
using (Stream stream = File.OpenRead(jsonPath))
{
IJsonFormatterResolver resolver = CompositeResolver.Create(StandardResolver.AllowPrivateSnakeCase);
string updatePath = JsonSerializer.Deserialize<TitleUpdateMetadata>(stream, resolver).Selected;
if (!File.Exists(updatePath))
{
version = "";
return false;
}
using (FileStream file = new FileStream(updatePath, FileMode.Open, FileAccess.Read))
{
PartitionFileSystem nsp = new PartitionFileSystem(file.AsStorage());
foreach (DirectoryEntryEx ticketEntry in nsp.EnumerateEntries("/", "*.tik"))
{
Result result = nsp.OpenFile(out IFile ticketFile, ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
if (result.IsSuccess())
{
Ticket ticket = new Ticket(ticketFile.AsStream());
_virtualFileSystem.KeySet.ExternalKeySet.Add(new RightsId(ticket.RightsId), new AccessKey(ticket.GetTitleKey(_virtualFileSystem.KeySet)));
}
}
foreach (DirectoryEntryEx fileEntry in nsp.EnumerateEntries("/", "*.nca"))
{
nsp.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());
if ($"{nca.Header.TitleId.ToString("x16")[..^3]}000" != titleId)
{
break;
}
if (nca.Header.ContentType == NcaContentType.Control)
{
ApplicationControlProperty controlData = new ApplicationControlProperty();
nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(out IFile nacpFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
nacpFile.Read(out long _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();
version = controlData.DisplayVersion.ToString();
return true;
}
}
}
}
}
version = "";
return false;
}
} }
} }

View file

@ -192,12 +192,17 @@ namespace Ryujinx.Ui
parent.Present(); parent.Present();
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 titleVersionSection = string.IsNullOrWhiteSpace(_device.System.TitleVersionString) ? string.Empty
: $" v{_device.System.TitleVersionString}";
string titleIdSection = string.IsNullOrWhiteSpace(_device.System.TitleIdText) ? string.Empty string titleIdSection = string.IsNullOrWhiteSpace(_device.System.TitleIdText) ? string.Empty
: " | " + _device.System.TitleIdText.ToUpper(); : $" ({_device.System.TitleIdText.ToUpper()})";
parent.Title = $"Ryujinx {Program.Version}{titleNameSection}{titleIdSection}"; string titleArchSection = _device.System.TitleIs64Bit ? " (64-bit)" : " (32-bit)";
parent.Title = $"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
}); });
Thread renderLoopThread = new Thread(Render) Thread renderLoopThread = new Thread(Render)

View file

@ -12,7 +12,6 @@ using Ryujinx.Common.Logging;
using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.FileSystem;
using System; using System;
using System.Buffers; using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -38,6 +37,7 @@ namespace Ryujinx.Ui
#pragma warning disable IDE0044 #pragma warning disable IDE0044
[GUI] MenuItem _openSaveUserDir; [GUI] MenuItem _openSaveUserDir;
[GUI] MenuItem _openSaveDeviceDir; [GUI] MenuItem _openSaveDeviceDir;
[GUI] MenuItem _manageTitleUpdates;
[GUI] MenuItem _extractRomFs; [GUI] MenuItem _extractRomFs;
[GUI] MenuItem _extractExeFs; [GUI] MenuItem _extractExeFs;
[GUI] MenuItem _extractLogo; [GUI] MenuItem _extractLogo;
@ -51,21 +51,21 @@ namespace Ryujinx.Ui
{ {
builder.Autoconnect(this); builder.Autoconnect(this);
_openSaveUserDir.Activated += OpenSaveUserDir_Clicked;
_openSaveDeviceDir.Activated += OpenSaveDeviceDir_Clicked;
_openSaveUserDir.Sensitive = !Util.IsEmpty(controlData.ByteSpan) && controlData.Value.UserAccountSaveDataSize > 0;
_openSaveDeviceDir.Sensitive = !Util.IsEmpty(controlData.ByteSpan) && controlData.Value.DeviceSaveDataSize > 0;
_extractRomFs.Activated += ExtractRomFs_Clicked;
_extractExeFs.Activated += ExtractExeFs_Clicked;
_extractLogo.Activated += ExtractLogo_Clicked;
_gameTableStore = gameTableStore; _gameTableStore = gameTableStore;
_rowIter = rowIter; _rowIter = rowIter;
_virtualFileSystem = virtualFileSystem; _virtualFileSystem = virtualFileSystem;
_controlData = controlData; _controlData = controlData;
_openSaveUserDir.Activated += OpenSaveUserDir_Clicked;
_openSaveDeviceDir.Activated += OpenSaveDeviceDir_Clicked;
_manageTitleUpdates.Activated += ManageTitleUpdates_Clicked;
_extractRomFs.Activated += ExtractRomFs_Clicked;
_extractExeFs.Activated += ExtractExeFs_Clicked;
_extractLogo.Activated += ExtractLogo_Clicked;
_openSaveUserDir.Sensitive = !Util.IsEmpty(controlData.ByteSpan) && controlData.Value.UserAccountSaveDataSize > 0;
_openSaveDeviceDir.Sensitive = !Util.IsEmpty(controlData.ByteSpan) && controlData.Value.DeviceSaveDataSize > 0;
string ext = System.IO.Path.GetExtension(_gameTableStore.GetValue(_rowIter, 9).ToString()).ToLower(); string ext = System.IO.Path.GetExtension(_gameTableStore.GetValue(_rowIter, 9).ToString()).ToLower();
if (ext != ".nca" && ext != ".nsp" && ext != ".pfs0" && ext != ".xci") if (ext != ".nca" && ext != ".nsp" && ext != ".pfs0" && ext != ".xci")
{ {
@ -449,7 +449,6 @@ namespace Ryujinx.Ui
}); });
} }
// Events
private void OpenSaveDeviceDir_Clicked(object sender, EventArgs args) private void OpenSaveDeviceDir_Clicked(object sender, EventArgs args)
{ {
string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0]; string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0];
@ -468,6 +467,15 @@ namespace Ryujinx.Ui
OpenSaveDir(titleName, titleIdNumber, filter); OpenSaveDir(titleName, titleIdNumber, filter);
} }
private void ManageTitleUpdates_Clicked(object sender, EventArgs args)
{
string titleName = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[0];
string titleId = _gameTableStore.GetValue(_rowIter, 2).ToString().Split("\n")[1].ToLower();
TitleUpdateWindow titleUpdateWindow = new TitleUpdateWindow(titleId, titleName, _virtualFileSystem);
titleUpdateWindow.Show();
}
private void ExtractRomFs_Clicked(object sender, EventArgs args) private void ExtractRomFs_Clicked(object sender, EventArgs args)
{ {
ExtractSection(NcaSectionType.Data); ExtractSection(NcaSectionType.Data);

View file

@ -29,6 +29,20 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
</object> </object>
</child> </child>
<child>
<object class="GtkMenuItem" id="_manageTitleUpdates">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Manage Title Updates</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child> <child>
<object class="GtkMenuItem" id="_extractRomFs"> <object class="GtkMenuItem" id="_extractRomFs">
<property name="visible">True</property> <property name="visible">True</property>

View file

@ -0,0 +1,204 @@
using Gtk;
using JsonPrettyPrinterPlus;
using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSystem;
using LibHac.FsSystem.NcaUtils;
using LibHac.Ns;
using LibHac.Spl;
using Ryujinx.Common.Configuration;
using Ryujinx.HLE.FileSystem;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Utf8Json;
using Utf8Json.Resolvers;
using GUI = Gtk.Builder.ObjectAttribute;
namespace Ryujinx.Ui
{
public class TitleUpdateWindow : Window
{
private readonly string _titleId;
private readonly VirtualFileSystem _virtualFileSystem;
private TitleUpdateMetadata _titleUpdateWindowData;
private Dictionary<RadioButton, string> _radioButtonToPathDictionary = new Dictionary<RadioButton, string>();
#pragma warning disable CS0649
#pragma warning disable IDE0044
[GUI] Label _baseTitleInfoLabel;
[GUI] Box _availableUpdatesBox;
[GUI] RadioButton _noUpdateRadioButton;
#pragma warning restore CS0649
#pragma warning restore IDE0044
public TitleUpdateWindow(string titleId, string titleName, VirtualFileSystem virtualFileSystem) : this(new Builder("Ryujinx.Ui.TitleUpdateWindow.glade"), titleId, titleName, virtualFileSystem) { }
private TitleUpdateWindow(Builder builder, string titleId, string titleName, VirtualFileSystem virtualFileSystem) : base(builder.GetObject("_titleUpdateWindow").Handle)
{
builder.Autoconnect(this);
_titleId = titleId;
_virtualFileSystem = virtualFileSystem;
try
{
using (Stream stream = File.OpenRead(System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", _titleId, "updates.json")))
{
IJsonFormatterResolver resolver = CompositeResolver.Create(StandardResolver.AllowPrivateSnakeCase);
_titleUpdateWindowData = JsonSerializer.Deserialize<TitleUpdateMetadata>(stream, resolver);
}
}
catch
{
_titleUpdateWindowData = new TitleUpdateMetadata
{
Selected = "",
Paths = new List<string>()
};
}
_baseTitleInfoLabel.Text = $"Updates Available for {titleName} [{titleId}]";
foreach (string path in _titleUpdateWindowData.Paths)
{
AddUpdate(path);
}
_noUpdateRadioButton.Active = true;
foreach (KeyValuePair<RadioButton, string> keyValuePair in _radioButtonToPathDictionary)
{
if (keyValuePair.Value == _titleUpdateWindowData.Selected)
{
keyValuePair.Key.Active = true;
}
}
}
private void AddUpdate(string path)
{
if (File.Exists(path))
{
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
PartitionFileSystem nsp = new PartitionFileSystem(file.AsStorage());
foreach (DirectoryEntryEx ticketEntry in nsp.EnumerateEntries("/", "*.tik"))
{
Result result = nsp.OpenFile(out IFile ticketFile, ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
if (result.IsSuccess())
{
Ticket ticket = new Ticket(ticketFile.AsStream());
_virtualFileSystem.KeySet.ExternalKeySet.Add(new RightsId(ticket.RightsId), new AccessKey(ticket.GetTitleKey(_virtualFileSystem.KeySet)));
}
}
foreach (DirectoryEntryEx fileEntry in nsp.EnumerateEntries("/", "*.nca"))
{
nsp.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();
Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());
if ($"{nca.Header.TitleId.ToString("x16")[..^3]}000" == _titleId)
{
if (nca.Header.ContentType == NcaContentType.Control)
{
ApplicationControlProperty controlData = new ApplicationControlProperty();
nca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(out IFile nacpFile, "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure();
nacpFile.Read(out long _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure();
RadioButton radioButton = new RadioButton($"Version {controlData.DisplayVersion.ToString()} - {path}");
radioButton.JoinGroup(_noUpdateRadioButton);
_availableUpdatesBox.Add(radioButton);
_radioButtonToPathDictionary.Add(radioButton, path);
radioButton.Show();
radioButton.Active = true;
}
}
else
{
GtkDialog.CreateErrorDialog("The specified file does not contain an update for the selected title!");
break;
}
}
}
}
}
private void AddButton_Clicked(object sender, EventArgs args)
{
FileChooserDialog fileChooser = new FileChooserDialog("Select update files", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept)
{
SelectMultiple = true,
Filter = new FileFilter()
};
fileChooser.SetPosition(WindowPosition.Center);
fileChooser.Filter.AddPattern("*.nsp");
if (fileChooser.Run() == (int)ResponseType.Accept)
{
foreach (string path in fileChooser.Filenames)
{
AddUpdate(path);
}
}
fileChooser.Dispose();
}
private void RemoveButton_Clicked(object sender, EventArgs args)
{
foreach (RadioButton radioButton in _noUpdateRadioButton.Group)
{
if (radioButton.Label != "No Update" && radioButton.Active)
{
_availableUpdatesBox.Remove(radioButton);
_radioButtonToPathDictionary.Remove(radioButton);
radioButton.Dispose();
}
}
}
private void SaveButton_Clicked(object sender, EventArgs args)
{
_titleUpdateWindowData.Paths.Clear();
foreach (string paths in _radioButtonToPathDictionary.Values)
{
_titleUpdateWindowData.Paths.Add(paths);
}
foreach (RadioButton radioButton in _noUpdateRadioButton.Group)
{
if (radioButton.Active)
{
_titleUpdateWindowData.Selected = _radioButtonToPathDictionary.TryGetValue(radioButton, out string updatePath) ? updatePath : "";
}
}
IJsonFormatterResolver resolver = CompositeResolver.Create(StandardResolver.AllowPrivateSnakeCase);
string path = System.IO.Path.Combine(_virtualFileSystem.GetBasePath(), "games", _titleId, "updates.json");
byte[] data = JsonSerializer.Serialize(_titleUpdateWindowData, resolver);
File.WriteAllText(path, Encoding.UTF8.GetString(data, 0, data.Length).PrettyPrintJson());
MainWindow.UpdateGameTable();
Dispose();
}
private void CancelButton_Clicked(object sender, EventArgs args)
{
Dispose();
}
}
}

View file

@ -0,0 +1,198 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="_titleUpdateWindow">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Ryujinx - Title Update Manager</property>
<property name="modal">True</property>
<property name="window_position">center</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox" id="MainBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="UpdatesBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="_baseTitleInfoLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="label" translatable="yes">Available Updates</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="_availableUpdatesBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkRadioButton" id="_noUpdateRadioButton">
<property name="label" translatable="yes">No Update</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="layout_style">start</property>
<child>
<object class="GtkButton" id="_addUpdate">
<property name="label" translatable="yes">Add</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Adds an update to this list</property>
<property name="margin_left">10</property>
<signal name="clicked" handler="AddButton_Clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="_removeUpdate">
<property name="label" translatable="yes">Remove</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Removes the selected update</property>
<property name="margin_left">10</property>
<signal name="clicked" handler="RemoveButton_Clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="_saveButton">
<property name="label" translatable="yes">Save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_right">10</property>
<property name="margin_top">2</property>
<property name="margin_bottom">2</property>
<signal name="clicked" handler="SaveButton_Clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="_cancelButton">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_right">10</property>
<property name="margin_top">2</property>
<property name="margin_bottom">2</property>
<signal name="clicked" handler="CancelButton_Clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>