-
Notifications
You must be signed in to change notification settings - Fork 0
/
WoWCyclotronConfig.cs
131 lines (118 loc) · 3.51 KB
/
WoWCyclotronConfig.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.IO;
using System.Text.Json;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WoWCyclotron
{
public enum MultiBoxLayouts
{
SingleRow,
LShape,
DoubleRow,
PictureInPicture,
CustomConfig,
SingleRowFill,
}
public enum MultiBoxOrientation
{
Horizontal,
Vertical,
Both,
}
public enum MultiBoxMainWindow
{
TopLeft,
BottomLeft,
}
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 bool isInside(int x, int y)
{
return x >= Left && y >= Top && x < (Left + Width) && y < (Top + Height);
}
}
public class WoWCyclotronConfig
{
public int boxCount = 5;
public int maxBoxCount = 10;
public MultiBoxLayouts layout = MultiBoxLayouts.SingleRow;
public MultiBoxMainWindow layoutMain = MultiBoxMainWindow.TopLeft;
public MultiBoxOrientation layoutOrientation = MultiBoxOrientation.Horizontal;
public bool borderless = true;
public bool alwaysOnTop = false;
private String installPath = null;
public String[] installPaths = null;
public bool mouseFocusTracking = true;
public bool taskbarAutohide = false;
public bool subtractTaskbarHeight = false;
public bool closeWoWWithApp = false;
public bool taskbarAutohideFalseOnClose = true;
public String swapWindowHotkey = "Control-Tab";
public String cycleFocusHotkeys = "D1, D2, D3, D4, D5, Oem102, Y, X, C, V";
public int focusSnapbackDelay = 350;
public String unsecureClipboardString;
public Rectangle PIPPosition = new Rectangle(800, 800, 240, 135);
public Rectangle[] customLayout;
public Rectangle previousAppPosition = new Rectangle();
public const String configFileName = "WoWCyclotron.json";
public static WoWCyclotronConfig load()
{
WoWCyclotronConfig config;
try
{
JsonSerializerOptions options = new JsonSerializerOptions();
options.IncludeFields = true;
String jsonString = File.ReadAllText(configFileName);
config = JsonSerializer.Deserialize<WoWCyclotronConfig>(jsonString, options);
}
catch (FileNotFoundException)
{
// ignore if not found
config = new WoWCyclotronConfig();
}
catch (Exception e)
{
MessageBox.Show("Error while reading config file \"" + configFileName + "\", try fixing errors or deleting it. Error: " + e.Message);
throw;
}
// 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());
}
}
}
}