LenovoLegionToolkit

Форк
0
976 строк · 30.5 Кб
1
using System;
2
using System.Collections.Generic;
3
using System.Collections.ObjectModel;
4
using System.Diagnostics;
5
using System.Drawing;
6
using System.IO;
7
using System.Linq;
8
using System.Text;
9
using LenovoLegionToolkit.Lib.Extensions;
10
using Newtonsoft.Json;
11
using Octokit;
12

13
namespace LenovoLegionToolkit.Lib;
14

15
public readonly struct BatteryInformation
16
{
17
    public bool IsCharging { get; init; }
18
    public int BatteryPercentage { get; init; }
19
    public int BatteryLifeRemaining { get; init; }
20
    public int FullBatteryLifeRemaining { get; init; }
21
    public int DischargeRate { get; init; }
22
    public int EstimateChargeRemaining { get; init; }
23
    public int DesignCapacity { get; init; }
24
    public int FullChargeCapacity { get; init; }
25
    public int CycleCount { get; init; }
26
    public bool IsLowBattery { get; init; }
27
    public double? BatteryTemperatureC { get; init; }
28
    public DateTime? ManufactureDate { get; init; }
29
    public DateTime? FirstUseDate { get; init; }
30
}
31

32
public readonly struct BiosVersion
33
{
34
    public string Prefix { get; }
35
    public int? Version { get; }
36

37
    public BiosVersion(string prefix, int? version)
38
    {
39
        Prefix = prefix;
40
        Version = version;
41
    }
42

43
    public bool IsHigherOrEqualThan(BiosVersion other)
44
    {
45
        if (!Prefix.Equals(other.Prefix, StringComparison.InvariantCultureIgnoreCase))
46
            return false;
47

48
        if (Version is null || other.Version is null)
49
            return true;
50

51
        return Version >= other.Version;
52
    }
53

54
    public bool IsLowerThan(BiosVersion other)
55
    {
56
        if (!Prefix.Equals(other.Prefix, StringComparison.InvariantCultureIgnoreCase))
57
            return false;
58

59
        if (Version is null || other.Version is null)
60
            return true;
61

62
        return Version < other.Version;
63
    }
64

65
    public override string ToString() => $"{nameof(Prefix)}: {Prefix}, {nameof(Version)}: {Version}";
66
}
67

68
public readonly struct Brightness
69
{
70
    public byte Value { get; private init; }
71

72
    public static implicit operator Brightness(byte value) => new() { Value = value };
73
}
74

75
public readonly struct DiscreteCapability
76
{
77
    public CapabilityID Id { get; }
78
    public int Value { get; }
79

80
    public DiscreteCapability(CapabilityID id, int value)
81
    {
82
        Id = id;
83
        Value = value;
84
    }
85
}
86

87
public readonly struct DisplayAdvancedColorInfo
88
{
89
    public bool AdvancedColorSupported { get; }
90
    public bool AdvancedColorEnabled { get; }
91
    public bool WideColorEnforced { get; }
92
    public bool AdvancedColorForceDisabled { get; }
93

94
    public DisplayAdvancedColorInfo(bool advancedColorSupported, bool advancedColorEnabled, bool wideColorEnforced, bool advancedColorForceDisabled)
95
    {
96
        AdvancedColorSupported = advancedColorSupported;
97
        AdvancedColorEnabled = advancedColorEnabled;
98
        WideColorEnforced = wideColorEnforced;
99
        AdvancedColorForceDisabled = advancedColorForceDisabled;
100
    }
101
}
102

103
public readonly struct DriverInfo
104
{
105
    public string DeviceId { get; init; }
106
    public string HardwareId { get; init; }
107
    public Version? Version { get; init; }
108
    public DateTime? Date { get; init; }
109
}
110

111
public readonly struct FanTableData
112
{
113
    public FanTableType Type { get; init; }
114
    public byte FanId { get; init; }
115
    public byte SensorId { get; init; }
116
    public ushort[] FanSpeeds { get; init; }
117
    public ushort[] Temps { get; init; }
118

119
    public override string ToString() =>
120
        $"{nameof(Type)}: {Type}," +
121
        $" {nameof(FanId)}: {FanId}," +
122
        $" {nameof(SensorId)}: {SensorId}," +
123
        $" {nameof(FanSpeeds)}: [{string.Join(", ", FanSpeeds)}]," +
124
        $" {nameof(Temps)}: [{string.Join(", ", Temps)}]," +
125
        $" {nameof(Type)}: {Type}";
126
}
127

