This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFrmUpdate.cs
64 lines (58 loc) · 2.21 KB
/
FrmUpdate.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MythicalLauncher
{
public partial class FrmUpdate : Form
{
string appPath = Application.StartupPath + "\\example3.rar";
public FrmUpdate()
{
InitializeComponent();
}
private void ProgressChanged(object sneder, DownloadProgressChangedEventArgs e) {
progressBar1.Value = e.ProgressPercentage;
label2.Text = "Downloading... " + BytesToString(e.BytesReceived) + " / " + BytesToString(e.TotalBytesToReceive);
}
private void Completed(object sender, AsyncCompletedEventArgs e) {
label2.Text = "Done!";
DialogResult dr = MessageBox.Show("Do you want to install","Done",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
try {
if(dr == DialogResult.Yes){
System.Diagnostics.Process.Start(appPath);
Application.Exit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Stop();
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://localhost/can/example3.rar"),appPath);
}
private static string BytesToString(long byteCount)
{
string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
long bytes = Math.Abs(byteCount);
int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
double num = Math.Round(bytes / Math.Pow(1024, place),1);
return (Math.Sign(bytes) * num).ToString() + suf[place];
}
private void Form2_Load(object sender, EventArgs e)
{
}
}
}