This function makes certain that the pilot data is up to date with the actual pilot file, writing if needed.
| 410 | // This function makes certain that the pilot data is up to date with the |
| 411 | // actual pilot file, writing if needed. |
| 412 | int pilot::flush(bool new_file) { |
| 413 | if (!write_pending) |
| 414 | return PLTW_NO_ERROR; // no need to write, data hasn't changed |
| 415 | |
| 416 | if (!filename) { |
| 417 | Int3(); |
| 418 | return PLTW_NO_FILENAME; // no filename was given |
| 419 | } |
| 420 | |
| 421 | CFILE *file; |
| 422 | char real_filename[_MAX_PATH]; |
| 423 | |
| 424 | // open and process file |
| 425 | ddio_MakePath(real_filename, Base_directory, filename, NULL); |
| 426 | |
| 427 | if (new_file && cfexist(real_filename)) { |
| 428 | // the file already exists, we can't write out |
| 429 | mprintf(0, "PLTW: File (%s) exists, can't create\n", real_filename); |
| 430 | return PLTW_FILE_EXISTS; |
| 431 | } |
| 432 | |
| 433 | try { |
| 434 | verify(); |
| 435 | |
| 436 | file = cfopen(real_filename, "wb"); |
| 437 | if (!file) { |
| 438 | mprintf(0, "PLTW: File (%s) can't be opened\n", real_filename); |
| 439 | return PLTW_FILE_CANTOPEN; |
| 440 | } |
| 441 | |
| 442 | // Write out our fileversion |
| 443 | file_version = PLT_FILE_VERSION; |
| 444 | cf_WriteInt(file, file_version); |
| 445 | |
| 446 | write_name(file); |
| 447 | write_ship_info(file); |
| 448 | write_custom_multiplayer_data(file); |
| 449 | write_difficulty(file); |
| 450 | write_profanity_filter(file); |
| 451 | write_audiotaunts(file); |
| 452 | write_hud_data(file); |
| 453 | write_mission_data(file); |
| 454 | write_taunts(file); |
| 455 | write_weapon_select(file); |
| 456 | write_gameplay_toggles(file); // version 0x24 PFV_GAMETOGGLES |
| 457 | write_guidebot_name(file); |
| 458 | write_controls(file); |
| 459 | |
| 460 | cfclose(file); |
| 461 | |
| 462 | } catch (cfile_error) { |
| 463 | // catch and handle CFILE errors |
| 464 | mprintf(0, "PLTW: CFILE Exception writing data\n"); |
| 465 | Int3(); |
| 466 | try { |
| 467 | cfclose(file); |
| 468 | } catch (...) { |
| 469 | mprintf(0, "PLTW: Unable to close file due to exception\n"); |
no test coverage detected