FilePtr FileSystem::getFile (const std::string& filename) const { if (!getAbsoluteWritePath().empty()) { const std::string path = getAbsoluteWritePath() + getDataDir() + filename; SDL_RWops *rwopsLocal = createRWops(path); if (rwopsLocal != nullptr) { FilePtr ptr(new File(rwopsLocal, path)); return ptr; } } const std::string path = getDataDir() + filename; SDL_RWops *rwops = createRWops(path); FilePtr ptr(new File(rwops, path)); return ptr; }
long FileSystem::writeSysFile (const std::string& filename, const unsigned char *buf, size_t length, bool overwrite) const { if (filename.empty()) return -1L; const std::string path = getAbsoluteWritePath() + filename; SDL_RWops *rwops = createRWops(path, "wb"); FilePtr file(new File(rwops, path)); if (!overwrite && file->exists()) return -1L; const long ret = file->write(buf, length); if (ret < 0) error(LOG_FILE, "failed to write file " + path); else info(LOG_FILE, "wrote file " + path + " of size " + string::toString(ret)); return ret; }
long FileSystem::writeSysFile (const std::string& filename, const unsigned char *buf, size_t length, bool overwrite) const { if (filename.empty()) return -1L; const std::string path = getAbsoluteWritePath() + filename; SDL_RWops *rwops = createRWops(path, "wb"); FilePtr file(new File(rwops, path)); if (!overwrite && file->exists()) return -1L; const long ret = file->write(buf, length); if (ret < 0) Log::error(LOG_COMMON, "failed to write file %s", path.c_str()); else Log::info(LOG_COMMON, "wrote file %s of size %li", path.c_str(), ret); return ret; }
long FileSystem::writeFile (const std::string& filename, const unsigned char *buf, size_t length, bool overwrite) const { if (filename.empty()) return -1L; const std::string path = _homeDir + filename; SDL_RWops *rwops = createRWops(path, "wb"); File file(rwops, filename); if (!overwrite && file.exists()) { info(LOG_FILE, "file already exists: " + path); return -1L; } if (!System.mkdir(_homeDir)) { error(LOG_FILE, "could not create directory: " + _homeDir); return -1L; } createDir(file); info(LOG_FILE, "writing file " + path); return file.write(buf, length); }