Skip to content

Commit b3c4567

Browse files
committed
Fix calling UserFeedback dialog crashes app due to nulled game property
fix #839 Put the only thing GameProperty used (game header) inside a trycatch so it can fail when GameProperty is somehow broken.
1 parent b892fc1 commit b3c4567

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

CollapseLauncher/XAMLs/Theme/CustomControls/UserFeedbackDialog/UserFeedbackDialog.cs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using CollapseLauncher.Statics;
66
using CommunityToolkit.WinUI;
77
using Hi3Helper;
8+
using Hi3Helper.SentryHelper;
89
using Hi3Helper.Shared.Region;
910
using Microsoft.UI.Input;
1011
using Microsoft.UI.Text;
@@ -92,15 +93,25 @@ protected override void OnApplyTemplate()
9293
_layoutCloseButton?.EnableImplicitAnimation();
9394

9495
// Assign dialog title image background
95-
GamePresetProperty currentGameProperty = GamePropertyVault.GetCurrentGameProperty();
96-
GameNameType gameNameType = currentGameProperty.GamePreset.GameType;
97-
string relFilePath = gameNameType switch
96+
var relFilePath = @"Assets\\Images\\GamePoster\\headerposter_genshin.png";
97+
try
9898
{
99-
GameNameType.Zenless => @"Assets\\Images\\GamePoster\\headerposter_zzz.png",
100-
GameNameType.Honkai => @"Assets\\Images\\GamePoster\\headerposter_honkai.png",
101-
GameNameType.StarRail => @"Assets\\Images\\GamePoster\\headerposter_starrail.png",
102-
_ => @"Assets\\Images\\GamePoster\\headerposter_genshin.png"
103-
};
99+
var currentGameProperty = GamePropertyVault.GetCurrentGameProperty();
100+
var gameNameType = currentGameProperty.GamePreset.GameType;
101+
relFilePath = gameNameType switch
102+
{
103+
GameNameType.Zenless => @"Assets\\Images\\GamePoster\\headerposter_zzz.png",
104+
GameNameType.Honkai => @"Assets\\Images\\GamePoster\\headerposter_honkai.png",
105+
GameNameType.StarRail => @"Assets\\Images\\GamePoster\\headerposter_starrail.png",
106+
_ => @"Assets\\Images\\GamePoster\\headerposter_genshin.png"
107+
};
108+
}
109+
catch (Exception ex)
110+
{
111+
SentryHelper.ExceptionHandler(ex);
112+
Logger.LogWriteLine($"[UserFeedbackDialog::OnApplyTemplate] Failed to grab game type! Returning default game header..." +
113+
$"\r\n{ex}", LogType.Error, true);
114+
}
104115
// Get the title image background and load it.
105116
FileInfo filePathInfo = new(Path.Combine(LauncherConfig.AppExecutableDir, relFilePath));
106117
if (filePathInfo.Exists)
@@ -155,8 +166,8 @@ protected override void OnApplyTemplate()
155166
// Find an overlay grid where the UI element will be spawn to
156167
_parentOverlayGrid = XamlRoot.FindOverlayGrid(_isAlwaysOnTop);
157168
// Get the count of the Rows and Column so it can be spanned across the grid.
158-
int parentGridRowCount = _parentOverlayGrid?.RowDefinitions.Count ?? 1;
159-
int parentGridColumnCount = _parentOverlayGrid?.ColumnDefinitions.Count ?? 1;
169+
var parentGridRowCount = _parentOverlayGrid?.RowDefinitions.Count ?? 1;
170+
var parentGridColumnCount = _parentOverlayGrid?.ColumnDefinitions.Count ?? 1;
160171
// Add the UI element to the grid
161172
_parentOverlayGrid?.AddElementToGridRowColumn(this,
162173
0,
@@ -200,14 +211,14 @@ protected override void OnApplyTemplate()
200211
private void AssignLocalization()
201212
{
202213
// Assign locale for Text header, button, placeholders and stuffs...
203-
_layoutTitleGridText?.BindProperty(TextBlock.TextProperty, Locale.Lang._Dialogs, nameof(Locale.Lang._Dialogs.UserFeedback_DialogTitle));
204-
_layoutFeedbackTitleInput?.BindProperty(TextBox.PlaceholderTextProperty, Locale.Lang._Dialogs, nameof(Locale.Lang._Dialogs.UserFeedback_TextFieldTitlePlaceholder));
205-
_layoutFeedbackMessageInput?.BindProperty(TextBox.PlaceholderTextProperty, Locale.Lang._Dialogs, nameof(Locale.Lang._Dialogs.UserFeedback_TextFieldMessagePlaceholder));
206-
SetTextBoxPropertyHeaderLocale(_layoutFeedbackTitleInput, Locale.Lang._Dialogs.UserFeedback_TextFieldTitleHeader, Locale.Lang._Dialogs.UserFeedback_TextFieldRequired);
207-
SetTextBoxPropertyHeaderLocale(_layoutFeedbackMessageInput, Locale.Lang._Dialogs.UserFeedback_TextFieldMessageHeader, Locale.Lang._Dialogs.UserFeedback_TextFieldRequired);
208-
_layoutFeedbackRatingText?.BindProperty(TextBlock.TextProperty, Locale.Lang._Dialogs, nameof(Locale.Lang._Dialogs.UserFeedback_RatingText));
209-
SetButtonPropertyTextLocale(_layoutPrimaryButton, Locale.Lang._Dialogs, nameof(Locale.Lang._Dialogs.UserFeedback_SubmitBtn));
210-
SetButtonPropertyTextLocale(_layoutCloseButton, Locale.Lang._Dialogs, nameof(Locale.Lang._Dialogs.UserFeedback_CancelBtn));
214+
_layoutTitleGridText?.BindProperty(TextBlock.TextProperty, Lang._Dialogs, nameof(Lang._Dialogs.UserFeedback_DialogTitle));
215+
_layoutFeedbackTitleInput?.BindProperty(TextBox.PlaceholderTextProperty, Lang._Dialogs, nameof(Lang._Dialogs.UserFeedback_TextFieldTitlePlaceholder));
216+
_layoutFeedbackMessageInput?.BindProperty(TextBox.PlaceholderTextProperty, Lang._Dialogs, nameof(Lang._Dialogs.UserFeedback_TextFieldMessagePlaceholder));
217+
SetTextBoxPropertyHeaderLocale(_layoutFeedbackTitleInput, Lang._Dialogs.UserFeedback_TextFieldTitleHeader, Lang._Dialogs.UserFeedback_TextFieldRequired);
218+
SetTextBoxPropertyHeaderLocale(_layoutFeedbackMessageInput, Lang._Dialogs.UserFeedback_TextFieldMessageHeader, Lang._Dialogs.UserFeedback_TextFieldRequired);
219+
_layoutFeedbackRatingText?.BindProperty(TextBlock.TextProperty, Lang._Dialogs, nameof(Lang._Dialogs.UserFeedback_RatingText));
220+
SetButtonPropertyTextLocale(_layoutPrimaryButton, Lang._Dialogs, nameof(Lang._Dialogs.UserFeedback_SubmitBtn));
221+
SetButtonPropertyTextLocale(_layoutCloseButton, Lang._Dialogs, nameof(Lang._Dialogs.UserFeedback_CancelBtn));
211222
}
212223

213224
private static void SetButtonPropertyTextLocale(Button? button, object localeObject, string nameOfLocale)

0 commit comments

Comments
 (0)