forked from zajrik/rift-timer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cs
132 lines (108 loc) · 4.34 KB
/
Settings.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
132
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace RiftTimer
{
public partial class Settings : Form
{
public Settings()
{
InitializeComponent();
// Create necessary directories if they don't already exist
if (!Directory.Exists("logs")) Directory.CreateDirectory("logs");
if (!Directory.Exists("temp")) Directory.CreateDirectory("temp");
LoadConfig();
// Load checkbox state for userTopMost pref
onTopCheckBox.CheckState = Properties.Settings.Default.userTopMost
? CheckState.Checked
: CheckState.Unchecked;
// Dismiss the settings window unless the user has oppened it manually
if (Properties.Settings.Default.settingsChosen)
Accept_Click(this, new EventArgs());
}
// Load from and save config to file, allows keeping settings between updates
private void LoadConfig()
{
if (!File.Exists(Environment.CurrentDirectory + @"\temp\RiftTimer.config"))
{
File.Create(@"temp\RiftTimer.config");
}
else
{
string[] configBuffer = File.ReadAllLines(@"temp\RiftTimer.config");
string[] configLineBuffer;
foreach (string line in configBuffer)
{
configLineBuffer = line.Split(':');
config.Add(configLineBuffer[0], configLineBuffer[1]);
}
Properties.Settings.Default.playerClass = Int32.Parse(config["playerClass"]);
Properties.Settings.Default.difficulty = Int32.Parse(config["difficulty"]);
Properties.Settings.Default.posX = Int32.Parse(config["posX"]);
Properties.Settings.Default.posY = Int32.Parse(config["posY"]);
Properties.Settings.Default.settingsChosen = Boolean.Parse(config["settingsChosen"]);
Properties.Settings.Default.userTopMost = Boolean.Parse(config["userTopMost"]);
Properties.Settings.Default.Save();
}
}
private void SaveConfig()
{
string[] configBuffer = new string[]
{
$"playerClass:{Properties.Settings.Default.playerClass}",
$"difficulty:{Properties.Settings.Default.difficulty}",
$"posX:{Properties.Settings.Default.posX}",
$"posY:{Properties.Settings.Default.posY}",
$"settingsChosen:{Properties.Settings.Default.settingsChosen}",
$"userTopMost:{Properties.Settings.Default.userTopMost}"
};
File.WriteAllLines(@"temp\RiftTimer.config", configBuffer);
}
// Center within default location of Rift Timer window
private void Settings_Shown(object sender, EventArgs e)
{
int posX = Properties.Settings.Default.posX;
int posY = Properties.Settings.Default.posY;
// (490, 321) is the base Size of the Rift Timer window
int locX = (posX + ((490 - this.Width) / 2));
int locY = (posY + ((321 - this.Height) / 2));
this.Location = new Point(locX, locY);
}
private Dictionary<string, string> config = new Dictionary<string, string>();
private List<string> timesList = new List<string>();
private bool isSessionLogged = false;
private string logFileName = "";
// Save settings and launch the chosen themed Rift Timer
private void Accept_Click(object sender, EventArgs e)
{
// Save selected options
Properties.Settings.Default.userTopMost = onTopCheckBox.CheckState == CheckState.Checked;
Properties.Settings.Default.settingsChosen = true;
Properties.Settings.Default.Save();
Theme.Default.RiftTimer riftTimer = new Theme.Default.RiftTimer(
timesList,
isSessionLogged,
logFileName
);
this.Hide();
riftTimer.ShowDialog();
if (riftTimer.DialogResult == DialogResult.OK)
{
this.Show();
Settings_Shown(this, e);
timesList = riftTimer.riftsList;
isSessionLogged = riftTimer.isSessionLogged;
logFileName = riftTimer.logFileName;
}
else if (riftTimer.DialogResult == DialogResult.Cancel)
{
SaveConfig();
Close();
}
}
}
}