128
public readonly struct FanTable
129
{
130
    // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
131
    // ReSharper disable MemberCanBePrivate.Global
132
    // ReSharper disable IdentifierTypo
133
    // ReSharper disable InconsistentNaming
134

135
    public byte FSTM { get; init; }
136
    public byte FSID { get; init; }
137
    public uint FSTL { get; init; }
138
    public ushort FSS0 { get; init; }
139
    public ushort FSS1 { get; init; }
140
    public ushort FSS2 { get; init; }
141
    public ushort FSS3 { get; init; }
142
    public ushort FSS4 { get; init; }
143
    public ushort FSS5 { get; init; }
144
    public ushort FSS6 { get; init; }
145
    public ushort FSS7 { get; init; }
146
    public ushort FSS8 { get; init; }
147
    public ushort FSS9 { get; init; }
148

149
    // ReSharper restore AutoPropertyCanBeMadeGetOnly.Global
150
    // ReSharper restore MemberCanBePrivate.Global
151
    // ReSharper restore IdentifierTypo
152
    // ReSharper restore InconsistentNaming
153

154
    public FanTable(ushort[] fanTable)
155
    {
156
        if (fanTable.Length != 10)
157
            // ReSharper disable once LocalizableElement
158
            throw new ArgumentException("Fan table length must be 10.", nameof(fanTable));
159

160
        FSTM = 1;
161
        FSID = 0;
162
        FSTL = 0;
163
        FSS0 = fanTable[0];
164
        FSS1 = fanTable[1];
165
        FSS2 = fanTable[2];
166
        FSS3 = fanTable[3];
167
        FSS4 = fanTable[4];
168
        FSS5 = fanTable[5];
169
        FSS6 = fanTable[6];
170
        FSS7 = fanTable[7];
171
        FSS8 = fanTable[8];
172
        FSS9 = fanTable[9];
173
    }
174

175
    public ushort[] GetTable() => new[] { FSS0, FSS1, FSS2, FSS3, FSS4, FSS5, FSS6, FSS7, FSS8, FSS9 };
176

177
    public byte[] GetBytes()
178
    {
179
        using var ms = new MemoryStream(new byte[64]);
180
        ms.WriteByte(FSTM);
181
        ms.WriteByte(FSID);
182
        ms.Write(BitConverter.GetBytes(FSTL));
183
        ms.Write(BitConverter.GetBytes(FSS0));
184
        ms.Write(BitConverter.GetBytes(FSS1));
185
        ms.Write(BitConverter.GetBytes(FSS2));
186
        ms.Write(BitConverter.GetBytes(FSS3));
187
        ms.Write(BitConverter.GetBytes(FSS4));
188
        ms.Write(BitConverter.GetBytes(FSS5));
189
        ms.Write(BitConverter.GetBytes(FSS6));
190
        ms.Write(BitConverter.GetBytes(FSS7));
191
        ms.Write(BitConverter.GetBytes(FSS8));
192
        ms.Write(BitConverter.GetBytes(FSS9));
193
        return ms.ToArray();
194
    }
195

196
    public override string ToString() =>
197
        $"{nameof(FSTM)}: {FSTM}," +
198
        $" {nameof(FSID)}: {FSID}," +
199
        $" {nameof(FSTL)}: {FSTL}," +
200
        $" {nameof(FSS0)}: {FSS0}," +
201
        $" {nameof(FSS1)}: {FSS1}," +
202
        $" {nameof(FSS2)}: {FSS2}," +
203
        $" {nameof(FSS3)}: {FSS3}," +
204
        $" {nameof(FSS4)}: {FSS4}," +
205
        $" {nameof(FSS5)}: {FSS5}," +
206
        $" {nameof(FSS6)}: {FSS6}," +
207
        $" {nameof(FSS7)}: {FSS7}," +
208
        $" {nameof(FSS8)}: {FSS8}," +
209
        $" {nameof(FSS9)}: {FSS9}";
210
}
211

212
public readonly struct FanTableInfo
213
{
214
    public FanTableData[] Data { get; }
215
    public FanTable Table { get; }
216

217
    public FanTableInfo(FanTableData[] data, FanTable table)
218
    {
219
        Data = data;
220
        Table = table;
221
    }
222

223
    public override string ToString() =>
224
        $"{nameof(Data)}: [{string.Join(", ", Data)}]," +
225
        $" {nameof(Table)}: {Table}";
226
}
227

228
public readonly struct GPUOverclockInfo
229
{
230
    public static readonly GPUOverclockInfo Zero = new();
231

232
    public int CoreDeltaMhz { get; init; }
233
    public int MemoryDeltaMhz { get; init; }
234

235

236
    #region Equality
237

238
    public override bool Equals(object? obj)
239
    {
240
        return obj is GPUOverclockInfo other && Equals(other);
241
    }
242

243
    public override int GetHashCode()
244
    {
245
        return HashCode.Combine(CoreDeltaMhz, MemoryDeltaMhz);
246
    }
247

248
    public static bool operator ==(GPUOverclockInfo left, GPUOverclockInfo right) => left.Equals(right);
249

250
    public static bool operator !=(GPUOverclockInfo left, GPUOverclockInfo right) => !left.Equals(right);
251

252
    #endregion
253

254
    public override string ToString() => $"{nameof(CoreDeltaMhz)}: {CoreDeltaMhz}, {nameof(MemoryDeltaMhz)}: {MemoryDeltaMhz}";
255

256
}
257

