37 PHYSFS_permitSymbolicLinks(1);
54 for(
const std::string& dir : possiblePaths) {
55 if(!PHYSFS_mount(dir.c_str(),
nullptr, 0))
58 if(PHYSFS_exists(existentFile.c_str())) {
64 PHYSFS_unmount(dir.c_str());
77 dirName = appWriteDirName;
79 std::string writeDir = userDir + dirName;
81 if(!PHYSFS_setWriteDir(writeDir.c_str())) {
82 if(!PHYSFS_setWriteDir(userDir.c_str()) || !PHYSFS_mkdir(dirName.c_str())) {
83 g_logger.
error(
stdext::format(
"Unable to create write directory '%s': %s", writeDir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
92 if(!PHYSFS_setWriteDir(writeDir.c_str())) {
93 g_logger.
error(
stdext::format(
"Unable to set write directory '%s': %s", writeDir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())));
97 if(!m_writeDir.empty())
100 m_writeDir = writeDir;
110 std::string savePath = path;
111 if(!PHYSFS_mount(path.c_str(),
nullptr, pushFront ? 0 : 1)) {
113 for(std::string searchPath : m_searchPaths) {
114 std::string newPath = searchPath + path;
115 if(PHYSFS_mount(newPath.c_str(),
nullptr, pushFront ? 0 : 1)) {
128 m_searchPaths.push_front(savePath);
130 m_searchPaths.push_back(savePath);
136 if(!PHYSFS_unmount(path.c_str()))
138 auto it = std::find(m_searchPaths.begin(), m_searchPaths.end(), path);
139 assert(it != m_searchPaths.end());
140 m_searchPaths.erase(it);
147 for(
auto it = files.rbegin(); it != files.rend(); ++it) {
148 const std::string& file = *it;
151 std::string
package = getRealDir(packagesDir) + "/" + file;
165 PHYSFS_Stat stat = {};
166 if (!PHYSFS_stat(directoryName.c_str(), &stat)) {
170 return stat.filetype == PHYSFS_FILETYPE_DIRECTORY;
176 if(buffer.length() == 0) {
177 out.clear(std::ios::eofbit);
180 out.clear(std::ios::goodbit);
181 out.write(&buffer[0], buffer.length());
182 out.seekg(0, std::ios::beg);
189 PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str());
193 int fileSize = PHYSFS_fileLength(file);
194 std::string buffer(fileSize, 0);
195 PHYSFS_readBytes(file, (
void*)&buffer[0], fileSize);
203 PHYSFS_file* file = PHYSFS_openWrite(fileName.c_str());
205 g_logger.
error(PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
209 PHYSFS_writeBytes(file, (
void*)data, size);
216 std::streampos oldPos = in.tellg();
217 in.seekg(0, std::ios::end);
218 std::streampos size = in.tellg();
219 in.seekg(0, std::ios::beg);
220 std::vector<char> buffer(size);
221 in.read(&buffer[0], size);
223 in.seekg(oldPos, std::ios::beg);
236 PHYSFS_File* file = PHYSFS_openRead(fullPath.c_str());
244 PHYSFS_File* file = PHYSFS_openAppend(fileName.c_str());
252 PHYSFS_File* file = PHYSFS_openWrite(fileName.c_str());
260 return PHYSFS_delete(
resolvePath(fileName).c_str()) != 0;
265 return PHYSFS_mkdir(directory.c_str());
270 std::list<std::string> files;
271 auto rc = PHYSFS_enumerateFiles(
resolvePath(directoryPath).c_str());
273 for(
int i = 0; rc[i] !=
nullptr; i++)
274 files.emplace_back(rc[i]);
282 if(!fs::exists(path))
283 return std::vector<std::string>();
291 std::vector<std::string> files;
296 for (fs::directory_iterator it(path), end; it != end; ++it) {
297 if(fs::is_directory(it->path().generic_string()) && recursive) {
298 std::vector<std::string> subfiles =
discoverPath(it->path(), filenameOnly, recursive);
299 files.insert(files.end(), subfiles.begin(), subfiles.end());
302 files.push_back(it->path().filename().string());
304 files.push_back(it->path().generic_string() +
"/" + it->path().filename().string());
313 std::string fullPath;
318 if(!scriptPath.empty())
319 fullPath += scriptPath +
"/";
331 const char *cdir = PHYSFS_getRealDir(
resolvePath(path).c_str());
344 return PHYSFS_getBaseDir();
349 return PHYSFS_getUserDir();
356 return filename +
"." + type;