-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
106 lines (94 loc) · 3.93 KB
/
MainForm.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
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace OEMConfigurator {
public partial class MainForm : Form {
private Configurator cnf = new Configurator();
private string imgPath = null;
private string tmpFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\KyngoOEMConfigurator";
private string oemLogoPath = Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\System32\oem.bmp";
public MainForm() {
InitializeComponent();
this.buildContents();
}
private void buildContents() {
this.txtManufacturer.Text = cnf.GetOEMRecord("Manufacturer");
this.txtModel.Text = cnf.GetOEMRecord("Model");
this.txtSupportHours.Text = cnf.GetOEMRecord("SupportHours");
this.txtSupportPhone.Text = cnf.GetOEMRecord("SupportPhone");
this.txtSupportURL.Text = cnf.GetOEMRecord("SupportURL");
string regLogoPath = cnf.GetOEMRecord("Logo");
if (regLogoPath != "") {
try {
if (Directory.Exists(this.tmpFolder) == true) {
Directory.Delete(this.tmpFolder, true);
}
Directory.CreateDirectory(this.tmpFolder);
if (File.Exists(oemLogoPath) == true) {
File.Copy(oemLogoPath, tmpFolder + @"\oem.bmp");
}
} catch (Exception) {
MessageBox.Show("An error occurred when reading the current OEM logo!", "Load error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
if (regLogoPath != null && regLogoPath != "") {
this.loadImage(tmpFolder + @"\oem.bmp", true);
}
}
}
private void loadImage(string imgPath, bool isFromRegistry) {
if (File.Exists(imgPath) == true) {
Bitmap bmp = new Bitmap(imgPath);
imgLogo.Image = bmp;
btnClearLogo.Enabled = true;
this.imgPath = ofdImageSelector.FileName;
} else {
if (isFromRegistry == true) {
MessageBox.Show("The specified image does not exist!\n\n" + imgPath, "Image error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} else {
MessageBox.Show("The image found in the registry does not exist!", "Image error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
private void clickBtnChangeImage(object sender, EventArgs e) {
if (ofdImageSelector.ShowDialog() == DialogResult.OK) {
this.loadImage(ofdImageSelector.FileName, false);
}
}
private void clickBtnClearImage(object sender, EventArgs e) {
imgLogo.Image = null;
imgPath = null;
btnClearLogo.Enabled = false;
}
private void clickBtnApplyChanges(object sender, EventArgs e) {
bool copyImage = false;
if (this.imgPath != null) {
try {
if (File.Exists(oemLogoPath)) {
File.Delete(oemLogoPath);
}
File.Copy(imgPath, oemLogoPath);
copyImage = true;
} catch (Exception) {
MessageBox.Show("The logo could not be copied to a secure directory!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
copyImage = false;
}
}
cnf.ChangeOEMRecord("Manufacturer", this.txtManufacturer.Text);
cnf.ChangeOEMRecord("Model", this.txtModel.Text);
cnf.ChangeOEMRecord("SupportHours", this.txtSupportHours.Text);
cnf.ChangeOEMRecord("SupportPhone", this.txtSupportPhone.Text);
cnf.ChangeOEMRecord("SupportURL", this.txtSupportURL.Text);
if (copyImage == true) {
cnf.ChangeOEMRecord("Logo", oemLogoPath);
} else {
cnf.RemoveOEMRecord("Logo");
}
MessageBox.Show("The new settings have been applied!", "OEM Records applied", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void clickBtnAbout(object sender, EventArgs e) {
MessageBox.Show("OEMConfigurator\n\nSimple tool to edit the OEM registry entries regarding your computer's brand and OEM specs.\n\nCreated by Kyngo\n\nhttps://github.com/Kyngo/OEMConfigurator", "OEMConfigurator", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}