void FileSystem::createPathCache() { #ifdef __APPLE__ CacheEnumCBData data(p); PHYSFS_enumerateFilesCallback("", cacheEnumCB, &data); #else PHYSFS_enumerateFilesCallback("", cacheEnumCB, p); #endif p->havePathCache = true; }
void AddonManager::disable_addon(const AddonId& addon_id) { log_debug << "disabling addon " << addon_id << std::endl; auto& addon = get_installed_addon(addon_id); if (!addon.is_enabled()) { log_warning << "Tried disabling already disabled Add-On" << std::endl; } else { log_debug << "Removing archive \"" << addon.get_install_filename() << "\" from search path" << std::endl; if (PHYSFS_unmount(addon.get_install_filename().c_str()) == 0) { log_warning << "Could not remove " << addon.get_install_filename() << " from search path: " << PHYSFS_getLastError() << std::endl; } else { if(addon.get_type() == Addon::LANGUAGEPACK) { PHYSFS_enumerateFilesCallback(addon.get_id().c_str(), remove_from_dictionary_path, NULL); } addon.set_enabled(false); } } }
void AddonManager::enable_addon(const AddonId& addon_id) { log_debug << "enabling addon " << addon_id << std::endl; Addon& addon = get_installed_addon(addon_id); if (addon.is_enabled()) { log_warning << "Tried enabling already enabled Add-on" << std::endl; } else { log_debug << "Adding archive \"" << addon.get_install_filename() << "\" to search path" << std::endl; //int PHYSFS_mount(addon.installed_install_filename.c_str(), "addons/", 0) if (PHYSFS_addToSearchPath(addon.get_install_filename().c_str(), 0) == 0) { log_warning << "Could not add " << addon.get_install_filename() << " to search path: " << PHYSFS_getLastError() << std::endl; } else { if(addon.get_type() == Addon::LANGUAGEPACK) { PHYSFS_enumerateFilesCallback(addon.get_id().c_str(), add_to_dictionary_path, NULL); } addon.set_enabled(true); } } }
std::list<std::string> Filesystem::enumerate(const std::string &directory) { std::list<std::string> list; // enumerate PHYSFS_enumerateFilesCallback(directory.c_str(), filesystem_enumerate_callback, &list); // sort the result list.sort(); return list; }
static void cacheEnumCB(void *d, const char *origdir, const char *fname) { #ifdef __APPLE__ CacheEnumCBData *data = static_cast<CacheEnumCBData*>(d); FileSystemPrivate *p = data->p; #else FileSystemPrivate *p = static_cast<FileSystemPrivate*>(d); #endif char buf[512]; if (*origdir == '\0') strncpy(buf, fname, sizeof(buf)); else snprintf(buf, sizeof(buf), "%s/%s", origdir, fname); #ifdef __APPLE__ char bufNfc[sizeof(buf)]; data->nfcFromNfd(bufNfc, buf, sizeof(bufNfc)); #else char *const bufNfc = buf; #endif char *ptr = bufNfc; /* Trim leading slash */ if (*ptr == '/') ++ptr; std::string mixedCase(ptr); for (char *q = bufNfc; *q; ++q) *q = tolower(*q); p->pathCache.insert(std::string(ptr), mixedCase); for (char *q = ptr+strlen(ptr); q > ptr; --q) { if (*q == '/') break; if (*q != '.') continue; *q = '\0'; p->pathCache.insert(std::string(ptr), mixedCase); } PHYSFS_enumerateFilesCallback(mixedCase.c_str(), cacheEnumCB, d); }
bool completeFilenameReg(const char *filepath, char *outBuffer, size_t outN) { strcpySafe(outBuffer, filepath, outN, -1); size_t len = strlen(outBuffer); char *delim; /* Find the deliminator separating directory and file name */ for (delim = outBuffer + len; delim > outBuffer; --delim) if (*delim == '/') break; bool root = (delim == outBuffer); CompleteFilenameData d; if (!root) { /* If we have such a deliminator, we set it to '\0' so we * can pass the first half to PhysFS as the directory name, * and compare all filenames against the second half */ d.outBuf = delim+1; d.filenameLen = len - (delim - outBuffer + 1); *delim = '\0'; } else { /* Otherwise the file is in the root directory */ d.outBuf = outBuffer; d.filenameLen = len - (delim - outBuffer); } d.found = false; d.outBufN = outN - (d.outBuf - outBuffer); PHYSFS_enumerateFilesCallback(root ? "" : outBuffer, completeFilenameRegCB, &d); if (!d.found) return false; /* Now we put the deliminator back in to form the completed * file path (if required) */ if (delim != outBuffer) *delim = '/'; return true; }
void AddonManager::enable_addon(const AddonId& addon_id) { log_debug << "enabling addon " << addon_id << std::endl; auto& addon = get_installed_addon(addon_id); if (addon.is_enabled()) { log_warning << "Tried enabling already enabled Add-on" << std::endl; } else { log_debug << "Adding archive \"" << addon.get_install_filename() << "\" to search path" << std::endl; //int PHYSFS_mount(addon.installed_install_filename.c_str(), "addons/", 0) std::string mountpoint; switch (addon.get_format()) { case Addon::ORIGINAL: mountpoint = ""; break; default: mountpoint = "custom/" + addon_id; break; } if (PHYSFS_mount(addon.get_install_filename().c_str(), mountpoint.c_str(), 0) == 0) { log_warning << "Could not add " << addon.get_install_filename() << " to search path: " << PHYSFS_getLastError() << std::endl; } else { if(addon.get_type() == Addon::LANGUAGEPACK) { PHYSFS_enumerateFilesCallback(addon.get_id().c_str(), add_to_dictionary_path, NULL); } addon.set_enabled(true); } } }
void enumerateFiles(const string& directory, EnumFilesCallback callback, void * extra) { PHYSFS_enumerateFilesCallback(directory.c_str(), callback, extra); }
void FileSystem::initFontSets(SharedFontState &sfs) { FontSetsCBData d = { p, &sfs }; PHYSFS_enumerateFilesCallback("Fonts", fontSetEnumCB, &d); }
vector<Path> FileSystem::GetFilesInDirectory(const Path & directory) { vector<Path> paths; PHYSFS_enumerateFilesCallback(directory.generic_string().c_str(), AppendFiles, &paths); return paths; }