-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathFormOptions.cs
112 lines (101 loc) · 3.75 KB
/
FormOptions.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
using Microsoft.Win32;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace Coffeed
{
public partial class FormOptions : Form
{
IniFile Settings = new IniFile(Path.Combine(Application.StartupPath, "coffeed.conf"));
public FormOptions()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
System.IO.File.WriteAllText(Path.Combine(Application.StartupPath, "coffeed.conf"), "");
Settings.Write("putty_path", puttypath.Text);
Settings.Write("startup", checkBox1.Checked.ToString());
if (System.IO.File.Exists(Path.Combine(Application.StartupPath, "coffeed.conf")))
{
var startup = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
if (Settings.Read("startup").ToLowerInvariant() == "true")
{
startup.SetValue("Coffeed", Path.Combine(Application.StartupPath, AppDomain.CurrentDomain.FriendlyName));
}
else if (Settings.Read("startup").ToLowerInvariant() == "false")
{
startup.DeleteValue("Coffeed", false);
}
}
}
catch (Exception err)
{
Logging.M(err.Message, "Oops, there's an error that needs special attetion.");
Logging.LogError(err);
}
this.Close();
}
private void FormOptions_Load(object sender, EventArgs e)
{
DetectNecessaryApps();
if (System.IO.File.Exists(Path.Combine(Application.StartupPath,"coffeed.conf")))
{
puttypath.Text = Settings.Read("putty_path");
checkBox1.Checked = Convert.ToBoolean(Settings.Read("startup"));
}
}
private void DetectNecessaryApps()
{
if (!string.IsNullOrEmpty(Program.PuttyDetector()))
{
btnInstallPutty.Enabled = false;
btnInstallPutty.Text = "Installed";
btnInstallPutty.BackColor = Color.LimeGreen;
}
else
{
btnInstallPutty.Enabled = true;
btnInstallPutty.BackColor = Color.Tomato;
btnInstallPutty.Text = "Install";
}
if (!string.IsNullOrEmpty(Program.FileZillaDetector()))
{
btnInstallFileZilla.BackColor = Color.LimeGreen;
btnInstallFileZilla.Enabled = false;
btnInstallFileZilla.Text = "Installed";
}
else
{
btnInstallFileZilla.Enabled = true;
btnInstallFileZilla.BackColor = Color.Tomato;
btnInstallFileZilla.Text = "Install";
}
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog putty = new OpenFileDialog();
putty.Filter = "Executable Putty|*.exe";
putty.DefaultExt = "exe";
putty.FileName = "Putty.exe";
putty.Title = "Browse Putty Path";
if (putty.ShowDialog() == DialogResult.OK)
{
puttypath.Text = putty.FileName;
}
}
private void btnInstallFileZilla_Click(object sender, EventArgs e)
{
Program.InstallFileZilla();
DetectNecessaryApps();
}
private void btnInstallPutty_Click(object sender, EventArgs e)
{
Program.InstallPutty();
DetectNecessaryApps();
}
}
}