size_t ex_fsys_fwrite ( ex_file_t *_file, const void *_buf, uint64 _size ) { #if 0 return (size_t)PHYSFS_writeBytes( _file, _buf, _size ); #else return (size_t)PHYSFS_write( _file, _buf, 1, (uint)_size ); #endif }
static size_t physfsrwops_write(SDL_RWops *rw, const void *ptr, size_t size, size_t num) { PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, size * num); if (rc != size * num) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); return rc; } /* physfsrwops_write */
static size_t SDL_RWopsWrite(SDL_RWops *ops, const void *buffer, size_t size, size_t num) { PHYSFS_File *f = sdlPHYS(ops); if (!f) return 0; PHYSFS_sint64 result = PHYSFS_writeBytes(f, buffer, size*num); return (result != -1) ? (result / size) : 0; }
int OFileStreambuf::overflow(int c) { char c2 = static_cast<char>(c); if(pbase() == pptr()) return 0; size_t size = pptr() - pbase(); PHYSFS_sint64 res = PHYSFS_writeBytes(file, pbase(), size); if(res <= 0) return traits_type::eof(); if(c != traits_type::eof()) { PHYSFS_sint64 res_ = PHYSFS_writeBytes(file, &c2, 1); if(res_ <= 0) return traits_type::eof(); } setp(buf, buf + res); return 0; }
bool copyDir(const char* dirSrcName, const char* dirDstName) { PHYSFS_Stat stat; if (PHYSFS_stat(dirSrcName, &stat) == 0 || stat.filetype != PHYSFS_FILETYPE_DIRECTORY) { return false; } if (PHYSFS_stat(dirDstName, &stat) != 0 && stat.filetype != PHYSFS_FILETYPE_DIRECTORY) { return false; } createDir(dirDstName); auto paths = PHYSFS_enumerateFiles(dirSrcName); if (paths != nullptr) { for (char** path = paths; *path != nullptr; path++) { auto fullSrcPath = std::string(dirSrcName) + '/' + *path; auto fullDstPath = std::string(dirDstName) + '/' + *path; if (PHYSFS_stat(fullSrcPath.c_str(), &stat) == 0) { continue; } if (stat.filetype == PHYSFS_FILETYPE_DIRECTORY) { copyDir(fullSrcPath.c_str(), fullDstPath.c_str()); } else { // copy file (read source file and write destination) sf::PhysFSStream fileRead(fullSrcPath); auto fileWrite = PHYSFS_openWrite(fullDstPath.c_str()); if (fileRead.hasError() == false && fileWrite != nullptr) { std::vector<uint8_t> data((size_t)fileRead.getSize()); fileRead.read(data.data(), fileRead.getSize()); PHYSFS_writeBytes(fileWrite, data.data(), data.size()); PHYSFS_close(fileWrite); } } } PHYSFS_freeList(paths); return true; } return false; }
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num) #endif { PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1; const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size); const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen); if (rc != ((PHYSFS_sint64) writelen)) SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError()); #if TARGET_SDL2 return (size_t) rc; #else return (int) rc; #endif } /* physfsrwops_write */
bool saveText(const std::string_view filePath, const std::string_view str) noexcept { try { std::filesystem::path path(filePath); if (path.has_parent_path() == true) { createDir(path.parent_path().u8string().c_str()); } auto file = PHYSFS_openWrite(filePath.data()); if (file != nullptr) { PHYSFS_writeBytes(file, str.data(), str.size()); return PHYSFS_close(file) != 0; } } catch (std::exception&) {} return false; }
size_t on_data(void* ptr, size_t size, size_t nmemb) { PHYSFS_writeBytes(m_fout.get(), ptr, size * nmemb); return size * nmemb; }