bool deleteAll(const char* filePath, bool deleteRoot) { PHYSFS_Stat fileStat; if (PHYSFS_stat(filePath, &fileStat) == 0) { return false; } bool ret = false; if (fileStat.filetype == PHYSFS_FILETYPE_DIRECTORY) { auto paths = PHYSFS_enumerateFiles(filePath); if (paths != nullptr) { auto writeDir = PHYSFS_getWriteDir(); if (writeDir != nullptr) { for (char** path = paths; *path != nullptr; path++) { auto fullPath = std::string(filePath) + '/' + *path; if (PHYSFS_stat(fullPath.c_str(), &fileStat) == 0) { continue; } if (fileStat.filetype == PHYSFS_FILETYPE_DIRECTORY) { deleteAll(fullPath.c_str(), true); } else { auto realDir = PHYSFS_getRealDir(fullPath.c_str()); if (realDir != nullptr) { if (std::strcmp(writeDir, realDir) == 0) { ret = PHYSFS_delete(fullPath.c_str()) != 0; } } } } } PHYSFS_freeList(paths); } if (deleteRoot == true) { ret = PHYSFS_delete(filePath) != 0; } } else { ret = PHYSFS_delete(filePath) != 0; } return ret; }
bool CResourceManager::RemoveDirectory(const std::string& directory) { if (PHYSFS_isInit()) { std::string path = CleanPath(directory); for (auto file : ListFiles(path)) { if (PHYSFS_delete((path + "/" + file).c_str()) == 0) return false; } return PHYSFS_delete(path.c_str()) != 0; } return false; }
bool Resources::remove(const char* filename) { if(!PHYSFS_delete(filename)) { PError << "couldn't remove file '" << filename << "': " << PHYSFS_getLastError() << endl; return PFalse; }; return PTrue; }
bool vsFile::Delete( const vsString &filename ) // static method { if ( DirectoryExists(filename) ) // This file is a directory, don't delete it! return false; return PHYSFS_delete(filename.c_str()) != 0; }
bool CResourceManager::Remove(const std::string& filename) { if (PHYSFS_isInit()) { return PHYSFS_delete(filename.c_str()) != 0; } return false; }
int ex_fsys_rm ( const char *_filename ) { if ( ex_fsys_isfile (_filename) ) { __PHYSFS_CHECK( PHYSFS_delete(_filename) ); return 0; } ex_set_error ( "[fsys] Error: %s is not a file", _filename ); return -1; }
/**Deletes a file from the filesystem * \param filename Filename relative to PHYSFS writedir to delete * \return True on success */ bool Filesystem::DeleteFile( const string &filename ) { int retval; if( (retval = PHYSFS_delete( filename.c_str() ) ) == 0 ) { LogMsg(ERR, "Could not delete file (%s): %s\n", filename.c_str(), PHYSFS_getLastError()); return false; } return true; }
void DeleteFile(std::string path) { if (!IsLoaded()) { Logger::begin("Filesystem", Logger::LogLevel_Error) << "FS not loaded" << Logger::end(); return; } if (!hasSetUserDir) { Logger::begin("Filesystem", Logger::LogLevel_Error) << "UserDir needs to be set to touchFiles" << Logger::end(); return; } PHYSFS_delete(path.c_str()); }
bool vsFile::DeleteEmptyDirectory( const vsString &filename ) { // If it's not a directory, don't delete it! // // Note that PHYSFS_delete will return an error if we // try to delete a non-empty directory. // if ( DirectoryExists(filename) ) return PHYSFS_delete(filename.c_str()) != 0; return false; }
void AddonManager::install_addon(const AddonId& addon_id) { { // remove addon if it already exists auto it = std::find_if(m_installed_addons.begin(), m_installed_addons.end(), [&addon_id](const std::unique_ptr<Addon>& addon) { return addon->get_id() == addon_id; }); if (it != m_installed_addons.end()) { log_debug << "reinstalling addon " << addon_id << std::endl; if ((*it)->is_enabled()) { disable_addon((*it)->get_id()); } m_installed_addons.erase(it); } else { log_debug << "installing addon " << addon_id << std::endl; } } auto& repository_addon = get_repository_addon(addon_id); std::string install_filename = FileSystem::join(m_addon_directory, repository_addon.get_filename()); m_downloader.download(repository_addon.get_url(), install_filename); MD5 md5 = md5_from_file(install_filename); if (repository_addon.get_md5() != md5.hex_digest()) { if (PHYSFS_delete(install_filename.c_str()) == 0) { log_warning << "PHYSFS_delete failed: " << PHYSFS_getLastError() << std::endl; } throw std::runtime_error("Downloading Add-on failed: MD5 checksums differ"); } else { const char* realdir = PHYSFS_getRealDir(install_filename.c_str()); if (!realdir) { throw std::runtime_error("PHYSFS_getRealDir failed: " + install_filename); } else { add_installed_archive(install_filename, md5.hex_digest()); } } }
int ex_fsys_rmdir ( const char *_dir, bool _force ) { if ( ex_fsys_isdir (_dir) ) { // TODO: if force, remove all the files in the directory, then delete it. // if not, check if the directory is empty and delete it. __PHYSFS_CHECK( PHYSFS_delete(_dir) ); return 0; } ex_set_error ( "[fsys] Error: %s is not a directory", _dir ); return -1; }
bool Filesystem::unlink(const std::string &filename) { int failure; failure = PHYSFS_delete(filename.c_str()); if (failure) { return false; } else { return true; } }
/*************************************************************************** Delete a savegame. saveGameName should be a .gam extension save game filename reference. We delete this file, any .es file with the same name, and any files in the directory with the same name. ***************************************************************************/ void deleteSaveGame(char* saveGameName) { char **files, **i; ASSERT( strlen(saveGameName) < MAX_STR_LENGTH,"deleteSaveGame; save game name too long" ); PHYSFS_delete(saveGameName); saveGameName[strlen(saveGameName)-4] = '\0';// strip extension strcat(saveGameName,".es"); // remove script data if it exists. PHYSFS_delete(saveGameName); saveGameName[strlen(saveGameName)-3] = '\0';// strip extension // check for a directory and remove that too. files = PHYSFS_enumerateFiles(saveGameName); for (i = files; *i != NULL; ++i) { char del_file[PATH_MAX]; // Construct the full path to the file by appending the // filename to the directory it is in. snprintf(del_file, sizeof(del_file), "%s/%s", saveGameName, *i); debug(LOG_SAVE, "Deleting [%s].", del_file); // Delete the file if (!PHYSFS_delete(del_file)) { debug(LOG_ERROR, "Warning [%s] could not be deleted due to PhysicsFS error: %s", del_file, PHYSFS_getLastError()); } } PHYSFS_freeList(files); if (!PHYSFS_delete(saveGameName)) // now (should be)empty directory { debug(LOG_ERROR, "Warning directory[%s] could not be deleted because %s", saveGameName,PHYSFS_getLastError()); } return; }
bool deleteFile(const char* filePath) noexcept { auto writeDir = PHYSFS_getWriteDir(); auto realDir = PHYSFS_getRealDir(filePath); if (writeDir != nullptr && realDir != nullptr) { if (strcmp(writeDir, realDir) == 0) { return PHYSFS_delete(filePath) != 0; } } return false; }
bool j1FileSystem::DeleteSaveFile() { p2SString save_file("save_state"); bool ret = (PHYSFS_delete(save_file.GetString()) != 0); if (ret == false) { LOG("File system error when trying to delete Save State file: %s \n", PHYSFS_getLastError()); } return ret; }
/******************************** * EntityCompiler_ExtractRoutines * count the anomunt of entities @ data: int * @ origdir: @ fname: */ static void EntityCompiler_ExtractRoutines(void * data, const char *origdir, const char *fname) { if ( g_str_has_suffix(fname, ".inc") && !g_str_has_prefix(fname, "private_") ) { gchar * internal_file_path = g_strdup_printf("%s/%s", origdir, fname); gchar * content = NULL; PHYSFS_mkdir(origdir); PHYSFS_delete( internal_file_path ); if ( Meg_file_get_contents(internal_file_path, &content, NULL, NULL) ) Meg_file_set_contents(internal_file_path, content, -1, NULL); } }
bool physfsDrive::RemoveDir(const char * dir) { char newdir[CROSS_LEN]; strcpy(newdir,basedir); strcat(newdir,dir); CROSS_FILENAME(newdir); dirCache.ExpandName(newdir); normalize(newdir,basedir); if (PHYSFS_isDirectory(newdir) && PHYSFS_delete(newdir)) { CROSS_FILENAME(newdir); dirCache.DeleteEntry(newdir,true); return true; } return false; }
bool physfsDrive::FileUnlink(const char * name) { char newname[CROSS_LEN]; strcpy(newname,basedir); strcat(newname,name); CROSS_FILENAME(newname); dirCache.ExpandName(newname); normalize(newname,basedir); if (PHYSFS_delete(newname)) { CROSS_FILENAME(newname); dirCache.DeleteEntry(newname); return true; }; return false; }
static int cmd_delete(char *args) { if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ if (PHYSFS_delete(args)) printf("Successful.\n"); else printf("Failure. reason: %s.\n", PHYSFS_getLastError()); return(1); } /* cmd_delete */
void finish_zip(const char *zipname) { int len = strlen(zipname); if (zipname[len-4] == '.' || zipname[len-3] == 't' || zipname[len-2] == 'm' || zipname[len-1] == 'p') { char *newname = strdup(zipname); newname[len - 4] = '\0'; PHYSFS_delete(newname); PHYSFS_rename(zipname, newname); push_save_return(newname); free(newname); } else { push_save_return(zipname); } }
void AddonManager::uninstall_addon(const AddonId& addon_id) { log_debug << "uninstalling addon " << addon_id << std::endl; auto& addon = get_installed_addon(addon_id); if (addon.is_enabled()) { disable_addon(addon_id); } log_debug << "deleting file \"" << addon.get_install_filename() << "\"" << std::endl; PHYSFS_delete(addon.get_install_filename().c_str()); m_installed_addons.erase(std::remove_if(m_installed_addons.begin(), m_installed_addons.end(), [&addon](const std::unique_ptr<Addon>& rhs) { return addon.get_id() == rhs->get_id(); }), m_installed_addons.end()); }
void probeDir(const std::string& dirname) { if (PHYSFS_isDirectory(dirname.c_str()) == 0) { if (PHYSFS_exists(dirname.c_str())) { PHYSFS_delete(dirname.c_str()); } if (PHYSFS_mkdir(dirname.c_str())) { std::cout << PHYSFS_getWriteDir() << dirname << " created" << std::endl; } else { std::cout << "Warning: Creation of" << PHYSFS_getWriteDir() << dirname << " failed!" << std::endl; } } }
// ----------------------------------------------------------------------------- // Called when control center gets destroyed. // This code is common to whether control center is implicitly imbedded in a boss, // or is an object of its own. // if objp == NULL that means the boss was the control center and don't set Dead_controlcen_object_num void do_controlcen_destroyed_stuff(object *objp) { int i; if ((Game_mode & GM_MULTI_ROBOTS) && Control_center_destroyed) return; // Don't allow resetting if control center and boss on same level // Must toggle walls whether it is a boss or control center. for (i=0;i<ControlCenterTriggers.num_links;i++) wall_toggle(&Segments[ControlCenterTriggers.seg[i]], ControlCenterTriggers.side[i]); // And start the countdown stuff. Control_center_destroyed = 1; // If a secret level, delete secret.sgc to indicate that we can't return to our secret level. if (Current_level_num < 0) { int rval; rval = !PHYSFS_delete(PLAYER_DIR "secret.sgc"); mprintf((0, "Deleting secret.sgc, return value = %i\n", rval)); } if (Base_control_center_explosion_time != DEFAULT_CONTROL_CENTER_EXPLOSION_TIME) Total_countdown_time = Base_control_center_explosion_time + Base_control_center_explosion_time * (NDL-Difficulty_level-1)/2; else Total_countdown_time = Alan_pavlish_reactor_times[Difficulty_level]; Countdown_timer = i2f(Total_countdown_time); if (!Control_center_present || objp==NULL) { //Assert(objp == NULL); return; } //Assert(objp != NULL); Dead_controlcen_object_num = OBJECT_NUMBER(objp); }
int fs_remove(const char *path) { return PHYSFS_delete(path); }
void deleteFile(const string& filename) { PHYSFS_delete(filename.c_str()); }
static int cmd_stressbuffer(char *args) { int num; if (*args == '\"') { args++; args[strlen(args) - 1] = '\0'; } /* if */ num = atoi(args); if (num < 0) printf("buffer must be greater than or equal to zero.\n"); else { PHYSFS_File *f; int rndnum; printf("Stress testing with (%d) byte buffer...\n", num); f = PHYSFS_openWrite("test.txt"); if (f == NULL) printf("Couldn't open test.txt for writing: %s.\n", PHYSFS_getLastError()); else { int i, j; char buf[37]; char buf2[37]; if (!PHYSFS_setBuffer(f, num)) { printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); PHYSFS_delete("test.txt"); return(1); } /* if */ strcpy(buf, "abcdefghijklmnopqrstuvwxyz0123456789"); srand((unsigned int) time(NULL)); for (i = 0; i < 10; i++) { for (j = 0; j < 10000; j++) { PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0)); PHYSFS_uint32 left = 36 - right; if (PHYSFS_write(f, buf, left, 1) != 1) { printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0)); if (rndnum == 42) { if (!PHYSFS_flush(f)) { printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ } /* if */ if (PHYSFS_write(f, buf + left, 1, right) != right) { printf("PHYSFS_write() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0)); if (rndnum == 42) { if (!PHYSFS_flush(f)) { printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ } /* if */ } /* for */ if (!PHYSFS_flush(f)) { printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ } /* for */ if (!PHYSFS_close(f)) { printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError()); return(1); /* oh well. */ } /* if */ printf(" ... test file written ...\n"); f = PHYSFS_openRead("test.txt"); if (f == NULL) { printf("Failed to reopen stress file for reading: %s.\n", PHYSFS_getLastError()); return(1); } /* if */ if (!PHYSFS_setBuffer(f, num)) { printf("PHYSFS_setBuffer() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ for (i = 0; i < 10; i++) { for (j = 0; j < 10000; j++) { PHYSFS_uint32 right = 1 + (PHYSFS_uint32) (35.0 * rand() / (RAND_MAX + 1.0)); PHYSFS_uint32 left = 36 - right; if (PHYSFS_read(f, buf2, left, 1) != 1) { printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0)); if (rndnum == 42) { if (!PHYSFS_flush(f)) { printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ } /* if */ if (PHYSFS_read(f, buf2 + left, 1, right) != right) { printf("PHYSFS_read() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ rndnum = 1 + (int) (1000.0 * rand() / (RAND_MAX + 1.0)); if (rndnum == 42) { if (!PHYSFS_flush(f)) { printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ } /* if */ if (memcmp(buf, buf2, 36) != 0) { printf("readback is mismatched on iterations (%d, %d).\n", i, j); printf("wanted: ["); for (i = 0; i < 36; i++) printf("%c", buf[i]); printf("]\n"); printf(" got: ["); for (i = 0; i < 36; i++) printf("%c", buf2[i]); printf("]\n"); PHYSFS_close(f); return(1); } /* if */ } /* for */ if (!PHYSFS_flush(f)) { printf("PHYSFS_flush() failed: %s.\n", PHYSFS_getLastError()); PHYSFS_close(f); return(1); } /* if */ } /* for */ printf(" ... test file read ...\n"); if (!PHYSFS_eof(f)) printf("PHYSFS_eof() returned true! That's wrong.\n"); if (!PHYSFS_close(f)) { printf("PHYSFS_close() failed: %s.\n", PHYSFS_getLastError()); return(1); /* oh well. */ } /* if */ PHYSFS_delete("test.txt"); printf("stress test completed successfully.\n"); } /* else */ } /* else */ return(1); } /* cmd_stressbuffer */
int main(int argc, char **argv) { int rc; char buf[128]; PHYSFS_File *f; if (!PHYSFS_init(argv[0])) { fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError()); return 1; } /* if */ if (!PHYSFS_addToSearchPath(".", 1)) { fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError()); PHYSFS_deinit(); return 1; } /* if */ if (!PHYSFS_setWriteDir(".")) { fprintf(stderr, "PHYSFS_setWriteDir(): %s\n", PHYSFS_getLastError()); PHYSFS_deinit(); return 1; } /* if */ if (!PHYSFS_mkdir("/a/b/c")) { fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError()); PHYSFS_deinit(); return 1; } /* if */ if (!PHYSFS_mkdir("/a/b/C")) { fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError()); PHYSFS_deinit(); return 1; } /* if */ f = PHYSFS_openWrite("/a/b/c/x.txt"); PHYSFS_close(f); if (f == NULL) { fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError()); PHYSFS_deinit(); return 1; } /* if */ f = PHYSFS_openWrite("/a/b/C/X.txt"); PHYSFS_close(f); if (f == NULL) { fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError()); PHYSFS_deinit(); return 1; } /* if */ strcpy(buf, "/a/b/c/x.txt"); rc = PHYSFSEXT_locateCorrectCase(buf); if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0)) printf("test 1 failed\n"); strcpy(buf, "/a/B/c/x.txt"); rc = PHYSFSEXT_locateCorrectCase(buf); if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0)) printf("test 2 failed\n"); strcpy(buf, "/a/b/C/x.txt"); rc = PHYSFSEXT_locateCorrectCase(buf); if ((rc != 0) || (strcmp(buf, "/a/b/C/X.txt") != 0)) printf("test 3 failed\n"); strcpy(buf, "/a/b/c/X.txt"); rc = PHYSFSEXT_locateCorrectCase(buf); if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0)) printf("test 4 failed\n"); strcpy(buf, "/a/b/c/z.txt"); rc = PHYSFSEXT_locateCorrectCase(buf); if ((rc != -1) || (strcmp(buf, "/a/b/c/z.txt") != 0)) printf("test 5 failed\n"); strcpy(buf, "/A/B/Z/z.txt"); rc = PHYSFSEXT_locateCorrectCase(buf); if ((rc != -2) || (strcmp(buf, "/a/b/Z/z.txt") != 0)) printf("test 6 failed\n"); printf("Testing completed.\n"); printf(" If no errors were reported, you're good to go.\n"); PHYSFS_delete("/a/b/c/x.txt"); PHYSFS_delete("/a/b/C/X.txt"); PHYSFS_delete("/a/b/c"); PHYSFS_delete("/a/b/C"); PHYSFS_delete("/a/b"); PHYSFS_delete("/a"); PHYSFS_deinit(); return 0; } /* main */
void ReplayMenuState::step() { IMGUI& imgui = IMGUI::getSingleton(); if (mReplaying) { RenderManager* rmanager = &RenderManager::getSingleton(); if(mReplayRecorder->getPacketType()==ID_INPUT) { mReplayMatch->setPlayersInput(mReplayRecorder->getInput()); mReplayMatch->step(); } presentGame(*mReplayMatch); rmanager->setBlobColor(LEFT_PLAYER, mLeftPlayer.getColor()); rmanager->setBlobColor(RIGHT_PLAYER, mRightPlayer.getColor()); PlayerSide side = mReplayMatch->winningPlayer(); if (side != NO_PLAYER) { std::stringstream tmp; if(side == LEFT_PLAYER) tmp << mReplayRecorder->getPlayerName(LEFT_PLAYER); else tmp << mReplayRecorder->getPlayerName(RIGHT_PLAYER); imgui.doOverlay(GEN_ID, Vector2(200, 150), Vector2(650, 450)); imgui.doImage(GEN_ID, Vector2(200, 250), "gfx/pokal.bmp"); imgui.doText(GEN_ID, Vector2(274, 250), tmp.str()); imgui.doText(GEN_ID, Vector2(274, 300), TextManager::getSingleton()->getString(TextManager::GAME_WIN)); if (imgui.doButton(GEN_ID, Vector2(290, 350), TextManager::getSingleton()->getString(TextManager::LBL_OK))) { mReplaying = false; delete mReplayMatch; delete mReplayRecorder; imgui.resetSelection(); } if (imgui.doButton(GEN_ID, Vector2(400, 350), TextManager::getSingleton()->getString(TextManager::RP_SHOW_AGAIN))) { delete mReplayMatch; delete mReplayRecorder; loadCurrentReplay(); imgui.resetSelection(); } imgui.doCursor(); } else if ((InputManager::getSingleton()->exit()) || (mReplayRecorder->endOfFile())) { mReplaying = false; delete mReplayMatch; delete mReplayRecorder; imgui.resetSelection(); } } else { imgui.doCursor(); imgui.doImage(GEN_ID, Vector2(400.0, 300.0), "background"); imgui.doOverlay(GEN_ID, Vector2(0.0, 0.0), Vector2(800.0, 600.0)); if (imgui.doButton(GEN_ID, Vector2(224.0, 10.0), TextManager::getSingleton()->getString(TextManager::RP_PLAY)) && mSelectedReplay != -1) { loadCurrentReplay(); imgui.resetSelection(); } else if (imgui.doButton(GEN_ID, Vector2(424.0, 10.0), TextManager::getSingleton()->getString(TextManager::LBL_CANCEL))) { deleteCurrentState(); setCurrentState(new MainMenuState()); } else imgui.doSelectbox(GEN_ID, Vector2(34.0, 50.0), Vector2(634.0, 550.0), mReplayFiles, mSelectedReplay); if (imgui.doButton(GEN_ID, Vector2(644.0, 60.0), TextManager::getSingleton()->getString(TextManager::RP_DELETE))) { if (!mReplayFiles.empty()) if (PHYSFS_delete(std::string("replays/" + mReplayFiles[mSelectedReplay] + ".bvr").c_str())) { mReplayFiles.erase(mReplayFiles.begin()+mSelectedReplay); if (mSelectedReplay >= mReplayFiles.size()) mSelectedReplay = mReplayFiles.size()-1; } } if (mChecksumError) { imgui.doInactiveMode(false); imgui.doOverlay(GEN_ID, Vector2(210, 180), Vector2(650, 370)); imgui.doText(GEN_ID, Vector2(250, 200), TextManager::getSingleton()->getString(TextManager::RP_CHECKSUM)); imgui.doText(GEN_ID, Vector2(250, 250), TextManager::getSingleton()->getString(TextManager::RP_FILE_CORRUPT)); if (imgui.doButton(GEN_ID, Vector2(400, 330), TextManager::getSingleton()->getString(TextManager::LBL_OK))) { mChecksumError = false; } else { imgui.doInactiveMode(true); } } } }
bool FileSystem::deleteFile(const std::string& filename) { return PHYSFS_delete(filename.c_str()); }
//write out player's saved games. returns errno (0 == no error) int write_player_file() { char filename[PATH_MAX]; PHYSFS_file *file; int errno_ret, i; if ( Newdemo_state == ND_STATE_PLAYBACK ) return -1; errno_ret = WriteConfigFile(); memset(filename, '\0', PATH_MAX); snprintf(filename, PATH_MAX, GameArg.SysUsePlayersDir? "Players/%.8s.plx" : "%.8s.plx", Players[Player_num].callsign); write_player_d1x(filename); snprintf(filename, PATH_MAX, GameArg.SysUsePlayersDir? "Players/%.8s.plr" : "%.8s.plr", Players[Player_num].callsign); file = PHYSFSX_openWriteBuffered(filename); if (!file) return errno; PHYSFS_writeULE32(file, SAVE_FILE_ID); PHYSFS_writeULE16(file, SAVED_GAME_VERSION); PHYSFS_writeULE16(file, PLAYER_STRUCT_VERSION); PHYSFS_writeSLE32(file, PlayerCfg.NHighestLevels); PHYSFS_writeSLE32(file, PlayerCfg.DefaultDifficulty); PHYSFS_writeSLE32(file, PlayerCfg.AutoLeveling); errno_ret = EZERO; //write higest level info if ((PHYSFS_write( file, PlayerCfg.HighestLevels, sizeof(hli), PlayerCfg.NHighestLevels) != PlayerCfg.NHighestLevels)) { errno_ret = errno; PHYSFS_close(file); return errno_ret; } if (PHYSFS_write( file, saved_games,sizeof(saved_games),1) != 1) { errno_ret = errno; PHYSFS_close(file); return errno_ret; } #ifdef NETWORK if ((PHYSFS_write( file, PlayerCfg.NetworkMessageMacro, MAX_MESSAGE_LEN, 4) != 4)) { errno_ret = errno; PHYSFS_close(file); return errno_ret; } #else { //PHYSFS_seek( file, PHYSFS_tell(file)+MAX_MESSAGE_LEN * 4 ); // Seeking is bad for Mac OS 9 char dummy[MAX_MESSAGE_LEN][4]; if ((PHYSFS_write( file, dummy, MAX_MESSAGE_LEN, 4) != 4)) { errno_ret = errno; PHYSFS_close(file); return errno_ret; } } #endif //write kconfig info { if (PHYSFS_write(file, PlayerCfg.KeySettings[0], sizeof(PlayerCfg.KeySettings[0]), 1) != 1) errno_ret=errno; if (PHYSFS_write(file, PlayerCfg.KeySettings[1], sizeof(PlayerCfg.KeySettings[1]), 1) != 1) errno_ret=errno; for (i = 0; i < MAX_CONTROLS*3; i++) if (PHYSFS_write(file, "0", sizeof(ubyte), 1) != 1) // Skip obsolete Flightstick/Thrustmaster/Gravis map fields errno_ret=errno; if (PHYSFS_write(file, PlayerCfg.KeySettings[2], sizeof(PlayerCfg.KeySettings[2]), 1) != 1) errno_ret=errno; for (i = 0; i < MAX_CONTROLS; i++) if (PHYSFS_write(file, "0", sizeof(ubyte), 1) != 1) // Skip obsolete Cyberman map field errno_ret=errno; if(errno_ret == EZERO) { ubyte old_avg_joy_sensitivity = 8; if (PHYSFS_write( file, &PlayerCfg.ControlType, sizeof(ubyte), 1 )!=1) errno_ret=errno; else if (PHYSFS_write( file, &old_avg_joy_sensitivity, sizeof(ubyte), 1 )!=1) errno_ret=errno; } } if (!PHYSFS_close(file)) errno_ret = errno; if (errno_ret != EZERO) { PHYSFS_delete(filename); //delete bogus file nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s",TXT_ERROR_WRITING_PLR, strerror(errno_ret)); } return errno_ret; }