mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 09:20:24 +08:00
Compare commits
1 Commits
dev-v2
...
rft/wpf_co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ee785bd62 |
@@ -211,6 +211,7 @@ public static class ConfigFactory
|
||||
{
|
||||
var key = "Root.Configurations." + name + ".";
|
||||
config.PropertyChanged += OnPropertyChangedFactory(key);
|
||||
config.WpfSettings.EventBinding(key, OnPropertyChangedFactory);
|
||||
config.DragItemIsChecked.CollectionChanged += OnCollectionChangedFactory<string, bool>(key + nameof(SpecificConfig.DragItemIsChecked) + ".");
|
||||
config.InfrastOrder.CollectionChanged += OnCollectionChangedFactory<string, int>(key + nameof(SpecificConfig.InfrastOrder) + ".");
|
||||
|
||||
|
||||
29
src/MaaWpfGui/Configuration/Single/Settings/Performance.cs
Normal file
29
src/MaaWpfGui/Configuration/Single/Settings/Performance.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
// <copyright file="Performance.cs" company="MaaAssistantArknights">
|
||||
// Part of the MaaWpfGui project, maintained by the MaaAssistantArknights team (Maa Team)
|
||||
// Copyright (C) 2021-2025 MaaAssistantArknights Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License v3.0 only as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
#nullable enable
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace MaaWpfGui.Configuration.Single.Settings;
|
||||
|
||||
public class Performance : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public bool UseGpu { get; set; }
|
||||
|
||||
public string GpuDescription { get; set; } = string.Empty;
|
||||
|
||||
public string GpuInstancePath { get; set; } = string.Empty;
|
||||
|
||||
public bool AllowDeprecatedGpu { get; set; }
|
||||
}
|
||||
30
src/MaaWpfGui/Configuration/Single/Settings/WpfSettings.cs
Normal file
30
src/MaaWpfGui/Configuration/Single/Settings/WpfSettings.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
// <copyright file="WpfSettings.cs" company="MaaAssistantArknights">
|
||||
// Part of the MaaWpfGui project, maintained by the MaaAssistantArknights team (Maa Team)
|
||||
// Copyright (C) 2021-2025 MaaAssistantArknights Contributors
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License v3.0 only as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY
|
||||
// </copyright>
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace MaaWpfGui.Configuration.Single.Settings;
|
||||
|
||||
public class WpfSettings : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public void EventBinding(string prefix, Func<string, PropertyChangedEventHandler> valueFactory)
|
||||
{
|
||||
PropertyChanged += valueFactory.Invoke(prefix + nameof(WpfSettings) + ".");
|
||||
Performance.PropertyChanged += valueFactory.Invoke(prefix + nameof(WpfSettings) + "." + nameof(Performance) + ".");
|
||||
}
|
||||
|
||||
public Performance Performance { get; set; } = new();
|
||||
}
|
||||
@@ -16,6 +16,7 @@ using System.Text.Json.Serialization;
|
||||
using JetBrains.Annotations;
|
||||
using MaaWpfGui.Configuration.Factory;
|
||||
using MaaWpfGui.Configuration.Single.MaaTask;
|
||||
using MaaWpfGui.Configuration.Single.Settings;
|
||||
using ObservableCollections;
|
||||
|
||||
namespace MaaWpfGui.Configuration.Single;
|
||||
@@ -35,6 +36,9 @@ public class SpecificConfig : INotifyPropertyChanged, IJsonOnDeserialized
|
||||
[JsonInclude]
|
||||
public ObservableList<BaseTask> TaskQueue { get; private set; } = [];
|
||||
|
||||
[JsonInclude]
|
||||
public WpfSettings WpfSettings { get; private set; } = new();
|
||||
|
||||
[JsonInclude]
|
||||
public int TaskSelectedIndex { get; set; } = -1;
|
||||
|
||||
|
||||
@@ -325,10 +325,10 @@ public static class ConfigurationKeys
|
||||
public const string ExternalNotificationCustomWebhookBody = "ExternalNotification.CustomWebhook.Body";
|
||||
public const string ExternalNotificationCustomWebhookHeaders = "ExternalNotification.CustomWebhook.Headers";
|
||||
|
||||
public const string PerformanceUseGpu = "Performance.UseGpu";
|
||||
public const string PerformancePreferredGpuDescription = "Performance.PreferredGpuDescription";
|
||||
public const string PerformancePreferredGpuInstancePath = "Performance.PreferredGpuInstancePath";
|
||||
public const string PerformanceAllowDeprecatedGpu = "Performance.AllowDeprecatedGpu";
|
||||
public const string PerformanceUseGpu = "Performance.UseGpu"; // √
|
||||
public const string PerformancePreferredGpuDescription = "Performance.PreferredGpuDescription"; // √
|
||||
public const string PerformancePreferredGpuInstancePath = "Performance.PreferredGpuInstancePath"; // √
|
||||
public const string PerformanceAllowDeprecatedGpu = "Performance.AllowDeprecatedGpu"; // √
|
||||
|
||||
// The following should not be modified manually
|
||||
public const string VersionName = "VersionUpdate.name";
|
||||
|
||||
@@ -34,6 +34,7 @@ public class ConfigConverter
|
||||
private static readonly string ConfigurationNewFile = ConfigFactory.ConfigFile;
|
||||
private static readonly string ConfigurationOldBakFile = ConfigurationHelper.ConfigFile + ".old";
|
||||
private static readonly string ConfigurationOldFile = ConfigurationHelper.ConfigFile;
|
||||
private static bool HasBackupOldConfig = false;
|
||||
|
||||
public static bool ConvertConfig()
|
||||
{
|
||||
@@ -60,20 +61,18 @@ public class ConfigConverter
|
||||
ret &= ConvertTaskQueue();
|
||||
}
|
||||
|
||||
if (ConfigurationHelper.ContainsKey(ConfigurationKeys.PerformanceUseGpu))
|
||||
{
|
||||
ret = ret && ConvertWpfSettings();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 迁移任务队列,v5.15编写
|
||||
private static bool ConvertTaskQueue()
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(ConfigurationOldFile, ConfigurationOldBakFile, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "备份配置失败: {Message}", ex.Message);
|
||||
}
|
||||
BackupOldConfig();
|
||||
string[] configKeys = [ConfigurationKeys.AnnouncementInfo, ConfigurationKeys.DoNotRemindThisAnnouncementAgain, ConfigurationKeys.DoNotShowAnnouncement,
|
||||
ConfigurationKeys.VersionName, ConfigurationKeys.VersionUpdateBody, ConfigurationKeys.VersionUpdateIsFirstBoot, ConfigurationKeys.VersionUpdatePackage,
|
||||
ConfigurationKeys.VersionUpdateDoNotShowUpdate, ConfigurationKeys.CustomInfrastEnabled, ConfigurationKeys.CustomInfrastPlanShowInFightSettings,
|
||||
@@ -515,6 +514,37 @@ public class ConfigConverter
|
||||
return true;
|
||||
}
|
||||
|
||||
// 迁移Wpf设置, v6.14编写
|
||||
private static bool ConvertWpfSettings()
|
||||
{
|
||||
BackupOldConfig();
|
||||
|
||||
var currentConfigName = ConfigurationHelper.GetCurrentConfiguration();
|
||||
foreach (var configName in ConfigurationHelper.GetConfigurationList())
|
||||
{
|
||||
ConfigurationHelper.SwitchConfiguration(configName);
|
||||
if (!ConfigFactory.SwitchConfig(configName))
|
||||
{
|
||||
_logger.Error("配置迁移失败,无法切换到配置: {ConfigName}", configName);
|
||||
throw new Exception($"配置迁移失败,无法切换到配置{configName}");
|
||||
}
|
||||
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.UseGpu = ConfigurationHelper.GetValue(ConfigurationKeys.PerformanceUseGpu, false);
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuDescription = ConfigurationHelper.GetValue(ConfigurationKeys.PerformancePreferredGpuDescription, string.Empty);
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuInstancePath = ConfigurationHelper.GetValue(ConfigurationKeys.PerformancePreferredGpuInstancePath, string.Empty);
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.AllowDeprecatedGpu = ConfigurationHelper.GetValue(ConfigurationKeys.PerformanceAllowDeprecatedGpu, false);
|
||||
|
||||
ConfigurationHelper.DeleteValue(ConfigurationKeys.PerformanceUseGpu);
|
||||
ConfigurationHelper.DeleteValue(ConfigurationKeys.PerformancePreferredGpuDescription);
|
||||
ConfigurationHelper.DeleteValue(ConfigurationKeys.PerformancePreferredGpuInstancePath);
|
||||
ConfigurationHelper.DeleteValue(ConfigurationKeys.PerformanceAllowDeprecatedGpu);
|
||||
}
|
||||
|
||||
ConfigurationHelper.SwitchConfiguration(currentConfigName);
|
||||
ConfigFactory.SwitchConfig(currentConfigName);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static JObject? ParseJsonFile(string filePath)
|
||||
{
|
||||
if (File.Exists(filePath) is false)
|
||||
@@ -535,4 +565,21 @@ public class ConfigConverter
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void BackupOldConfig()
|
||||
{
|
||||
if (HasBackupOldConfig)
|
||||
{
|
||||
return;
|
||||
}
|
||||
HasBackupOldConfig = true;
|
||||
try
|
||||
{
|
||||
File.Copy(ConfigurationOldFile, ConfigurationOldBakFile, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "备份配置失败: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Configuration.Factory;
|
||||
using MaaWpfGui.Extensions;
|
||||
using Microsoft.Win32;
|
||||
using Windows.Win32;
|
||||
@@ -39,8 +39,8 @@ public abstract class GpuOption
|
||||
|
||||
public static bool AllowDeprecatedGpu
|
||||
{
|
||||
get => ConfigurationHelper.GetValue(ConfigurationKeys.PerformanceAllowDeprecatedGpu, false);
|
||||
set => ConfigurationHelper.SetValue(ConfigurationKeys.PerformanceAllowDeprecatedGpu, value.ToString());
|
||||
get => ConfigFactory.CurrentConfig.WpfSettings.Performance.AllowDeprecatedGpu;
|
||||
set => ConfigFactory.CurrentConfig.WpfSettings.Performance.AllowDeprecatedGpu = value;
|
||||
}
|
||||
|
||||
// use string literal to efficiently store uint16 array
|
||||
@@ -215,10 +215,8 @@ public abstract class GpuOption
|
||||
{
|
||||
try
|
||||
{
|
||||
var req = new DISPLAYCONFIG_ADAPTER_NAME
|
||||
{
|
||||
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER
|
||||
{
|
||||
var req = new DISPLAYCONFIG_ADAPTER_NAME {
|
||||
header = new DISPLAYCONFIG_DEVICE_INFO_HEADER {
|
||||
size = (uint)sizeof(DISPLAYCONFIG_ADAPTER_NAME),
|
||||
adapterId = luid,
|
||||
id = 0,
|
||||
@@ -399,8 +397,7 @@ public abstract class GpuOption
|
||||
// Intel: pre-Xe (Gen9, Gen11)
|
||||
// AMD: pre-Polaris (Sea Islands, Volcanic Islands, Arctic Islands)
|
||||
// NVIDIA: maybe pre-Pascal? (Kepler, Maxwell)
|
||||
ReadOnlySpan<ushort> devIdBlacklist = desc.VendorId switch
|
||||
{
|
||||
ReadOnlySpan<ushort> devIdBlacklist = desc.VendorId switch {
|
||||
0x8086 => IntelBlacklist,
|
||||
0x1002 => AmdBlacklist,
|
||||
0x10de => NvidiaBlacklist,
|
||||
@@ -417,11 +414,11 @@ public abstract class GpuOption
|
||||
|
||||
public static GpuOption GetCurrent()
|
||||
{
|
||||
var preferredGpuInstancePath = ConfigurationHelper.GetValue(ConfigurationKeys.PerformancePreferredGpuInstancePath, string.Empty);
|
||||
var preferredGpuDescription = ConfigurationHelper.GetValue(ConfigurationKeys.PerformancePreferredGpuDescription, string.Empty);
|
||||
var preferredGpuInstancePath = ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuInstancePath;
|
||||
var preferredGpuDescription = ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuDescription;
|
||||
|
||||
GpuOption result;
|
||||
if (ConfigurationHelper.GetValue(ConfigurationKeys.PerformanceUseGpu, false))
|
||||
if (ConfigFactory.CurrentConfig.WpfSettings.Performance.UseGpu)
|
||||
{
|
||||
var options = GetGpuOptions();
|
||||
if (ReferenceEquals(options, _unavailableOptions))
|
||||
@@ -454,17 +451,19 @@ public abstract class GpuOption
|
||||
switch (option)
|
||||
{
|
||||
case DisableOption:
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.PerformanceUseGpu, "false");
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.UseGpu = false;
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuDescription = string.Empty;
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuInstancePath = string.Empty;
|
||||
break;
|
||||
case SystemDefaultOption:
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.PerformanceUseGpu, "true");
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.PerformancePreferredGpuDescription, string.Empty);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.PerformancePreferredGpuInstancePath, string.Empty);
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.UseGpu = true;
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuDescription = string.Empty;
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuInstancePath = string.Empty;
|
||||
break;
|
||||
case SpecificGpuOption x:
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.PerformanceUseGpu, "true");
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.PerformancePreferredGpuDescription, x.GpuInfo.Description);
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.PerformancePreferredGpuInstancePath, x.InstancePath);
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.UseGpu = true;
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuDescription = x.GpuInfo.Description;
|
||||
ConfigFactory.CurrentConfig.WpfSettings.Performance.GpuInstancePath = x.InstancePath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user