-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathUpdateForm.cs
59 lines (52 loc) · 1.77 KB
/
UpdateForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace Noxico
{
public partial class UpdateForm : Form
{
private bool didFirstFile;
private string server = "http://helmet.kafuka.org/noxico/files/";
private WebClient wc = new WebClient();
public UpdateForm()
{
InitializeComponent();
Refresh();
Show();
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
label1.Text = "Downloading executable...";
wc.DownloadFileAsync(new Uri(server + "Noxico.exe"), "Noxico._xe");
}
void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (!didFirstFile)
{
didFirstFile = true;
label1.Text = "Downloading data file...";
wc.DownloadFileAsync(new Uri(server + "Noxico.nox"), "Noxico._ox");
}
else
{
File.WriteAllText("update.bat", "del Noxico.exe" + Environment.NewLine + "del Noxico.nox" + Environment.NewLine + "ren Noxico._xe Noxico.exe" + Environment.NewLine + "ren Noxico._ix Noxico.nox" + Environment.NewLine + "start Noxico.exe" + Environment.NewLine + "del update.bat");
System.Diagnostics.Process.Start("update.bat");
Application.Exit();
}
}
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
label2.Text = string.Format("{0} of {1}", e.BytesReceived, e.TotalBytesToReceive);
progressBar1.Value = e.ProgressPercentage;
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}