Skip to content

Commit 7901c1b

Browse files
committed
v1.3.7
- Added the news tab back in the launcher, with a fallback incase Psyonix keeps blocking the launcher from downloading news. - Fixed the update or installer popup getting stuck open if an error occurred while downloading, now if an error happens it will ask you if you want to try again. - Fixed a crash that could happen when spamming the previous and next buttons in the news back too fast.
1 parent 3403df7 commit 7901c1b

8 files changed

Lines changed: 97 additions & 34 deletions

File tree

Architecture/Result.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ namespace CodeRedLauncher
66
public class Result
77
{
88
public bool Succeeded { get; set; }
9-
public string FailReason { get; set; }
9+
public string? FailReason { get; set; }
1010

1111
public Result()
1212
{
1313
Succeeded = false;
1414
FailReason = null;
1515
}
1616

17-
public Result(bool bSucceeded, string failReason = "")
17+
public Result(bool bSucceeded, string? failReason = null)
1818
{
1919
Succeeded = bSucceeded;
2020
FailReason = failReason;
2121
}
22-
23-
bool HasFailReason()
22+
23+
public bool HasFailReason()
2424
{
25-
return (FailReason != null);
25+
return !string.IsNullOrEmpty(FailReason);
2626
}
2727
}
2828
}

Controls/CRNews.cs

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace CodeRedLauncher.Controls
1111
{
1212
public partial class CRNews : UserControl
1313
{
14+
private string m_altUrl = "https://raw.githubusercontent.com/CodeRedModding/CodeRed-Retrievers/main/Public/News.cr"; // Psyonix started blocking requests to their site...have to use my own now.
15+
private string m_altThumbnail = "https://i.imgur.com/g9ssgL7.png";
16+
1417
private IconStore m_calendarIcons = new IconStore();
1518
private IconStore m_authorIcons = new IconStore();
1619
private IconStore m_categoryIcons = new IconStore();
@@ -33,13 +36,16 @@ private class NewsStorage
3336

3437
public NewsStorage(string bodyContent)
3538
{
39+
Timestamp = "Rocket League";
40+
Author = "Psyonix Team";
3641
ParseJson(bodyContent);
3742
}
3843

3944
public void ParseJson(string bodyContent)
4045
{
4146
if (bodyContent.Contains("slug"))
4247
{
48+
bodyContent = bodyContent.Replace("\": \"", "\":\"");
4349
Match titleMatch = Regex.Match(bodyContent, "(?<=\"title\":\")(.*?)(?=\")");
4450
Match urlMatch = Regex.Match(bodyContent, "(?<=\"slug\":\")(.*?)(?=\")");
4551
Match imageMatch = Regex.Match(bodyContent, "(?<=\"imageUrl\":\")(.*?)(?=\")");
@@ -415,6 +421,7 @@ private async Task<NewsStorage> ParseLink(NewsStorage newsStorage)
415421
newsStorage.ThumbnailUrl = thumbnailMatch.Groups[1].Value;
416422
Int32 jpg = newsStorage.ThumbnailUrl.IndexOf(".jpg");
417423
Int32 png = newsStorage.ThumbnailUrl.IndexOf(".png");
424+
Int32 webp = newsStorage.ThumbnailUrl.IndexOf(".webp");
418425

419426
if (jpg > 0)
420427
{
@@ -424,6 +431,10 @@ private async Task<NewsStorage> ParseLink(NewsStorage newsStorage)
424431
{
425432
newsStorage.ThumbnailUrl = (newsStorage.ThumbnailUrl.Substring(0, png) + ".png");
426433
}
434+
else if (webp > 0)
435+
{
436+
newsStorage.ThumbnailUrl = (newsStorage.ThumbnailUrl.Substring(0, webp) + ".webp");
437+
}
427438
}
428439

429440
Match thumbnailMatchAlt = Regex.Match(pageBody, "<p dir=\"ltr\"><img src=\"(.*)\" data-id=\"");
@@ -454,44 +465,63 @@ private async Task<NewsStorage> ParseLink(NewsStorage newsStorage)
454465
return newsStorage;
455466
}
456467

457-
public async void ParseArticles(string url)
468+
public async void ParseArticles(string url, bool bRecursive = false)
458469
{
459470
if (!string.IsNullOrEmpty(url))
460471
{
461-
return; // Fuck Psyonix for blocking requests to their news url, billion dollar company can't give us an actual api to use.
462-
472+
bool fallback = false;
463473
string pageBody = await Downloaders.DownloadPage(url);
464474

465-
if (!string.IsNullOrEmpty(pageBody))
475+
if (!string.IsNullOrEmpty(pageBody))
466476
{
467477
m_articles.Clear();
468478
ResetArticles();
469-
MatchCollection articleLinks = Regex.Matches(pageBody.Replace("\\", ""), "(?=\"title\")(.*?)(?=})");
479+
480+
MatchCollection articleLinks = Regex.Matches(pageBody.Replace("\\", ""), (bRecursive ? "(?s)(?=\"title).*?(?=})" : "(?=\"title\")(.*?)(?=})"));
470481

471482
Int32 articles = 0;
472483

473484
for (Int32 i = 0; i < articleLinks.Count; i++)
474485
{
475486
Match link = articleLinks[i];
476487

477-
if (link.Success && link.Groups[1].Success && link.Groups[1].Value.Contains("slug"))
488+
if (link.Success && link.Groups[0].Success && link.Groups[0].ToString().Contains("slug"))
478489
{
479490
articles++;
480-
m_articles.Add(new NewsStorage(link.Groups[1].Value));
491+
m_articles.Add(new NewsStorage(link.Groups[0].ToString()));
481492
}
482493

483-
if (articles >= m_maxIndexes)
494+
if (articles == m_maxIndexes)
484495
{
485496
break;
486497
}
487498
}
488499

489-
LoadAllIndexes(); // Parse and download everything in the background.
490-
LoadPreviousArticle();
500+
if (articles > 0)
501+
{
502+
Logger.Write("Found news article links!");
503+
LoadAllIndexes(); // Parse and download everything in the background.
504+
LoadPreviousArticle();
505+
return;
506+
}
507+
else
508+
{
509+
fallback = true;
510+
}
491511
}
492512
else
493513
{
494-
Logger.Write("Failed to download news article info!", LogLevel.LEVEL_WARN);
514+
fallback = true;
515+
}
516+
517+
if (fallback && !bRecursive)
518+
{
519+
Logger.Write("Couldn't find official news links, resorting to fallback url!");
520+
ParseArticles(m_altUrl, true);
521+
}
522+
else if (bRecursive)
523+
{
524+
Logger.Write("Fallback url failed, no news links found!");
495525
}
496526
}
497527
}
@@ -524,7 +554,7 @@ public async void LoadAllIndexes()
524554
if (newsStorage.ThumbnailImage == null)
525555
{
526556
newsStorage.ThumbnailUrl = "";
527-
newsStorage.ThumbnailUrlAlt = "https://i.imgur.com/dmpY0zQ.png";
557+
newsStorage.ThumbnailUrlAlt = m_altThumbnail;
528558
newsStorage.ThumbnailImage = await Downloaders.DownloadImage(newsStorage.ThumbnailUrlAlt);
529559
}
530560
}
@@ -570,7 +600,7 @@ private async void LoadIndex()
570600
if (newsStorage.ThumbnailImage == null)
571601
{
572602
newsStorage.ThumbnailUrl = "";
573-
newsStorage.ThumbnailUrlAlt = "https://i.imgur.com/dmpY0zQ.png";
603+
newsStorage.ThumbnailUrlAlt = m_altThumbnail;
574604
newsStorage.ThumbnailImage = await Downloaders.DownloadImage(newsStorage.ThumbnailUrlAlt);
575605
}
576606

@@ -611,22 +641,34 @@ private async void LoadIndex()
611641

612642
private void PreviousBtn_Click(object sender, EventArgs e)
613643
{
614-
LoadPreviousArticle();
644+
if (PreviousBtn.BackgroundImage != null)
645+
{
646+
LoadPreviousArticle();
647+
}
615648
}
616649

617650
private void PreviousBtn_DoubleClick(object sender, EventArgs e)
618651
{
619-
LoadPreviousArticle();
652+
if (PreviousBtn.BackgroundImage != null)
653+
{
654+
LoadPreviousArticle();
655+
}
620656
}
621657

622658
private void NextBtn_Click(object sender, EventArgs e)
623659
{
624-
LoadNextArticle();
660+
if (NextBtn.BackgroundImage != null)
661+
{
662+
LoadNextArticle();
663+
}
625664
}
626665

627666
private void NextBtn_DoubleClick(object sender, EventArgs e)
628667
{
629-
LoadNextArticle();
668+
if (NextBtn.BackgroundImage != null)
669+
{
670+
LoadNextArticle();
671+
}
630672
}
631673

632674
private void ThumbnailImg_Click(object sender, EventArgs e)

Controls/CRUpdate.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public enum UpdateLayouts : byte
2020
Downloading,
2121
Module,
2222
Launcher,
23-
Both
23+
Both,
24+
Fail
2425
}
2526

2627
private UpdateLayouts m_updateType = UpdateLayouts.Module;
@@ -213,6 +214,14 @@ public void UpdateTheme()
213214
DenyBtn.Visible = true;
214215
GameBtn.Visible = false;
215216
}
217+
else if (UpdateType == UpdateLayouts.Fail)
218+
{
219+
DescriptionLbl.Text = "An error occurred while downloading the latest version, would you like to try again?";
220+
m_buttonsEnabled = true;
221+
AcceptBtn.Visible = true;
222+
DenyBtn.Visible = true;
223+
GameBtn.Visible = false;
224+
}
216225

