From feff160c74a6d6e28bc9e70495069a9f4ae221cb Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Sun, 27 Feb 2022 07:37:16 +0000 Subject: [PATCH] rebased --- Ryujinx.Ava/Common/ApplicationHelper.cs | 12 ++-- Ryujinx.Ava/Common/ApplicationLibrary.cs | 57 ++++++++-------- Ryujinx.Ava/Ui/Models/TitleUpdateModel.cs | 2 +- .../Ui/ViewModels/MainWindowViewModel.cs | 65 +++++++++++++------ .../Ui/Windows/TitleUpdateWindow.axaml | 4 +- .../Ui/Windows/TitleUpdateWindow.axaml.cs | 8 +-- 6 files changed, 84 insertions(+), 64 deletions(-) diff --git a/Ryujinx.Ava/Common/ApplicationHelper.cs b/Ryujinx.Ava/Common/ApplicationHelper.cs index 9dc2f49760d9..0da73a00f220 100644 --- a/Ryujinx.Ava/Common/ApplicationHelper.cs +++ b/Ryujinx.Ava/Common/ApplicationHelper.cs @@ -43,7 +43,7 @@ public static void Initialize(VirtualFileSystem virtualFileSystem,HorizonClient } private static bool TryFindSaveData(string titleName, ulong titleId, - BlitStruct controlHolder, SaveDataFilter filter, out ulong saveDataId) + BlitStruct controlHolder, in SaveDataFilter filter, out ulong saveDataId) { saveDataId = default; @@ -85,8 +85,8 @@ private static bool TryFindSaveData(string titleName, ulong titleId, Uid user = new(1, 0); // TODO: Remove Hardcoded value. - result = EnsureApplicationSaveData(_horizonClient.Fs, out _, new ApplicationId(titleId), - ref control, ref user); + result = _horizonClient.Fs.EnsureApplicationSaveData(out _, new LibHac.Ncm.ApplicationId(titleId), in control, in user); + if (result.IsFailure()) { @@ -113,12 +113,10 @@ private static bool TryFindSaveData(string titleName, ulong titleId, return false; } - public static void OpenSaveDir(SaveDataFilter saveDataFilter, ulong titleId, + public static void OpenSaveDir(in SaveDataFilter saveDataFilter, ulong titleId, BlitStruct controlData, string titleName) { - saveDataFilter.SetProgramId(new ProgramId(titleId)); - - if (!TryFindSaveData(titleName, titleId, controlData, saveDataFilter, out ulong saveDataId)) + if (!TryFindSaveData(titleName, titleId, controlData, in saveDataFilter, out ulong saveDataId)) { return; } diff --git a/Ryujinx.Ava/Common/ApplicationLibrary.cs b/Ryujinx.Ava/Common/ApplicationLibrary.cs index 0afb302f7d33..dc540e644998 100644 --- a/Ryujinx.Ava/Common/ApplicationLibrary.cs +++ b/Ryujinx.Ava/Common/ApplicationLibrary.cs @@ -217,15 +217,17 @@ public static void LoadApplications(List appDirs, } else { - // Store the ControlFS in variable called controlFs GetControlFsAndTitleId(pfs, out IFileSystem controlFs, out titleId); - ReadControlData(controlFs, controlHolder.ByteSpan); + if (IsUpdateApplied(titleId, out IFileSystem updatedControlFs)) + { + // Replace the original ControlFs by the updated one. + controlFs = updatedControlFs; + } - // Get the title name, title ID, developer name and version number from the NACP - version = IsUpdateApplied(titleId, out string updateVersion) ? updateVersion : controlHolder.Value.DisplayVersion.ToString(); + ReadControlData(controlFs, controlHolder.ByteSpan); - GetNameIdDeveloper(ref controlHolder.Value, out titleName, out _, out developer); + GetGameInfomation(ref controlHolder.Value, out titleName, out _, out developer, out version); // Read the icon from the ControlFS and store it as a byte array try @@ -337,8 +339,8 @@ byte[] Read(long position, int size) // Get the title name, title ID, developer name and version number from the NACP version = controlHolder.Value.DisplayVersion.ToString(); - GetNameIdDeveloper(ref controlHolder.Value, out titleName, out titleId, - out developer); + GetGameInfomation(ref controlHolder.Value, out titleName, out titleId, + out developer, out version); } else { @@ -739,15 +741,15 @@ private static string ConvertSecondsToReadableString(double seconds) return readableString; } - private static void GetNameIdDeveloper(ref ApplicationControlProperty controlData, out string titleName, - out string titleId, out string publisher) + private static void GetGameInfomation(ref ApplicationControlProperty controlData, out string titleName, + out string titleId, out string publisher, out string version) { Enum.TryParse(_desiredTitleLanguage.ToString(), out TitleLanguage desiredTitleLanguage); - if (controlData.Titles.Length > (int)desiredTitleLanguage) + if (controlData.Title.ItemsRo.Length > (int)desiredTitleLanguage) { - titleName = controlData.Titles[(int)desiredTitleLanguage].Name.ToString(); - publisher = controlData.Titles[(int)desiredTitleLanguage].Publisher.ToString(); + titleName = controlData.Title[(int)desiredTitleLanguage].NameString.ToString(); + publisher = controlData.Title[(int)desiredTitleLanguage].PublisherString.ToString(); } else { @@ -757,11 +759,11 @@ private static void GetNameIdDeveloper(ref ApplicationControlProperty controlDat if (string.IsNullOrWhiteSpace(titleName)) { - foreach (ApplicationControlTitle controlTitle in controlData.Titles) + foreach (ref readonly var controlTitle in controlData.Title.ItemsRo) { - if (!((U8Span)controlTitle.Name).IsEmpty()) + if (!controlTitle.NameString.IsEmpty()) { - titleName = controlTitle.Name.ToString(); + titleName = controlTitle.NameString.ToString(); break; } } @@ -769,11 +771,11 @@ private static void GetNameIdDeveloper(ref ApplicationControlProperty controlDat if (string.IsNullOrWhiteSpace(publisher)) { - foreach (ApplicationControlTitle controlTitle in controlData.Titles) + foreach (ref readonly var controlTitle in controlData.Title.ItemsRo) { - if (!((U8Span)controlTitle.Publisher).IsEmpty()) + if (!controlTitle.PublisherString.IsEmpty()) { - publisher = controlTitle.Publisher.ToString(); + publisher = controlTitle.PublisherString.ToString(); break; } } @@ -783,7 +785,7 @@ private static void GetNameIdDeveloper(ref ApplicationControlProperty controlDat { titleId = controlData.PresenceGroupId.ToString("x16"); } - else if (controlData.SaveDataOwnerId.Value != 0) + else if (controlData.SaveDataOwnerId != 0) { titleId = controlData.SaveDataOwnerId.ToString(); } @@ -795,10 +797,14 @@ private static void GetNameIdDeveloper(ref ApplicationControlProperty controlDat { titleId = "0000000000000000"; } + + version = controlData.DisplayVersionString.ToString(); } - private static bool IsUpdateApplied(string titleId, out string version) + private static bool IsUpdateApplied(string titleId, out IFileSystem updatedControlFs) { + updatedControlFs = null; + string updatePath = "(unknown)"; try @@ -807,14 +813,7 @@ private static bool IsUpdateApplied(string titleId, out string version) if (patchNca != null && controlNca != null) { - ApplicationControlProperty controlData = new ApplicationControlProperty(); - using var nacpFile = new UniqueRef(); - - controlNca.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None).OpenFile(ref nacpFile.Ref(), "/control.nacp".ToU8Span(), OpenMode.Read).ThrowIfFailure(); - - nacpFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref controlData), ReadOption.None).ThrowIfFailure(); - - version = controlData.DisplayVersion.ToString(); + updatedControlFs = controlNca?.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.None); return true; } @@ -829,8 +828,6 @@ private static bool IsUpdateApplied(string titleId, out string version) Logger.Warning?.Print(LogClass.Application, $"Your key set is missing a key with the name: {exception.Name}. Errored File: {updatePath}"); } - version = ""; - return false; } } diff --git a/Ryujinx.Ava/Ui/Models/TitleUpdateModel.cs b/Ryujinx.Ava/Ui/Models/TitleUpdateModel.cs index 16d4c212f6a2..8a9603b9eb4e 100644 --- a/Ryujinx.Ava/Ui/Models/TitleUpdateModel.cs +++ b/Ryujinx.Ava/Ui/Models/TitleUpdateModel.cs @@ -8,7 +8,7 @@ public class TitleUpdateModel public bool IsNoUpdate { get; } public ApplicationControlProperty Control { get; } public string Path { get; } - public string Label => IsNoUpdate ? "No Update" : $"Version {Control.DisplayVersion.ToString()} - {Path}"; + public string Label => IsNoUpdate ? "No Update" : $"Version {Control.DisplayVersionString.ToString()} - {Path}"; public TitleUpdateModel(ApplicationControlProperty control, string path, bool isNoUpdate = false) { diff --git a/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs b/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs index d687e485d787..478fec1e1f3f 100644 --- a/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs +++ b/Ryujinx.Ava/Ui/ViewModels/MainWindowViewModel.cs @@ -1192,9 +1192,21 @@ public void OpenUserSaveDirectory() if (selection != null) { - SaveDataFilter filter = new(); - filter.SetUserId(new UserId(1, 0)); - OpenSaveDirectory(filter, selection); + Task.Run(() => + { + if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, + out ulong titleIdNumber)) + { + ContentDialogHelper.CreateErrorDialog(_owner, + LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]); + + return; + } + + var userId = new LibHac.Fs.UserId((ulong)_owner.AccountManager.LastOpenedUser.UserId.High, (ulong)_owner.AccountManager.LastOpenedUser.UserId.Low); + var saveDataFilter = SaveDataFilter.Make(titleIdNumber, saveType: default, userId, saveDataId: default, index: default); + OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber); + }); } } @@ -1416,9 +1428,20 @@ public void OpenDeviceSaveDirectory() if (selection != null) { - SaveDataFilter filter = new(); - filter.SetSaveDataType(SaveDataType.Device); - OpenSaveDirectory(filter, selection); + Task.Run(() => + { + if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, + out ulong titleIdNumber)) + { + ContentDialogHelper.CreateErrorDialog(_owner, + LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]); + + return; + } + + var saveDataFilter = SaveDataFilter.Make(titleIdNumber, SaveDataType.Device, userId: default, saveDataId: default, index: default); + OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber); + }); } } @@ -1428,24 +1451,26 @@ public void OpenBcatSaveDirectory() if (selection != null) { - SaveDataFilter filter = new(); - filter.SetSaveDataType(SaveDataType.Bcat); - OpenSaveDirectory(filter, selection); - } - } + Task.Run(() => + { + if (!ulong.TryParse(selection.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, + out ulong titleIdNumber)) + { + ContentDialogHelper.CreateErrorDialog(_owner, + LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]); - private void OpenSaveDirectory(SaveDataFilter filter, ApplicationData data) - { - if (!ulong.TryParse(data.TitleId, NumberStyles.HexNumber, CultureInfo.InvariantCulture, - out ulong titleIdNumber)) - { - ContentDialogHelper.CreateErrorDialog(_owner, - LocaleManager.Instance["DialogRyujinxErrorMessage"], LocaleManager.Instance["DialogInvalidTitleIdErrorMessage"]); + return; + } - return; + var saveDataFilter = SaveDataFilter.Make(titleIdNumber, SaveDataType.Bcat, userId: default, saveDataId: default, index: default); + OpenSaveDirectory(in saveDataFilter, selection, titleIdNumber); + }); } + } - Task.Run(() => ApplicationHelper.OpenSaveDir(filter, titleIdNumber, data.ControlHolder, data.TitleName)); + private void OpenSaveDirectory(in SaveDataFilter filter, ApplicationData data, ulong titleId) + { + ApplicationHelper.OpenSaveDir(in filter, titleId, data.ControlHolder, data.TitleName); } private void ExtractLogo() diff --git a/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml b/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml index e2327fe0f63c..27056395228f 100644 --- a/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml +++ b/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml @@ -49,8 +49,8 @@ Items="{Binding TitleUpdates}"> - - + + diff --git a/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml.cs b/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml.cs index c8d41e517a61..c5a5f4a1e806 100644 --- a/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml.cs +++ b/Ryujinx.Ava/Ui/Windows/TitleUpdateWindow.axaml.cs @@ -208,8 +208,8 @@ private void SortUpdates() list.Sort((x, y) => { - var v = x.Control.DisplayVersion.ToString(); - var u = y.Control.DisplayVersion.ToString(); + var v = x.Control.DisplayVersionString.ToString(); + var u = y.Control.DisplayVersionString.ToString(); if (string.IsNullOrEmpty(v)) { @@ -220,8 +220,8 @@ private void SortUpdates() return 1; } - return Version.Parse(x.Control.DisplayVersion.ToString()) - .CompareTo(Version.Parse(y.Control.DisplayVersion.ToString())) * -1; + return Version.Parse(x.Control.DisplayVersionString.ToString()) + .CompareTo(Version.Parse(y.Control.DisplayVersionString.ToString())) * -1; }); TitleUpdates.Clear();