void ScanForTarFiles() { Searchpath sp; char path[MAX_PATH]; uint num = 0; DEBUG(misc, 1, "Scanning for tars"); FOR_ALL_SEARCHPATHS(sp) { FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR); num += ScanPathForTarFiles(path, strlen(path)); FioAppendDirectory(path, MAX_PATH, sp, AI_DIR); num += ScanPathForTarFiles(path, strlen(path)); FioAppendDirectory(path, MAX_PATH, sp, AI_LIBRARY_DIR); num += ScanPathForTarFiles(path, strlen(path)); FioAppendDirectory(path, MAX_PATH, sp, SCENARIO_DIR); num += ScanPathForTarFiles(path, strlen(path)); } DEBUG(misc, 1, "Scan complete, found %d files", num); }
char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir) { Searchpath sp; /* Find and return the first valid directory */ FOR_ALL_SEARCHPATHS(sp) { char *ret = FioAppendDirectory(buf, buflen, sp, subdir); if (FileExists(buf)) return ret; } /* Could not find the directory, fall back to a base path */ ttd_strlcpy(buf, _personal_dir, buflen); return buf; }
/** * Scan for files with the given extention in the given search path. * @param extension the extension of files to search for. * @param sd the sub directory to search in. * @param tars whether to search in the tars too. * @param recursive whether to search recursively * @return the number of found files, i.e. the number of times that * AddFile returned true. */ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool recursive) { Searchpath sp; char path[MAX_PATH]; TarFileList::iterator tar; uint num = 0; FOR_ALL_SEARCHPATHS(sp) { FioAppendDirectory(path, MAX_PATH, sp, sd); num += ScanPath(this, extension, path, strlen(path), recursive); } if (tars) { FOR_ALL_TARS(tar) { num += ScanTar(this, extension, tar); } } return num; }
bool ScriptInstance::LoadCompatibilityScripts(const char *api_version, Subdirectory dir) { char script_name[32]; seprintf(script_name, lastof(script_name), "compat_%s.nut", api_version); char buf[MAX_PATH]; Searchpath sp; FOR_ALL_SEARCHPATHS(sp) { FioAppendDirectory(buf, MAX_PATH, sp, dir); ttd_strlcat(buf, script_name, MAX_PATH); if (!FileExists(buf)) continue; if (this->engine->LoadScript(buf)) return true; ScriptLog::Error("Failed to load API compatibility script"); DEBUG(script, 0, "Error compiling / running API compatibility script: %s", buf); return false; } ScriptLog::Warning("API compatibility script not found"); return true; }
static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last) { /* Show heightmap files * .PNG PNG Based heightmap files * .BMP BMP Based heightmap files */ FiosType type = FIOS_TYPE_INVALID; #ifdef WITH_PNG if (strcasecmp(ext, ".png") == 0) type = FIOS_TYPE_PNG; #endif /* WITH_PNG */ if (strcasecmp(ext, ".bmp") == 0) type = FIOS_TYPE_BMP; if (type == FIOS_TYPE_INVALID) return FIOS_TYPE_INVALID; TarFileList::iterator it = _tar_filelist[SCENARIO_DIR].find(file); if (it != _tar_filelist[SCENARIO_DIR].end()) { /* If the file is in a tar and that tar is not in a heightmap * directory we are for sure not supposed to see it. * Examples of this are pngs part of documentation within * collections of NewGRFs or 32 bpp graphics replacement PNGs. */ bool match = false; Searchpath sp; FOR_ALL_SEARCHPATHS(sp) { char buf[MAX_PATH]; FioAppendDirectory(buf, sizeof(buf), sp, HEIGHTMAP_DIR); if (strncmp(buf, it->second.tar_filename, strlen(buf)) == 0) { match = true; break; } } if (!match) return FIOS_TYPE_INVALID; }
/** * Scan for files with the given extention in the given search path. * @param extension the extension of files to search for. * @param sd the sub directory to search in. * @param tars whether to search in the tars too. * @param recursive whether to search recursively * @return the number of found files, i.e. the number of times that * AddFile returned true. */ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool recursive) { Searchpath sp; char path[MAX_PATH]; TarFileList::iterator tar; uint num = 0; FOR_ALL_SEARCHPATHS(sp) { /* Don't search in the working directory */ if (sp == SP_WORKING_DIR && !_do_scan_working_directory) continue; FioAppendDirectory(path, MAX_PATH, sp, sd); num += ScanPath(this, extension, path, strlen(path), recursive); } if (tars) { FOR_ALL_TARS(tar) { num += ScanTar(this, extension, tar); } } return num; }