217226
if (ControlType == ControlTheme.Dark)
218227
{

Forms/MainFrm.Designer.cs

Lines changed: 0 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,16 +1312,16 @@ private async void UpdatePopup_ButtonClickAccept(object sender, EventArgs e)
13121312

13131313
if (report.Succeeded)
13141314
{
1315+
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
13151316
UpdatePopup.HidePopup();
13161317
ProcessTmr.Start();
13171318
CheckForUpdates(true, false);
13181319
}
1319-
else if (report.FailReason != null)
1320+
else if (report.HasFailReason())
13201321
{
1322+
UpdatePopup.UpdateType = CRUpdate.UpdateLayouts.Fail;
13211323
Logger.Write(report.FailReason, LogLevel.LEVEL_ERROR);
13221324
}
1323-
1324-
NewsCtrl.ParseArticles(await Retrievers.GetNewsUrl());
13251325
}
13261326

13271327
private async void UpdatePopup_ButtonClickDeny(object sender, EventArgs e)

Framework/Assembly.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static class Assembly
88
private static readonly string m_description = "Manages and injects the CodeRed module for Rocket League. ";
99
private static readonly string m_product = "CodeRedLauncher";
1010
private static readonly string m_copyright = "CodeRedModding 2024";
11-
private static readonly string m_version = "1.3.6";
11+
private static readonly string m_version = "1.3.7";
1212
private static readonly bool m_termsOfUse = false;
1313
private static readonly bool m_privatePolicy = false;
1414

