Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Dec 2, 2024
1 parent 51077a6 commit b2bfed0
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/Snap.Hutao/Snap.Hutao/Core/Setting/SettingKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ internal static class SettingKeys
public const string OverridePhysicalDriverType = "OverridePhysicalDriverType";
public const string PhysicalDriverIsAlwaysSolidState = "PhysicalDriverIsAlwaysSolidState";
public const string AlwaysIsFirstRunAfterUpdate = "AlwaysIsFirstRunAfterUpdate";
public const string AlphaBuildUseCNPatchEndpoint = "AlphaBuildUseCNPatchEndpoint";
public const string AlphaBuildUseCnPatchEndpoint = "AlphaBuildUseCNPatchEndpoint";
public const string AlphaBuildUseFjPatchEndpoint = "AlphaBuildUseFJPatchEndpoint";
#endregion

#region Obsolete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Model.Entity.Primitive;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata.Item;
using Snap.Hutao.Service.Cultivation.Consumption;
using Snap.Hutao.Service.Inventory;
using Snap.Hutao.Service.Metadata.ContextAbstraction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Web.Hutao;
Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Service/Update/UpdateService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Core;
Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Service/Update/UpdateStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using CommunityToolkit.Common;
Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/UI/Shell/NotifyIconController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Microsoft.Win32;
Expand Down
11 changes: 8 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/UI/Shell/NotifyIconMessageWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Core.Graphics;
Expand Down Expand Up @@ -76,7 +76,7 @@ public unsafe NotifyIconMessageWindow()

public HWND HWND { get; }

