From 9df1ca705481ff5ec5d54376092d891715155ca1 Mon Sep 17 00:00:00 2001 From: SongSongSo Date: Tue, 23 May 2023 15:12:39 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9BFix=20CustomSteamPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Pages/Settings/Settings_Steam.axaml | 4 +- .../Resources/Strings.Designer.cs | 9 ++ src/BD.WTTS.Client/Resources/Strings.resx | 3 + .../Settings/Abstractions/ISteamSettings.cs | 2 +- .../Settings/SettingsProperty.cs | 2 +- .../Settings/Steam/O_SteamSettings.cs | 118 ------------------ .../Settings/Steam/SteamSettings.cs | 14 ++- .../ViewModels/Pages/SettingsPageViewModel.cs | 3 +- 8 files changed, 29 insertions(+), 126 deletions(-) delete mode 100644 src/BD.WTTS.Client/Settings/Steam/O_SteamSettings.cs diff --git a/src/BD.WTTS.Client.Avalonia/UI/Views/Pages/Settings/Settings_Steam.axaml b/src/BD.WTTS.Client.Avalonia/UI/Views/Pages/Settings/Settings_Steam.axaml index c193f5a4a..dc60c9dbb 100644 --- a/src/BD.WTTS.Client.Avalonia/UI/Views/Pages/Settings/Settings_Steam.axaml +++ b/src/BD.WTTS.Client.Avalonia/UI/Views/Pages/Settings/Settings_Steam.axaml @@ -14,8 +14,8 @@ mc:Ignorable="d"> - + diff --git a/src/BD.WTTS.Client/Resources/Strings.Designer.cs b/src/BD.WTTS.Client/Resources/Strings.Designer.cs index c0fd04571..8683974a6 100644 --- a/src/BD.WTTS.Client/Resources/Strings.Designer.cs +++ b/src/BD.WTTS.Client/Resources/Strings.Designer.cs @@ -5374,6 +5374,15 @@ namespace BD.WTTS.Client.Resources { } } + /// + /// 查找类似 Steam 路径 的本地化字符串。 + /// + public static string Settings_Steam_Path { + get { + return ResourceManager.GetString("Settings_Steam_Path", resourceCulture); + } + } + /// /// 查找类似 以管理员权限运行 Steam 的本地化字符串。 /// diff --git a/src/BD.WTTS.Client/Resources/Strings.resx b/src/BD.WTTS.Client/Resources/Strings.resx index a107fc25e..6dd58c81b 100644 --- a/src/BD.WTTS.Client/Resources/Strings.resx +++ b/src/BD.WTTS.Client/Resources/Strings.resx @@ -2422,4 +2422,7 @@ AAAAA-BBBBB-CCCC3 启动网络加速失败 + + Steam 路径 + \ No newline at end of file diff --git a/src/BD.WTTS.Client/Settings/Abstractions/ISteamSettings.cs b/src/BD.WTTS.Client/Settings/Abstractions/ISteamSettings.cs index e26cee85f..7c44e0da6 100644 --- a/src/BD.WTTS.Client/Settings/Abstractions/ISteamSettings.cs +++ b/src/BD.WTTS.Client/Settings/Abstractions/ISteamSettings.cs @@ -16,7 +16,7 @@ public interface ISteamSettings string SteamSkin { get; set; } /// - /// Steam 程序路径 + /// Steam 默认程序路径 /// string SteamProgramPath { get; set; } diff --git a/src/BD.WTTS.Client/Settings/SettingsProperty.cs b/src/BD.WTTS.Client/Settings/SettingsProperty.cs index 19186cf5d..938c07c90 100644 --- a/src/BD.WTTS.Client/Settings/SettingsProperty.cs +++ b/src/BD.WTTS.Client/Settings/SettingsProperty.cs @@ -6,7 +6,7 @@ public class SettingsProperty setter; readonly Func getter; - readonly IDisposable? disposable; + IDisposable? disposable; readonly IOptionsMonitor monitor; TValue? value; bool disposedValue; diff --git a/src/BD.WTTS.Client/Settings/Steam/O_SteamSettings.cs b/src/BD.WTTS.Client/Settings/Steam/O_SteamSettings.cs deleted file mode 100644 index 73617cb35..000000000 --- a/src/BD.WTTS.Client/Settings/Steam/O_SteamSettings.cs +++ /dev/null @@ -1,118 +0,0 @@ -//#if (WINDOWS || MACCATALYST || MACOS || LINUX) && !(IOS || ANDROID) - -//// ReSharper disable once CheckNamespace -//namespace BD.WTTS.Settings; - -///// -///// Steam 设置 -///// -//public sealed class SteamSettings : SettingsHost2 -//{ -// private static readonly ISteamService _service = Ioc.Get(); - -// static SteamSettings() -// { -// if (!IApplication.IsDesktop()) return; -// IsRunSteamMinimized.ValueChanged += IsRunSteamMinimized_ValueChanged; -// IsRunSteamNoCheckUpdate.ValueChanged += IsRunSteamNoCheckUpdate_ValueChanged; -// IsRunSteamChina.ValueChanged += IsRunSteamChina_ValueChanged; -// } - -// static void IsRunSteamNoCheckUpdate_ValueChanged(object? sender, ValueChangedEventArgs e) -// { -// if (e.NewValue) -// SteamStratParameter.Value += " -noverifyfiles"; -// else if (SteamStratParameter.Value != null) -// SteamStratParameter.Value = SteamStratParameter.Value.Replace("-noverifyfiles", "").Trim(); -// } - -// static void IsRunSteamMinimized_ValueChanged(object? sender, ValueChangedEventArgs e) -// { -// if (e.NewValue) -// SteamStratParameter.Value += " -silent"; -// else if (SteamStratParameter.Value != null) -// SteamStratParameter.Value = SteamStratParameter.Value.Replace("-silent", "").Trim(); -// } - -// static void IsRunSteamChina_ValueChanged(object? sender, ValueChangedEventArgs e) -// { -// if (e.NewValue) -// SteamStratParameter.Value += " -steamchina"; -// else if (SteamStratParameter.Value != null) -// SteamStratParameter.Value = SteamStratParameter.Value.Replace("-steamchina", "").Trim(); -// } - -// static readonly SerializableProperty? _SteamStratParameter = IApplication.IsDesktop() ? -// GetProperty(defaultValue: null) : null; - -// /// -// /// Steam 启动参数 -// /// -// public static SerializableProperty SteamStratParameter => _SteamStratParameter ?? throw new PlatformNotSupportedException(); - -// //static readonly SerializableProperty? _SteamSkin = IApplication.IsDesktop() ? GetProperty(defaultValue: string.Empty, autoSave: true) : null; -// ///// -// ///// Steam 皮肤 -// ///// -// //[SupportedOSPlatform("Windows")] -// //[SupportedOSPlatform("macOS")] -// //[SupportedOSPlatform("Linux")] -// //public static SerializableProperty SteamSkin => _SteamSkin ?? throw new PlatformNotSupportedException(); - -// static readonly SerializableProperty? _SteamProgramPath = IApplication.IsDesktop() ? GetProperty(defaultValue: _service.SteamProgramPath) : null; - -// public static SerializableProperty SteamProgramPath => (_CustomSteamPath == null || _CustomSteamPath.Value == null) ? _SteamProgramPath ?? throw new PlatformNotSupportedException() : _CustomSteamPath; - -// static readonly SerializableProperty? _CustomSteamPath = IApplication.IsDesktop() ? GetProperty(null, true, "CustomSteamPath") : null; - -// public static SerializableProperty CustomSteamPath => _CustomSteamPath ?? throw new PlatformNotSupportedException(); - -// static readonly SerializableProperty? _IsAutoRunSteam = IApplication.IsDesktop() ? GetProperty(defaultValue: false) : null; - -// /// -// /// 自动运行 Steam -// /// -// public static SerializableProperty IsAutoRunSteam => _IsAutoRunSteam ?? throw new PlatformNotSupportedException(); - -// static readonly SerializableProperty? _IsRunSteamMinimized = IApplication.IsDesktop() ? GetProperty(defaultValue: false) : null; - -// /// -// /// Steam 启动时最小化到托盘 -// /// -// public static SerializableProperty IsRunSteamMinimized => _IsRunSteamMinimized ?? throw new PlatformNotSupportedException(); - -// static readonly SerializableProperty? _IsRunSteamNoCheckUpdate = IApplication.IsDesktop() ? GetProperty(defaultValue: false) : null; - -// /// -// /// Steam 启动时不检查更新 -// /// -// public static SerializableProperty IsRunSteamNoCheckUpdate => _IsRunSteamNoCheckUpdate ?? throw new PlatformNotSupportedException(); - -// static readonly SerializableProperty? _IsRunSteamChina = IApplication.IsDesktop() ? GetProperty(defaultValue: false) : null; - -// /// -// /// Steam 启动时模拟为蒸汽平台(Steam国服)启动 -// /// -// public static SerializableProperty IsRunSteamChina => _IsRunSteamChina ?? throw new PlatformNotSupportedException(); - -// static readonly SerializableProperty? _IsEnableSteamLaunchNotification = IApplication.IsDesktop() ? GetProperty(defaultValue: true) : null; - -// /// -// /// 检测到 Steam 登录时弹出消息通知 -// /// -// public static SerializableProperty IsEnableSteamLaunchNotification => _IsEnableSteamLaunchNotification ?? throw new PlatformNotSupportedException(); - -// /// -// /// Steam 下载完成执行任务 -// /// -// public static SerializableProperty? DownloadCompleteSystemEndMode = IApplication.IsDesktop() ? GetProperty(defaultValue: OSExitMode.Sleep) : null; - -// static readonly SerializableProperty? _IsRunSteamAdministrator = IApplication.IsDesktop() ? GetProperty(defaultValue: true) : null; - -// /// -// /// 以管理员权限运行 Steam -// /// -// public static SerializableProperty IsRunSteamAdministrator => _IsRunSteamAdministrator ?? throw new PlatformNotSupportedException(); -//} - -//#endif \ No newline at end of file diff --git a/src/BD.WTTS.Client/Settings/Steam/SteamSettings.cs b/src/BD.WTTS.Client/Settings/Steam/SteamSettings.cs index 0c823b553..4820c2bd8 100644 --- a/src/BD.WTTS.Client/Settings/Steam/SteamSettings.cs +++ b/src/BD.WTTS.Client/Settings/Steam/SteamSettings.cs @@ -63,7 +63,7 @@ partial class SteamSettings_ : ISettings [SettingsGeneration] public static class SteamSettings { - //private static readonly ISteamService _service = Ioc.Get(); + static readonly ISteamService steamService = Ioc.Get(); static SteamSettings() { @@ -104,10 +104,18 @@ public static class SteamSettings public static SettingsProperty SteamSkin { get; } = new(); /// - public static SettingsProperty SteamProgramPath = new(); + public static SettingsProperty SteamProgramPath = new() + { +#if (WINDOWS || MACCATALYST || MACOS || LINUX) && !(IOS || ANDROID) + Value = steamService.SteamProgramPath, +#endif + }; /// - public static SettingsProperty CustomSteamPath { get; } = new(); + public static SettingsProperty CustomSteamPath { get; } = new() + { + Value = (CustomSteamPath == null || CustomSteamPath.Value == null) ? SteamProgramPath.Value : CustomSteamPath.Value, + }; /// public static SettingsProperty IsAutoRunSteam { get; } = new(); diff --git a/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs b/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs index d58f47127..5c8155499 100644 --- a/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs +++ b/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs @@ -61,7 +61,8 @@ public sealed partial class SettingsPageViewModel : TabItemViewModel var openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Steam|steam.exe"; openFileDialog.ShowDialog(); - SteamSettings.SteamProgramPath.Value = openFileDialog.FileName; + if (openFileDialog.FileName == string.Empty) return; + SteamSettings.CustomSteamPath.Value = openFileDialog.FileName; } #endif