258
public readonly struct GodModeDefaults
259
{
260
    public int? CPULongTermPowerLimit { get; init; }
261
    public int? CPUShortTermPowerLimit { get; init; }
262
    public int? CPUPeakPowerLimit { get; init; }
263
    public int? CPUCrossLoadingPowerLimit { get; init; }
264
    public int? CPUPL1Tau { get; init; }
265
    public int? APUsPPTPowerLimit { get; init; }
266
    public int? CPUTemperatureLimit { get; init; }
267
    public int? GPUPowerBoost { get; init; }
268
    public int? GPUConfigurableTGP { get; init; }
269
    public int? GPUTemperatureLimit { get; init; }
270
    public int? GPUTotalProcessingPowerTargetOnAcOffsetFromBaseline { get; init; }
271
    public int? GPUToCPUDynamicBoost { get; init; }
272
    public FanTable? FanTable { get; init; }
273
    public bool? FanFullSpeed { get; init; }
274

275
    public override string ToString() =>
276
        $"{nameof(CPULongTermPowerLimit)}: {CPULongTermPowerLimit}," +
277
        $" {nameof(CPUShortTermPowerLimit)}: {CPUShortTermPowerLimit}," +
278
        $" {nameof(CPUPeakPowerLimit)}: {CPUPeakPowerLimit}," +
279
        $" {nameof(CPUCrossLoadingPowerLimit)}: {CPUCrossLoadingPowerLimit}," +
280
        $" {nameof(CPUPL1Tau)}: {CPUPL1Tau}," +
281
        $" {nameof(APUsPPTPowerLimit)}: {APUsPPTPowerLimit}," +
282
        $" {nameof(CPUTemperatureLimit)}: {CPUTemperatureLimit}," +
283
        $" {nameof(GPUPowerBoost)}: {GPUPowerBoost}," +
284
        $" {nameof(GPUConfigurableTGP)}: {GPUConfigurableTGP}," +
285
        $" {nameof(GPUTemperatureLimit)}: {GPUTemperatureLimit}," +
286
        $" {nameof(GPUTotalProcessingPowerTargetOnAcOffsetFromBaseline)}: {GPUTotalProcessingPowerTargetOnAcOffsetFromBaseline}," +
287
        $" {nameof(GPUToCPUDynamicBoost)}: {GPUToCPUDynamicBoost}," +
288
        $" {nameof(FanTable)}: {FanTable}," +
289
        $" {nameof(FanFullSpeed)}: {FanFullSpeed}";
290
}
291

292
public readonly struct GodModeState
293
{
294
    public Guid ActivePresetId { get; init; }
295
    public ReadOnlyDictionary<Guid, GodModePreset> Presets { get; init; }
296
}
297

298
public readonly struct GodModePreset
299
{
300
    public string Name { get; init; }
301
    public StepperValue? CPULongTermPowerLimit { get; init; }
302
    public StepperValue? CPUShortTermPowerLimit { get; init; }
303
    public StepperValue? CPUPeakPowerLimit { get; init; }
304
    public StepperValue? CPUCrossLoadingPowerLimit { get; init; }
305
    public StepperValue? CPUPL1Tau { get; init; }
306
    public StepperValue? APUsPPTPowerLimit { get; init; }
307
    public StepperValue? CPUTemperatureLimit { get; init; }
308
    public StepperValue? GPUPowerBoost { get; init; }
309
    public StepperValue? GPUConfigurableTGP { get; init; }
310
    public StepperValue? GPUTemperatureLimit { get; init; }
311
    public StepperValue? GPUTotalProcessingPowerTargetOnAcOffsetFromBaseline { get; init; }
312
    public StepperValue? GPUToCPUDynamicBoost { get; init; }
313
    public FanTableInfo? FanTableInfo { get; init; }
314
    public bool? FanFullSpeed { get; init; }
315
    public int? MinValueOffset { get; init; }
316
    public int? MaxValueOffset { get; init; }
317

318
    public override string ToString() =>
319
        $"{nameof(Name)}: {Name}," +
320
        $" {nameof(CPULongTermPowerLimit)}: {CPULongTermPowerLimit}," +
321
        $" {nameof(CPUShortTermPowerLimit)}: {CPUShortTermPowerLimit}," +
322
        $" {nameof(CPUPeakPowerLimit)}: {CPUPeakPowerLimit}," +
323
        $" {nameof(CPUCrossLoadingPowerLimit)}: {CPUCrossLoadingPowerLimit}," +
324
        $" {nameof(CPUPL1Tau)}: {CPUPL1Tau}," +
325
        $" {nameof(APUsPPTPowerLimit)}: {APUsPPTPowerLimit}," +
326
        $" {nameof(CPUTemperatureLimit)}: {CPUTemperatureLimit}," +
327
        $" {nameof(GPUPowerBoost)}: {GPUPowerBoost}," +
328
        $" {nameof(GPUConfigurableTGP)}: {GPUConfigurableTGP}," +
329
        $" {nameof(GPUTemperatureLimit)}: {GPUTemperatureLimit}," +
330
        $" {nameof(GPUTotalProcessingPowerTargetOnAcOffsetFromBaseline)}: {GPUTotalProcessingPowerTargetOnAcOffsetFromBaseline}," +
331
        $" {nameof(GPUToCPUDynamicBoost)}: {GPUToCPUDynamicBoost}," +
332
        $" {nameof(FanTableInfo)}: {FanTableInfo}," +
333
        $" {nameof(FanFullSpeed)}: {FanFullSpeed}," +
334
        $" {nameof(MinValueOffset)}: {MinValueOffset}," +
335
        $" {nameof(MaxValueOffset)}: {MaxValueOffset}";
336
}
337