Framework/Retrievers.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static async Task<bool> WebsiteOnline(string url)
4444
return false;
4545
}
4646

47-
public static async Task<Image> DownloadImage(string url)
47+
public static async Task<Image> DownloadImage(string url, bool bNoCache = true)
4848
{
4949
Image image = null;
5050

@@ -55,9 +55,13 @@ public static async Task<Image> DownloadImage(string url)
5555
try
5656
{
5757
client.Timeout = m_timeout;
58-
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
5958
client.DefaultRequestHeaders.UserAgent.ParseAdd(m_userAgent);
6059

60+
if (bNoCache)
61+
{
62+
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
63+
}
64+
6165
HttpResponseMessage response = await client.GetAsync(url);
6266

6367
if (response.IsSuccessStatusCode)
@@ -89,7 +93,7 @@ public static async Task<Image> DownloadImage(string url)
8993
return image;
9094
}
9195

92-
public static async Task<string> DownloadPage(string url)
96+
public static async Task<string> DownloadPage(string url, bool bNoCache = true)
9397
{
9498
string pageContent = "";
9599

@@ -100,9 +104,13 @@ public static async Task<string> DownloadPage(string url)
100104
using (HttpClient client = new HttpClient())
101105
{
102106
client.Timeout = m_timeout;
103-
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
104107
client.DefaultRequestHeaders.UserAgent.ParseAdd(m_userAgent);
105108

109+
if (bNoCache)
110+
{
111+
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
112+
}
113+
106114
HttpResponseMessage response = await client.GetAsync(url);
107115

108116
if (response.IsSuccessStatusCode)
@@ -124,7 +132,7 @@ public static async Task<string> DownloadPage(string url)
124132
return pageContent;
125133
}
126134

127-
public static async Task<bool> DownloadFile(string url, Architecture.Path folder, string fileName)
135+
public static async Task<bool> DownloadFile(string url, Architecture.Path folder, string fileName, bool bNoCache = true)
128136
{
129137
if (folder.Exists() && !string.IsNullOrEmpty(url))
130138
{
@@ -135,6 +143,11 @@ public static async Task<bool> DownloadFile(string url, Architecture.Path folder
135143
client.Timeout = m_timeout;
136144
client.DefaultRequestHeaders.UserAgent.ParseAdd(m_userAgent);
137145

146+
if (bNoCache)
147+
{
148+
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true, NoStore = true };
149+
}
150+
138151
HttpResponseMessage response = await client.GetAsync(url);
139152

140153
if (response.IsSuccessStatusCode)

Properties/PublishProfiles/FolderProfile.pubxml.user

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
44
-->
55
<Project>
66
<PropertyGroup>
7-
<History>True|2024-04-12T17:00:36.7074137Z;True|2024-04-03T06:47:45.9088839-04:00;True|2024-02-27T19:00:12.7481260-05:00;True|2024-02-05T12:33:56.3871704-05:00;True|2024-02-05T12:33:40.9055040-05:00;True|2024-02-05T12:14:05.2718245-05:00;True|2024-01-11T22:34:10.0545942-05:00;True|2023-12-14T11:42:08.7749851-05:00;True|2023-12-11T04:37:59.0581676-05:00;True|2023-12-07T20:21:05.0260676-05:00;True|2023-12-07T20:15:40.7222580-05:00;True|2023-12-06T22:55:16.4882440-05:00;True|2023-12-06T22:53:36.1925636-05:00;True|2023-11-17T06:42:46.9521154-05:00;True|2023-11-17T06:36:00.5885901-05:00;True|2023-11-16T22:32:34.0407922-05:00;True|2023-10-25T18:05:44.6144276-04:00;True|2023-10-19T21:35:47.3332415-04:00;True|2023-09-29T15:21:56.0574702-04:00;True|2023-09-16T19:07:06.5515071-04:00;True|2023-09-16T19:06:08.9803131-04:00;True|2023-09-13T19:11:25.4534084-04:00;True|2023-09-12T15:15:53.5080335-04:00;True|2023-09-12T11:21:47.2201303-04:00;True|2023-09-11T17:53:54.1085377-04:00;True|2023-07-03T19:19:37.2984651-04:00;True|2023-06-23T12:19:10.5480937-04:00;True|2023-06-07T16:24:13.6686440-04:00;True|2023-06-07T16:19:33.2384233-04:00;True|2023-06-02T14:20:34.8667609-04:00;True|2023-06-02T14:19:16.9938932-04:00;True|2023-05-17T17:31:36.2391578-04:00;True|2023-05-13T13:56:01.0765277-04:00;True|2023-04-26T17:18:01.3003846-04:00;True|2023-04-17T18:09:22.0218857-04:00;True|2023-04-15T08:12:25.4751548-04:00;True|2023-02-23T17:42:55.3711325-05:00;True|2023-01-26T05:55:54.7338406-05:00;True|2023-01-14T16:37:43.9661254-05:00;True|2023-01-11T15:04:57.9184587-05:00;True|2023-01-01T06:51:43.9653309-05:00;True|2022-12-29T03:28:57.5161186-05:00;True|2022-12-25T20:55:07.0626032-05:00;True|2022-12-24T18:45:18.2492814-05:00;True|2022-12-24T17:58:05.8108440-05:00;True|2022-12-23T00:36:55.2356565-05:00;True|2022-12-22T20:46:31.3667454-05:00;True|2022-12-22T20:36:59.8978942-05:00;True|2022-12-22T20:32:40.9627042-05:00;True|2022-12-22T20:27:45.7845417-05:00;True|2022-12-22T20:08:26.4442830-05:00;True|2022-12-22T20:07:06.2254198-05:00;True|2022-12-22T20:01:04.3986967-05:00;True|2022-12-22T19:57:34.6741553-05:00;True|2022-12-22T19:46:09.3566048-05:00;True|2022-12-22T19:45:03.2884935-05:00;True|2022-12-22T19:36:42.2434776-05:00;True|2022-12-22T19:31:21.4738973-05:00;True|2022-12-22T19:27:34.9406205-05:00;False|2022-12-22T19:27:27.7152676-05:00;True|2022-12-22T19:14:05.9421852-05:00;True|2022-12-22T18:02:42.2130135-05:00;</History>
7+
<History>True|2024-05-12T20:12:06.7431879Z;True|2024-04-12T13:00:36.7074137-04:00;True|2024-04-03T06:47:45.9088839-04:00;True|2024-02-27T19:00:12.7481260-05:00;True|2024-02-05T12:33:56.3871704-05:00;True|2024-02-05T12:33:40.9055040-05:00;True|2024-02-05T12:14:05.2718245-05:00;True|2024-01-11T22:34:10.0545942-05:00;True|2023-12-14T11:42:08.7749851-05:00;True|2023-12-11T04:37:59.0581676-05:00;True|2023-12-07T20:21:05.0260676-05:00;True|2023-12-07T20:15:40.7222580-05:00;True|2023-12-06T22:55:16.4882440-05:00;True|2023-12-06T22:53:36.1925636-05:00;True|2023-11-17T06:42:46.9521154-05:00;True|2023-11-17T06:36:00.5885901-05:00;True|2023-11-16T22:32:34.0407922-05:00;True|2023-10-25T18:05:44.6144276-04:00;True|2023-10-19T21:35:47.3332415-04:00;True|2023-09-29T15:21:56.0574702-04:00;True|2023-09-16T19:07:06.5515071-04:00;True|2023-09-16T19:06:08.9803131-04:00;True|2023-09-13T19:11:25.4534084-04:00;True|2023-09-12T15:15:53.5080335-04:00;True|2023-09-12T11:21:47.2201303-04:00;True|2023-09-11T17:53:54.1085377-04:00;True|2023-07-03T19:19:37.2984651-04:00;True|2023-06-23T12:19:10.5480937-04:00;True|2023-06-07T16:24:13.6686440-04:00;True|2023-06-07T16:19:33.2384233-04:00;True|2023-06-02T14:20:34.8667609-04:00;True|2023-06-02T14:19:16.9938932-04:00;True|2023-05-17T17:31:36.2391578-04:00;True|2023-05-13T13:56:01.0765277-04:00;True|2023-04-26T17:18:01.3003846-04:00;True|2023-04-17T18:09:22.0218857-04:00;True|2023-04-15T08:12:25.4751548-04:00;True|2023-02-23T17:42:55.3711325-05:00;True|2023-01-26T05:55:54.7338406-05:00;True|2023-01-14T16:37:43.9661254-05:00;True|2023-01-11T15:04:57.9184587-05:00;True|2023-01-01T06:51:43.9653309-05:00;True|2022-12-29T03:28:57.5161186-05:00;True|2022-12-25T20:55:07.0626032-05:00;True|2022-12-24T18:45:18.2492814-05:00;True|2022-12-24T17:58:05.8108440-05:00;True|2022-12-23T00:36:55.2356565-05:00;True|2022-12-22T20:46:31.3667454-05:00;True|2022-12-22T20:36:59.8978942-05:00;True|2022-12-22T20:32:40.9627042-05:00;True|2022-12-22T20:27:45.7845417-05:00;True|2022-12-22T20:08:26.4442830-05:00;True|2022-12-22T20:07:06.2254198-05:00;True|2022-12-22T20:01:04.3986967-05:00;True|2022-12-22T19:57:34.6741553-05:00;True|2022-12-22T19:46:09.3566048-05:00;True|2022-12-22T19:45:03.2884935-05:00;True|2022-12-22T19:36:42.2434776-05:00;True|2022-12-22T19:31:21.4738973-05:00;True|2022-12-22T19:27:34.9406205-05:00;False|2022-12-22T19:27:27.7152676-05:00;True|2022-12-22T19:14:05.9421852-05:00;True|2022-12-22T18:02:42.2130135-05:00;</History>
88
<LastFailureDetails />
99
</PropertyGroup>
1010
</Project>

0 commit comments

Comments
 (0)