Skip to content

Commit

Permalink
Merge pull request #2236 from DGP-Studio/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx authored Nov 25, 2024
2 parents bb7f180 + a655cae commit ec3f7b0
Show file tree
Hide file tree
Showing 102 changed files with 746 additions and 532 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup .NET
if: ${{ needs.select-runner.outputs.runner == 'windows-latest' }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0
Expand Down Expand Up @@ -105,7 +106,3 @@ jobs:
Write-Host "Cleaning up NuGet cache..."
Remove-Item -Recurse -Force "$env:USERPROFILE\.nuget\packages"
Write-Host "NuGet cache cleaned."
Write-Host "Cleaning up .NET install folder..."
Remove-Item -Recurse -Force "C:\Users\Public\Documents\dotnet_install"
Write-Host ".NET install folder cleaned."
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao.Test/Snap.Hutao.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Core/HutaoRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static class HutaoRuntime
public static string LocalCache { get; } = ApplicationData.Current.LocalCacheFolder.Path;

public static string FamilyName { get; } = Package.Current.Id.FamilyName;

public static string FullName { get; } = Package.Current.Id.FullName;

public static string DeviceId { get; } = InitializeDeviceId();
Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Core/IO/DirectoryOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static bool UnsafeRename(string path, string name, FILEOPERATION_FLAGS fl
using (shellItem)
{
fileOperation.SetOperationFlags(flags);
fileOperation.RenameItem(shellItem, name, default!);
fileOperation.RenameItem(shellItem, name, default);

return SUCCEEDED(fileOperation.PerformOperations());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Snap.Hutao/Snap.Hutao/Core/IO/FileOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static bool UnsafeDelete(string path)

using (shellItem)
{
fileOperation.DeleteItem(shellItem, default!);
fileOperation.DeleteItem(shellItem, default);
return SUCCEEDED(fileOperation.PerformOperations());
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ public static bool UnsafeMove(string sourceFileName, string destFileName)

using (destShellItem)
{
fileOperation.MoveItem(sourceShellItem, destShellItem, default, default!);
fileOperation.MoveItem(sourceShellItem, destShellItem, default, default);
return SUCCEEDED(fileOperation.PerformOperations());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Core.IO.Http.Loopback;
using Snap.Hutao.Win32.Registry;
using System.Net;
using System.Reflection;
Expand All @@ -14,24 +15,32 @@ internal sealed partial class HttpProxyUsingSystemProxy : ObservableObject, IWeb
private const string ProxySettingPath = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections";

private static readonly Lazy<MethodInfo> LazyConstructSystemProxyMethod = new(GetConstructSystemProxyMethod);
private static readonly Uri ProxyTestDestination = "https://hut.ao".ToUri();

private readonly IServiceProvider serviceProvider;
private readonly LoopbackSupport loopbackSupport;
private readonly RegistryWatcher watcher;

public HttpProxyUsingSystemProxy(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
loopbackSupport = serviceProvider.GetRequiredService<LoopbackSupport>();
UpdateInnerProxy();

watcher = new(ProxySettingPath, OnSystemProxySettingsChanged);
watcher.Start(serviceProvider.GetRequiredService<ILogger<HttpProxyUsingSystemProxy>>());
}

public bool IsUsingProxyAndNotWorking
{
get => GetProxy(ProxyTestDestination) is not null && !loopbackSupport.IsLoopbackEnabled;
}

public string CurrentProxyUri
{
get
{
Uri? proxyUri = GetProxy("https://hut.ao".ToUri());
Uri? proxyUri = GetProxy(ProxyTestDestination);
return proxyUri is null
? SH.ViewPageFeedbackCurrentProxyNoProxyDescription
: proxyUri.AbsoluteUri;
Expand Down Expand Up @@ -84,6 +93,12 @@ public void OnSystemProxySettingsChanged()
taskContext.BeginInvokeOnMainThread(() => OnPropertyChanged(nameof(CurrentProxyUri)));
}

[Command("EnableLoopbackCommand")]
public void EnableLoopback()
{
loopbackSupport.EnableLoopback();
}

private static MethodInfo GetConstructSystemProxyMethod()
{
Type? systemProxyInfoType = typeof(System.Net.Http.SocketsHttpHandler).Assembly.GetType("System.Net.Http.SystemProxyInfo");
Expand Down
1 change: 1 addition & 0 deletions src/Snap.Hutao/Snap.Hutao/Core/Setting/SettingKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ internal static class SettingKeys
public const string LowLevelKeyboardWebView2VideoRewind = "LowLevelKeyboardWebView2VideoRewind";
public const string WebView2VideoFastForwardOrRewindSeconds = "WebView2VideoFastForwardOrRewindSeconds";
public const string CompactWebView2WindowInactiveOpacity = "CompactWebView2WindowInactiveOpacity";
public const string CompactWebView2WindowPreviousSourceUrl = "CompactWebView2WindowPreviousSourceUrl";
#endregion

#region DevTool
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.

using JetBrains.Annotations;
using Microsoft.UI.Xaml.Controls;

namespace Snap.Hutao.Factory.ContentDialog;
Expand All @@ -11,11 +12,11 @@ internal interface IContentDialogFactory

ITaskContext TaskContext { get; }

ValueTask<ContentDialogResult> CreateForConfirmAsync(string title, string content);
ValueTask<ContentDialogResult> CreateForConfirmAsync([LocalizationRequired] string title, [LocalizationRequired] string content);

ValueTask<ContentDialogResult> CreateForConfirmCancelAsync(string title, string content, ContentDialogButton defaultButton = ContentDialogButton.Close);
ValueTask<ContentDialogResult> CreateForConfirmCancelAsync([LocalizationRequired] string title, [LocalizationRequired] string content, ContentDialogButton defaultButton = ContentDialogButton.Close);

ValueTask<Microsoft.UI.Xaml.Controls.ContentDialog> CreateForIndeterminateProgressAsync(string title);
ValueTask<Microsoft.UI.Xaml.Controls.ContentDialog> CreateForIndeterminateProgressAsync([LocalizationRequired] string title);

ValueTask<TContentDialog> CreateInstanceAsync<TContentDialog>(params object[] parameters)
where TContentDialog : Microsoft.UI.Xaml.Controls.ContentDialog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,29 @@ public unsafe ValueResult<bool, string> PickFolder(string? title)
}
}

private static unsafe void SetFileTypes(ObjectReference<IFileDialog.Vftbl> fileDialog, (string Name, string Type)[] filters)
private static unsafe void SetFileTypes(ObjectReference<IFileDialog.Vftbl> fileDialog, ReadOnlySpan<(string Name, string Type)> filters)
{
List<nint> unmanagedStringPtrs = new(filters.Length * 2);
List<COMDLG_FILTERSPEC> filterSpecs = new(filters.Length);
foreach ((string name, string type) in filters)
Span<nint> unmanagedStringPtrs = stackalloc nint[filters.Length * 2];
Span<COMDLG_FILTERSPEC> filterSpecs = stackalloc COMDLG_FILTERSPEC[filters.Length];

for (int index = 0; index < filters.Length; index++)
{
nint pName = Marshal.StringToHGlobalUni(name);
nint pType = Marshal.StringToHGlobalUni(type);
unmanagedStringPtrs.Add(pName);
unmanagedStringPtrs.Add(pType);
(string name, string type) = filters[index];
nint pName = Marshal.StringToCoTaskMemUni(name);
nint pType = Marshal.StringToCoTaskMemUni(type);
unmanagedStringPtrs[index * 2] = pName;
unmanagedStringPtrs[(index * 2) + 1] = pType;
COMDLG_FILTERSPEC spec = default;
spec.pszName = *(PCWSTR*)&pName;
spec.pszSpec = *(PCWSTR*)&pType;
filterSpecs.Add(spec);
filterSpecs[index] = spec;
}

fileDialog.SetFileTypes(CollectionsMarshal.AsSpan(filterSpecs));
fileDialog.SetFileTypes(filterSpecs);

foreach (ref readonly nint ptr in CollectionsMarshal.AsSpan(unmanagedStringPtrs))
foreach (ref readonly nint ptr in unmanagedStringPtrs)
{
Marshal.FreeHGlobal(ptr);
CoTaskMemFree((void*)ptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Model/Calculable/ICalculable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Snap.Hutao.Model.Calculable;

internal interface ICalculable : INameIcon
internal interface ICalculable : INameIcon<Uri>
{
QualityType Quality { get; }

Expand Down
6 changes: 2 additions & 4 deletions src/Snap.Hutao/Snap.Hutao/Model/INameIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

namespace Snap.Hutao.Model;

internal interface INameIcon<TIcon>
internal interface INameIcon<out TIcon>
{
string Name { get; }

TIcon Icon { get; }
}

internal interface INameIcon : INameIcon<Uri>;
}
4 changes: 2 additions & 2 deletions src/Snap.Hutao/Snap.Hutao/Model/INameIconSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Snap.Hutao.Model;

internal interface INameIconSide : INameIcon
internal interface INameIconSide<out TIcon> : INameIcon<TIcon>
{
Uri SideIcon { get; }
TIcon SideIcon { get; }
}
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Model/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Snap.Hutao.Model;

internal class Item : INameIcon
internal class Item : INameIcon<Uri>
{
public string Name { get; init; } = default!;

Expand Down
17 changes: 0 additions & 17 deletions src/Snap.Hutao/Snap.Hutao/Model/NameDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@

namespace Snap.Hutao.Model;

/// <summary>
/// 名称与描述
/// </summary>
internal class NameDescription
{
/// <summary>
/// 构造一个空的名称与描述
/// </summary>
public NameDescription()
{
}

/// <summary>
/// 构造一个新的名称与描述
/// </summary>
/// <param name="name">名称</param>
/// <param name="description">描述</param>
public NameDescription(string name, string description)
{
Name = name;
Expand All @@ -28,13 +17,7 @@ public NameDescription(string name, string description)

public static NameDescription Default { get; } = new(SH.ModelNameValueDefaultName, SH.ModelNameValueDefaultDescription);

/// <summary>
/// 名称
/// </summary>
public string Name { get; set; } = default!;

/// <summary>
/// 描述
/// </summary>
public string Description { get; set; } = default!;
}
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Identity
Name="60568DGPStudio.SnapHutao"
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
Version="1.12.3.0" />
Version="1.12.4.0" />

<Properties>
<DisplayName>Snap Hutao</DisplayName>
Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Package.development.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Identity
Name="60568DGPStudio.SnapHutaoDev"
Publisher="CN=35C8E923-85DF-49A7-9172-B39DC6312C52"
Version="1.12.3.0" />
Version="1.12.4.0" />

<Properties>
<DisplayName>Snap Hutao Dev</DisplayName>
Expand Down
51 changes: 27 additions & 24 deletions src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1382,6 +1382,9 @@
<data name="ViewDialogFeedbackEnableLoopbackContent" xml:space="preserve">
<value>You need other tools to restore the loopback after it is exempted</value>
</data>
<data name="ViewDialogFeedbackEnableLoopbackDescription" xml:space="preserve">
<value>检测到系统代理已配置,但未解除 Loopback 限制,胡桃将无法正常联网。</value>
</data>
<data name="ViewDialogFeedbackEnableLoopbackTitle" xml:space="preserve">
<value>Confirm to Config Loopback Exemption</value>
</data>
Expand Down Expand Up @@ -3002,6 +3005,30 @@
<data name="ViewPageSettingCompactWebView2InactiveOpacityHeader" xml:space="preserve">
<value>窗口不透明度</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardDescription" xml:space="preserve">
<value>更改控制视频快进的快捷键</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardHeader" xml:space="preserve">
<value>视频快进</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardOrRewindDescription" xml:space="preserve">
<value>更改视频快进与快退的时间</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardOrRewindHeader" xml:space="preserve">
<value>快进快退</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoPlayPauseDescription" xml:space="preserve">
<value>更改控制视频播放与暂停的快捷键</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoPlayPauseHeader" xml:space="preserve">
<value>视频播放暂停</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoRewindDescription" xml:space="preserve">
<value>更改控制视频快退的快捷键</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoRewindHeader" xml:space="preserve">
<value>视频快退</value>
</data>
<data name="ViewPageSettingCopyDeviceIdAction" xml:space="preserve">
<value>Copy</value>
</data>
Expand Down Expand Up @@ -3197,30 +3224,6 @@
<data name="ViewPageSettingKeyShortcutHeader" xml:space="preserve">
<value>Shortcut Keys</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardDescription" xml:space="preserve">
<value>更改控制视频快进的快捷键</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardHeader" xml:space="preserve">
<value>视频快进</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoPlayPauseDescription" xml:space="preserve">
<value>更改控制视频播放与暂停的快捷键</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoPlayPauseHeader" xml:space="preserve">
<value>视频播放暂停</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoRewindDescription" xml:space="preserve">
<value>更改控制视频快退的快捷键</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoRewindHeader" xml:space="preserve">
<value>视频快退</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardOrRewindDescription" xml:space="preserve">
<value>更改视频快进与快退的时间</value>
</data>
<data name="ViewPageSettingCompactWebView2VideoFastForwardOrRewindHeader" xml:space="preserve">
<value>快进快退</value>
</data>
<data name="ViewPageSettingNotifyIconDescription" xml:space="preserve">
<value>Show icon in notification area, to allow background task, restart the program to activate</value>
</data>
Expand Down
Loading

0 comments on commit ec3f7b0

Please sign in to comment.