From 55adb638553ad98abada5511b3ccde51f4b29c81 Mon Sep 17 00:00:00 2001 From: Aaron Murgatroyd Date: Sun, 18 May 2025 02:38:17 +1000 Subject: [PATCH] Defaulted language if any errors occur when loading locale so that Avalonia Preview works. Added Status to Sort and Search for XCI File trimmer. --- assets/locales.json | 27 ++++++++++++++++++- src/Ryujinx/Common/LocaleManager.cs | 16 ++++++++--- .../XCITrimmerFileStatusConverter.cs | 17 +++++++----- .../UI/ViewModels/XciTrimmerViewModel.cs | 21 ++++++++++++--- .../UI/Views/Dialog/XciTrimmerView.axaml | 16 +++++++---- .../UI/Views/Dialog/XciTrimmerView.axaml.cs | 18 +++++++++++-- 6 files changed, 94 insertions(+), 21 deletions(-) diff --git a/assets/locales.json b/assets/locales.json index d7d42dded..e8ede7844 100644 --- a/assets/locales.json +++ b/assets/locales.json @@ -21272,6 +21272,31 @@ "zh_TW": "節省的儲存空間" } }, + { + "ID": "XCITrimmerSortStatus", + "Translations": { + "ar_SA": "", + "de_DE": "", + "el_GR": "", + "en_US": "Status", + "es_ES": "", + "fr_FR": "", + "he_IL": "", + "it_IT": "", + "ja_JP": "", + "ko_KR": "", + "no_NO": "", + "pl_PL": "", + "pt_BR": "", + "ru_RU": "", + "sv_SE": "", + "th_TH": "", + "tr_TR": "", + "uk_UA": "", + "zh_CN": "", + "zh_TW": "" + } + }, { "ID": "XCITrimmerTrim", "Translations": { @@ -24748,4 +24773,4 @@ } } ] -} \ No newline at end of file +} diff --git a/src/Ryujinx/Common/LocaleManager.cs b/src/Ryujinx/Common/LocaleManager.cs index e6648fd7e..68e9961c2 100644 --- a/src/Ryujinx/Common/LocaleManager.cs +++ b/src/Ryujinx/Common/LocaleManager.cs @@ -47,10 +47,18 @@ namespace Ryujinx.Ava.Common.Locale private void Load() { - string localeLanguageCode = !string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value) ? - ConfigurationState.Instance.UI.LanguageCode.Value : CultureInfo.CurrentCulture.Name.Replace('-', '_'); - - LoadLanguage(localeLanguageCode); + try + { + string localeLanguageCode = !string.IsNullOrEmpty(ConfigurationState.Instance.UI.LanguageCode.Value) + ? ConfigurationState.Instance.UI.LanguageCode.Value + : CultureInfo.CurrentCulture.Name.Replace('-', '_'); + + LoadLanguage(localeLanguageCode); + } + catch + { + LoadLanguage(DefaultLanguageCode); + } // Save whatever we ended up with. if (Program.PreviewerDetached) diff --git a/src/Ryujinx/UI/Helpers/Converters/XCITrimmerFileStatusConverter.cs b/src/Ryujinx/UI/Helpers/Converters/XCITrimmerFileStatusConverter.cs index c3fb1fe95..a485a1a2d 100644 --- a/src/Ryujinx/UI/Helpers/Converters/XCITrimmerFileStatusConverter.cs +++ b/src/Ryujinx/UI/Helpers/Converters/XCITrimmerFileStatusConverter.cs @@ -25,19 +25,24 @@ namespace Ryujinx.Ava.UI.Helpers return null; } - if (value is not XCITrimmerFileModel app) + if (value is not XCITrimmerFileModel model) { return null; } - return app.PercentageProgress != null ? String.Empty : - app.ProcessingOutcome != OperationOutcome.Successful && app.ProcessingOutcome != OperationOutcome.Undetermined ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusFailedLabel] : - app.Trimmable & app.Untrimmable ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusPartialLabel] : - app.Trimmable ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusTrimmableLabel] : - app.Untrimmable ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusUntrimmableLabel] : + return model.PercentageProgress != null ? String.Empty : + model.ProcessingOutcome != OperationOutcome.Successful && model.ProcessingOutcome != OperationOutcome.Undetermined ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusFailedLabel] : + model.Trimmable & model.Untrimmable ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusPartialLabel] : + model.Trimmable ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusTrimmableLabel] : + model.Untrimmable ? LocaleManager.Instance[LocaleKeys.TitleXCIStatusUntrimmableLabel] : String.Empty; } + public static string From(XCITrimmerFileModel model) + { + return (string)Instance.Convert(model, typeof(string), null, CultureInfo.CurrentUICulture) ?? String.Empty; + } + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); diff --git a/src/Ryujinx/UI/ViewModels/XciTrimmerViewModel.cs b/src/Ryujinx/UI/ViewModels/XciTrimmerViewModel.cs index 2085ffe26..ec9561896 100644 --- a/src/Ryujinx/UI/ViewModels/XciTrimmerViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/XciTrimmerViewModel.cs @@ -10,6 +10,7 @@ using Ryujinx.Ava.Systems.AppLibrary; using Ryujinx.Common.Utilities; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Globalization; using System.Linq; using System.Threading; using static Ryujinx.Common.Utilities.XCIFileTrimmer; @@ -28,6 +29,7 @@ namespace Ryujinx.Ava.UI.ViewModels public enum SortField { Name, + Status, Saved } @@ -246,6 +248,7 @@ namespace Ryujinx.Ava.UI.ViewModels { return string.IsNullOrWhiteSpace(_search) || content.Name.ToLower().Contains(_search.ToLower()) + || XCITrimmerFileStatusConverter.From(content).ToLower().Contains(_search.ToLower()) || content.Path.ToLower().Contains(_search.ToLower()); } @@ -270,17 +273,23 @@ namespace Ryujinx.Ava.UI.ViewModels case SortField.Name: result = x.Name.CompareTo(y.Name); break; + case SortField.Status: + result = XCITrimmerFileStatusConverter.From(x).CompareTo(XCITrimmerFileStatusConverter.From(y)); + break; case SortField.Saved: result = x.PotentialSavingsB.CompareTo(y.PotentialSavingsB); break; } - if (!_viewModel.SortingAscending) - result = -result; - if (result == 0) result = x.Path.CompareTo(y.Path); + if (result == 0) + result = x.Name.CompareTo(y.Name); + + if (!_viewModel.SortingAscending) + result = -result; + return result; } } @@ -467,6 +476,7 @@ namespace Ryujinx.Ava.UI.ViewModels return SortingField switch { SortField.Name => LocaleManager.Instance[LocaleKeys.XCITrimmerSortName], + SortField.Status => LocaleManager.Instance[LocaleKeys.XCITrimmerSortStatus], SortField.Saved => LocaleManager.Instance[LocaleKeys.XCITrimmerSortSaved], _ => string.Empty, }; @@ -487,6 +497,11 @@ namespace Ryujinx.Ava.UI.ViewModels get => _sortField == SortField.Name; } + public bool IsSortedByStatus + { + get => _sortField == SortField.Status; + } + public bool IsSortedBySaved { get => _sortField == SortField.Saved; diff --git a/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml b/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml index d149d246c..aff6098fd 100644 --- a/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml +++ b/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml @@ -45,13 +45,19 @@ Orientation="Vertical"> + diff --git a/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml.cs b/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml.cs index 8fb8c151c..a9dec1c46 100644 --- a/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml.cs +++ b/src/Ryujinx/UI/Views/Dialog/XciTrimmerView.axaml.cs @@ -62,14 +62,28 @@ namespace Ryujinx.Ava.UI.Views.Dialog public void Sort_Checked(object sender, RoutedEventArgs args) { - if (sender is RadioButton { Tag: string sortField }) + if (sender is not RadioButton { Tag: string sortField, IsChecked: { } isChecked }) + { + return; + } + + if (isChecked) + { ViewModel.SortingField = Enum.Parse(sortField); + } } public void Order_Checked(object sender, RoutedEventArgs args) { - if (sender is RadioButton { Tag: string sortOrder }) + if (sender is not RadioButton { Tag: string sortOrder, IsChecked: { } isChecked }) + { + return; + } + + if (isChecked) + { ViewModel.SortingAscending = sortOrder is "Ascending"; + } } private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)