mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
add 'Enabled Advanced' option to setting page
This commit is contained in:
@@ -31,6 +31,11 @@ internal sealed class SettingEntry
|
||||
/// </summary>
|
||||
public const string SystemBackdropType = "SystemBackdropType";
|
||||
|
||||
/// <summary>
|
||||
/// 启用高级功能
|
||||
/// </summary>
|
||||
public const string EnabledAdvanced = "EnabledAdvanced";
|
||||
|
||||
/// <summary>
|
||||
/// 实时便笺刷新时间
|
||||
/// </summary>
|
||||
|
||||
@@ -3561,6 +3561,15 @@ namespace Snap.Hutao.Resource.Localization {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 启用「启动游戏-高级功能」的任意功能 您需要在设置里解锁它 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string ViewPageLaunchGameAdvancedFeatureElevationHint {
|
||||
get {
|
||||
return ResourceManager.GetString("ViewPageLaunchGameAdvancedFeatureElevationHint", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 高级功能 的本地化字符串。
|
||||
/// </summary>
|
||||
@@ -4191,6 +4200,33 @@ namespace Snap.Hutao.Resource.Localization {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 在完整阅读原神和胡桃工具箱用户协议后,我选择启用「启动游戏-高级功能」 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string ViewPageSettingEnabledAdvancedDescription {
|
||||
get {
|
||||
return ResourceManager.GetString("ViewPageSettingEnabledAdvancedDescription", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 启动高级功能 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string ViewPageSettingEnabledAdvancedHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("ViewPageSettingEnabledAdvancedHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 您解锁了「启动游戏-高级功能」!其含有潜在违反原神服务条款的风险,一旦启用,您将咨询承担可能的后果。慎重选择! 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string ViewPageSettingFeaturesDangerousHint {
|
||||
get {
|
||||
return ResourceManager.GetString("ViewPageSettingFeaturesDangerousHint", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 Github 上反馈的问题会优先处理 的本地化字符串。
|
||||
/// </summary>
|
||||
|
||||
@@ -1284,6 +1284,9 @@
|
||||
<data name="ViewPageLaunchGameAction" xml:space="preserve">
|
||||
<value>启动游戏</value>
|
||||
</data>
|
||||
<data name="ViewPageLaunchGameAdvancedFeatureElevationHint" xml:space="preserve">
|
||||
<value>启用「启动游戏-高级功能」的任意功能 您需要在设置里解锁它</value>
|
||||
</data>
|
||||
<data name="ViewPageLaunchGameAdvanceHeader" xml:space="preserve">
|
||||
<value>高级功能</value>
|
||||
</data>
|
||||
@@ -1494,6 +1497,15 @@
|
||||
<data name="ViewPageSettingEmptyHistoryVisibleOn" xml:space="preserve">
|
||||
<value>显示</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingEnabledAdvancedDescription" xml:space="preserve">
|
||||
<value>在完整阅读原神和胡桃工具箱用户协议后,我选择启用「启动游戏-高级功能」</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingEnabledAdvancedHeader" xml:space="preserve">
|
||||
<value>启动高级功能</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingFeaturesDangerousHint" xml:space="preserve">
|
||||
<value>您解锁了「启动游戏-高级功能」!其含有潜在违反原神服务条款的风险,一旦启用,您将咨询承担可能的后果。慎重选择!</value>
|
||||
</data>
|
||||
<data name="ViewPageSettingFeedbackDescription" xml:space="preserve">
|
||||
<value>Github 上反馈的问题会优先处理</value>
|
||||
</data>
|
||||
|
||||
@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using System.Globalization;
|
||||
@@ -24,6 +25,7 @@ internal sealed class AppOptions : ObservableObject, IOptions<AppOptions>
|
||||
private bool? isEmptyHistoryWishVisible;
|
||||
private Core.Windowing.BackdropType? backdropType;
|
||||
private CultureInfo? currentCulture;
|
||||
private bool? enabledAdvanced;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的应用程序选项
|
||||
@@ -171,6 +173,40 @@ internal sealed class AppOptions : ObservableObject, IOptions<AppOptions>
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用高级功能
|
||||
/// </summary>
|
||||
public bool EnabledAdvanced
|
||||
{
|
||||
get
|
||||
{
|
||||
if (enabledAdvanced == null)
|
||||
{
|
||||
using (IServiceScope scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
string? value = appDbContext.Settings.SingleOrDefault(e => e.Key == SettingEntry.EnabledAdvanced)?.Value;
|
||||
_ = Activation.GetElevated() == true ? enabledAdvanced = value != null && bool.Parse(value) : enabledAdvanced = false;
|
||||
}
|
||||
}
|
||||
|
||||
return enabledAdvanced.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref enabledAdvanced, value))
|
||||
{
|
||||
using (IServiceScope scope = serviceScopeFactory.CreateScope())
|
||||
{
|
||||
AppDbContext appDbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
appDbContext.Settings.ExecuteDeleteWhere(e => e.Key == SettingEntry.EnabledAdvanced);
|
||||
appDbContext.Settings.AddAndSave(new(SettingEntry.EnabledAdvanced, value.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public AppOptions Value { get => this; }
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Model.Binding.Cultivation;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Entity.Primitive;
|
||||
using Snap.Hutao.Model.Metadata.Item;
|
||||
|
||||
@@ -301,16 +301,16 @@ internal sealed class GameService : IGameService
|
||||
try
|
||||
{
|
||||
Interlocked.Increment(ref runningGamesCounter);
|
||||
bool isElevated = Activation.GetElevated();
|
||||
bool isPassCheck = Activation.GetElevated() == appOptions.EnabledAdvanced ? true : false;
|
||||
|
||||
game.Start();
|
||||
|
||||
if (isElevated && launchOptions.MultipleInstances)
|
||||
if (isPassCheck && launchOptions.MultipleInstances)
|
||||
{
|
||||
ProcessInterop.DisableProtection(game, gamePath);
|
||||
}
|
||||
|
||||
if (isElevated && launchOptions.UnlockFps)
|
||||
if (isPassCheck && launchOptions.UnlockFps)
|
||||
{
|
||||
await ProcessInterop.UnlockFpsAsync(game, launchOptions).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -251,12 +251,18 @@
|
||||
</wsc:Setting>
|
||||
</wsc:SettingsGroup>
|
||||
|
||||
<wsc:SettingsGroup Header="{shcm:ResourceString Name=ViewPageLaunchGameAdvanceHeader}" IsEnabled="{Binding IsElevated}">
|
||||
<wsc:SettingsGroup Header="{shcm:ResourceString Name=ViewPageLaunchGameAdvanceHeader}" IsEnabled="{Binding AppOptions.EnabledAdvanced}">
|
||||
<InfoBar
|
||||
IsClosable="False"
|
||||
IsOpen="{Binding IsElevated}"
|
||||
IsOpen="{Binding AppOptions.EnabledAdvanced}"
|
||||
Message="{shcm:ResourceString Name=ViewPageLaunchGameAdvanceHint}"
|
||||
Severity="Error"/>
|
||||
<InfoBar
|
||||
Margin="0,2,0,0"
|
||||
IsClosable="False"
|
||||
IsOpen="{Binding AppOptions.EnabledAdvanced, Converter={StaticResource BoolNegationConverter}}"
|
||||
Message="{shcm:ResourceString Name=ViewPageLaunchGameAdvancedFeatureElevationHint}"
|
||||
Severity="Warning"/>
|
||||
<wsc:Setting
|
||||
Description="{shcm:ResourceString Name=ViewPageLaunchGameMultipleInstancesDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageLaunchGameMultipleInstancesHeader}"
|
||||
|
||||
@@ -209,6 +209,32 @@
|
||||
</wsc:SettingsGroup>
|
||||
|
||||
<wsc:SettingsGroup Foreground="{ThemeResource SystemFillColorCriticalBrush}" Header="{shcm:ResourceString Name=ViewPageSettingDangerousHeader}">
|
||||
<InfoBar
|
||||
IsClosable="False"
|
||||
IsOpen="{Binding Options.EnabledAdvanced}"
|
||||
Message="{shcm:ResourceString Name=ViewPageSettingFeaturesDangerousHint}"
|
||||
Severity="Error"/>
|
||||
<InfoBar
|
||||
Margin="0,2,0,0"
|
||||
IsClosable="False"
|
||||
IsOpen="{Binding IsElevated, Converter={StaticResource BoolNegationConverter}}"
|
||||
Message="{shcm:ResourceString Name=ViewPageLaunchGameElevationHint}"
|
||||
Severity="Warning"/>
|
||||
|
||||
<wsc:Setting
|
||||
Background="{StaticResource SystemFillColorCriticalBackgroundBrush}"
|
||||
Description="{shcm:ResourceString Name=ViewPageSettingEnabledAdvancedDescription}"
|
||||
Header="{shcm:ResourceString Name=ViewPageSettingEnabledAdvancedHeader}"
|
||||
Icon="">
|
||||
<wsc:Setting.ActionContent>
|
||||
<ToggleSwitch
|
||||
Width="120"
|
||||
IsEnabled="{Binding IsElevated}"
|
||||
IsOn="{Binding Options.EnabledAdvanced, Mode=TwoWay}"
|
||||
Style="{StaticResource ToggleSwitchSettingStyle}"/>
|
||||
</wsc:Setting.ActionContent>
|
||||
</wsc:Setting>
|
||||
|
||||
<InfoBar
|
||||
IsClosable="False"
|
||||
IsOpen="True"
|
||||
|
||||
@@ -53,6 +53,7 @@ internal sealed class LaunchGameViewModel : Abstraction.ViewModel
|
||||
gameService = serviceProvider.GetRequiredService<IGameService>();
|
||||
memoryCache = serviceProvider.GetRequiredService<IMemoryCache>();
|
||||
Options = serviceProvider.GetRequiredService<LaunchOptions>();
|
||||
AppOptions = serviceProvider.GetRequiredService<AppOptions>();
|
||||
this.serviceProvider = serviceProvider;
|
||||
|
||||
LaunchCommand = new AsyncRelayCommand(LaunchAsync, AsyncRelayCommandOptions.AllowConcurrentExecutions);
|
||||
@@ -100,6 +101,11 @@ internal sealed class LaunchGameViewModel : Abstraction.ViewModel
|
||||
/// </summary>
|
||||
public LaunchOptions Options { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 应用选项
|
||||
/// </summary>
|
||||
public AppOptions AppOptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 游戏资源
|
||||
/// </summary>
|
||||
|
||||
@@ -8,6 +8,7 @@ using Microsoft.Windows.AppLifecycle;
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Core.IO;
|
||||
using Snap.Hutao.Core.IO.DataTransfer;
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
using Snap.Hutao.Core.Setting;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Factory.Abstraction;
|
||||
@@ -162,6 +163,11 @@ internal sealed class SettingViewModel : Abstraction.ViewModel
|
||||
/// </summary>
|
||||
public ExperimentalFeaturesViewModel Experimental { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否提权
|
||||
/// </summary>
|
||||
public bool IsElevated { get => Activation.GetElevated(); }
|
||||
|
||||
/// <summary>
|
||||
/// 设置游戏路径命令
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user