338
public readonly struct GPUStatus
339
{
340
    public GPUState State { get; }
341
    public string? PerformanceState { get; }
342
    public List<Process> Processes { get; }
343
    public int ProcessCount => Processes.Count;
344

345
    public GPUStatus(GPUState state, string? performanceState, List<Process> processes)
346
    {
347
        State = state;
348
        PerformanceState = performanceState;
349
        Processes = processes;
350
    }
351
}
352

353
public readonly struct HardwareId
354
{
355
    public static readonly HardwareId Empty = new();
356

357
    public string Vendor { get; init; }
358
    public string Device { get; init; }
359

360
    #region Equality
361

362
    public override bool Equals(object? obj)
363
    {
364
        if (obj is not HardwareId other)
365
            return false;
366

367
        if (!Vendor.Equals(other.Vendor, StringComparison.InvariantCultureIgnoreCase))
368
            return false;
369

370
        if (!Device.Equals(other.Device, StringComparison.InvariantCultureIgnoreCase))
371
            return false;
372

373
        return true;
374
    }
375

376
    public override int GetHashCode() => HashCode.Combine(Vendor, Device);
377

378
    public static bool operator ==(HardwareId left, HardwareId right) => left.Equals(right);
379

380
    public static bool operator !=(HardwareId left, HardwareId right) => !left.Equals(right);
381

382
    #endregion
383
}
384

385
public readonly struct MachineInformation
386
{
387
    public readonly struct FeatureData
388
    {
389
        public static readonly FeatureData Unknown = new() { Source = SourceType.Unknown };
390

391
        public enum SourceType
392
        {
393
            Unknown,
394
            Flags,
395
            CapabilityData
396
        }
397

398
        public SourceType Source { get; init; }
399
        public bool IGPUMode { get; init; }
400
        public bool AIChip { get; init; }
401
        public bool FlipToStart { get; init; }
402
        public bool NvidiaGPUDynamicDisplaySwitching { get; init; }
403
        public bool InstantBootAc { get; init; }
404
        public bool InstantBootUsbPowerDelivery { get; init; }
405
        public bool AMDSmartShiftMode { get; init; }
406
        public bool AMDSkinTemperatureTracking { get; init; }
407
    }
408

409
    public readonly struct PropertyData
410
    {
411
        public bool SupportsGodMode => SupportsGodModeV1 || SupportsGodModeV2;
412

413
        public (bool status, bool connectivity) SupportsAlwaysOnAc { get; init; }
414
        public bool SupportsGodModeV1 { get; init; }
415
        public bool SupportsGodModeV2 { get; init; }
416
        public bool SupportsGSync { get; init; }
417
        public bool SupportsIGPUMode { get; init; }
418
        public bool SupportsAIMode { get; init; }
419
        public bool SupportBootLogoChange { get; init; }
420
        public bool HasQuietToPerformanceModeSwitchingBug { get; init; }
421
        public bool HasGodModeToOtherModeSwitchingBug { get; init; }
422
        public bool IsExcludedFromLenovoLighting { get; init; }
423
        public bool IsExcludedFromPanelLogoLenovoLighting { get; init; }
424
    }
425

426
    public string Vendor { get; init; }
427
    public string MachineType { get; init; }
428
    public string Model { get; init; }
429
    public string SerialNumber { get; init; }
430
    public BiosVersion? BiosVersion { get; init; }
431
    public string? BiosVersionRaw { get; init; }
432
    public PowerModeState[] SupportedPowerModes { get; init; }
433
    public int SmartFanVersion { get; init; }
434
    public int LegionZoneVersion { get; init; }
435
    public FeatureData Features { get; init; }
436
    public PropertyData Properties { get; init; }
437
}
438

