LenovoLegionToolkit
84 строки · 3.7 Кб
1using System;2using System.Collections.Generic;3using System.IO;4using System.Linq;5using LenovoLegionToolkit.Lib.Utils;6
7// ReSharper disable StringLiteralTypo
8
9namespace LenovoLegionToolkit.WPF;10
11public class Flags12{
13public bool IsTraceEnabled { get; }14public bool Minimized { get; }15public bool SkipCompatibilityCheck { get; }16public bool DisableTrayTooltip { get; }17public bool AllowAllPowerModesOnBattery { get; }18public bool ForceDisableRgbKeyboardSupport { get; }19public bool ForceDisableSpectrumKeyboardSupport { get; }20public bool ForceDisableLenovoLighting { get; }21public bool ExperimentalGPUWorkingMode { get; }22public bool EnableHybridModeAutomation { get; }23public Uri? ProxyUrl { get; }24public string? ProxyUsername { get; }25public string? ProxyPassword { get; }26public bool ProxyAllowAllCerts { get; }27
28public Flags(IEnumerable<string> startupArgs)29{30var args = startupArgs.Concat(LoadExternalArgs()).ToArray();31
32IsTraceEnabled = BoolValue(args, "--trace");33Minimized = BoolValue(args, "--minimized");34SkipCompatibilityCheck = BoolValue(args, "--skip-compat-check");35DisableTrayTooltip = BoolValue(args, "--disable-tray-tooltip");36AllowAllPowerModesOnBattery = BoolValue(args, "--allow-all-power-modes-on-battery");37ForceDisableRgbKeyboardSupport = BoolValue(args, "--force-disable-rgbkb");38ForceDisableSpectrumKeyboardSupport = BoolValue(args, "--force-disable-spectrumkb");39ForceDisableLenovoLighting = BoolValue(args, "--force-disable-lenovolighting");40ExperimentalGPUWorkingMode = BoolValue(args, "--experimental-gpu-working-mode");41EnableHybridModeAutomation = BoolValue(args, "--enable-hybrid-mode-automation");42ProxyUrl = Uri.TryCreate(StringValue(args, "--proxyUrl"), UriKind.Absolute, out var uri) ? uri : null;43ProxyUsername = StringValue(args, "--proxyUsername");44ProxyPassword = StringValue(args, "--proxyPassword");45ProxyAllowAllCerts = BoolValue(args, "--proxyAllowAllCerts");46}47
48private static IEnumerable<string> LoadExternalArgs()49{50try51{52var argsFile = Path.Combine(Folders.AppData, "args.txt");53return !File.Exists(argsFile) ? Array.Empty<string>() : File.ReadAllLines(argsFile);54}55catch56{57return Array.Empty<string>();58}59}60
61private static bool BoolValue(IEnumerable<string> values, string key) => values.Contains(key);62
63private static string? StringValue(IEnumerable<string> values, string key)64{65var value = values.FirstOrDefault(s => s.StartsWith(key));66return value?.Remove(0, key.Length + 1);67}68
69public override string ToString() =>70$"{nameof(IsTraceEnabled)}: {IsTraceEnabled}," +71$" {nameof(Minimized)}: {Minimized}," +72$" {nameof(SkipCompatibilityCheck)}: {SkipCompatibilityCheck}," +73$" {nameof(DisableTrayTooltip)}: {DisableTrayTooltip}," +74$" {nameof(AllowAllPowerModesOnBattery)}: {AllowAllPowerModesOnBattery}," +75$" {nameof(ForceDisableRgbKeyboardSupport)}: {ForceDisableRgbKeyboardSupport}," +76$" {nameof(ForceDisableSpectrumKeyboardSupport)}: {ForceDisableSpectrumKeyboardSupport}," +77$" {nameof(ForceDisableLenovoLighting)}: {ForceDisableLenovoLighting}," +78$" {nameof(ExperimentalGPUWorkingMode)}: {ExperimentalGPUWorkingMode}," +79$" {nameof(EnableHybridModeAutomation)}: {EnableHybridModeAutomation}," +80$" {nameof(ProxyUrl)}: {ProxyUrl}," +81$" {nameof(ProxyUsername)}: {ProxyUsername}," +82$" {nameof(ProxyPassword)}: {ProxyPassword}," +83$" {nameof(ProxyAllowAllCerts)}: {ProxyAllowAllCerts}";84}
85