forked from MarkusMaal/BlueScreenSimulatorPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateInterface.cs
253 lines (234 loc) · 9.61 KB
/
UpdateInterface.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Cryptography;
namespace UltimateBlueScreenSimulator
{
public partial class UpdateInterface : Form
{
public bool finalize = false;
WebClient webClient; // Our WebClient that will be doing the downloading for us
readonly Stopwatch sw = new Stopwatch(); // The stopwatch which we will be using to calculate the download speed
string GoodHash = "6ABA5BC55589EE8D64E30B36596E5517";
public UpdateInterface()
{
InitializeComponent();
}
private void UpdateInterface_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
if (Launchstatus.Image == Properties.Resources.current)
{
e.Cancel = false;
}
if (finalize)
{
e.Cancel = false;
}
}
public void DownloadFile(string urlAddress, string location)
{
try
{
using (webClient = new WebClient())
{
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
// The variable that will be holding the url address (making sure it starts with http://)
Uri URL = urlAddress.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ? new Uri(urlAddress) : new Uri("http://" + urlAddress);
// Start the stopwatch which we will be using to calculate the download speed
sw.Start();
try
{
// Start downloading the file
webClient.DownloadFileAsync(URL, location);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
if (location.EndsWith(".txt"))
{
File.SetAttributes(location, FileAttributes.Hidden);
}
} catch (Exception ex)
{
if (Program.f1.enableeggs)
{
Metaerror me = new Metaerror
{
message = ex.Message,
stack_trace = ex.StackTrace,
type = "VioletScreen"
};
switch (me.ShowDialog())
{
case DialogResult.Abort:
Application.Exit();
return;
case DialogResult.Retry:
DownloadFile(urlAddress, location);
return;
case DialogResult.Ignore:
break;
}
} else
{
MessageBox.Show("An error has occoured.\n\n" + ex.Message + "\n\n" + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
// The event that will fire whenever the progress of the WebClient is changed
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
// Calculate download speed and output it to labelSpeed.
dloadState.Text = string.Format("{0} KB downloaded (Transfer rate: {1} kb/s)", (e.BytesReceived / 1024d).ToString("0.00"), (e.BytesReceived / 1024d / sw.Elapsed.TotalSeconds).ToString("0.00"));
// Update the progressbar percentage only when the value is not the same.
updateProgress.Value = e.ProgressPercentage;
}
// The event that will trigger when the WebClient is completed
private void Completed(object sender, AsyncCompletedEventArgs e)
{
// Reset the stopwatch.
sw.Reset();
if (e.Cancelled == true)
{
SetStatus(DownloadStatus, "Failure");
}
else
{
if (this.Visible)
{
dloadState.Visible = false;
SetStatus(DownloadStatus, "Success");
if (Program.f1.hashverify == true)
{
SetStatus(HashStatus, "Processing");
hashWait.Enabled = true;
}
else if (Program.f1.hashverify == false)
{
SetStatus(HashStatus, "Success");
SetStatus(Launchstatus, "Processing");
installWait.Enabled = true;
}
}
}
}
private void UpdateInterface_Load(object sender, EventArgs e)
{
if (Program.f1.hashverify == false) { hashCheckLabel.Text = "Hashchecking (will be skipped)"; }
GoodHash = File.ReadAllText("hash.txt").Trim();
if (!finalize)
{
SetStatus(DownloadStatus, "Processing");
SetStatus(HashStatus, "Pending");
SetStatus(Launchstatus, "Pending");
SetStatus(TempStatus, "Pending");
DownloadFile(Program.update_server + "/BSSP_latest.zim", "BSSP.exe");
}
if (finalize)
{
SetStatus(DownloadStatus, "Success");
SetStatus(HashStatus, "Success");
SetStatus(Launchstatus, "Success");
SetStatus(TempStatus, "Processing");
updateProgress.Visible = false;
dloadState.Visible = false;
cleanWait.Enabled = true;
}
}
void SetStatus(PictureBox pb, string status)
{
if (status == "Success")
{
pb.Image = Properties.Resources.success;
}
if (status == "Fail")
{
pb.Image = Properties.Resources.failure;
}
if (status == "Pending")
{
pb.Image = Properties.Resources.pending;
}
if (status == "Processing")
{
pb.Image = Properties.Resources.current;
}
}
private void HashWait_Tick(object sender, EventArgs e)
{
updateProgress.Visible = false;
hashWait.Enabled = false;
MD5 d5 = MD5.Create();
Byte[] hash = d5.ComputeHash(File.ReadAllBytes("BSSP.exe"));
string comparate = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
if (comparate.ToUpper() == GoodHash)
{
SetStatus(HashStatus, "Success");
SetStatus(Launchstatus, "Processing");
installWait.Enabled = true;
} else
{
SetStatus(HashStatus, "Fail");
if (MessageBox.Show("Hashcheck failed. Would you like to try again?", "Update unsuccessful", MessageBoxButtons.YesNo, MessageBoxIcon.Error)==DialogResult.Yes)
{
SetStatus(DownloadStatus, "Processing");
SetStatus(HashStatus, "Pending");
SetStatus(Launchstatus, "Pending");
SetStatus(TempStatus, "Pending");
DownloadFile(Program.update_server + "/BSSP_latest.zim", "BSSP.exe");
} else
{
SetStatus(Launchstatus, "Processing");
Program.f1.Show();
this.Hide();
this.Close();
}
}
}
private void InstallWait_Tick(object sender, EventArgs e)
{
installWait.Enabled = false;
File.Copy("BSSP.exe", "BSSP_new.exe");
Process p = new Process();
p.StartInfo.FileName = "BSSP.exe";
p.StartInfo.Arguments = "/finalize_update";
p.Start();
Program.f1.Close();
this.Close();
}
private void CleanWait_Tick(object sender, EventArgs e)
{
cleanWait.Enabled = false;
File.SetAttributes("UltimateBlueScreenSimulator.exe", FileAttributes.Hidden);
File.Delete("UltimateBlueScreenSimulator.exe");
File.Move("BSSP_new.exe", "UltimateBlueScreenSimulator.exe");
System.IO.File.WriteAllText("finish.bat", Properties.Resources.final);
Process p = new Process();
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "finish.bat";
p.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
p.Start();
this.Close();
}
private void BlinkBlink_Tick(object sender, EventArgs e)
{
if (warningLabel.ForeColor == SystemColors.ControlText)
{
warningLabel.ForeColor = Color.Red;
} else
{
warningLabel.ForeColor = SystemColors.ControlText;
}
}
}
}