public void Dispose()
public unsafe void Dispose()
{
if (isDisposed)
{
Expand All @@ -88,13 +88,18 @@ public void Dispose()
DestroyWindow(HWND);
WindowTable.TryRemove(HWND, out _);

fixed (char* className = WindowClassName)
{
UnregisterClassW(className);
}

GC.SuppressFinalize(this);
}

[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
private static unsafe LRESULT OnWindowProcedure(HWND hwnd, uint uMsg, WPARAM wParam, LPARAM lParam)
{
if (!WindowTable.TryGetValue(hwnd, out NotifyIconMessageWindow? window))
if (!WindowTable.TryGetValue(hwnd, out NotifyIconMessageWindow? window) || XamlApplicationLifetime.Exiting)
{
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
Expand Down
14 changes: 12 additions & 2 deletions src/Snap.Hutao/Snap.Hutao/UI/Xaml/View/Page/TestPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,18 @@
<ToggleSwitch IsOn="{Binding AlwaysIsFirstRunAfterUpdate, Mode=TwoWay}"/>
</cwc:SettingsCard>

<cwc:SettingsCard Header="Alpha Build Use CN Patch Endpoint">
<ToggleSwitch IsOn="{Binding AlphaBuildUseCNPatchEndpoint, Mode=TwoWay}"/>
<cwc:SettingsCard Header="Alpha Build Generic API Endpoint">
<StackPanel Orientation="Horizontal">
<ToggleSwitch
IsOn="{Binding AlphaBuildUseCNPatchEndpoint, Mode=TwoWay}"
OffContent="Oversea Endpoints"
OnContent="Chinese Endpoints"/>
<ToggleSwitch
IsEnabled="{Binding AlphaBuildUseCNPatchEndpoint}"
IsOn="{Binding AlphaBuildUseFJPatchEndpoint, Mode=TwoWay}"
OffContent="No Secondary Endpoints"
OnContent="Fujian Endpoints"/>
</StackPanel>
</cwc:SettingsCard>

<TextBlock Style="{ThemeResource SettingsSectionHeaderTextBlockStyle}" Text="Gacha Service"/>
Expand Down
21 changes: 18 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/TestViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Microsoft.CodeAnalysis.CSharp.Scripting;
Expand Down Expand Up @@ -151,15 +151,30 @@ public bool AlwaysIsFirstRunAfterUpdate

public bool AlphaBuildUseCNPatchEndpoint
{
get => LocalSetting.Get(SettingKeys.AlphaBuildUseCNPatchEndpoint, false);
get => LocalSetting.Get(SettingKeys.AlphaBuildUseCnPatchEndpoint, false);
set
{
if (IsViewDisposed)
{
return;
}

LocalSetting.Set(SettingKeys.AlphaBuildUseCNPatchEndpoint, value);
LocalSetting.Set(SettingKeys.AlphaBuildUseCnPatchEndpoint, value);
OnPropertyChanged();
}
}

public bool AlphaBuildUseFJPatchEndpoint
{
get => LocalSetting.Get(SettingKeys.AlphaBuildUseFjPatchEndpoint, false);
set
{
if (IsViewDisposed)
{
return;
}

LocalSetting.Set(SettingKeys.AlphaBuildUseFjPatchEndpoint, value);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/ViewModel/TitleViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -63,7 +63,7 @@ public static string Title
protected override async ValueTask<bool> LoadOverrideAsync()
{
ShowUpdateLogWindowAfterUpdate();
NotifyIfDateFolderHasReparsePoint();
NotifyIfDataFolderHasReparsePoint();
await DoCheckUpdateAsync().ConfigureAwait(false);
await CheckProxyAndLoopbackAsync().ConfigureAwait(false);
return true;
Expand Down Expand Up @@ -180,7 +180,7 @@ private async ValueTask<bool> DownloadPackageAsync(IProgress<UpdateStatus> progr
return downloadSuccess;
}

private void NotifyIfDateFolderHasReparsePoint()
private void NotifyIfDataFolderHasReparsePoint()
{
if (new DirectoryInfo(HutaoRuntime.DataFolder).Attributes.HasFlag(FileAttributes.ReparsePoint))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public IHutaoEndpoints Create()
#elif DEBUG && FORCE_USE_RELEASE_ENDPOINT
return serviceProvider.GetRequiredKeyedService<IHutaoEndpoints>(HutaoEndpointsKind.Release);
#else
return Core.Setting.LocalSetting.Get(Core.Setting.SettingKeys.AlphaBuildUseCNPatchEndpoint, false)
? serviceProvider.GetRequiredKeyedService<IHutaoEndpoints>(HutaoEndpointsKind.AlphaCN)
return Core.Setting.LocalSetting.Get(Core.Setting.SettingKeys.AlphaBuildUseCnPatchEndpoint, false)
? Core.Setting.LocalSetting.Get(Core.Setting.SettingKeys.AlphaBuildUseFjPatchEndpoint, false)
? serviceProvider.GetRequiredKeyedService<IHutaoEndpoints>(HutaoEndpointsKind.AlphaFJ)
: serviceProvider.GetRequiredKeyedService<IHutaoEndpoints>(HutaoEndpointsKind.AlphaCN)
: serviceProvider.GetRequiredKeyedService<IHutaoEndpoints>(HutaoEndpointsKind.AlphaOS);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

namespace Snap.Hutao.Web.Hutao;
Expand Down
6 changes: 5 additions & 1 deletion src/Snap.Hutao/Snap.Hutao/Win32/User32.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) DGP Studio. All rights reserved.
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using Snap.Hutao.Win32.Foundation;
Expand Down Expand Up @@ -322,6 +322,10 @@ public static unsafe BOOL SetPropW(HWND hWnd, string @string, [Optional] HANDLE
[SupportedOSPlatform("windows5.0")]
public static extern BOOL UnhookWindowsHookEx(HHOOK hhk);

[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern BOOL UnregisterClassW(PCWSTR lpClassName, [Optional] HINSTANCE hInstance);

[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern BOOL UnregisterHotKey([Optional] HWND hWnd, int id);
Expand Down

0 comments on commit b2bfed0

Please sign in to comment.