LenovoLegionToolkit

Форк
0
84 строки · 3.7 Кб
1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using LenovoLegionToolkit.Lib.Utils;
6

7
// ReSharper disable StringLiteralTypo
8

9
namespace LenovoLegionToolkit.WPF;
10

11
public class Flags
12
{
13
    public bool IsTraceEnabled { get; }
14
    public bool Minimized { get; }
15
    public bool SkipCompatibilityCheck { get; }
16
    public bool DisableTrayTooltip { get; }
17
    public bool AllowAllPowerModesOnBattery { get; }
18
    public bool ForceDisableRgbKeyboardSupport { get; }
19
    public bool ForceDisableSpectrumKeyboardSupport { get; }
20
    public bool ForceDisableLenovoLighting { get; }
21
    public bool ExperimentalGPUWorkingMode { get; }
22
    public bool EnableHybridModeAutomation { get; }
23
    public Uri? ProxyUrl { get; }
24
    public string? ProxyUsername { get; }
25
    public string? ProxyPassword { get; }
26
    public bool ProxyAllowAllCerts { get; }
27

28
    public Flags(IEnumerable<string> startupArgs)
29
    {
30
        var args = startupArgs.Concat(LoadExternalArgs()).ToArray();
31

32
        IsTraceEnabled = BoolValue(args, "--trace");
33
        Minimized = BoolValue(args, "--minimized");
34
        SkipCompatibilityCheck = BoolValue(args, "--skip-compat-check");
35
        DisableTrayTooltip = BoolValue(args, "--disable-tray-tooltip");
36
        AllowAllPowerModesOnBattery = BoolValue(args, "--allow-all-power-modes-on-battery");
37
        ForceDisableRgbKeyboardSupport = BoolValue(args, "--force-disable-rgbkb");
38
        ForceDisableSpectrumKeyboardSupport = BoolValue(args, "--force-disable-spectrumkb");
39
        ForceDisableLenovoLighting = BoolValue(args, "--force-disable-lenovolighting");
40
        ExperimentalGPUWorkingMode = BoolValue(args, "--experimental-gpu-working-mode");
41
        EnableHybridModeAutomation = BoolValue(args, "--enable-hybrid-mode-automation");
42
        ProxyUrl = Uri.TryCreate(StringValue(args, "--proxyUrl"), UriKind.Absolute, out var uri) ? uri : null;
43
        ProxyUsername = StringValue(args, "--proxyUsername");
44
        ProxyPassword = StringValue(args, "--proxyPassword");
45
        ProxyAllowAllCerts = BoolValue(args, "--proxyAllowAllCerts");
46
    }
47

48
    private static IEnumerable<string> LoadExternalArgs()
49
    {
50
        try
51
        {
52
            var argsFile = Path.Combine(Folders.AppData, "args.txt");
53
            return !File.Exists(argsFile) ? Array.Empty<string>() : File.ReadAllLines(argsFile);
54
        }
55
        catch
56
        {
57
            return Array.Empty<string>();
58
        }
59
    }
60

61
    private static bool BoolValue(IEnumerable<string> values, string key) => values.Contains(key);
62

63
    private static string? StringValue(IEnumerable<string> values, string key)
64
    {
65
        var value = values.FirstOrDefault(s => s.StartsWith(key));
66
        return value?.Remove(0, key.Length + 1);
67
    }
68

69
    public 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

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.