char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename) { Searchpath sp; assert(subdir < NUM_SUBDIRS); FOR_ALL_SEARCHPATHS(sp) { FioGetFullPath(buf, buflen, sp, subdir, filename); if (FileExists(buf)) break; #if !defined(WIN32) /* Be, as opening files, aware that sometimes the filename * might be in uppercase when it is in lowercase on the * disk. Ofcourse Windows doesn't care about casing. */ strtolower(buf + strlen(_searchpaths[sp]) - 1); if (FileExists(buf)) break; #endif } return buf; }
/** * Determine the full filename of a piece of content information * @param ci the information to get the filename from * @param compressed should the filename end with .gz? * @return a statically allocated buffer with the filename or * NULL when no filename could be made. */ static char *GetFullFilename(const ContentInfo *ci, bool compressed) { Subdirectory dir; switch (ci->type) { default: return NULL; case CONTENT_TYPE_BASE_GRAPHICS: dir = DATA_DIR; break; case CONTENT_TYPE_BASE_MUSIC: dir = GM_DIR; break; case CONTENT_TYPE_BASE_SOUNDS: dir = DATA_DIR; break; case CONTENT_TYPE_NEWGRF: dir = DATA_DIR; break; case CONTENT_TYPE_AI: dir = AI_DIR; break; case CONTENT_TYPE_AI_LIBRARY: dir = AI_LIBRARY_DIR; break; case CONTENT_TYPE_SCENARIO: dir = SCENARIO_DIR; break; case CONTENT_TYPE_HEIGHTMAP: dir = HEIGHTMAP_DIR; break; } static char buf[MAX_PATH]; FioGetFullPath(buf, lengthof(buf), SP_AUTODOWNLOAD_DIR, dir, ci->filename); strecat(buf, compressed ? ".tar.gz" : ".tar", lastof(buf)); return buf; }