summaryrefslogtreecommitdiff
path: root/grapher/Models/Serialized/GUISettings.cs
blob: b7fe4de411479cb413be767a3661a97d9df9e19d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace grapher.Models.Serialized
{
    [Serializable]
    public class GUISettings
    {
        #region Constructors

        public GUISettings() {}

        #endregion Constructors

        #region Properties


        public int DPI { get; set; }

        public int PollRate { get; set; }

        public bool ShowLastMouseMove { get; set; }

        public bool ShowVelocityAndGain { get; set; }

        public bool AutoWriteToDriverOnStartup { get; set; }

        public bool StreamingMode { get; set; }

        #endregion Properties

        #region Methods

        public override bool Equals(object obj)
        {
            if (obj is not GUISettings other)
            {
                return false;
            }

            return Equals(other);
        }

        public bool Equals(GUISettings other)
        {
            return DPI == other.DPI &&
                PollRate == other.PollRate &&
                ShowLastMouseMove == other.ShowLastMouseMove &&
                ShowVelocityAndGain == other.ShowVelocityAndGain &&
                AutoWriteToDriverOnStartup == other.AutoWriteToDriverOnStartup &&
                StreamingMode == other.StreamingMode;
        }

        public override int GetHashCode()
        {
            return DPI.GetHashCode() ^
                PollRate.GetHashCode() ^
                ShowLastMouseMove.GetHashCode() ^
                ShowVelocityAndGain.GetHashCode() ^
                AutoWriteToDriverOnStartup.GetHashCode() ^
                StreamingMode.GetHashCode();
        }

        public void Save()
        {
            File.WriteAllText(Constants.GuiConfigFileName, JsonSerializer.Serialize(this));
        }

        public static GUISettings MaybeLoad()
        {
            GUISettings settings = null;

            try
            {
                settings = JsonSerializer.Deserialize<GUISettings>(
                    File.ReadAllText(Constants.GuiConfigFileName));
            }
            catch (Exception ex)
            {
                if (!(ex is JsonException || ex is FileNotFoundException))
                {
                    throw;
                }
            }

            return settings;
        }

        #endregion Methods

    }
}