-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmSettings.cs
128 lines (110 loc) · 4.33 KB
/
frmSettings.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
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.Win32;
namespace _4chget
{
public partial class frmSettings : Form
{
Settings sett;
Language la;
bool optinstall;
public frmSettings()
{
InitializeComponent();
}
public void Init()
{
XmlSerializer xs = new XmlSerializer(typeof(Settings));
FileStream fs = new FileStream("settings.xml", FileMode.Open, FileAccess.Read);
sett = (Settings)xs.Deserialize(fs);
fs.Close();
txtSavePath.Text = sett.SavePath;
cbSaveOP.Checked = sett.SaveOP;
la = LanguageManager.LoadLanguage(sett.Language);
btnDiscard.Text = la.Discard;
btnSave.Text = la.Save;
cbSaveOP.Text = la.SaveOP;
label1.Text = la.SavePath;
btnHelp.Text = la.Help;
label2.Text = la._Language;
btnOSL.Text = la.OpenSourceLicenses;
if (File.Exists("urlhdlinst"))
{
btnInstallURLHandler.Text = la.UninstallURLHandler;
optinstall = false;
} else
{
btnInstallURLHandler.Text = la.InstallURLHandler;
optinstall = true;
}
Regex regex = new Regex(@"[a-zA-Z0-9\.]*\.lang");
cobLanguage.Text = sett.Language;
foreach (string s in Directory.GetFiles(Environment.CurrentDirectory))
{
if (regex.IsMatch(s))
{
cobLanguage.Items.Add(Path.GetFileName(s));
}
}
}
private void btnDiscard_Click(object sender, EventArgs e)
{
Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
Settings news = new Settings();
news.SaveOP = cbSaveOP.Checked;
news.SavePath = txtSavePath.Text;
news.Language = cobLanguage.Text;
File.Delete("settings.xml");
FileStream fs = new FileStream("settings.xml", FileMode.Create, FileAccess.Write);
XmlSerializer xs = new XmlSerializer(typeof(Settings));
xs.Serialize(fs, news);
fs.Close();
}
private void btnHelp_Click(object sender, EventArgs e)
{
Process.Start(Environment.CurrentDirectory + "\\hlp\\index.html");
}
private void btnCreateTemplate_Click(object sender, EventArgs e)
{
Settings news = new Settings();
news.SaveOP = cbSaveOP.Checked;
news.SavePath = txtSavePath.Text;
FileStream fs = new FileStream("settings.xml", FileMode.OpenOrCreate, FileAccess.Write);
XmlSerializer xs = new XmlSerializer(typeof(Settings));
xs.Serialize(fs, news);
fs.Close();
}
private void btnOSL_Click(object sender, EventArgs e)
{
frmOSL osl = new frmOSL(la);
osl.ShowDialog();
osl.Dispose();
}
private void btnInstallURLHandler_Click(object sender, EventArgs e)
{
if (optinstall)
{
RegistryKey Key = Registry.ClassesRoot.CreateSubKey("4chget");
Key.CreateSubKey("DefaultIcon").SetValue("", "4chget.exe,1");
Key.SetValue("", "4chget:Protocol");
Key.SetValue("URL Protocol", "");
string apppath = Application.ExecutablePath;
Key.CreateSubKey(@"shell\open\command").SetValue("", apppath + " \"%1\"");
File.WriteAllText("urlhdlinst", "1");
MessageBox.Show("Installed URL protocol handler for 4chget!", "4chget", MessageBoxButtons.OK, MessageBoxIcon.Information);
} else
{
Registry.ClassesRoot.DeleteSubKeyTree("4chget");
File.Delete("urlhdlinst");
MessageBox.Show("Uninstalled URL protocol handler for 4chget!", "4chget", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}