439
public struct Package
440
{
441
    public string Id { get; init; }
442
    public string Title { get; init; }
443
    public string Description { get; init; }
444
    public string Version { get; init; }
445
    public string Category { get; init; }
446
    public string FileName { get; init; }
447
    public string FileSize { get; init; }
448
    public string? FileCrc { get; init; }
449
    public DateTime ReleaseDate { get; init; }
450
    public string? Readme { get; init; }
451
    public string FileLocation { get; init; }
452
    public bool IsUpdate { get; init; }
453
    public RebootType Reboot { get; init; }
454

455
    private string? _index;
456

457
    public string Index
458
    {
459
        get
460
        {
461
            _index ??= new StringBuilder()
462
                .Append(Title)
463
                .Append(Description)
464
                .Append(Version)
465
                .Append(Category)
466
                .Append(FileName)
467
                .ToString();
468
            return _index;
469
        }
470
    }
471
}
472

473
public readonly struct Notification
474
{
475
    public NotificationType Type { get; }
476

477
    public object[] Args { get; }
478

479
    public Notification(NotificationType type, params object[] args)
480
    {
481
        Type = type;
482
        Args = args;
483
    }
484

485
    public override string ToString()
486
    {
487
        return $"{nameof(Type)}: {Type}," +
488
               $" {nameof(Args)}: [{string.Join(", ", Args)}]";
489
    }
490
}
491

492
public readonly struct PowerPlan
493
{
494
    public Guid Guid { get; }
495
    public string Name { get; }
496
    public bool IsActive { get; }
497

498
    public PowerPlan(Guid guid, string name, bool isActive)
499
    {
500
        Guid = guid;
501
        Name = name;
502
        IsActive = isActive;
503
    }
504

505
    public override string ToString() => Name;
506
}
507

508
public readonly struct ProcessEventInfo
509
{
510
    public ProcessEventInfoType Type { get; }
511

512
    public ProcessInfo Process { get; }
513

514
    public ProcessEventInfo(ProcessEventInfoType type, ProcessInfo process)
515
    {
516
        Type = type;
517
        Process = process;
518
    }
519
}
520

521
public readonly struct ProcessInfo : IComparable
522
{
523
    public static ProcessInfo FromPath(string path) => new(Path.GetFileNameWithoutExtension(path), path);
524

525
    public string Name { get; }
526

527
    public string? ExecutablePath { get; }
528

529
    [JsonConstructor]
530
    public ProcessInfo(string name, string? executablePath)
531
    {
532
        Name = name;
533
        ExecutablePath = executablePath;
534
    }
535

536
    public override string ToString() => $"{nameof(Name)}: {Name}, {nameof(ExecutablePath)}: {ExecutablePath}";
537

538
    #region Equality
539

540
    public int CompareTo(object? obj)
541
    {
542
        var other = obj is null ? default : (ProcessInfo)obj;
543
        var result = string.Compare(Name, other.Name, StringComparison.InvariantCultureIgnoreCase);
544
        return result != 0 ? result : string.Compare(ExecutablePath, other.ExecutablePath, StringComparison.InvariantCultureIgnoreCase);
545
    }
546

547
    public override bool Equals(object? obj) => obj is ProcessInfo info && Name == info.Name && ExecutablePath == info.ExecutablePath;
548

549
    public override int GetHashCode() => HashCode.Combine(Name, ExecutablePath);
550

551
    public static bool operator ==(ProcessInfo left, ProcessInfo right) => left.Equals(right);
552

553
    public static bool operator !=(ProcessInfo left, ProcessInfo right) => !(left == right);
554

555
    public static bool operator <(ProcessInfo left, ProcessInfo right) => left.CompareTo(right) < 0;
556

557
    public static bool operator <=(ProcessInfo left, ProcessInfo right) => left.CompareTo(right) <= 0;
558

559
    public static bool operator >(ProcessInfo left, ProcessInfo right) => left.CompareTo(right) > 0;
560

561
    public static bool operator >=(ProcessInfo left, ProcessInfo right) => left.CompareTo(right) >= 0;
562

563
    #endregion
564
}
565

566
public readonly struct RangeCapability
567
{
568
    public CapabilityID Id { get; }
569
    public int DefaultValue { get; }
570
    public int Min { get; }
571
    public int Max { get; }
572
    public int Step { get; }
573

574
    public RangeCapability(CapabilityID id, int defaultValue, int min, int max, int step)
575
    {
576
        Id = id;
577
        DefaultValue = defaultValue;
578
        Min = min;
579
        Max = max;
580
        Step = step;
581
    }
582
}
583

