| 1 |
/* |
| 2 |
Copyright (C) 2009-2011 wxLauncher Team |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU General Public License |
| 6 |
as published by the Free Software Foundation; either version 2 |
| 7 |
of the License, or (at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "generated/configure_launcher.h" |
| 20 |
#include "apis/FlagListManager.h" |
| 21 |
#include "apis/ProfileManager.h" |
| 22 |
#include "apis/TCManager.h" |
| 23 |
#include "datastructures/FSOExecutable.h" |
| 24 |
#include "global/ProfileKeys.h" |
| 25 |
|
| 26 |
#include "global/MemoryDebugging.h" |
| 27 |
|
| 28 |
/** \class FlagListManager |
| 29 |
FlagListManager is used to notify controls that have registered with it |
| 30 |
that the flag file processing's status has changed. It also extracts |
| 31 |
the data in flag files generated by FS2 Open executables. */ |
| 32 |
LAUNCHER_DEFINE_EVENT_TYPE(EVT_FLAG_FILE_PROCESSING_STATUS_CHANGED); |
| 33 |
|
| 34 |
#include <wx/arrimpl.cpp> // Magic Incantation |
| 35 |
WX_DEFINE_OBJARRAY(FlagFileArray); |
| 36 |
|
| 37 |
EventHandlers FlagListManager::ffProcessingStatusChangedHandlers; |
| 38 |
|
| 39 |
void FlagListManager::RegisterFlagFileProcessingStatusChanged(wxEvtHandler *handler) { |
| 40 |
wxASSERT(FlagListManager::IsInitialized()); |
| 41 |
wxASSERT_MSG(ffProcessingStatusChangedHandlers.IndexOf(handler) == wxNOT_FOUND, |
| 42 |
wxString::Format( |
| 43 |
_T("RegisterFlagFileProcessingStatusChanged(): Handler at %p already registered."), |
| 44 |
handler)); |
| 45 |
FlagListManager::ffProcessingStatusChangedHandlers.Append(handler); |
| 46 |
} |
| 47 |
|
| 48 |
void FlagListManager::UnRegisterFlagFileProcessingStatusChanged(wxEvtHandler *handler) { |
| 49 |
wxASSERT(FlagListManager::IsInitialized()); |
| 50 |
wxASSERT_MSG(ffProcessingStatusChangedHandlers.IndexOf(handler) != wxNOT_FOUND, |
| 51 |
wxString::Format( |
| 52 |
_T("UnRegisterFlagFileProcessingStatusChanged(): Handler at %p not registered."), |
| 53 |
handler)); |
| 54 |
FlagListManager::ffProcessingStatusChangedHandlers.DeleteObject(handler); |
| 55 |
} |
| 56 |
|
| 57 |
void FlagListManager::GenerateFlagFileProcessingStatusChanged(const FlagFileProcessingStatus& status) { |
| 58 |
wxASSERT(FlagListManager::IsInitialized()); |
| 59 |
|
| 60 |
wxCommandEvent event(EVT_FLAG_FILE_PROCESSING_STATUS_CHANGED, wxID_NONE); |
| 61 |
event.SetInt(status); |
| 62 |
|
| 63 |
wxLogDebug(_T("Generating EVT_FLAG_FILE_PROCESSING_STATUS_CHANGED event")); |
| 64 |
for (EventHandlers::iterator |
| 65 |
iter = FlagListManager::ffProcessingStatusChangedHandlers.begin(), |
| 66 |
end = FlagListManager::ffProcessingStatusChangedHandlers.end(); |
| 67 |
iter != end; ++iter) { |
| 68 |
wxEvtHandler* current = *iter; |
| 69 |
current->AddPendingEvent(event); |
| 70 |
wxLogDebug(_T(" Sent EVT_FLAG_FILE_PROCESSING_STATUS_CHANGED event to %p"), current); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
FlagListManager* FlagListManager::flagListManager = NULL; |
| 75 |
|
| 76 |
bool FlagListManager::Initialize() { |
| 77 |
wxASSERT(!FlagListManager::IsInitialized()); |
| 78 |
|
| 79 |
FlagListManager::flagListManager = new FlagListManager(); |
| 80 |
return true; |
| 81 |
} |
| 82 |
|
| 83 |
void FlagListManager::DeInitialize() { |
| 84 |
wxASSERT(FlagListManager::IsInitialized()); |
| 85 |
|
| 86 |
if (!FlagListManager::ffProcessingStatusChangedHandlers.IsEmpty()) { |
| 87 |
wxLogDebug(_T("FlagListManager::DeInitialize(): contents of handler list:")); |
| 88 |
for (EventHandlers::const_iterator |
| 89 |
iter = FlagListManager::ffProcessingStatusChangedHandlers.begin(), |
| 90 |
end = FlagListManager::ffProcessingStatusChangedHandlers.end(); |
| 91 |
iter != end; ++iter) { |
| 92 |
wxLogDebug(_T(" handler at %p"), *iter); |
| 93 |
} |
| 94 |
FlagListManager::ffProcessingStatusChangedHandlers.Clear(); |
| 95 |
} |
| 96 |
|
| 97 |
FlagListManager* temp = FlagListManager::flagListManager; |
| 98 |
FlagListManager::flagListManager = NULL; |
| 99 |
delete temp; |
| 100 |
} |
| 101 |
|
| 102 |
bool FlagListManager::IsInitialized() { |
| 103 |
return (FlagListManager::flagListManager != NULL); |
| 104 |
} |
| 105 |
|
| 106 |
FlagListManager* FlagListManager::GetFlagListManager() { |
| 107 |
wxCHECK_MSG(FlagListManager::IsInitialized(), |
| 108 |
NULL, |
| 109 |
_T("Attempt to get flag list manager when it has not been initialized.")); |
| 110 |
|
| 111 |
return FlagListManager::flagListManager; |
| 112 |
} |
| 113 |
|
| 114 |
FlagListManager::FlagListManager() |
| 115 |
: data(NULL), proxyData(NULL), buildCaps(0) { |
| 116 |
TCManager::RegisterTCBinaryChanged(this); |
| 117 |
} |
| 118 |
|
| 119 |
FlagListManager::~FlagListManager() { |
| 120 |
TCManager::UnRegisterTCBinaryChanged(this); |
| 121 |
this->DeleteExistingData(); |
| 122 |
} |
| 123 |
|
| 124 |
BEGIN_EVENT_TABLE(FlagListManager, wxEvtHandler) |
| 125 |
EVT_COMMAND(wxID_NONE, EVT_TC_BINARY_CHANGED, FlagListManager::OnBinaryChanged) |
| 126 |
END_EVENT_TABLE() |
| 127 |
|
| 128 |
void FlagListManager::OnBinaryChanged(wxCommandEvent& event) { |
| 129 |
wxCHECK_RET(this->GetProcessingStatus() != WAITING_FOR_FLAG_FILE, |
| 130 |
_T("Received binary changed event in middle of flag file processing.")); |
| 131 |
|
| 132 |
this->DeleteExistingData(); |
| 133 |
this->SetProcessingStatus(INITIAL_STATUS); |
| 134 |
} |
| 135 |
|
| 136 |
void FlagListManager::DeleteExistingData() { |
| 137 |
if (this->data != NULL) { |
| 138 |
FlagFileData* temp = this->data; |
| 139 |
this->data = NULL; |
| 140 |
delete temp; |
| 141 |
} |
| 142 |
|
| 143 |
if (this->proxyData != NULL) { |
| 144 |
ProxyFlagData* temp = this->proxyData; |
| 145 |
this->proxyData = NULL; |
| 146 |
delete temp; |
| 147 |
} |
| 148 |
|
| 149 |
this->buildCaps = 0; |
| 150 |
} |
| 151 |
|
| 152 |
void FlagListManager::BeginFlagFileProcessing() { |
| 153 |
wxCHECK_RET(this->GetProcessingStatus() != WAITING_FOR_FLAG_FILE, |
| 154 |
_T("Began flag file processing while processing was underway.")); |
| 155 |
|
| 156 |
this->DeleteExistingData(); // don't leak any existing data |
| 157 |
|
| 158 |
this->data = new FlagFileData(); |
| 159 |
this->proxyData = new ProxyFlagData(); |
| 160 |
|
| 161 |
wxString tcPath, exeName; |
| 162 |
wxFileName exeFilename; |
| 163 |
|
| 164 |
wxLogDebug(_T("Initializing flag file processing.")); |
| 165 |
|
| 166 |
if ( !ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_ROOT_FOLDER, &tcPath) ) { |
| 167 |
this->SetProcessingStatus(MISSING_TC); |
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
if (!wxFileName::DirExists(tcPath)) { |
| 172 |
this->SetProcessingStatus(NONEXISTENT_TC); |
| 173 |
return; |
| 174 |
} |
| 175 |
|
| 176 |
if (!FSOExecutable::HasFSOExecutables(wxFileName(tcPath, wxEmptyString))) { |
| 177 |
this->SetProcessingStatus(INVALID_TC); |
| 178 |
return; |
| 179 |
} |
| 180 |
|
| 181 |
if ( !ProMan::GetProfileManager()->ProfileRead(PRO_CFG_TC_CURRENT_BINARY, &exeName)) { |
| 182 |
this->SetProcessingStatus(MISSING_EXE); |
| 183 |
return; |
| 184 |
} |
| 185 |
|
| 186 |
#if IS_APPLE // needed because on OSX exeName is a relative path from TC root dir |
| 187 |
exeFilename.Assign(tcPath + wxFileName::GetPathSeparator() + exeName); |
| 188 |
#else |
| 189 |
exeFilename.Assign(tcPath, exeName); |
| 190 |
#endif |
| 191 |
|
| 192 |
wxLogDebug(_T("exeName: ") + exeName); |
| 193 |
wxLogDebug(_T("exeFilename: ") + exeFilename.GetFullPath()); |
| 194 |
|
| 195 |
if (!exeFilename.FileExists()) { |
| 196 |
this->SetProcessingStatus(INVALID_BINARY); |
| 197 |
return; |
| 198 |
} |
| 199 |
// Make sure that the directory that I am going to change to exists |
| 200 |
wxFileName tempExecutionLocation; |
| 201 |
tempExecutionLocation.AssignDir(GetProfileStorageFolder()); |
| 202 |
tempExecutionLocation.AppendDir(_T("temp_flag_folder")); |
| 203 |
if ( !tempExecutionLocation.DirExists() |
| 204 |
&& !tempExecutionLocation.Mkdir() ) { |
| 205 |
|
| 206 |
wxLogError(_T("Unable to create flag folder at %s"), |
| 207 |
tempExecutionLocation.GetFullPath().c_str()); |
| 208 |
this->SetProcessingStatus(CANNOT_CREATE_FLAGFILE_FOLDER); |
| 209 |
return; |
| 210 |
} |
| 211 |
|
| 212 |
FlagFileArray flagFileLocations; |
| 213 |
flagFileLocations.Add(wxFileName(tcPath, _T("flags.lch"))); |
| 214 |
flagFileLocations.Add(wxFileName(tempExecutionLocation.GetFullPath(), _T("flags.lch"))); |
| 215 |
|
| 216 |
// remove potential flag files to eliminate any confusion. |
| 217 |
for( size_t i = 0; i < flagFileLocations.Count(); i++ ) { |
| 218 |
bool exists = flagFileLocations[i].FileExists(); |
| 219 |
if (exists) { |
| 220 |
::wxRemoveFile(flagFileLocations[i].GetFullPath()); |
| 221 |
wxLogDebug(_T(" Cleaned up %s ... %s"), |
| 222 |
flagFileLocations[i].GetFullPath().c_str(), |
| 223 |
(flagFileLocations[i].FileExists())? _T("Failed") : _T("Removed")); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
wxString commandline; |
| 228 |
// use "" to correct for spaces in path to exeFilename |
| 229 |
if (exeFilename.GetFullPath().Find(_T(" ")) != wxNOT_FOUND) { |
| 230 |
commandline = _T("\"") + exeFilename.GetFullPath() + _T("\"") + _T(" -get_flags"); |
| 231 |
} else { |
| 232 |
commandline = exeFilename.GetFullPath() + _T(" -get_flags"); |
| 233 |
} |
| 234 |
|
| 235 |
wxLogDebug(_T(" Called FS2 Open with command line '%s'."), commandline.c_str()); |
| 236 |
FlagProcess *process = new FlagProcess(flagFileLocations); |
| 237 |
|
| 238 |
#if wxCHECK_VERSION(2, 9, 2) |
| 239 |
wxExecuteEnv env; |
| 240 |
env.cwd = tempExecutionLocation.GetFullPath(); |
| 241 |
|
| 242 |
::wxExecute(commandline, wxEXEC_ASYNC, process, &env); |
| 243 |
#else |
| 244 |
wxString previousWorkingDir(::wxGetCwd()); |
| 245 |
// hopefully this doesn't goof anything up |
| 246 |
if (!::wxSetWorkingDirectory(tempExecutionLocation.GetFullPath())) { |
| 247 |
wxLogError(_T("Unable to change working directory to %s"), |
| 248 |
tempExecutionLocation.GetFullPath().c_str()); |
| 249 |
this->SetProcessingStatus(CANNOT_CHANGE_WORKING_FOLDER); |
| 250 |
delete process; |
| 251 |
return; |
| 252 |
} |
| 253 |
|
| 254 |
::wxExecute(commandline, wxEXEC_ASYNC, process); |
| 255 |
|
| 256 |
if ( !::wxSetWorkingDirectory(previousWorkingDir) ) { |
| 257 |
wxLogError(_T("Unable to change back to working directory %s"), |
| 258 |
previousWorkingDir.c_str()); |
| 259 |
this->SetProcessingStatus(CANNOT_CHANGE_WORKING_FOLDER); |
| 260 |
return; |
| 261 |
} |
| 262 |
#endif |
| 263 |
|
| 264 |
this->SetProcessingStatus(WAITING_FOR_FLAG_FILE); |
| 265 |
} |
| 266 |
|
| 267 |
wxString FlagListManager::GetStatusMessage() const { |
| 268 |
wxCHECK_MSG(!this->IsProcessingOK(), wxEmptyString, |
| 269 |
_T("status message requested, even though processing succeeded")); |
| 270 |
|
| 271 |
wxString msg; |
| 272 |
|
| 273 |
switch(this->GetProcessingStatus()) { |
| 274 |
case INITIAL_STATUS: |
| 275 |
msg = _("Waiting for flag file processing to be initialized."); |
| 276 |
break; |
| 277 |
case MISSING_TC: |
| 278 |
msg = _("No FS2 Open game has been selected.\n\nSelect the root folder of an FS2 Open game on the Basic Settings page."); |
| 279 |
break; |
| 280 |
case NONEXISTENT_TC: |
| 281 |
msg = _("The selected root folder does not exist.\n\nSelect a different FS2 Open game on the Basic Settings page."); |
| 282 |
break; |
| 283 |
case INVALID_TC: |
| 284 |
msg = wxString(_("The selected root folder does not contain any FS2 Open executables.\n\n")) + |
| 285 |
_("On the Basic Settings page, either select a different root folder, or add FS2 Open executables to the selected root folder and press the Refresh button."); |
| 286 |
break; |
| 287 |
case MISSING_EXE: |
| 288 |
msg = _("No FS2 Open executable has been selected.\n\nSelect an executable on the Basic Settings page."); |
| 289 |
break; |
| 290 |
case INVALID_BINARY: |
| 291 |
msg = _("The selected FS2 Open executable does not exist.\n\nSelect another on the Basic Settings page."); |
| 292 |
break; |
| 293 |
case WAITING_FOR_FLAG_FILE: |
| 294 |
msg = _("Waiting for flag file to be generated and parsed."); |
| 295 |
break; |
| 296 |
case FLAG_FILE_NOT_GENERATED: |
| 297 |
msg = _("The executable did not generate a flag file.\n\nMake sure that the executable is an FS2 Open executable."); |
| 298 |
break; |
| 299 |
case FLAG_FILE_NOT_VALID: |
| 300 |
msg = _("Generated flag file was not complete.\n\nPlease talk to a maintainer of this launcher, since you probably found a bug."); |
| 301 |
break; |
| 302 |
case FLAG_FILE_NOT_SUPPORTED: |
| 303 |
msg = _("Generated flag file is not supported.\n\nUpdate the launcher or talk to a maintainer of this launcher if you have the most recent version."); |
| 304 |
break; |
| 305 |
default: |
| 306 |
msg = wxString::Format( |
| 307 |
_("Unknown error (%d) occurred while obtaining the flag file from the FS2 Open executable."), |
| 308 |
this->GetProcessingStatus()); |
| 309 |
break; |
| 310 |
} |
| 311 |
|
| 312 |
return msg; |
| 313 |
} |
| 314 |
|
| 315 |
FlagFileData* FlagListManager::GetFlagFileData() { |
| 316 |
wxCHECK_MSG(this->IsProcessingOK(), NULL, |
| 317 |
_T("attempt to get flag file data even though processing hasn't succeeded")); |
| 318 |
|
| 319 |
wxCHECK_MSG(this->data != NULL, NULL, |
| 320 |
_T("attempt to get flag file data after it has already been retrieved")); |
| 321 |
|
| 322 |
FlagFileData* temp = this->data; |
| 323 |
this->data = NULL; |
| 324 |
return temp; |
| 325 |
} |
| 326 |
|
| 327 |
ProxyFlagData* FlagListManager::GetProxyFlagData() { |
| 328 |
wxCHECK_MSG(this->IsProcessingOK(), NULL, |
| 329 |
_T("attempt to get proxy flag data list even though processing hasn't succeeded")); |
| 330 |
|
| 331 |
wxCHECK_MSG(this->proxyData != NULL, NULL, |
| 332 |
_T("attempt to get proxy flag data list after it has already been retrieved")); |
| 333 |
|
| 334 |
ProxyFlagData* temp = this->proxyData; |
| 335 |
this->proxyData = NULL; |
| 336 |
return temp; |
| 337 |
} |
| 338 |
|
| 339 |
wxByte FlagListManager::GetBuildCaps() const { |
| 340 |
wxCHECK_MSG(this->IsProcessingOK(), 0, |
| 341 |
_T("attempt to get build caps even though processing hasn't succeeded")); |
| 342 |
|
| 343 |
return this->buildCaps; |
| 344 |
} |
| 345 |
|
| 346 |
FlagListManager::ProcessingStatus FlagListManager::ParseFlagFile(const wxFileName& flagfilename) { |
| 347 |
if (!flagfilename.FileExists()) { |
| 348 |
wxLogError(_T("The FS2 Open executable did not generate a flag file.")); |
| 349 |
return FLAG_FILE_NOT_GENERATED; |
| 350 |
} |
| 351 |
|
| 352 |
wxFile flagfile(flagfilename.GetFullPath()); |
| 353 |
wxLogDebug(_T("Reading flag file %s."), flagfilename.GetFullPath().c_str()); |
| 354 |
// Flagfile requires that we use 32 bit little-endian numbers |
| 355 |
wxInt32 easy_flag_size, flag_size, num_easy_flags, num_flags; |
| 356 |
size_t bytesRead; |
| 357 |
|
| 358 |
bytesRead = flagfile.Read(&easy_flag_size, sizeof(easy_flag_size)); |
| 359 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(easy_flag_size) ) { |
| 360 |
wxLogError(_T(" Flag file is too short (failed to read easy_flag_size)")); |
| 361 |
return FLAG_FILE_NOT_VALID; |
| 362 |
} |
| 363 |
if ( easy_flag_size != 32 ) { |
| 364 |
wxLogError(_T(" Easy flag size (%d) is not supported"), easy_flag_size); |
| 365 |
return FLAG_FILE_NOT_SUPPORTED; |
| 366 |
} |
| 367 |
|
| 368 |
bytesRead = flagfile.Read(&flag_size, sizeof(flag_size)); |
| 369 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(flag_size) ) { |
| 370 |
wxLogError(_T(" Flag file is too short (failed to read flag_size)")); |
| 371 |
return FLAG_FILE_NOT_VALID; |
| 372 |
} |
| 373 |
if ( flag_size != 344 ) { |
| 374 |
wxLogError(_T(" Exe flag structure (%d) size is not supported"), flag_size); |
| 375 |
return FLAG_FILE_NOT_SUPPORTED; |
| 376 |
} |
| 377 |
|
| 378 |
bytesRead = flagfile.Read(&num_easy_flags, sizeof(num_easy_flags)); |
| 379 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(num_easy_flags) ) { |
| 380 |
wxLogError(_T(" Flag file is too short (failed to read num_easy_flags)")); |
| 381 |
return FLAG_FILE_NOT_VALID; |
| 382 |
} |
| 383 |
|
| 384 |
for ( int i = 0; i < num_easy_flags; i++ ) { |
| 385 |
char easy_flag[32]; |
| 386 |
bytesRead = flagfile.Read(&easy_flag, sizeof(easy_flag)); |
| 387 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(easy_flag) ) { |
| 388 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (easy_flag)"), sizeof(easy_flag), bytesRead); |
| 389 |
return FLAG_FILE_NOT_VALID; |
| 390 |
} |
| 391 |
wxString easyFlagStr(easy_flag, wxConvUTF8, strlen(easy_flag)); |
| 392 |
this->data->AddEasyFlag(easyFlagStr); |
| 393 |
} |
| 394 |
|
| 395 |
bytesRead = flagfile.Read(&num_flags, sizeof(num_flags)); |
| 396 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(num_flags) ) { |
| 397 |
wxLogError(_T(" Flag file is too short (failed to read num_flags)")); |
| 398 |
return FLAG_FILE_NOT_VALID; |
| 399 |
} |
| 400 |
|
| 401 |
for ( int i = 0; i < num_flags; i++ ) { |
| 402 |
char flag_string[20]; |
| 403 |
char description[40]; |
| 404 |
wxInt32 fso_only, easy_on_flags, easy_off_flags; |
| 405 |
char easy_catagory[16], web_url[256]; |
| 406 |
|
| 407 |
bytesRead = flagfile.Read(&flag_string, sizeof(flag_string)); |
| 408 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(flag_string) ) { |
| 409 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (flag_string)"), sizeof(flag_string), bytesRead); |
| 410 |
return FLAG_FILE_NOT_VALID; |
| 411 |
} |
| 412 |
|
| 413 |
bytesRead = flagfile.Read(&description, sizeof(description)); |
| 414 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(description) ) { |
| 415 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (description)"), sizeof(description), bytesRead); |
| 416 |
return FLAG_FILE_NOT_VALID; |
| 417 |
} |
| 418 |
|
| 419 |
bytesRead = flagfile.Read(&fso_only, sizeof(fso_only)); |
| 420 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(fso_only) ) { |
| 421 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (fso_only)"), sizeof(fso_only), bytesRead); |
| 422 |
return FLAG_FILE_NOT_VALID; |
| 423 |
} |
| 424 |
|
| 425 |
bytesRead = flagfile.Read(&easy_on_flags, sizeof(easy_on_flags)); |
| 426 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(easy_on_flags) ) { |
| 427 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (easy_on_flags)"), sizeof(easy_on_flags), bytesRead); |
| 428 |
return FLAG_FILE_NOT_VALID; |
| 429 |
} |
| 430 |
|
| 431 |
bytesRead = flagfile.Read(&easy_off_flags, sizeof(easy_off_flags)); |
| 432 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(easy_off_flags) ) { |
| 433 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (easy_off_flags)"), sizeof(easy_off_flags), bytesRead); |
| 434 |
return FLAG_FILE_NOT_VALID; |
| 435 |
} |
| 436 |
|
| 437 |
bytesRead = flagfile.Read(&easy_catagory, sizeof(easy_catagory)); |
| 438 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(easy_catagory) ) { |
| 439 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (easy_category)"), sizeof(easy_catagory), bytesRead); |
| 440 |
return FLAG_FILE_NOT_VALID; |
| 441 |
} |
| 442 |
|
| 443 |
bytesRead = flagfile.Read(&web_url, sizeof(web_url)); |
| 444 |
if ( (size_t)wxInvalidOffset == bytesRead || bytesRead != sizeof(web_url) ) { |
| 445 |
wxLogError(_T(" Flag file is too short, expected %d, got %ld bytes (web_url)"), sizeof(web_url), bytesRead); |
| 446 |
return FLAG_FILE_NOT_VALID; |
| 447 |
} |
| 448 |
|
| 449 |
flag_string[sizeof(flag_string)-1] = _T('\0'); |
| 450 |
description[sizeof(description)-1] = _T('\0'); |
| 451 |
easy_catagory[sizeof(easy_catagory)-1] = _T('\0'); |
| 452 |
web_url[sizeof(web_url)-1] = _T('\0'); |
| 453 |
|
| 454 |
Flag* flag = new Flag(); |
| 455 |
|
| 456 |
flag->flagString = wxString(flag_string, wxConvUTF8, strlen(flag_string)); |
| 457 |
flag->shortDescription = wxString(description, wxConvUTF8, strlen(description)); |
| 458 |
flag->webURL = wxString(web_url, wxConvUTF8, strlen(web_url)); |
| 459 |
flag->fsoCatagory = wxString(easy_catagory, wxConvUTF8, strlen(easy_catagory)); |
| 460 |
flag->isRecomendedFlag = false; // much better from a UI point of view than "true" |
| 461 |
|
| 462 |
flag->easyEnable = easy_on_flags; |
| 463 |
flag->easyDisable = easy_off_flags; |
| 464 |
|
| 465 |
this->data->AddFlag(flag); |
| 466 |
} |
| 467 |
|
| 468 |
wxLogDebug(_T(" easy_flag_size: %d, %lu; flag_size: %d, %lu; num_easy_flags: %d, %lu; num_flags: %d, %lu"), |
| 469 |
easy_flag_size, sizeof(easy_flag_size), |
| 470 |
flag_size, sizeof(flag_size), |
| 471 |
num_easy_flags, sizeof(num_easy_flags), |
| 472 |
num_flags, sizeof(num_flags)); |
| 473 |
|
| 474 |
// build capabilities, which are needed for supporting the new sound code |
| 475 |
wxByte buildCaps; |
| 476 |
bytesRead = flagfile.Read(&buildCaps, sizeof(buildCaps)); |
| 477 |
if ( (size_t)wxInvalidOffset == bytesRead ) { |
| 478 |
wxLogInfo(_T(" Old build that does not output its capabilities, must not support OpenAL")); |
| 479 |
buildCaps = 0; |
| 480 |
} |
| 481 |
this->buildCaps = buildCaps; |
| 482 |
|
| 483 |
this->data->GenerateFlagSets(); |
| 484 |
|
| 485 |
this->proxyData = this->data->GenerateProxyFlagData(); |
| 486 |
|
| 487 |
return PROCESSING_OK; |
| 488 |
} |
| 489 |
|
| 490 |
void FlagListManager::SetProcessingStatus(const ProcessingStatus& processingStatus) { |
| 491 |
this->processingStatus = processingStatus; |
| 492 |
wxLogDebug(_T("current flag file processing status: %d"), processingStatus); |
| 493 |
this->GenerateFlagFileProcessingStatusChanged(this->GetFlagFileProcessingStatus()); |
| 494 |
} |
| 495 |
|
| 496 |
FlagListManager::FlagFileProcessingStatus FlagListManager::GetFlagFileProcessingStatus() const { |
| 497 |
const ProcessingStatus& processingStatus = this->GetProcessingStatus(); |
| 498 |
|
| 499 |
if (processingStatus == PROCESSING_OK) { |
| 500 |
return FlagListManager::FLAG_FILE_PROCESSING_OK; |
| 501 |
} else if (processingStatus == WAITING_FOR_FLAG_FILE) { |
| 502 |
return FlagListManager::FLAG_FILE_PROCESSING_WAITING; |
| 503 |
} else if (processingStatus == INITIAL_STATUS) { |
| 504 |
return FlagListManager::FLAG_FILE_PROCESSING_RESET; |
| 505 |
} else { |
| 506 |
return FlagListManager::FLAG_FILE_PROCESSING_ERROR; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
FlagListManager::FlagProcess::FlagProcess(FlagFileArray flagFileLocations) |
| 511 |
: flagFileLocations(flagFileLocations) { |
| 512 |
} |
| 513 |
|
| 514 |
void FlagListManager::FlagProcess::OnTerminate(int pid, int status) { |
| 515 |
wxLogDebug(_T(" FS2 Open returned %d when polled for the flags"), status); |
| 516 |
|
| 517 |
// Find the flag file |
| 518 |
wxFileName flagfile; |
| 519 |
for( size_t i = 0; i < flagFileLocations.Count(); i++ ) { |
| 520 |
bool exists = flagFileLocations[i].FileExists(); |
| 521 |
if (exists) { |
| 522 |
flagfile = flagFileLocations[i]; |
| 523 |
wxLogDebug(_T(" Searching for flag file at %s ... %s"), |
| 524 |
flagFileLocations[i].GetFullPath().c_str(), |
| 525 |
(flagFileLocations[i].FileExists())? _T("Located") : _T("Not Here")); |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
if ( !flagfile.FileExists() ) { |
| 530 |
FlagListManager::GetFlagListManager()->SetProcessingStatus(FLAG_FILE_NOT_GENERATED); |
| 531 |
wxLogError(_T(" FS2 Open did not generate a flag file.")); |
| 532 |
return; |
| 533 |
} |
| 534 |
|
| 535 |
FlagListManager::GetFlagListManager()->SetProcessingStatus( |
| 536 |
FlagListManager::GetFlagListManager()->ParseFlagFile(flagfile)); |
| 537 |
|
| 538 |
if ( FlagListManager::GetFlagListManager()->IsProcessingOK() ) { |
| 539 |
::wxRemoveFile(flagfile.GetFullPath()); |
| 540 |
} |
| 541 |
|
| 542 |
delete this; |
| 543 |
} |