FS2_Open
Open source remastering of the Freespace 2 engine
multi_update.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) Volition, Inc. 1999. All rights reserved.
3  *
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 the
6  * source.
7  *
8 */
9 
10 
11 
12 
13 #include "network/multi_update.h"
14 #include "popup/popup.h"
16 #include "osapi/osregistry.h"
17 #include "globalincs/version.h"
18 #include "inetfile/inetgetfile.h"
19 #include "cfile/cfile.h"
20 
21 
22 
23 // -------------------------------------------------------------------------------------------------------------------
24 // MULTI UPDATE DEFINES/VARS
25 //
26 
27 // file get object
29 
30 // set this to be true so that game_shutdown() will fire up the launcher, then post a quit game event
32 
33 // error code string for convenient reporting
35 
36 // -------------------------------------------------------------------------------------------------------------------
37 // MULTI UPDATE FUNCTIONS
38 //
39 
40 // initialize the http xfer of the version info file, return 1 on success
42 {
43  return 0;
44 }
45 
46 // do frame for the popup. returns 0 if not done yet, 1 if succeeded, 2 on error
48 {
49  // sanity
50  if(Multi_update_get == NULL){
51  // error string
52  strcpy_s(Multi_update_error_string, XSTR("Could not get data from website", 977));
53 
54  return 2;
55  }
56 
57  // error
58  if(Multi_update_get->IsFileError()){
59  delete Multi_update_get;
60  Multi_update_get = NULL;
61 
62  // error string
63  strcpy_s(Multi_update_error_string, XSTR("Could not get data from website", 977));
64 
65  return 2;
66  }
67 
68  // done!
69  if(Multi_update_get->IsFileReceived()){
70  delete Multi_update_get;
71  Multi_update_get = NULL;
72  return 1;
73  }
74 
75  // connecting, receiving
76  if(Multi_update_get->IsConnecting() || Multi_update_get->IsReceiving()){
77  return 0;
78  }
79 
80  return 0;
81 }
82 
83 // close down the http xfer
85 {
86 }
87 
88 // error verifying, prompt the user for some action
90 {
91  char out_str[512];
92 
93  memset(out_str, 0, 512);
94  strcpy_s(out_str, "(");
96  strcat_s(out_str, ")\n\n");
97  strcat_s(out_str, XSTR("There was an error verifying your version of FreeSpace, if you continue, you will not necessarily be up to date", 978));
98 
99  switch(popup(PF_USE_AFFIRMATIVE_ICON | PF_USE_NEGATIVE_ICON, 2, XSTR("&Go back", 1524), XSTR("&Continue", 1525), out_str)){
100  // continue on in freespace like nothing happened
101  case 1:
102  case -1:
103  return MULTI_UPDATE_CONTINUE;
104 
105  // go back to the main menu
106  default:
107  return MULTI_UPDATE_MAIN_MENU;
108  }
109 }
110 
111 // check to see if the version of FS on this machine is not recent. run in a popup
112 // if the versions don't check out, bail to the launcher
113 // returns 0 if freespace should continue, 1 if freespace should go back to the main menu,
114 // and 2 if the "shutdown" event was posted
116 {
117  //char msg[512] = "";
118  //int ret_code;
119  //int my_code = MULTI_UPDATE_MAIN_MENU;
120 
121 
122  // we just assume that everything is up to date
123  return MULTI_UPDATE_CONTINUE;
124 
125 
126 /*
127  // maybe skip
128  if(os_config_read_uint(NULL, "SkipVerify", 0)){
129  return MULTI_UPDATE_CONTINUE;
130  }
131 
132  memset(Multi_update_error_string, 0, 512);
133 
134  // initialize the http connection
135  if(!multi_update_http_init()){
136  return multi_update_error_verifying();
137  }
138 
139  // run the popup
140  extern char Multi_options_proxy[512];
141  extern ushort Multi_options_proxy_port;
142  if(strlen(Multi_options_proxy) > 0){
143  sprintf(msg, "%s (%s : %d)", XSTR("Verifying FreeSpace Version",981), Multi_options_proxy, Multi_options_proxy_port);
144  } else {
145  strcpy_s(msg, XSTR("Verifying FreeSpace Version",981));
146  }
147  ret_code = popup_till_condition(multi_update_http_do, XSTR("Cancel",948), msg);
148 
149  // determine what to do now
150  switch(ret_code){
151  // success
152  case 1 :
153  // compare the versions
154  switch(version_compare(VERSION_LOC_FNAME, NULL, NULL, NULL, NULL, NULL, NULL)){
155  // error
156  case -1:
157  my_code = multi_update_error_verifying();
158  break;
159 
160  // earlier version - need to update
161  case 0:
162  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))){
163  // update later (go back to main hall for now
164  case 0 :
165  case -1:
166  my_code = MULTI_UPDATE_MAIN_MENU;
167  break;
168 
169  default:
170  // set things up so that the launcher is launched when FreeSpace is done closing
171  Multi_update_fireup_launcher_on_exit = 1;
172  gameseq_post_event(GS_EVENT_QUIT_GAME);
173 
174  my_code = MULTI_UPDATE_SHUTTING_DOWN;
175  }
176  break;
177 
178  // same version or higher
179  case 1:
180  case 2:
181  my_code = MULTI_UPDATE_CONTINUE;
182  break;
183  }
184  break;
185 
186  // error of some kind (should probably notify the user or something)
187  case 2:
188  my_code = multi_update_error_verifying();
189  break;
190 
191  // this should never happen, but if it does, go back to the main menu
192  default :
193  my_code = multi_update_error_verifying();
194  break;
195  }
196 
197  // close down
198  multi_update_http_close();
199 
200  return my_code;
201 */
202 }
void multi_update_http_close()
char Multi_update_error_string[512]
int Multi_update_fireup_launcher_on_exit
bool IsConnecting()
bool IsFileReceived()
InetGetFile * Multi_update_get
bool IsReceiving()
bool IsFileError()
#define MULTI_UPDATE_CONTINUE
Definition: multi_update.h:20
const char * XSTR(const char *str, int index)
Definition: localize.cpp:851
int multi_update_http_do()
int multi_update_error_verifying()
#define strcat_s(...)
Definition: safe_strings.h:68
int multi_update_http_init()
#define MULTI_UPDATE_MAIN_MENU
Definition: multi_update.h:22
int multi_update_gobaby()
#define strcpy_s(...)
Definition: safe_strings.h:67