Skip to content

Commit

Permalink
Fix crashes related to URL protocol
Browse files Browse the repository at this point in the history
- Fix crash when using URL protocol to load a region for the first time
- Fix crash when changing region too fast related to BG dim/undim
- Remove some unused using's
  • Loading branch information
gablm committed Apr 4, 2024
1 parent e7c8d7f commit fb042f5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ internal static async void Dimm()
IBackgroundMediaLoader? loader = GetImageLoader(CurrentAppliedMediaType);
if (loader == null) return;
await loader.DimmAsync(_cancellationToken?.Token ?? default);
}
}
catch { }

Check warning on line 363 in CollapseLauncher/Classes/Helper/Background/BackgroundMediaUtility.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Empty general catch clause

Empty general catch clause suppresses any errors
finally
{
_isCurrentDimmAnimRun = false;
Expand All @@ -383,6 +384,7 @@ internal static async void Undimm()
if (loader == null) return;
await loader.UndimmAsync(_cancellationToken?.Token ?? default);
}
catch { }

Check warning on line 387 in CollapseLauncher/Classes/Helper/Background/BackgroundMediaUtility.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Empty general catch clause

Empty general catch clause suppresses any errors
finally
{
_isCurrentUndimmAnimRun = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async ValueTask LoadAsync(string filePath, bool isImageLoadForFirstTime,
// Get the image stream
token.ThrowIfCancellationRequested();
await using (FileStream? imageStream = BackgroundMediaUtility.GetAlternativeFileStream() ??
await ImageLoaderHelper.LoadImage(filePath, isRequestInit, isImageLoadForFirstTime))
await ImageLoaderHelper.LoadImage(filePath, false, isImageLoadForFirstTime))
{
// Return if the stream is null due to cancellation or an error.
if (imageStream == null)
Expand Down
8 changes: 1 addition & 7 deletions CollapseLauncher/Classes/Helper/Metadata/BHI3LInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CollapseLauncher.Helper.Metadata
namespace CollapseLauncher.Helper.Metadata
{
internal class BHI3LInfo
{
Expand Down
4 changes: 1 addition & 3 deletions CollapseLauncher/Classes/Helper/Metadata/Stamp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;

#nullable enable
#nullable enable
namespace CollapseLauncher.Helper.Metadata
{
public class Stamp
Expand Down
69 changes: 38 additions & 31 deletions CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ public partial class MainPage : Page
{
#region Properties
private bool LockRegionChangeBtn;
private bool DisableInstantRegionChange;
private bool IsTitleIconForceShow;
private bool IsNotificationPanelShow;
private bool IsLoadNotifComplete;
private bool IsLoadFrameCompleted = true;
private bool IsFirstStartup = true;
private int CurrentGameCategory = -1;
private int CurrentGameRegion = -1;
private bool IsLoadFrameCompleted = true;
private bool IsFirstStartup = true;
private int CurrentGameCategory = -1;
private int CurrentGameRegion = -1;

private RegionResourceProp _gameAPIProp { get; set; }

Expand Down Expand Up @@ -119,11 +120,11 @@ private async void StartRoutine(object sender, RoutedEventArgs e)
(m_window as MainWindow)?.CloseApp();
return;
}
#if !DEBUG
#if !DEBUG
LauncherUpdateWatcher.StartCheckUpdate(false);
#else
#else
LogWriteLine("Running debug build, stopping update checks!", LogType.Error, false);
#endif
#endif

LoadGamePreset();
SetThemeParameters();
Expand Down Expand Up @@ -161,7 +162,7 @@ private async Task InitializeStartup()
bool isCacheUpdaterMode = m_appMode == AppMode.Hi3CacheUpdater;
await LauncherMetadataHelper.Initialize(isCacheUpdaterMode);

if (isCacheUpdaterMode) SetActivatedRegion();
if (!isCacheUpdaterMode) SetActivatedRegion();

#if !DISABLEDISCORD
bool isInitialStart = GetAppConfigValue("EnableDiscordRPC").ToBool();
Expand Down Expand Up @@ -1005,8 +1006,9 @@ private void EnableRegionChangeButton(object sender, SelectionChangedEventArgs e
ChangeRegionWarning.Visibility = preset.Channel != GameChannel.Stable ? Visibility.Visible : Visibility.Collapsed;
ChangeRegionConfirmBtn.IsEnabled = !LockRegionChangeBtn;
ChangeRegionConfirmBtnNoWarning.IsEnabled = !LockRegionChangeBtn;

if (!IsShowRegionChangeWarning && IsInstantRegionChange && !IsFirstStartup) ChangeRegionInstant();

if (!IsShowRegionChangeWarning && IsInstantRegionChange && !DisableInstantRegionChange && !IsFirstStartup)
ChangeRegionInstant();
}
#endregion

Expand Down Expand Up @@ -1828,7 +1830,6 @@ private void SettingsPage_KeyboardShortcutsEvent(object sender, int e)
#endregion

#region AppActivation

private bool SetActivatedRegion()
{
var args = m_arguments.StartGame;
Expand Down Expand Up @@ -1877,37 +1878,43 @@ private bool SetActivatedRegion()
return false;
}

public void OpenAppActivation()
private async void ChangeToActivatedRegion()
{
if (m_arguments.StartGame == null)
if (!(IsLoadRegionComplete || IsExplicitCancel) || CannotUseKbShortcuts)
return;

DispatcherQueue.TryEnqueue(async () => {

if (!(IsLoadRegionComplete || IsExplicitCancel) || CannotUseKbShortcuts)
return;

bool sameRegion = SetActivatedRegion();
bool sameRegion = SetActivatedRegion();

LockRegionChangeBtn = true;
DisableInstantRegionChange = true;
LockRegionChangeBtn = true;
IsLoadRegionComplete = false;

PresetConfig Preset = LoadSavedGameSelection();
PresetConfig preset = LoadSavedGameSelection();

InvokeLoadingRegionPopup(true, Lang._MainPage.RegionLoadingTitle, RegionToChangeName);
if (await LoadRegionFromCurrentConfigV2(Preset))
{
ShowAsyncLoadingTimedOutPill();
if (await LoadRegionFromCurrentConfigV2(preset))
{
#if !DISABLEDISCORD
if (GetAppConfigValue("EnableDiscordRPC").ToBool() && !sameRegion)
AppDiscordPresence.SetupPresence();
if (GetAppConfigValue("EnableDiscordRPC").ToBool() && !sameRegion)
AppDiscordPresence.SetupPresence();
#endif
MainFrameChanger.ChangeMainFrame(typeof(HomePage));
InvokeLoadingRegionPopup(false);
}
InvokeLoadingRegionPopup(false);
LauncherFrame.BackStack.Clear();
MainFrameChanger.ChangeMainFrame(m_appMode == AppMode.Hi3CacheUpdater? typeof(CachesPage) : typeof(HomePage));
LogWriteLine($"Region changed to {preset.ZoneFullname}", LogType.Scheme, true);
}

LockRegionChangeBtn = false;
});
LockRegionChangeBtn = false;
DisableInstantRegionChange = false;
}

public void OpenAppActivation()
{
if (m_arguments.StartGame == null)
return;

DispatcherQueue.TryEnqueue(ChangeToActivatedRegion);
}
#endregion
}
}
1 change: 0 additions & 1 deletion Hi3Helper.Core/Classes/Shared/Region/ConfigV2Store.cs

This file was deleted.

0 comments on commit fb042f5

Please sign in to comment.