This repository was archived by the owner on Sep 2, 2025. It is now read-only.
forked from antonpup/Aurora
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·252 lines (223 loc) · 10.3 KB
/
Program.cs
File metadata and controls
executable file
·252 lines (223 loc) · 10.3 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
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
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Principal;
using System.Windows.Forms;
using System.Linq;
using System.Reflection;
using Version = SemVer.Version;
namespace Aurora_Updater
{
/// <summary>
/// The static storage.
/// </summary>
public static class StaticStorage
{
#region Static Fields
/// <summary>
/// The index.
/// </summary>
public static UpdateManager Manager;
#endregion
}
static class Program
{
private static string passedArgs = "";
private static bool isSilent = false;
private static bool isSilentMinor = false;
private static Version versionMajor;
private static Version versionMinor;
public static string exePath = "";
private static UpdateType installType = UpdateType.Undefined;
public static bool isElevated = false;
private static MainForm updateForm;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
foreach (var arg in args)
{
if (String.IsNullOrWhiteSpace(arg))
continue;
if (arg.Equals("-silent"))
isSilent = true;
else if (arg.Equals("-silent_minor"))
isSilentMinor = true;
else if (arg.Equals("-update_major"))
installType = UpdateType.Major;
else if (arg.Equals("-update_minor"))
installType = UpdateType.Minor;
passedArgs += arg + " ";
}
passedArgs.TrimEnd(' ');
exePath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
//Check privilege
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator);
string _maj = "";
string auroraPath;
if (File.Exists(auroraPath = Path.Combine(exePath, "Aurora.exe")))
_maj = FileVersionInfo.GetVersionInfo(auroraPath).FileVersion;
if (String.IsNullOrWhiteSpace(_maj))
{
if (!isSilent)
MessageBox.Show(
"Application launched incorrectly, no version was specified.\r\nPlease use Aurora if you want to check for updates.\r\nOptions -> \"Updates\" \"Check for Updates\"",
"Aurora Updater",
MessageBoxButtons.OK);
return;
}
versionMajor = new Version(_maj.TrimStart('v') + ".0.0", true);
string owner = FileVersionInfo.GetVersionInfo(auroraPath).CompanyName;
string repository = FileVersionInfo.GetVersionInfo(auroraPath).ProductName;
//Initialize UpdateManager
StaticStorage.Manager = new UpdateManager(versionMajor, owner, repository);
//Check if update retrieval was successful.
if (StaticStorage.Manager.updateState == UpdateStatus.Error)
return;
if (installType != UpdateType.Undefined)
{
if (isElevated)
{
updateForm = new MainForm(installType);
updateForm.ShowDialog();
}
else
{
MessageBox.Show(
"Updater was not granted Admin rights.",
"Aurora Updater - Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
else
{
Version latestV = new Version(StaticStorage.Manager.LatestRelease.TagName.TrimStart('v') + ".0.0", true);
if (latestV > versionMajor)
{
UpdateInfoForm userResult = new UpdateInfoForm()
{
changelog = StaticStorage.Manager.LatestRelease.Body,
updateDescription = StaticStorage.Manager.LatestRelease.Name,
updateVersion = latestV.ToString(),
currentVersion = versionMajor.ToString(),
updateSize = StaticStorage.Manager.LatestRelease.Assets.First(s => s.Name.StartsWith("release") || s.Name.StartsWith("Aurora-v")).Size,
preRelease = StaticStorage.Manager.LatestRelease.Prerelease
};
userResult.ShowDialog();
if (userResult.DialogResult == DialogResult.OK)
{
if (isElevated)
{
updateForm = new MainForm(UpdateType.Major);
updateForm.ShowDialog();
}
else
{
//Request user to grant admin rights
try
{
ProcessStartInfo updaterProc = new ProcessStartInfo();
updaterProc.FileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
updaterProc.Arguments = passedArgs + " -update_major";
updaterProc.Verb = "runas";
Process.Start(updaterProc);
return; //Exit, no further action required
}
catch (Exception exc)
{
MessageBox.Show(
$"Could not start Aurora Updater. Error:\r\n{exc}",
"Aurora Updater - Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
else
{
if (!isSilent)
MessageBox.Show(
"You have latest version of Aurora installed.",
"Aurora Updater",
MessageBoxButtons.OK);
}
/*string _min = "";
if (File.Exists(Path.Combine(exePath, "ver_minor.txt")))
_min = File.ReadAllText(Path.Combine(exePath, "ver_minor.txt"));
if (!String.IsNullOrWhiteSpace(_min))
{
versionMinor = new UpdateVersion(_min);
if (!(StaticStorage.Manager.response.Minor.Version <= versionMinor))
{
if (isSilentMinor)
StaticStorage.Manager.RetrieveUpdate(UpdateType.Minor);
else
{
UpdateInfoForm userResult = new UpdateInfoForm()
{
changelog = StaticStorage.Manager.response.Minor.Changelog,
updateDescription = StaticStorage.Manager.response.Minor.Description,
updateVersion = StaticStorage.Manager.response.Minor.Version.ToString(),
currentVersion = versionMinor.ToString(),
updateSize = StaticStorage.Manager.response.Minor.FileSize,
preRelease = StaticStorage.Manager.response.Minor.PreRelease
};
userResult.ShowDialog();
if (userResult.DialogResult == DialogResult.Yes)
{
if (isElevated)
{
updateForm = new MainForm(UpdateType.Minor);
updateForm.ShowDialog();
}
else
{
//Request user to grant admin rights
try
{
ProcessStartInfo updaterProc = new ProcessStartInfo();
updaterProc.FileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
updaterProc.Arguments = passedArgs + " -update_minor";
updaterProc.Verb = "runas";
Process.Start(updaterProc);
return; //Exit, no further action required
}
catch (Exception exc)
{
MessageBox.Show(
$"Could not start Aurora Updater. Error:\r\n{exc}",
"Aurora Updater - Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
}
else
{
if (!isSilent && !isSilentMinor)
MessageBox.Show(
"You have latest Minor version of Aurora installed.",
"Aurora Updater",
MessageBoxButtons.OK);
}
}
else
{
if (!isSilent)
MessageBox.Show(
"Application launched incorrectly, no version was specified.\r\nPlease use Aurora if you want to check for updates.\r\nOptions -> \"Updates\" \"Check for Updates\"",
"Aurora Updater",
MessageBoxButtons.OK);
}*/
}
}
}
}