Skip to content

Commit

Permalink
Ab warning dialog (#380)
Browse files Browse the repository at this point in the history
* move a/b code to hsr gsp & create new dialog type

* Use ``MainWindow``'s ``XamlRoot`` for dialogs

* Clean-up unused namespaces

* updated locale

* code cleanup

* added nullable to registry a/b detection & typo fixes

---------

Co-authored-by: Kemal Setya Adhi <[email protected]>
  • Loading branch information
Cryotechnic and neon-nyan authored Jan 30, 2024
1 parent 9fa3f32 commit ab6b586
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 17 deletions.
8 changes: 7 additions & 1 deletion CollapseLauncher/Classes/EventsManagement/EventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ internal class ThemeProperty
}
#endregion
#region ErrorSenderRegion
public enum ErrorType { Unhandled, GameError, Connection }
public enum ErrorType { Unhandled, GameError, Connection, Warning }

internal static class ErrorSender
{
Expand All @@ -160,6 +160,8 @@ internal static class ErrorSender
public static string ExceptionTitle;
public static string ExceptionSubtitle;
public static void SendException(Exception e, ErrorType eT = ErrorType.Unhandled) => invoker.SendException(e, eT);
public static void SendWarning(Exception e, ErrorType eT = ErrorType.Warning) =>
invoker.SendException(e, eT);
public static void SendExceptionWithoutPage(Exception e, ErrorType eT = ErrorType.Unhandled)
{
ExceptionContent = e.ToString();
Expand All @@ -183,6 +185,10 @@ public static void SetPageTitle(ErrorType errorType)
ExceptionTitle = Lang._UnhandledExceptionPage.UnhandledTitle3;
ExceptionSubtitle = Lang._UnhandledExceptionPage.UnhandledSubtitle3;
break;
case ErrorType.Warning:
ExceptionTitle = Lang._UnhandledExceptionPage.UnhandledTitle4;
ExceptionSubtitle = Lang._UnhandledExceptionPage.UnhandledSubtitle4;
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ internal class Model : IGameSettingsValue<Model>
{
#region Fields
private const string _ValueName = "GraphicsSettings_Model_h2986158309";
private const string _AbValueName = "App_Settings_h2319593470";
public static readonly int[] FPSIndex = new int[] { 30, 60, 120 };
public const int FPSDefaultIndex = 1; // 60 in FPSIndex[]
public static Dictionary<int, int> FPSIndexDict = GenerateStaticFPSIndexDict();
Expand Down Expand Up @@ -145,17 +144,6 @@ public static Model Load()
{
if (RegistryRoot == null) throw new NullReferenceException($"Cannot load {_ValueName} RegistryKey is unexpectedly not initialized!");
object? value = RegistryRoot.GetValue(_ValueName, null);

// A/B Testing as of 2023-12-26 (HSR v1.6.0)
object? abValue = RegistryRoot.GetValue(_AbValueName);
if (abValue != null)
{
ErrorSender.SendException(new Exception(
$"Due to miHoYo/Cognosphere A/B testing, Collapse currently does not support reading the" +
$"following key: {_AbValueName}\r\n\n" +
$"This may also cause the modifications of Game Settings through this page to behave unexpectedly.\r\n\n" +
$"We apologize for the inconvenience we may have caused. Please try again later.\r\n"));
}

if (value != null)
{
Expand Down
17 changes: 16 additions & 1 deletion CollapseLauncher/XAMLs/MainApp/Pages/Dialogs/SimpleDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,21 @@ public static async Task<ContentDialogResult> Dialog_ResetKeyboardShortcuts(UIEl
);
}

public static async Task<ContentDialogResult> Dialog_GenericWarning(UIElement Content)
{
return await SpawnDialog(
Lang._UnhandledExceptionPage.UnhandledTitle4,
Lang._UnhandledExceptionPage.UnhandledSubtitle4,
Content,
Lang._Misc.Okay,
null,
null,
ContentDialogButton.Primary,
ContentDialogTheme.Warning
);

}

public static async Task<ContentDialogResult> Dialog_ShowUnhandledExceptionMenu(UIElement Content)
{
async void CopyTextToClipboard(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -829,7 +844,7 @@ public static async Task<ContentDialogResult> SpawnDialog(
DefaultButton = defaultButton,
Background = (Brush)Application.Current.Resources["DialogAcrylicBrush"],
Style = (Style)Application.Current.Resources["CollapseContentDialogStyle"],
XamlRoot = Content.XamlRoot
XamlRoot = (InnerLauncherConfig.m_window as MainWindow).Content.XamlRoot
};
return await (InnerLauncherConfig.m_window as MainWindow).ContentDialog.ShowAsync();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CollapseLauncher.GameSettings.Honkai;
using CollapseLauncher.GameSettings.Honkai;
using CollapseLauncher.Interfaces;
#if !DISABLEDISCORD
using Hi3Helper.DiscordPresence;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using RegistryUtils;
using System;
using System.IO;
using CollapseLauncher.Dialogs;
using static Hi3Helper.Locale;
using static Hi3Helper.Logger;
using static Hi3Helper.Shared.Region.LauncherConfig;
Expand All @@ -28,6 +29,7 @@ public partial class StarRailGameSettingsPage : Page
private Brush InheritApplyTextColor { get; set; }
private RegistryMonitor RegistryWatcher { get; set; }
private bool IsNoReload { get; set; }
private const string _AbValueName = "App_Settings_h2319593470";
public StarRailGameSettingsPage()
{
try
Expand Down Expand Up @@ -67,7 +69,7 @@ private void RegistryListener(object sender, EventArgs e)
}
}

private void LoadPage()
private async void LoadPage()
{
BackgroundImgChanger.ToggleBackground(true);
Settings.ReloadSettings();
Expand All @@ -78,8 +80,16 @@ private void LoadPage()
GameSettingsApplyGrid.Translation = new System.Numerics.Vector3(0, 0, 64);

InheritApplyTextColor = ApplyText.Foreground;
#nullable enable
// A/B Testing as of 2023-12-26 (HSR v1.6.0)
object? abValue = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Cognosphere\Star Rail", _AbValueName, null);
if (abValue != null)
{
await SimpleDialogs.Dialog_GenericWarning(Content);
LogWriteLine($"A/B Value Found. Settings will not apply to the game.", LogType.Warning, true);
}
}

#nullable disable
private void RegistryExportClick(object sender, RoutedEventArgs e)
{
try
Expand Down
2 changes: 2 additions & 0 deletions Hi3Helper.Core/Lang/Locale/LangUnhandledExceptionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public sealed class LangUnhandledExceptionPage
public string UnhandledSubtitle2 { get; set; } = LangFallback?._UnhandledExceptionPage.UnhandledSubtitle2;
public string UnhandledTitle3 { get; set; } = LangFallback?._UnhandledExceptionPage.UnhandledTitle3;
public string UnhandledSubtitle3 { get; set; } = LangFallback?._UnhandledExceptionPage.UnhandledSubtitle3;
public string UnhandledTitle4 { get; set; } = LangFallback?._UnhandledExceptionPage.UnhandledTitle4;
public string UnhandledSubtitle4 { get; set; } = LangFallback?._UnhandledExceptionPage.UnhandledSubtitle4;
public string CopyClipboardBtn1 { get; set; } = LangFallback?._UnhandledExceptionPage.CopyClipboardBtn1;
public string CopyClipboardBtn2 { get; set; } = LangFallback?._UnhandledExceptionPage.CopyClipboardBtn2;
public string GoBackPageBtn1 { get; set; } = LangFallback?._UnhandledExceptionPage.GoBackPageBtn1;
Expand Down
5 changes: 5 additions & 0 deletions Hi3Helper.Core/Lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"UnhandledSubtitle2": "Oops, it seems like you've been disconnected from the Internet~ Or is it something else?",
"UnhandledTitle3": "Game Crashed",
"UnhandledSubtitle3": "The game has crashed with error details below:",
"UnhandledTitle4": "Warning",
"UnhandledSubtitle4": "This isn't a major issue, but we thought we should let you know:\r\nDue to miHoYo A/B testing, Collapse does not support reading the following key: App_Settings_h2319593470.\r\nWe apologize for the inconvenience and thank you for your understanding.",
"CopyClipboardBtn1": "Copy All to Clipboard",
"CopyClipboardBtn2": "Copied to Clipboard!",
"GoBackPageBtn1": "Go Back to Previous Page"
Expand Down Expand Up @@ -669,6 +671,9 @@
"OperationWarningNotCancellableMsg4": "\" to start the process or \"",
"OperationWarningNotCancellableMsg5": "\" to cancel the operation.",

"GenericWarningExceptionTitle": "Warning",
"GenericWarningExceptionSubtitle": "This isn't a major issue, but we thought we should let you know:"

"ShortcutCreationConfirmTitle": "Are you sure you want to continue?",
"ShortcutCreationConfirmSubtitle1": "A shortcut will be created in the following path:",
"ShortcutCreationConfirmSubtitle2": "If there is already a shortcut with the same name in this folder, it will be replaced.",
Expand Down

0 comments on commit ab6b586

Please sign in to comment.