Skip to content

Commit d06d441

Browse files
committed
v1.3.0
- Added more detailed logging when downloading and installing updates. - Optimizations for the news tab, if an update is found it will now wait before downloading articles and images until the update is finished. - Fixed a crash that could happen if your download speed was slow or had packet loss and the download stopped momentarily.
1 parent 2415d38 commit d06d441

7 files changed

Lines changed: 84 additions & 39 deletions

File tree

Controls/CRUpdate.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,16 @@ private void AcceptBtn_OnButtonClick(object sender, EventArgs e)
292292
}
293293
}
294294

295+
public event EventHandler ButtonClickDeny = null;
295296
private void DenyBtn_OnButtonClick(object sender, EventArgs e)
296297
{
297298
if (ButtonsEnabled)
298299
{
300+
if (ButtonClickDeny != null)
301+
{
302+
ButtonClickDeny.Invoke(this, e);
303+
}
304+
299305
HidePopup();
300306
}
301307
}

Forms/MainFrm.Designer.cs

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/MainFrm.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private void AutoCheckUpdatesBx_OnCheckChanged(object sender, EventArgs e)
174174

175175
if (AutoCheckUpdatesBx.BoxChecked)
176176
{
177-
CheckForUpdates(true);
177+
CheckForUpdates(true, true);
178178
}
179179
}
180180

@@ -189,7 +189,7 @@ private void PreventInjectionBx_OnCheckChanged(object sender, EventArgs e)
189189

190190
if (AutoCheckUpdatesBx.BoxChecked)
191191
{
192-
CheckForUpdates(true);
192+
CheckForUpdates(true, true);
193193
}
194194
}
195195

@@ -355,6 +355,7 @@ private void ExportLogsBtn_OnButtonClick(object sender, EventArgs e)
355355

356356
if (tempFolder.Exists())
357357
{
358+
Logger.Write("Old temporary folder found, deleting...");
358359
Directory.Delete(tempFolder.GetPath(), true);
359360
}
360361

@@ -448,7 +449,7 @@ private void ExportLogsBtn_OnButtonClick(object sender, EventArgs e)
448449
private void CheckUpdatesBtn_OnButtonClick(object sender, EventArgs e)
449450
{
450451
CheckUpdatesBtn.ButtonEnabled = false;
451-
CheckForUpdates(true);
452+
CheckForUpdates(true, true);
452453
}
453454

454455
private void TermsBtn_OnButtonClick(object sender, EventArgs e)
@@ -596,7 +597,7 @@ private void UpdateTmr_Tick(object sender, EventArgs e)
596597
if (!Updator.IsOutdated())
597598
{
598599
Logger.Write("Auto checking for updates...");
599-
CheckForUpdates(true);
600+
CheckForUpdates(true, true);
600601
}
601602
else
602603
{
@@ -727,6 +728,7 @@ private async void StartupRoutine(bool bInvalidate = false)
727728

728729
if (tempFolder.Exists())
729730
{
731+
Logger.Write("Old launcher folder found, deleting...");
730732
Directory.Delete(tempFolder.GetPath(), true); // This is to cleanup anything left over by the auto updator/dropper program.
731733
}
732734

@@ -868,12 +870,13 @@ private async void ContinueStartup(bool bInvalidate)
868870

869871
if (Configuration.ShouldCheckForUpdates())
870872
{
871-
await CheckForUpdates(false);
873+
await CheckForUpdates(false, true);
872874
}
873875
else
874876
{
875877
UpdateStatusCtrl.DisplayType = StatusTypes.Version_Idle;
876878
RetrieversToInterface();
879+
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
877880
}
878881
}
879882
else
@@ -893,7 +896,6 @@ private async void RetrieversToInterface()
893896
{
894897
if (!Configuration.OfflineMode.GetBoolValue())
895898
{
896-
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
897899
ChangelogCtrl.ModuleText = await Retrievers.GetModuleChangelog();
898900
ChangelogCtrl.LauncherText = await Retrievers.GetLauncherChangelog();
899901
DiscordInfoCtrl.DisplayDescription = await Retrievers.GetDiscordUrl();
@@ -1036,7 +1038,7 @@ private void UpdateTheme()
10361038
}
10371039

10381040
// If "bInvalidate" is set to true it forces the application to retrieve all local and remote information.
1039-
private async Task<bool> CheckForUpdates(bool bInvalidate, bool bShowPrompt = true)
1041+
private async Task<bool> CheckForUpdates(bool bInvalidate, bool bShowPrompt)
10401042
{
10411043
if (!Configuration.OfflineMode.GetBoolValue() || bInvalidate)
10421044
{
@@ -1109,6 +1111,10 @@ private async Task<bool> CheckForUpdates(bool bInvalidate, bool bShowPrompt = tr
11091111
UpdatePopup.ShowPopup();
11101112
}
11111113
}
1114+
else
1115+
{
1116+
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
1117+
}
11121118
}
11131119
else if (!ignoreModule && moduleOutdated)
11141120
{
@@ -1145,6 +1151,10 @@ private async Task<bool> CheckForUpdates(bool bInvalidate, bool bShowPrompt = tr
11451151
UpdatePopup.ShowPopup();
11461152
}
11471153
}
1154+
else
1155+
{
1156+
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
1157+
}
11481158
}
11491159
else if (launcherOutdated)
11501160
{
@@ -1166,6 +1176,10 @@ private async Task<bool> CheckForUpdates(bool bInvalidate, bool bShowPrompt = tr
11661176
UpdatePopup.ShowPopup();
11671177
}
11681178
}
1179+
else
1180+
{
1181+
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
1182+
}
11691183
}
11701184
else
11711185
{
@@ -1214,7 +1228,7 @@ private async void InstallCodeRed(bool bManuallyChoose)
12141228

12151229
if (moduleReport.Succeeded)
12161230
{
1217-
await CheckForUpdates(true);
1231+
await CheckForUpdates(true, false);
12181232
StartupRoutine(true);
12191233
InstallPopup.HidePopup();
12201234
}
@@ -1299,6 +1313,11 @@ private async void UpdatePopup_ButtonClickAccept(object sender, EventArgs e)
12991313
}
13001314
}
13011315

