-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathForm1.cs
140 lines (119 loc) · 4.99 KB
/
Form1.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
using System;
using System.Net;
using System.Windows.Forms;
namespace XeniaUpdater_C
{
/// <summary>
/// Correctly updating Xenia Updater:
/// Firstly, go to Form2.cs and change the buildDate string to the correct build date (Current date and time).
/// Then open the version-{branch}.txt for the branch you are updating, change it to match the build date in Form2.cs (Without the \n).
/// Near the bottom of this file (Form1.cs), change h.UpdateXeniaUpdater("branchHere") to the branch you are updating.
/// Finally, of course, change the build config in VS to build the correct version (Debug or Release).
///
/// If you are not the original developer of this software (Chopper1337), be sure to update the GitHub links associated with the self updater such that
/// updates are pulled from your fork and not from the original repo.
/// </summary>
public partial class Form1 : Form
{
public Form1()
{
//Create form
InitializeComponent();
Helper h = new Helper();
h.StartupTasks();
}
//Takes the parameters needed to update any branch of Xenia given the correct parameters
public void UpdateXenia(string folderName, string url, string zipFullName, string exeName)
{
Helper h = new Helper();
h.CreateFolders(folderName);
h.PreUpdateTask(folderName, zipFullName, exeName);
if (h.InternetAvailable() == true)
{
DownloadFile(url, zipFullName, folderName);
}
else
{
MessageBox.Show("Could not ping AppVeyor. Please check your internet connection.");
}
}
//Start Xenia given a folder and executable name
public void StartXenia(string folderName, string exeName)
{
Helper h = new Helper();
h.StartProcess(exeName, folderName);
}
//Downloads a file from a URL to a path with the file name you specify
public void DownloadFile(string downloadURL, string fileName, string folderName)
{
ToggleButtons(false);
using (WebClient wc = new WebClient())
{
//Download from URL to location
wc.DownloadFileAsync(new Uri(downloadURL), $"{folderName}/{fileName}");
//For each change in progrress, output progress to the wc_DownloadProgressChanged method
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
// For each update in the downloads progress, do this
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
percentageLBL.Text = $"{progressBar1.Value.ToString()}%";
if (progressBar1.Value == 100)
{
wc.Dispose();
ToggleButtons(true);
Helper h = new Helper();
h.ExtractBuild(folderName, fileName);
}
}
wc.Dispose();
}
}
void ToggleButtons(bool enabled)
{
masterUpdateBTN.Enabled = enabled;
masterStartBTN.Enabled = enabled;
canaryUpdateBTN.Enabled = enabled;
canaryStartBTN.Enabled = enabled;
updateBTN.Enabled = enabled;
}
private void button1_Click(object sender, System.EventArgs e)
{
string url = "https://github.com/xenia-project/release-builds-windows/releases/latest/download/xenia_master.zip";
UpdateXenia("XeniaMaster", url, "xenia_master.zip", "xenia.exe");
}
private void button2_Click(object sender, System.EventArgs e)
{
StartXenia("XeniaMaster", "xenia");
}
private void button4_Click(object sender, System.EventArgs e)
{
string url = "https://github.com/xenia-canary/xenia-canary/releases/latest/download/xenia_canary.zip";
UpdateXenia("XeniaCanary", url, "xenia_canary.zip", "xenia_canary.exe");
}
private void button3_Click(object sender, System.EventArgs e)
{
StartXenia("XeniaCanary", "xenia_canary");
}
private void infoBTN_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog();
}
private void updateBTN_Click(object sender, EventArgs e)
{
Helper h = new Helper();
h.UpdateXeniaUpdater("Release");
}
private void button1_Click_2(object sender, EventArgs e)
{
Helper h = new Helper();
h.OpenInstallFolder();
}
private void button2_Click_2(object sender, EventArgs e)
{
Helper h = new Helper();
h.UploadFile("xenia.log");
}
}
}