584
public readonly struct RGBColor
585
{
586
    public static readonly RGBColor Black = new(0, 0, 0);
587
    public static readonly RGBColor White = new(255, 255, 255);
588

589
    public byte R { get; }
590
    public byte G { get; }
591
    public byte B { get; }
592

593
    [JsonConstructor]
594
    public RGBColor(byte r, byte g, byte b)
595
    {
596
        R = r;
597
        G = g;
598
        B = b;
599
    }
600

601
    #region Equality
602

603
    public override bool Equals(object? obj)
604
    {
605
        return obj is RGBColor color && R == color.R && G == color.G && B == color.B;
606
    }
607

608
    public override int GetHashCode() => (R, G, B).GetHashCode();
609

610
    public static bool operator ==(RGBColor left, RGBColor right) => left.Equals(right);
611

612
    public static bool operator !=(RGBColor left, RGBColor right) => !left.Equals(right);
613

614
    #endregion
615

616
    public override string ToString() => $"{nameof(R)}: {R}, {nameof(G)}: {G}, {nameof(B)}: {B}";
617
}
618

619
public readonly struct RGBKeyboardBacklightBacklightPresetDescription
620
{
621
    public RGBKeyboardBacklightEffect Effect { get; } = RGBKeyboardBacklightEffect.Static;
622
    public RGBKeyboardBacklightSpeed Speed { get; } = RGBKeyboardBacklightSpeed.Slowest;
623
    public RGBKeyboardBacklightBrightness Brightness { get; } = RGBKeyboardBacklightBrightness.Low;
624
    public RGBColor Zone1 { get; } = RGBColor.White;
625
    public RGBColor Zone2 { get; } = RGBColor.White;
626
    public RGBColor Zone3 { get; } = RGBColor.White;
627
    public RGBColor Zone4 { get; } = RGBColor.White;
628

629
    [JsonConstructor]
630
    public RGBKeyboardBacklightBacklightPresetDescription(
631
        RGBKeyboardBacklightEffect effect,
632
        RGBKeyboardBacklightSpeed speed,
633
        RGBKeyboardBacklightBrightness brightness,
634
        RGBColor zone1,
635
        RGBColor zone2,
636
        RGBColor zone3,
637
        RGBColor zone4)
638
    {
639
        Effect = effect;
640
        Speed = speed;
641
        Brightness = brightness;
642
        Zone1 = zone1;
643
        Zone2 = zone2;
644
        Zone3 = zone3;
645
        Zone4 = zone4;
646
    }
647

648
    #region Equality
649

650
    public override bool Equals(object? obj)
651
    {
652
        return obj is RGBKeyboardBacklightBacklightPresetDescription settings &&
653
               Effect == settings.Effect &&
654
               Speed == settings.Speed &&
655
               Brightness == settings.Brightness &&
656
               Zone1.Equals(settings.Zone1) &&
657
               Zone2.Equals(settings.Zone2) &&
658
               Zone3.Equals(settings.Zone3) &&
659
               Zone4.Equals(settings.Zone4);
660
    }
661

662
    public override int GetHashCode() => HashCode.Combine(Effect, Speed, Brightness, Zone1, Zone2, Zone3, Zone4);
663

664
    public static bool operator ==(RGBKeyboardBacklightBacklightPresetDescription left, RGBKeyboardBacklightBacklightPresetDescription right)
665
    {
666
        return left.Equals(right);
667
    }
668

669
    public static bool operator !=(RGBKeyboardBacklightBacklightPresetDescription left, RGBKeyboardBacklightBacklightPresetDescription right)
670
    {
671
        return !(left == right);
672
    }
673

674
    #endregion
675

676
    public override string ToString() =>
677
        $"{nameof(Effect)}: {Effect}," +
678
        $" {nameof(Speed)}: {Speed}," +
679
        $" {nameof(Brightness)}: {Brightness}," +
680
        $" {nameof(Zone1)}: {Zone1}," +
681
        $" {nameof(Zone2)}: {Zone2}," +
682
        $" {nameof(Zone3)}: {Zone3}," +
683
        $" {nameof(Zone4)}: {Zone4}";
684
}
685

686
public readonly struct RGBKeyboardBacklightState
687
{
688
    public RGBKeyboardBacklightPreset SelectedPreset { get; }
689
    public Dictionary<RGBKeyboardBacklightPreset, RGBKeyboardBacklightBacklightPresetDescription> Presets { get; }
690

691
    [JsonConstructor]
692
    public RGBKeyboardBacklightState(RGBKeyboardBacklightPreset selectedPreset, Dictionary<RGBKeyboardBacklightPreset, RGBKeyboardBacklightBacklightPresetDescription> presets)
693
    {
694
        SelectedPreset = selectedPreset;
695
        Presets = presets;
696
    }
697
}
698

