-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainForm.cs
More file actions
82 lines (72 loc) · 2.74 KB
/
Copy pathMainForm.cs
File metadata and controls
82 lines (72 loc) · 2.74 KB
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
using MetroFramework.Forms;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows.Forms;
namespace Minecraft_Wii_U_Mod_Injector_Updater
{
public partial class MainForm : MetroForm
{
public MainForm()
{
InitializeComponent();
}
public static string DownloadUrl;
public string TempPath = $@"{Application.StartupPath}\Minecraft.Wii.U.Mod.Injector.Temp.exe";
public string TargetPath = $@"{Application.StartupPath}\Minecraft.Wii.U.Mod.Injector.exe";
private void StartDownloading(object sender, EventArgs e)
{
autoStart.Checked = Properties.Settings.Default.AutoStart;
var webClient = new WebClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
webClient.DownloadProgressChanged += DownloadProgress;
webClient.DownloadFileCompleted += Completed;
webClient.DownloadFileAsync(new Uri(DownloadUrl), TempPath);
}
private void DownloadProgress(object sender, DownloadProgressChangedEventArgs e)
{
statusLabel.Text = string.Format("Downloading... [ {0}/{1} MB ]", (e.BytesReceived / 1024.0 / 1024.0).ToString("0.00"), (e.TotalBytesToReceive / 1024.0 / 1024.0).ToString("0.00"));
progressBar.Value = e.ProgressPercentage;
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
{
Console.WriteLine("Mod Injector download aborted");
} else
{
if (File.Exists(TargetPath))
{
File.Delete(TargetPath);
}
File.Move(TempPath, TargetPath);
Console.WriteLine("Mod Injector download complete");
}
statusLabel.Text = "Finished!";
if (autoStart.Checked)
{
Process.Start(TargetPath);
Environment.Exit(0);
} else
{
startButton.Enabled = true;
}
}
private void ChangeAutoStart(object sender, EventArgs e)
{
if (autoStart.Checked)
{
MessageBox.Show("The Mod Injector will now automatically start the next time the updater is run.", "AutoStart", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Properties.Settings.Default.AutoStart = autoStart.Checked;
Properties.Settings.Default.Save();
}
private void Launch(object sender, EventArgs e)
{
Process.Start(TargetPath);
Environment.Exit(0);
}
}
}