void FileSystem::initDirectory (const std::string& directory) { ArchiveModules& archiveModules = FileSystemAPI_getArchiveModules(); std::string path = DirectoryCleaned(directory); g_strDirs.push_back(path); { ArchiveEntry entry; entry.name = path; entry.archive = OpenDirArchive(path); entry.is_pakfile = false; g_archives.push_back(entry); } if (g_bUsePak) { GDir* dir = g_dir_open(path.c_str(), 0, 0); if (dir != 0) { g_message("vfs directory: %s\n", path.c_str()); Archives archives; for (;;) { const char *name = g_dir_read_name(dir); if (name == 0) break; const char *ext = strrchr(name, '.'); if ((ext == 0) || *(++ext) == '\0' || GetArchiveTable(archiveModules, ext) == 0) continue; archives.insert(name); } g_dir_close(dir); // add the entries to the vfs for (Archives::iterator i = archives.begin(); i != archives.end(); ++i) { std::string filename = path + *i; initPK3File(filename); } } else { g_message("vfs directory not found: '%s'\n", path.c_str()); } } }
// reads all pak files from a dir void InitDirectory(const char* directory, ArchiveModules& archiveModules) { int j; g_numForbiddenDirs = 0; StringTokeniser st(GlobalRadiant().getGameDescriptionKeyValue("forbidden_paths"), " "); for(j = 0; j < VFS_MAXDIRS; ++j) { const char *t = st.getToken(); if(string_empty(t)) break; strncpy(g_strForbiddenDirs[g_numForbiddenDirs], t, PATH_MAX); g_strForbiddenDirs[g_numForbiddenDirs][PATH_MAX] = '\0'; ++g_numForbiddenDirs; } for(j = 0; j < g_numForbiddenDirs; ++j) { char* dbuf = g_strdup(directory); if(*dbuf && dbuf[strlen(dbuf)-1] == '/') dbuf[strlen(dbuf)-1] = 0; const char *p = strrchr(dbuf, '/'); p = (p ? (p+1) : dbuf); if(matchpattern(p, g_strForbiddenDirs[j], TRUE)) { g_free(dbuf); break; } g_free(dbuf); } if(j < g_numForbiddenDirs) { printf("Directory %s matched by forbidden dirs, removed\n", directory); return; } if (g_numDirs == VFS_MAXDIRS) return; strncpy(g_strDirs[g_numDirs], directory, PATH_MAX); g_strDirs[g_numDirs][PATH_MAX] = '\0'; FixDOSName (g_strDirs[g_numDirs]); AddSlash (g_strDirs[g_numDirs]); const char* path = g_strDirs[g_numDirs]; g_numDirs++; { archive_entry_t entry; entry.name = path; entry.archive = OpenArchive(path); entry.is_pakfile = false; g_archives.push_back(entry); } if (g_bUsePak) { GDir* dir = g_dir_open (path, 0, 0); if (dir != 0) { globalOutputStream() << "vfs directory: " << path << "\n"; const char* ignore_prefix = ""; const char* override_prefix = ""; { // See if we are in "sp" or "mp" mapping mode const char* gamemode = gamemode_get(); if (strcmp (gamemode, "sp") == 0) { ignore_prefix = "mp_"; override_prefix = "sp_"; } else if (strcmp (gamemode, "mp") == 0) { ignore_prefix = "sp_"; override_prefix = "mp_"; } } Archives archives; Archives archivesOverride; for(;;) { const char* name = g_dir_read_name(dir); if(name == 0) break; for(j = 0; j < g_numForbiddenDirs; ++j) { const char *p = strrchr(name, '/'); p = (p ? (p+1) : name); if(matchpattern(p, g_strForbiddenDirs[j], TRUE)) break; } if(j < g_numForbiddenDirs) continue; const char *ext = strrchr (name, '.'); if(ext && !string_compare_nocase_upper(ext, ".pk3dir")) { if (g_numDirs == VFS_MAXDIRS) continue; snprintf(g_strDirs[g_numDirs], PATH_MAX, "%s%s/", path, name); g_strDirs[g_numDirs][PATH_MAX] = '\0'; FixDOSName (g_strDirs[g_numDirs]); AddSlash (g_strDirs[g_numDirs]); g_numDirs++; { archive_entry_t entry; entry.name = g_strDirs[g_numDirs-1]; entry.archive = OpenArchive(g_strDirs[g_numDirs-1]); entry.is_pakfile = false; g_archives.push_back(entry); } } if ((ext == 0) || *(++ext) == '\0' || GetArchiveTable(archiveModules, ext) == 0) continue; // using the same kludge as in engine to ensure consistency if(!string_empty(ignore_prefix) && strncmp(name, ignore_prefix, strlen(ignore_prefix)) == 0) { continue; } if(!string_empty(override_prefix) && strncmp(name, override_prefix, strlen(override_prefix)) == 0) { archivesOverride.insert(name); continue; } archives.insert(name); } g_dir_close (dir); // add the entries to the vfs for(Archives::iterator i = archivesOverride.begin(); i != archivesOverride.end(); ++i) { char filename[PATH_MAX]; strcpy(filename, path); strcat(filename, (*i).c_str()); InitPakFile(archiveModules, filename); } for(Archives::iterator i = archives.begin(); i != archives.end(); ++i) { char filename[PATH_MAX]; strcpy(filename, path); strcat(filename, (*i).c_str()); InitPakFile(archiveModules, filename); } } else { globalErrorStream() << "vfs directory not found: " << path << "\n"; } } }