699
public readonly struct SensorData
700
{
701
    public static readonly SensorData Empty = new()
702
    {
703
        Utilization = -1,
704
        CoreClock = -1,
705
        MaxCoreClock = -1,
706
        MemoryClock = -1,
707
        MaxMemoryClock = -1,
708
        Temperature = -1,
709
        MaxTemperature = -1,
710
        FanSpeed = -1,
711
        MaxFanSpeed = -1
712
    };
713

714
    public int Utilization { get; init; }
715
    public int MaxUtilization { get; init; }
716
    public int CoreClock { get; init; }
717
    public int MaxCoreClock { get; init; }
718
    public int MemoryClock { get; init; }
719
    public int MaxMemoryClock { get; init; }
720
    public int Temperature { get; init; }
721
    public int MaxTemperature { get; init; }
722
    public int FanSpeed { get; init; }
723
    public int MaxFanSpeed { get; init; }
724

725
    public override string ToString() =>
726
        $"{nameof(Utilization)}: {Utilization}," +
727
        $" {nameof(MaxUtilization)}: {MaxUtilization}," +
728
        $" {nameof(CoreClock)}: {CoreClock}," +
729
        $" {nameof(MaxCoreClock)}: {MaxCoreClock}," +
730
        $" {nameof(MemoryClock)}: {MemoryClock}," +
731
        $" {nameof(MaxMemoryClock)}: {MaxMemoryClock}," +
732
        $" {nameof(Temperature)}: {Temperature}," +
733
        $" {nameof(MaxTemperature)}: {MaxTemperature}," +
734
        $" {nameof(FanSpeed)}: {FanSpeed}," +
735
        $" {nameof(MaxFanSpeed)}: {MaxFanSpeed}";
736
}
737

738
public readonly struct SensorsData
739
{
740
    public static readonly SensorsData Empty = new() { CPU = SensorData.Empty, GPU = SensorData.Empty };
741

742
    public SensorData CPU { get; init; }
743
    public SensorData GPU { get; init; }
744

745
    public override string ToString() => $"{nameof(CPU)}: {CPU}, {nameof(GPU)}: {GPU}";
746
}
747

748
public readonly struct SensorSettings
749
{
750
    public int CPUSensorID { get; init; }
751
    public int GPUSensorID { get; init; }
752
    public int CPUFanID { get; init; }
753
    public int GPUFanID { get; init; }
754
}
755

756
public readonly struct DpiScale : IDisplayName, IEquatable<DpiScale>
757
{
758
    public int Scale { get; }
759

760
    [JsonIgnore]
761
    public string DisplayName => $"{Scale}%";
762

763
    [JsonConstructor]
764
    public DpiScale(int scale)
765
    {
766
        Scale = scale;
767
    }
768

769
    #region Equality
770

771
    public override bool Equals(object? obj) => obj is DpiScale rate && Equals(rate);
772

773
    public bool Equals(DpiScale other) => Scale == other.Scale;
774

775
    public override int GetHashCode() => HashCode.Combine(Scale);
776

777
    public static bool operator ==(DpiScale left, DpiScale right) => left.Equals(right);
778

779
    public static bool operator !=(DpiScale left, DpiScale right) => !(left == right);
780

781
    #endregion
782
}
783

784
public readonly struct RefreshRate : IDisplayName, IEquatable<RefreshRate>
785
{
786
    public int Frequency { get; }
787

788
    [JsonIgnore]
789
    public string DisplayName => $"{Frequency} Hz";
790

791
    [JsonConstructor]
792
    public RefreshRate(int frequency)
793
    {
794
        Frequency = frequency;
795
    }
796

797
    public override string ToString() => $"{Frequency}Hz";
798

799
    #region Equality
800

801
    public override bool Equals(object? obj) => obj is RefreshRate rate && Equals(rate);
802

803
    public bool Equals(RefreshRate other) => Frequency == other.Frequency;
804

805
    public override int GetHashCode() => HashCode.Combine(Frequency);
806

807
    public static bool operator ==(RefreshRate left, RefreshRate right) => left.Equals(right);
808

809
    public static bool operator !=(RefreshRate left, RefreshRate right) => !(left == right);
810

811
    #endregion
812
}
813

