@@ -15,7 +15,16 @@ namespace ModApi.UpdateManager
1515 public static class UpdateManager
1616 {
1717 public static bool Development = false ;
18- public static string PathPrefix = "https://update.launcherkit.sporecommunity.com/" ;
18+ public static List < string > LauncherKitUpdateUrls = new List < string >
19+ {
20+ // Cloudflare R2 + Cache
21+ "https://update.launcherkit.sporecommunity.com/" ,
22+ // GitHub Releases
23+ "https://github.com/Spore-Community/modapi-launcher-kit/releases/latest/download/" ,
24+ // DavoOnline (might not work due to anti-bot firewall)
25+ "http://davoonline.com/sporemodder/rob55rod/ModAPI/"
26+ } ;
27+ public static string PathPrefix = LauncherKitUpdateUrls . First ( ) ;
1928 public static string AppDataPath = Environment . ExpandEnvironmentVariables ( @"%appdata%\Spore ModAPI Launcher" ) ;
2029 public static string UpdateInfoDestPath = Path . Combine ( AppDataPath , "update.info" ) ;
2130 public static string CurrentInfoDestPath = Path . Combine ( AppDataPath , "current.info" ) ;
@@ -105,23 +114,72 @@ public static void CheckForUpdates()
105114 if ( File . Exists ( UpdaterDestPath ) )
106115 File . Delete ( UpdaterDestPath ) ;
107116
108- if ( File . Exists ( UpdaterOverridePath ) )
109- PathPrefix = File . ReadAllText ( UpdaterOverridePath ) ;
110-
111- if ( ! File . Exists ( UpdaterBlockPath ) )
117+ if ( ! File . Exists ( UpdaterBlockPath ) && HasInternetConnection ( ) )
112118 {
113119 try
114120 {
115121 using ( var infoClient = new WebClient ( ) )
116122 {
117123 infoClient . Headers . Add ( "User-Agent" , HttpUserAgent ) ;
118- try
124+
125+ List < Exception > exceptions = new List < Exception > ( ) ;
126+ bool didDownload = false ;
127+
128+ // Try to download the update info file from the override path first
129+ if ( File . Exists ( UpdaterOverridePath ) )
130+ {
131+ PathPrefix = File . ReadAllText ( UpdaterOverridePath ) ;
132+
133+ // remove override if the URL is in our URL list
134+ foreach ( string url in LauncherKitUpdateUrls )
135+ {
136+ if ( url == PathPrefix )
137+ {
138+ File . Delete ( UpdaterOverridePath ) ;
139+ break ;
140+ }
141+ }
142+
143+ try
144+ {
145+ infoClient . DownloadFile ( Path . Combine ( PathPrefix , "update.info" ) , UpdateInfoDestPath ) ;
146+
147+ // Hides exceptions if the download was successful
148+ didDownload = true ;
149+ }
150+ catch ( Exception ex )
151+ {
152+ exceptions . Add ( ex ) ;
153+ }
154+ }
155+ // Try to download the update info file from each URL in the list
156+ else
119157 {
120- infoClient . DownloadFile ( Path . Combine ( PathPrefix , "update.info" ) , UpdateInfoDestPath ) ;
158+ foreach ( string url in LauncherKitUpdateUrls )
159+ {
160+ try
161+ {
162+ infoClient . DownloadFile ( Path . Combine ( url , "update.info" ) , UpdateInfoDestPath ) ;
163+
164+ // Hides exceptions if the download was successful
165+ didDownload = true ;
166+ PathPrefix = url ;
167+ break ;
168+ }
169+ catch ( Exception ex )
170+ {
171+ exceptions . Add ( ex ) ;
172+ }
173+ }
121174 }
122- catch ( Exception ex )
175+
176+ // If no download was successful, show all exceptions, one at a time
177+ if ( ! didDownload )
123178 {
124- ShowUpdateCheckFailedMessage ( ex ) ;
179+ foreach ( var ex in exceptions )
180+ {
181+ ShowUpdateCheckFailedMessage ( ex ) ;
182+ }
125183 }
126184 }
127185
@@ -237,5 +295,23 @@ static void ShowUnrecognizedUpdateInfoVersionMessage()
237295 {
238296 MessageBox . Show ( "This update to the Spore ModAPI Launcher Kit must be downloaded manually." ) ;
239297 }
298+
299+ static bool HasInternetConnection ( )
300+ {
301+ try
302+ {
303+ using ( var client = new WebClient ( ) )
304+ {
305+ client . Headers . Add ( "User-Agent" , HttpUserAgent ) ;
306+ client . DownloadString ( "https://1.1.1.1" ) ;
307+ return true ;
308+ }
309+ }
310+ catch ( Exception ex )
311+ {
312+ MessageBox . Show ( "The Launcher Kit could not connect to the internet to check for updates. The Launcher Kit will still work, but you may be missing the latest features and improvements.\n \n Current version: " + CurrentVersion + "\n \n " + ex . ToString ( ) ) ;
313+ return false ;
314+ }
315+ }
240316 }
241317}
0 commit comments