-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";
-
- Archives archives;
- Archives archivesOverride;
- const char* ignore_prefix = "";
- const char* override_prefix = "";
- bool is_pk3_vfs, is_pk4_vfs, is_dpk_vfs;
-
- is_pk3_vfs = GetArchiveTable( archiveModules, "pk3" );
- is_pk4_vfs = GetArchiveTable( archiveModules, "pk4" );
- is_dpk_vfs = GetArchiveTable( archiveModules, "dpk" );
-
- if ( !is_dpk_vfs ) {
- // 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_";
- }
- }
-
- 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, '.' );
- char tmppath[PATH_MAX];
-
- if ( is_dpk_vfs ) {
- if ( !!ext && !string_compare_nocase_upper( ext, ".dpkdir" ) ) {
- snprintf( tmppath, PATH_MAX, "%s%s/", path, name );
- tmppath[PATH_MAX] = '\0';
- FixDOSName( tmppath );
- AddSlash( tmppath );
- AddDpkPak( CopiedString( StringRange( name, ext ) ).c_str(), tmppath, false );
- }
- }
-
- if ( is_pk3_vfs || is_pk4_vfs ) {
- if ( !!ext && ( !string_compare_nocase_upper( ext, ".pk3dir" )
- || !string_compare_nocase_upper( ext, ".pk4dir" ) ) ) {
- snprintf( tmppath, PATH_MAX, "%s%s/", path, name );
- tmppath[PATH_MAX] = '\0';
- FixDOSName( tmppath );
- AddSlash( tmppath );
- AddPk3Dir( tmppath );
- }
- }
-
- // GetArchiveTable() needs "pk3" if ext is ".pk3"
- if ( ( ext == 0 ) || *( ext + 1 ) == '\0' || GetArchiveTable( archiveModules, ext + 1 ) == 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 ) {
- if ( !string_compare_nocase_upper( ext, ".dpk" ) ) {
- if ( is_dpk_vfs ) {
- archives.insert( name );
- }
- }
- else {
- archivesOverride.insert( name );
- }
- continue;
- }
-
- archives.insert( name );
- }
-
- g_dir_close( dir );
-
- // add the entries to the vfs
- char* fullpath;
- if ( is_dpk_vfs ) {
- for ( Archives::iterator i = archives.begin(); i != archives.end(); ++i ) {
- const char* name = i->c_str();
- const char* ext = strrchr( name, '.' );
- if ( !string_compare_nocase_upper( ext, "dpk" ) ) {
- CopiedString name_final = CopiedString( StringRange( name, ext ) );
- fullpath = string_new_concat( path, name );
- AddDpkPak( name_final.c_str(), fullpath, true );
- string_release( fullpath, string_length( fullpath ) );
- }
- }
- }
- if ( is_pk3_vfs || is_pk4_vfs ) {
- for ( Archives::iterator i = archivesOverride.begin(); i != archivesOverride.end(); ++i )
- {
- const char* name = i->c_str();
- const char* ext = strrchr( name, '.' );
- if ( !string_compare_nocase_upper( ext, "pk3" )
- || !string_compare_nocase_upper( ext, "pk4" ) ) {
- fullpath = string_new_concat( path, i->c_str() );
- InitPakFile( archiveModules, fullpath );
- string_release( fullpath, string_length( fullpath ) );
- }
- }
- for ( Archives::iterator i = archives.begin(); i != archives.end(); ++i )
- {
- const char* name = i->c_str();
- const char* ext = strrchr( name, '.' );
- if ( !string_compare_nocase_upper( ext, "pk3" )
- || !string_compare_nocase_upper( ext, "pk4" ) ) {
- fullpath = string_new_concat( path, i->c_str() );
- InitPakFile( archiveModules, fullpath );
- string_release( fullpath, string_length( fullpath ) );
- }
- }
- }
- }
- else
- {
- globalErrorStream() << "vfs directory not found: " << path << "\n";
- }
- }
+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";
+
+ Archives archives;
+ Archives archivesOverride;
+ const char *ignore_prefix = "";
+ const char *override_prefix = "";
+ bool is_pk3_vfs, is_pk4_vfs, is_dpk_vfs;
+
+ is_pk3_vfs = GetArchiveTable(archiveModules, "pk3");
+ is_pk4_vfs = GetArchiveTable(archiveModules, "pk4");
+ is_dpk_vfs = GetArchiveTable(archiveModules, "dpk");
+
+ if (!is_dpk_vfs) {
+ // 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_";
+ }
+ }
+
+ 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, '.');
+ char tmppath[PATH_MAX];
+
+ if (is_dpk_vfs) {
+ if (!!ext && !string_compare_nocase_upper(ext, ".dpkdir")) {
+ snprintf(tmppath, PATH_MAX, "%s%s/", path, name);
+ tmppath[PATH_MAX] = '\0';
+ FixDOSName(tmppath);
+ AddSlash(tmppath);
+ AddDpkPak(CopiedString(StringRange(name, ext)).c_str(), tmppath, false);
+ }
+ }
+
+ if (is_pk3_vfs || is_pk4_vfs) {
+ if (!!ext && (!string_compare_nocase_upper(ext, ".pk3dir")
+ || !string_compare_nocase_upper(ext, ".pk4dir"))) {
+ snprintf(tmppath, PATH_MAX, "%s%s/", path, name);
+ tmppath[PATH_MAX] = '\0';
+ FixDOSName(tmppath);
+ AddSlash(tmppath);
+ AddPk3Dir(tmppath);
+ }
+ }
+
+ // GetArchiveTable() needs "pk3" if ext is ".pk3"
+ if ((ext == 0) || *(ext + 1) == '\0' || GetArchiveTable(archiveModules, ext + 1) == 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) {
+ if (!string_compare_nocase_upper(ext, ".dpk")) {
+ if (is_dpk_vfs) {
+ archives.insert(name);
+ }
+ } else {
+ archivesOverride.insert(name);
+ }
+ continue;
+ }
+
+ archives.insert(name);
+ }
+
+ g_dir_close(dir);
+
+ // add the entries to the vfs
+ char *fullpath;
+ if (is_dpk_vfs) {
+ for (Archives::iterator i = archives.begin(); i != archives.end(); ++i) {
+ const char *name = i->c_str();
+ const char *ext = strrchr(name, '.');
+ if (!string_compare_nocase_upper(ext, ".dpk")) {
+ CopiedString name_final = CopiedString(StringRange(name, ext));
+ fullpath = string_new_concat(path, name);
+ AddDpkPak(name_final.c_str(), fullpath, true);
+ string_release(fullpath, string_length(fullpath));
+ }
+ }
+ }
+ if (is_pk3_vfs || is_pk4_vfs) {
+ for (Archives::iterator i = archivesOverride.begin(); i != archivesOverride.end(); ++i) {
+ const char *name = i->c_str();
+ const char *ext = strrchr(name, '.');
+ if (!string_compare_nocase_upper(ext, ".pk3")
+ || !string_compare_nocase_upper(ext, ".pk4")) {
+ fullpath = string_new_concat(path, i->c_str());
+ InitPakFile(archiveModules, fullpath);
+ string_release(fullpath, string_length(fullpath));
+ }
+ }
+ for (Archives::iterator i = archives.begin(); i != archives.end(); ++i) {
+ const char *name = i->c_str();
+ const char *ext = strrchr(name, '.');
+ if (!string_compare_nocase_upper(ext, ".pk3")
+ || !string_compare_nocase_upper(ext, ".pk4")) {
+ fullpath = string_new_concat(path, i->c_str());
+ InitPakFile(archiveModules, fullpath);
+ string_release(fullpath, string_length(fullpath));
+ }
+ }
+ }
+ } else {
+ globalErrorStream() << "vfs directory not found: " << path << "\n";
+ }
+ }