-
Notifications
You must be signed in to change notification settings - Fork 1
/
WoWStarterConfig.cs
108 lines (98 loc) · 3.02 KB
/
WoWStarterConfig.cs
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.IO;
using System.Text.Json;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WoWStarter
{
public enum MultiBoxLayouts
{
BottomRow,
BottomAndRight,
BottomDoubleRow,
PIPVertical,
//PIPHorizontal,
CustomConfig,
}
public struct Rectangle
{
public int Left, Top, Width, Height;
public Rectangle(int left, int top, int width, int height) { Left = left; Top = top; Width = width; Height = height; }
}
public class WoWStarterConfig
{
public int boxCount = 5;
public int maxBoxCount = 10;
public MultiBoxLayouts layout = MultiBoxLayouts.BottomRow;
public bool borderless = true;
public bool alwaysOnTop = false;
private String installPath = null;
public String[] installPaths = null;
public bool mouseFocusTracking = false;
public bool taskbarAutohide = false;
public bool maximizeHotkey = true;
public bool subtractTaskbarHeight = false;
public bool closeWoWWithApp = false;
public String maximizeHotkeyString = "Control-Tab";
public String unsecureClipboardString;
public Rectangle PIPPosition = new Rectangle(800, 800, 240, 135);
public Rectangle[] customLayout;
public const String configFileName = "WoWStarter.json";
public static WoWStarterConfig load()
{
WoWStarterConfig config;
try
{
JsonSerializerOptions options = new JsonSerializerOptions();
options.IncludeFields = true;
String jsonString = File.ReadAllText(configFileName);
config = JsonSerializer.Deserialize<WoWStarterConfig>(jsonString, options);
}
catch (FileNotFoundException)
{
// ignore
config = new WoWStarterConfig();
}
catch (Exception e)
{
MessageBox.Show("Error while reading config file, try fixing errors or deleting it: " + configFileName + e.ToString());
return null;
}
// initialize empty config
if (config.installPaths == null)
{
if (config.installPath != null)
config.installPaths = new String[] { config.installPath };
else
{
String wowInstall = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Blizzard Entertainment\World of Warcraft", "InstallPath", null).ToString();
config.installPaths = new String[] { wowInstall };
}
}
config.installPath = null;
if (config.customLayout == null)
{
config.customLayout = new Rectangle[5];
config.customLayout[0] = new Rectangle(0, 0, 1920, 1080);
for (int i = 1; i < config.customLayout.Length; i++)
config.customLayout[i] = new Rectangle(i * 320, 0, 320, 180);
}
return config;
}
public void save()
{
try
{
JsonSerializerOptions options = new JsonSerializerOptions();
options.IncludeFields = true;
options.WriteIndented = true;
String jsonString = JsonSerializer.Serialize(this, options);
File.WriteAllText(configFileName, jsonString);
}
catch (Exception e)
{
MessageBox.Show("Error while writing config file: " + configFileName + e.ToString());
}
}
}
}