814
public readonly struct Resolution : IDisplayName, IEquatable<Resolution>, IComparable<Resolution>
815
{
816
    [JsonProperty]
817
    private int Width { get; }
818

819
    [JsonProperty]
820
    private int Height { get; }
821

822
    [JsonIgnore]
823
    public string DisplayName => $"{Width} × {Height}";
824

825
    [JsonConstructor]
826
    public Resolution(int width, int height)
827
    {
828
        Width = width;
829
        Height = height;
830
    }
831

832
    public Resolution(Size size) : this(size.Width, size.Height) { }
833

834
    public override string ToString() => $"{Width}x{Height}";
835

836
    public int CompareTo(Resolution other)
837
    {
838
        var widthComparison = Width.CompareTo(other.Width);
839
        return widthComparison != 0
840
            ? widthComparison
841
            : Height.CompareTo(other.Height);
842
    }
843

844
    #region Conversion
845

846
    public static explicit operator Resolution(Size value) => new(value);
847

848
    public static implicit operator Size(Resolution data) => new(data.Width, data.Height);
849

850
    #endregion
851

852
    #region Equality
853

854
    public override bool Equals(object? obj) => obj is Resolution other && Equals(other);
855

856
    public bool Equals(Resolution other) => Width == other.Width && Height == other.Height;
857

858
    public override int GetHashCode() => HashCode.Combine(Width, Height);
859

860
    public static bool operator ==(Resolution left, Resolution right) => left.Equals(right);
861

862
    public static bool operator !=(Resolution left, Resolution right) => !(left == right);
863

864
    #endregion
865

866
}
867

868
public readonly struct SpectrumKeyboardBacklightEffect
869
{
870
    public SpectrumKeyboardBacklightEffectType Type { get; }
871
    public SpectrumKeyboardBacklightSpeed Speed { get; }
872
    public SpectrumKeyboardBacklightDirection Direction { get; }
873
    public SpectrumKeyboardBacklightClockwiseDirection ClockwiseDirection { get; }
874
    public RGBColor[] Colors { get; }
875
    public ushort[] Keys { get; }
876

877
    public SpectrumKeyboardBacklightEffect(SpectrumKeyboardBacklightEffectType type,
878
        SpectrumKeyboardBacklightSpeed speed,
879
        SpectrumKeyboardBacklightDirection direction,
880
        SpectrumKeyboardBacklightClockwiseDirection clockwiseDirection,
881
        RGBColor[] colors,
882
        ushort[] keys)
883
    {
884
        Type = type;
885
        Speed = speed;
886
        Direction = direction;
887
        ClockwiseDirection = clockwiseDirection;
888
        Colors = colors;
889
        Keys = type.IsAllLightsEffect() ? Array.Empty<ushort>() : keys;
890
    }
891
}
892

893
public readonly struct StepperValue
894
{
895
    public int Value { get; }
896
    public int Min { get; }
897
    public int Max { get; }
898
    public int Step { get; }
899
    public int[] Steps { get; }
900
    public int? DefaultValue { get; }
901

902
    public StepperValue(int value, int min, int max, int step, int[] steps, int? defaultValue)
903
    {
904
        Value = value;
905
        Min = min;
906
        Max = max;
907
        Step = step;
908
        Steps = steps;
909
        DefaultValue = defaultValue;
910
    }
911

912
    public StepperValue WithValue(int value) => new(value, Min, Max, Step, Steps, DefaultValue);
913

914
    public override string ToString() =>
915
        $"{nameof(Value)}: {Value}," +
916
        $" {nameof(Min)}: {Min}," +
917
        $" {nameof(Max)}: {Max}," +
918
        $" {nameof(Step)}: {Step}," +
919
        $" {nameof(Steps)}: [{string.Join(", ", Steps)}]," +
920
        $" {nameof(DefaultValue)} : {DefaultValue}";
921
}
922

923
public readonly struct Time
924
{
925
    public int Hour { get; init; }
926
    public int Minute { get; init; }
927

928
    #region Equality
929

930
    public override bool Equals(object? obj) => obj is Time time && Hour == time.Hour && Minute == time.Minute;
931

932
    public override int GetHashCode() => HashCode.Combine(Hour, Minute);
933

934
    public static bool operator ==(Time left, Time right) => left.Equals(right);
935

936
    public static bool operator !=(Time left, Time right) => !(left == right);
937

938
    #endregion
939
}
940

941
public readonly struct Update
942
{
943
    public Version Version { get; }
944
    public string Title { get; }
945
    public string Description { get; }
946
    public DateTimeOffset Date { get; }
947
    public string? Url { get; }
948

949
    public Update(Release release)
950
    {
951
        Version = Version.Parse(release.TagName);
952
        Title = release.Name;
953
        Description = release.Body;
954
        Date = release.PublishedAt ?? release.CreatedAt;
955
        Url = release.Assets.Where(ra => ra.Name.EndsWith("setup.exe", StringComparison.InvariantCultureIgnoreCase)).Select(ra => ra.BrowserDownloadUrl).FirstOrDefault();
956
    }
957
}
958

959
public readonly struct WarrantyInfo
960
{
961
    public DateTime? Start { get; init; }
962
    public DateTime? End { get; init; }
963
    public Uri? Link { get; init; }
964
}
965

966
public readonly struct WindowSize
967
{
968
    public double Width { get; }
969
    public double Height { get; }
970

971
    public WindowSize(double width, double height)
972
    {
973
        Width = width;
974
        Height = height;
975
    }
976
}
977

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

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

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

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