@@ -11,8 +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" ;
14+ private static bool m_usingAlt = false ;
15+ private static readonly 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.
16+ private static readonly string m_altThumbnail = "https://i.imgur.com/g9ssgL7.png" ;
1617
1718 private IconStore m_calendarIcons = new IconStore ( ) ;
1819 private IconStore m_authorIcons = new IconStore ( ) ;
@@ -30,14 +31,12 @@ private class NewsStorage
3031 public string ThumbnailUrlAlt { get ; set ; }
3132 public Image ThumbnailImage { get ; set ; } = null ;
3233 public string Title { get ; set ; }
33- public string Timestamp { get ; set ; }
34- public string Author { get ; set ; }
34+ public string Timestamp { get ; set ; } = "Rocket League" ;
35+ public string Author { get ; set ; } = "Psyonix Team" ;
3536 public bool Parsed { get ; set ; } = false ;
3637
3738 public NewsStorage ( string bodyContent )
3839 {
39- Timestamp = "Rocket League" ;
40- Author = "Psyonix Team" ;
4140 ParseJson ( bodyContent ) ;
4241 }
4342
@@ -70,6 +69,25 @@ public void ParseJson(string bodyContent)
7069 {
7170 ThumbnailUrl = imageMatch . Groups [ 1 ] . Value ;
7271 }
72+
73+ if ( m_usingAlt )
74+ {
75+ // Specific to the fallback url.
76+ Match dateMatch = Regex . Match ( bodyContent , "(?<=\" date\" :\" )(.*?)(?=\" )" ) ;
77+ Match authorMatch = Regex . Match ( bodyContent , "(?<=\" author\" :\" )(.*?)(?=\" )" ) ;
78+
79+ if ( dateMatch . Success && dateMatch . Groups [ 1 ] . Success )
80+ {
81+ Timestamp = dateMatch . Groups [ 1 ] . Value ;
82+ }
83+
84+ if ( authorMatch . Success && authorMatch . Groups [ 1 ] . Success )
85+ {
86+ Author = authorMatch . Groups [ 1 ] . Value ;
87+ }
88+
89+ Parsed = true ;
90+ }
7391 }
7492 }
7593
@@ -404,7 +422,7 @@ private void OpenCurrentArticle()
404422
405423 private async Task < NewsStorage > ParseLink ( NewsStorage newsStorage )
406424 {
407- if ( ! string . IsNullOrEmpty ( newsStorage . NewsUrl ) )
425+ if ( ! string . IsNullOrEmpty ( newsStorage . NewsUrl ) && ! m_usingAlt )
408426 {
409427 string pageBody = await Downloaders . DownloadPage ( newsStorage . NewsUrl ) ;
410428
@@ -517,6 +535,7 @@ public async void ParseArticles(string url, bool bRecursive = false)
517535 if ( fallback && ! bRecursive )
518536 {
519537 Logger . Write ( "Couldn't find official news links, resorting to fallback url!" ) ;
538+ m_usingAlt = true ;
520539 ParseArticles ( m_altUrl , true ) ;
521540 }
522541 else if ( bRecursive )
0 commit comments