-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetupForm.cs
68 lines (57 loc) · 2.64 KB
/
SetupForm.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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace CtrlVolume
{
public partial class SetupForm : Form
{
public SetupForm(List <string>SecondaryDevices)
{
InitializeComponent(); //initialize the form
foreach (var Device in SecondaryDevices)
{
deviceDropdown.Items.Add(Device);
}
}
private void SetupFormValidate(object sender, EventArgs e)
{
if(deviceDropdown.SelectedIndex != -1)
{
//device actually selected and ready to be saved
deviceDropDownSave.Enabled = true;
}
}
private void SetupFormSaveDevice(object sender, MouseEventArgs e)
{
Console.WriteLine("Saving");
Console.WriteLine(deviceDropdown.SelectedItem);
var GenericOps = new Generic();
var FileOps = new FileOperations();
Settings settings = new Settings
{
CtrlFriendlyName = deviceDropdown.SelectedItem.ToString()
};
GenericOps.SettingsPath(out string DefaultSettingsPath); //get path for settings file
FileOps.WriteFile(DefaultSettingsPath, settings); //Write to settings file
//Check if there is any data in the file
if (!FileOps.CheckFile(DefaultSettingsPath))
{
//file does not exist
Globals.FailedSetup = true;
errorMessage.Text = "Error: Failed to write to the config file '" + DefaultSettingsPath + "' at the same location as this executable!.\nThe setup cannot continue!\n Setup will start every time if it cannot access the setting file";
}
var WrittenContents = FileOps.ReadFile<Settings>(DefaultSettingsPath);
if (WrittenContents.CtrlFriendlyName == "" || WrittenContents.CtrlFriendlyName == " ")
{
//contents do not exist
Globals.FailedSetup = true;
errorMessage.Text = "Error: Successfully wrote the config file, but contents seem empty!\nThe setup cannot continue! \nVerify that the program has the necesary permissions to run and access the file '" + DefaultSettingsPath + "' in the same location as this executable. \nSetup will start every time if it cannot access the setting file";
}
if (!Globals.FailedSetup)
{
Globals.NeedsSetup = false; //mark setup done so monitor could start
Close(); //close if there are no problems
}
}
}
}