1316+
private async void UpdatePopup_ButtonClickDeny(object sender, EventArgs e)
1317+
{
1318+
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
1319+
}
1320+
13021321
private void PolicyPopup_ButtonClickAccept(object sender, EventArgs e)
13031322
{
13041323
PolicyPopup.HidePopup();

Forms/MainFrm.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@
273273
<metadata name="DashboardTabBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
274274
<value>True</value>
275275
</metadata>
276-
<metadata name="InstallPopup.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
277-
<value>True</value>
278-
</metadata>
279276
<metadata name="UpdatePopup.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
280277
<value>True</value>
281278
</metadata>
@@ -291,6 +288,9 @@
291288
<metadata name="DuplicatePopup.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
292289
<value>True</value>
293290
</metadata>
291+
<metadata name="InstallPopup.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
292+
<value>True</value>
293+
</metadata>
294294
<metadata name="ProcessTmr.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
295295
<value>17, 17</value>
296296
</metadata>

Framework/Retrievers.cs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,32 @@ public static async Task<Image> DownloadImage(string url)
5050
{
5151
using (HttpClient client = new HttpClient())
5252
{
53-
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
54-
HttpResponseMessage response = await client.GetAsync(url);
55-
56-
if (response.IsSuccessStatusCode)
53+
try
5754
{
58-
Stream stream = await response.Content.ReadAsStreamAsync();
55+
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
56+
HttpResponseMessage response = await client.GetAsync(url);
5957

60-
try
58+
if (response.IsSuccessStatusCode)
6159
{
62-
image = Image.FromStream(stream);
60+
Stream stream = await response.Content.ReadAsStreamAsync();
61+
62+
try
63+
{
64+
image = Image.FromStream(stream);
65+
}
66+
catch (Exception)
67+
{
68+
image = null;
69+
}
6370
}
64-
catch (Exception ex)
71+
else
6572
{
66-
image = null;
73+
Logger.Write("Website is offline, failed to download image for url \"" + url + "\"!", LogLevel.LEVEL_WARN);
6774
}
6875
}
69-
else
76+
catch (Exception)
7077
{
71-
Logger.Write("Website is offline, failed to download image for url \"" + url + "\"!", LogLevel.LEVEL_WARN);
78+
image = null;
7279
}
7380
}
7481
}
@@ -84,6 +91,7 @@ public static async Task<string> DownloadPage(string url)
8491
{
8592
using (HttpClient client = new HttpClient())
8693
{
94+
client.Timeout = TimeSpan.FromMinutes(30);
8795
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
8896
HttpResponseMessage response = await client.GetAsync(url);
8997

@@ -103,24 +111,22 @@ public static async Task<string> DownloadPage(string url)
103111

104112
public static async Task<bool> DownloadFile(string url, Architecture.Path folder, string fileName)
105113
{
106-
if (folder.Exists())
114+
if (folder.Exists() && !string.IsNullOrEmpty(url))
107115
{
108-
if (!String.IsNullOrEmpty(url))
116+
using (HttpClient client = new HttpClient())
109117
{
110-
using (HttpClient client = new HttpClient())
118+
client.Timeout = TimeSpan.FromMinutes(30);
119+
HttpResponseMessage response = await client.GetAsync(url);
120+
121+
if (response.IsSuccessStatusCode)
111122
{
112-
HttpResponseMessage response = await client.GetAsync(url);
123+
string path = (folder / fileName).GetPath();
124+
byte[] content = await response.Content.ReadAsByteArrayAsync();
113125

114-
if (response.IsSuccessStatusCode)
126+
if (content.Length > 0)
115127
{
116-
string path = (folder / fileName).GetPath();
117-
byte[] content = await response.Content.ReadAsByteArrayAsync();
118-
119-
if (content.Length > 0)
120-
{
121-
File.WriteAllBytes(path, content);
122-
return File.Exists(path);
123-
}
128+
File.WriteAllBytes(path, content);
129+
return File.Exists(path);
124130
}
125131
}
126132
}

Framework/Updator.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ private static async Task<Result> InstallModule(bool bForceInstall)
9292

9393
if (tempFolder.Exists())
9494
{
95+
Logger.Write("Deleting temporary folder...");
9596
Directory.Delete(tempFolder.GetPath(), true);
9697
}
9798

@@ -101,9 +102,10 @@ private static async Task<Result> InstallModule(bool bForceInstall)
101102
{
102103
string moduleUrl = await Retrievers.GetModuleUrl();
103104

104-
if (!String.IsNullOrEmpty(moduleUrl))
105+
if (!string.IsNullOrEmpty(moduleUrl))
105106
{
106107
Architecture.Path downloadedFile = (tempFolder / "CodeRedModule.zip");
108+
Logger.Write("Downloading module archive...");
107109

108110
if (await Downloaders.DownloadFile(moduleUrl, tempFolder, "CodeRedModule.zip"))
109111
{
@@ -116,6 +118,8 @@ private static async Task<Result> InstallModule(bool bForceInstall)
116118
Directory.CreateDirectory(modulePath.GetPath());
117119
}
118120

121+
Logger.Write("Extracting file from archive...");
122+
119123
using (ZipArchive zipArchive = ZipFile.OpenRead(downloadedFile.GetPath()))
120124
{
121125
foreach (ZipArchiveEntry archiveEntry in zipArchive.Entries)
@@ -158,6 +162,7 @@ private static async Task<Result> InstallModule(bool bForceInstall)
158162
}
159163
}
160164

165+
Logger.Write("Done!");
161166
report.Succeeded = true;
162167
Status &= ~UpdatorStatus.Module;
163168
Configuration.SaveChanges();
@@ -198,6 +203,7 @@ private static async Task<Result> InstallLauncher(bool bForceInstall)
198203

199204
if (tempFolder.Exists())
200205
{
206+
Logger.Write("Deleting temporary folder...");
201207
Directory.Delete(tempFolder.GetPath(), true);
202208
}
203209

@@ -208,17 +214,20 @@ private static async Task<Result> InstallLauncher(bool bForceInstall)
208214
string launcherUrl = await Retrievers.GetLauncherUrl();
209215
string dropperUrl = await Retrievers.GetDropperUrl();
210216

211-
if (!String.IsNullOrEmpty(launcherUrl) && !String.IsNullOrEmpty(dropperUrl))
217+
if (!string.IsNullOrEmpty(launcherUrl) && !string.IsNullOrEmpty(dropperUrl))
212218
{
213219
Architecture.Path launcherArchive = (tempFolder / "CodeRedLauncher.zip");
214220
Architecture.Path launcherExe = (tempFolder / "CodeRedLauncher.exe");
215221
Architecture.Path dropperArchive = (tempFolder / "CodeRedDropper.zip");
216222
Architecture.Path dropperExe = (tempFolder / "CodeRedDropper.exe");
223+
Logger.Write("Downloading launcher archive...");
217224

218225
if (await Downloaders.DownloadFile(launcherUrl, tempFolder, "CodeRedLauncher.zip"))
219226
{
220227
if (launcherArchive.Exists())
221228
{
229+
Logger.Write("Extracting file from archive...");
230+
222231
using (ZipArchive zipArchive = ZipFile.OpenRead(launcherArchive.GetPath()))
223232
{
224233
foreach (ZipArchiveEntry archiveEntry in zipArchive.Entries)
@@ -233,11 +242,14 @@ private static async Task<Result> InstallLauncher(bool bForceInstall)
233242
if (launcherExe.Exists())
234243
{
235244
File.Delete(launcherArchive.GetPath());
245+
Logger.Write("Downloading dropper archive...");
236246

237247
if (await Downloaders.DownloadFile(dropperUrl, tempFolder, "CodeRedDropper.zip"))
238248
{
239249
if (dropperArchive.Exists())
240250
{
251+
Logger.Write("Extracting file from archive...");
252+
241253
using (ZipArchive zipArchive = ZipFile.OpenRead(dropperArchive.GetPath()))
242254
{
243255
foreach (ZipArchiveEntry archiveEntry in zipArchive.Entries)
@@ -253,6 +265,7 @@ private static async Task<Result> InstallLauncher(bool bForceInstall)
253265

254266
if (dropperExe.Exists())
255267
{
268+
Logger.Write("Done!");
256269
report.Succeeded = true;
257270
Status &= ~UpdatorStatus.Launcher;
258271

0 commit comments

Comments
 (0)