2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Network/multi_update.cpp $
16 * Revision 1.3 2002/06/09 04:41:24 relnev
17 * added copyright header
19 * Revision 1.2 2002/05/26 20:22:48 theoddone33
20 * Most of network/ works
22 * Revision 1.1.1.1 2002/05/03 03:28:10 root
26 * 9 10/14/99 3:35p Jefff
29 * 8 8/24/99 1:50a Dave
30 * Fixed client-side afterburner stuttering. Added checkbox for no version
31 * checking on PXO join. Made button info passing more friendly between
34 * 7 8/22/99 1:19p Dave
35 * Fixed up http proxy code. Cleaned up scoring code. Reverse the order in
36 * which d3d cards are detected.
38 * 6 5/19/99 4:07p Dave
39 * Moved versioning code into a nice isolated common place. Fixed up
40 * updating code on the pxo screen. Fixed several stub problems.
42 * 5 2/04/99 6:29p Dave
43 * First full working rev of FS2 PXO support. Fixed Glide lighting
46 * 4 11/05/98 4:18p Dave
47 * First run nebula support. Beefed up localization a bit. Removed all
48 * conditional compiles for foreign versions. Modified mission file
51 * 3 10/09/98 2:57p Dave
52 * Starting splitting up OS stuff.
54 * 2 10/07/98 10:53a Dave
57 * 1 10/07/98 10:50a Dave
59 * 15 9/10/98 1:17p Dave
60 * Put in code to flag missions and campaigns as being MD or not in Fred
61 * and Freespace. Put in multiplayer support for filtering out MD
62 * missions. Put in multiplayer popups for warning of non-valid missions.
64 * 14 9/09/98 5:53p Dave
65 * Put in new tracker packets in API. Change cfile to be able to checksum
68 * 13 7/24/98 11:13a Allender
69 * change way that the version.nfo file is parsed so that bogus returns
70 * from the HTTP server are accurately caught
72 * 12 7/20/98 12:51p Allender
73 * don't remove the version.nfo file if we are exiting to launcher for
74 * update. The launcher asssumes that the file is already present.
76 * 11 7/15/98 10:50a Allender
77 * changed web site to get version.nfo from
79 * 10 7/15/98 10:17a Dave
80 * Made the website address lookup more robust.
82 * 9 7/15/98 10:04a Dave
83 * Change connect() procedure so that it uses non blocking sockets and
84 * freespace doesn't "hang"
86 * 8 7/13/98 10:30a Lawrance
87 * add index numbers for newly localized strings
89 * 7 7/13/98 10:12a Dave
90 * Remove improperly localized strings.
92 * 6 7/10/98 5:04p Dave
93 * Fix connection speed bug on standalone server.
95 * 5 7/10/98 11:33a Dave
96 * Give the user extra options when the need for updating is detected on
97 * PXO screen. Send special command line arg to fslauncher.
99 * 4 7/09/98 6:07p Dave
100 * Format the text in the error dialog better.
102 * 3 7/09/98 6:01p Dave
103 * Firsts full version of PXO updater. Put in stub for displaying
106 * 2 7/09/98 4:51p Dave
107 * First revision of PXO autoupdate check system.
109 * 1 7/09/98 2:09p Dave
118 #include "multi_update.h"
120 #include "gamesequence.h"
121 #include "osregistry.h"
124 #include "inetgetfile.h"
127 // -------------------------------------------------------------------------------------------------------------------
128 // MULTI UPDATE DEFINES/VARS
132 InetGetFile *Multi_update_get = NULL;
134 // set this to be true so that game_shutdown() will fire up the launcher, then post a quit game event
135 int Multi_update_fireup_launcher_on_exit = 0;
137 // error code string for convenient reporting
138 char Multi_update_error_string[512];
140 // -------------------------------------------------------------------------------------------------------------------
141 // MULTI UPDATE FUNCTIONS
144 // initialize the http xfer of the version info file, return 1 on success
145 int multi_update_http_init()
147 char url_file[512] = "";
148 char local_file[512] = "";
151 strcpy(url_file, VERSION_URL);
154 strcpy(local_file, Cfile_root_dir);
155 strcat(local_file, "\\");
156 strcat(local_file, VERSION_LOC_FNAME);
159 Multi_update_get = new InetGetFile(url_file, local_file);
160 if(Multi_update_get == NULL){
162 strcpy(Multi_update_error_string, XSTR("Could not get data from website", 977));
170 // do frame for the popup. returns 0 if not done yet, 1 if succeeded, 2 on error
171 int multi_update_http_do()
174 if(Multi_update_get == NULL){
176 strcpy(Multi_update_error_string, XSTR("Could not get data from website", 977));
182 if(Multi_update_get->IsFileError()){
183 delete Multi_update_get;
184 Multi_update_get = NULL;
187 strcpy(Multi_update_error_string, XSTR("Could not get data from website", 977));
193 if(Multi_update_get->IsFileReceived()){
194 delete Multi_update_get;
195 Multi_update_get = NULL;
199 // connecting, receiving
200 if(Multi_update_get->IsConnecting() || Multi_update_get->IsReceiving()){
207 // close down the http xfer
208 void multi_update_http_close()
212 // error verifying, prompt the user for some action
213 int multi_update_error_verifying()
217 memset(out_str, 0, 512);
218 strcpy(out_str, "(");
219 strcat(out_str, Multi_update_error_string);
220 strcat(out_str, ")\n\n");
221 strcat(out_str, XSTR("There was an error verifying your version of Freespace, if you continue, you will not necessarily be up to date", 978));
223 switch(popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON, 2, XSTR("&Go back", 1524), XSTR("&Continue", 1525), out_str)){
224 // continue on in freespace like nothing happened
227 return MULTI_UPDATE_CONTINUE;
229 // go back to the main menu
231 return MULTI_UPDATE_MAIN_MENU;
234 // should never happen, but if so, move back to the main menu
235 return MULTI_UPDATE_MAIN_MENU;
238 // check to see if the version of FS on this machine is not recent. run in a popup
239 // if the versions don't check out, bail to the launcher
240 // returns 0 if freespace should continue, 1 if freespace should go back to the main menu,
241 // and 2 if the "shutdown" event was posted
242 int multi_update_gobaby()
246 int my_code = MULTI_UPDATE_MAIN_MENU;
249 if(os_config_read_uint(NULL, "SkipVerify", 0)){
250 return MULTI_UPDATE_CONTINUE;
253 memset(Multi_update_error_string, 0, 512);
255 // initialize the http connection
256 if(!multi_update_http_init()){
257 return multi_update_error_verifying();
261 extern char Multi_options_proxy[512];
262 extern ushort Multi_options_proxy_port;
263 if(strlen(Multi_options_proxy) > 0){
264 sprintf(msg, "%s (%s : %d)", XSTR("Verifying Freespace Version",981), Multi_options_proxy, Multi_options_proxy_port);
266 strcpy(msg, XSTR("Verifying Freespace Version",981));
268 ret_code = popup_till_condition(multi_update_http_do, XSTR("Cancel",948), msg);
270 // determine what to do now
274 // compare the versions
275 switch(version_compare(VERSION_LOC_FNAME, NULL, NULL, NULL, NULL, NULL, NULL)){
278 my_code = multi_update_error_verifying();
281 // earlier version - need to update
283 switch(popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON, 2, "&Update Later", "&Yes", XSTR("A new version of Freespace is available. You must update to the new version to play on PXO\n\nAuto update now?", 980))){
284 // update later (go back to main hall for now
287 my_code = MULTI_UPDATE_MAIN_MENU;
291 // set things up so that the launcher is launched when Freespace is done closing
292 Multi_update_fireup_launcher_on_exit = 1;
293 gameseq_post_event(GS_EVENT_QUIT_GAME);
295 my_code = MULTI_UPDATE_SHUTTING_DOWN;
299 // same version or higher
302 my_code = MULTI_UPDATE_CONTINUE;
307 // error of some kind (should probably notify the user or something)
309 my_code = multi_update_error_verifying();
312 // this should never happen, but if it does, go back to the main menu
314 my_code = multi_update_error_verifying();
319 multi_update_http_close();