char *Sys_FindNext ( unsigned musthave, unsigned canthave ) { struct _finddata_t findinfo; if (findhandle == -1) return NULL; // jkrige - broken file search under windows // the player setup menu does not always display all the models that are installed // this is being caused by free-floating files inside the baseq2\players directory // this bugfix will also fix other similar faults potentially (this only affects Microsoft Windows) #ifndef _WIN32 if (_findnext (findhandle, &findinfo) == -1) return NULL; if ( !CompareAttributes( findinfo.attrib, musthave, canthave ) ) return NULL; Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); return findpath; #else while (_findnext(findhandle, &findinfo) != -1) { if (CompareAttributes(findinfo.attrib, musthave, canthave)) { Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); return findpath; } } return NULL; #endif // jkrige - broken file search under windows }
/* ----------------------------------------------------------------------------- Function: FS_FindNext -Continues a file search from a previous call to the FS_FindFirst function. Parameters: musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindNext( W32 musthave, W32 canthave ) { struct dirent *d; if( fdir == NULL ) { return NULL; } while( (d = readdir( fdir ) ) != NULL) { if( ! *findpattern || glob_match( findpattern, d->d_name ) ) { if( ! *findbase ) { my_strlcpy( findpath, d->d_name, sizeof( findpath ) ); } else { my_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name ); } if( CompareAttributes( findpath, musthave, canthave ) ) { return findpath; } } } return NULL; }
/** * @brief Opens the directory and returns the first file that matches our searchrules * @sa Sys_FindNext * @sa Sys_FindClose */ char *Sys_FindFirst (const char *path, unsigned musthave, unsigned canhave) { struct dirent *d; char *p; if (fdir) Sys_Error("Sys_BeginFind without close"); Q_strncpyz(findbase, path, sizeof(findbase)); if ((p = strrchr(findbase, '/')) != NULL) { *p = 0; Q_strncpyz(findpattern, p + 1, sizeof(findpattern)); } else Q_strncpyz(findpattern, "*", sizeof(findpattern)); if (Q_streq(findpattern, "*.*")) Q_strncpyz(findpattern, "*", sizeof(findpattern)); if ((fdir = opendir(findbase)) == NULL) return NULL; while ((d = readdir(fdir)) != NULL) { if (!*findpattern || Com_Filter(findpattern, d->d_name)) { if (CompareAttributes(findbase, d->d_name, musthave, canhave)) { Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, d->d_name); return findpath; } } } return NULL; }
char * Sys_FindFirst(char *path, unsigned musthave, unsigned canthave) { struct _finddata_t findinfo; if (findhandle) { Sys_Error("Sys_BeginFind without close"); } findhandle = 0; COM_FilePath(path, findbase); findhandle = _findfirst(path, &findinfo); if (findhandle == -1) { return NULL; } if (!CompareAttributes(findinfo.attrib, musthave, canthave)) { return NULL; } Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); return findpath; }
/* ----------------------------------------------------------------------------- Function: FS_FindNext -Continues a file search from a previous call to the FS_FindFirst function. Parameters: musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindNext( W32 musthave, W32 canthave ) { WIN32_FIND_DATA FindFileData; if( FindHandle == INVALID_HANDLE_VALUE ) { return NULL; } while( 1 ) { if( FindNextFile( FindHandle, &FindFileData ) == 0 ) { return NULL; } if( CompareAttributes( FindFileData.dwFileAttributes, musthave, canthave ) ) { break; } } if( ! *findbase ) { cs_snprintf( findpath, sizeof( findpath ), "%s", FindFileData.cFileName ); } else { cs_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, FindFileData.cFileName ); } return findpath; }
char *Sys_FindFirst (const char *path, unsigned musthave, unsigned canhave) { struct dirent *d; char *p; if (fdir) Sys_Error ("Sys_BeginFind without close"); // COM_FilePath (path, findbase); strcpy(findbase, path); if ((p = strrchr(findbase, '/')) != NULL) { *p = 0; strcpy(findpattern, p + 1); } else strcpy(findpattern, "*"); if (strcmp(findpattern, "*.*") == 0) strcpy(findpattern, "*"); if ((fdir = opendir(findbase)) == NULL) return NULL; while ((d = readdir(fdir)) != NULL) { if (!*findpattern || glob_match(findpattern, d->d_name)) { // if (*findpattern) // printf("%s matched %s\n", findpattern, d->d_name); if (CompareAttributes(findbase, d->d_name, musthave, canhave)) { sprintf (findpath, "%s/%s", findbase, d->d_name); return findpath; } } } return NULL; }
/** * @sa Sys_FindNext * @sa Sys_FindClose */ char *Sys_FindFirst (const char *path, unsigned musthave, unsigned canthave) { struct _finddata_t findinfo; if (findhandle) Sys_Error("Sys_BeginFind without close"); findhandle = 0; Com_FilePath(path, findbase, sizeof(findbase)); findhandle = _findfirst(path, &findinfo); while (findhandle != -1) { /* found one that matched */ if (!Q_streq(findinfo.name, ".") && !Q_streq(findinfo.name, "..") && CompareAttributes(findinfo.attrib, musthave, canthave)) { Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); return findpath; /* doesn't match - try the next one */ } else if (_findnext(findhandle, &findinfo) == -1) { /* ok, no further entries here - leave the while loop */ _findclose(findhandle); findhandle = -1; } } /* none found */ return NULL; }
char *Sys_FindFirst (const char *path, unsigned musthave, unsigned canthave ) { WIN32_FIND_DATA findinfo; if (findhandle != INVALID_HANDLE_VALUE) Sys_Error ("Sys_FindFirst without close"); COM_FilePath (path, findbase); findhandle = FindFirstFile(path, &findinfo); if (findhandle == INVALID_HANDLE_VALUE) return NULL; do { if (CompareAttributes(findinfo.dwFileAttributes, musthave, canthave)) { Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.cFileName); return findpath; } } while(FindNextFile(findhandle, &findinfo)); return NULL; }
/* ----------------------------------------------------------------------------- Function: FS_FindFirstFile() -Searches a directory for a file. Parameters: path -[in] Pointer to a NUL-terminated string that specifies a valid directory or path and file name. musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave ) { struct dirent *d; char *p; p; if( fdir ) { Com_Printf( "FS_FindFirst without close\n" ); return NULL; } FS_FilePath( (char *)path, findbase ); my_strlcpy( (char *)findpattern, FS_SkipPath( (char *)path ), sizeof( findpattern ) ); if( ! *findbase ) { if( (fdir = opendir( "." )) == NULL ) { return NULL; } } else { if( (fdir = opendir( findbase )) == NULL ) { return NULL; } } while( (d = readdir( fdir )) != NULL ) { if( ! *findpattern || glob_match( findpattern, d->d_name ) ) { if( ! *findbase ) { my_strlcpy( findpath, d->d_name, sizeof( findpath ) ); } else { my_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, d->d_name ); } if( CompareAttributes( findpath, musthave, canthave ) ) { return findpath; } } } return NULL; }
char *Sys_FindNext ( unsigned musthave, unsigned canthave ) { struct _finddata_t findinfo; if (findhandle == -1) return NULL; if (_findnext (findhandle, &findinfo) == -1) return NULL; if ( !CompareAttributes( findinfo.attrib, musthave, canthave ) ) return NULL; Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); return findpath; }
/* * Sys_FS_FindNext */ const char *Sys_FS_FindNext( unsigned musthave, unsigned canhave ) { struct dirent64 *d; assert( fdir ); assert( findbase && findpattern ); if( !fdir ) return NULL; while( ( d = readdir64( fdir ) ) != NULL ) { if( !CompareAttributes( d, findbase, musthave, canhave ) ) continue; if( fdots > 0 ) { // . and .. never match const char *base = COM_FileBase( d->d_name ); if( !strcmp( base, "." ) || !strcmp( base, ".." ) ) { fdots--; continue; } } if( !*findpattern || Com_GlobMatch( findpattern, d->d_name, 0 ) ) { const char *dname = d->d_name; size_t dname_len = strlen( dname ); size_t size = sizeof( char ) * ( findbase_size + dname_len + 1 + 1 ); if( findpath_size < size ) { if( findpath ) Mem_TempFree( findpath ); findpath_size = size * 2; // extra size to reduce reallocs findpath = Mem_TempMalloc( findpath_size ); } Q_snprintfz( findpath, findpath_size, "%s/%s%s", findbase, dname, dname[dname_len-1] != '/' && FS_DirentIsDir( d, findbase ) ? "/" : "" ); if( CompareAttributesForPath( d, findpath, musthave, canhave ) ) return findpath; } } return NULL; }
/** * @brief Returns the next file of the already opened directory (Sys_FindFirst) that matches our search mask * @sa Sys_FindClose * @sa Sys_FindFirst * @sa static var findpattern */ char *Sys_FindNext (unsigned musthave, unsigned canhave) { struct dirent *d; if (fdir == NULL) return NULL; while ((d = readdir(fdir)) != NULL) { if (!*findpattern || Com_Filter(findpattern, d->d_name)) { if (CompareAttributes(findbase, d->d_name, musthave, canhave)) { Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, d->d_name); return findpath; } } } return NULL; }
char *Sys_FindNext ( uint32 musthave, uint32 canthave ) { WIN32_FIND_DATA findinfo; if (findhandle == INVALID_HANDLE_VALUE) return NULL; if (!FindNextFile (findhandle, &findinfo)) return NULL; if (!CompareAttributes( findinfo.dwFileAttributes, musthave, canthave ) ) return NULL; Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.cFileName); return findpath; }
char *Sys_FindNext (unsigned musthave, unsigned canhave) { struct dirent *d; if (fdir == NULL) return NULL; while ((d = readdir(fdir)) != NULL) { if (!*findpattern || glob_match(findpattern, d->d_name)) { // if (*findpattern) // printf("%s matched %s\n", findpattern, d->d_name); if (CompareAttributes(findbase, d->d_name, musthave, canhave)) { sprintf (findpath, "%s/%s", findbase, d->d_name); return findpath; } } } return NULL; }
/** * @sa Sys_FindFirst * @sa Sys_FindClose */ char *Sys_FindNext (unsigned musthave, unsigned canthave) { struct _finddata_t findinfo; if (findhandle == -1) return NULL; /* until we found the next entry */ while (_findnext(findhandle, &findinfo) != -1) { if (!Q_streq(findinfo.name, ".") && !Q_streq(findinfo.name, "..") && CompareAttributes(findinfo.attrib, musthave, canthave)) { Com_sprintf(findpath, sizeof(findpath), "%s/%s", findbase, findinfo.name); return findpath; } } /* none found */ return NULL; }
char *Sys_FindFirst (char *path, uint32 musthave, uint32 canthave ) { WIN32_FIND_DATA findinfo; if (findhandle != INVALID_HANDLE_VALUE) Sys_Error ("Sys_BeginFind without close"); COM_FilePath (path, findbase); findhandle = FindFirstFile (path, &findinfo); if (findhandle == INVALID_HANDLE_VALUE) return NULL; if (!CompareAttributes( findinfo.dwFileAttributes, musthave, canthave ) ) return NULL; Com_sprintf (findpath, sizeof(findpath), "%s/%s", findbase, findinfo.cFileName); return findpath; }
/* ----------------------------------------------------------------------------- Function: FS_FindFirstFile() -Searches a directory for a file. Parameters: path -[in] Pointer to a NUL-terminated string that specifies a valid directory or path and file name. musthave -[in] File or directory must have these attributes. canthave- [in] File or directory can not have these attributes. Returns: On success string of file name or directory, otherwise NULL. Notes: ----------------------------------------------------------------------------- */ PUBLIC char *FS_FindFirst( const char *path, W32 musthave, W32 canthave ) { WIN32_FIND_DATA FindFileData; if( FindHandle ) { printf( "FS_FindFirst without close\n" ); return NULL; } FS_FilePath( path, findbase ); FindHandle = FindFirstFile( path, &FindFileData ); if( FindHandle == INVALID_HANDLE_VALUE ) { return NULL; } if( CompareAttributes( FindFileData.dwFileAttributes, musthave, canthave ) ) { if( ! *findbase ) { cs_strlcpy( findpath, FindFileData.cFileName, sizeof( findpath ) ); } else { cs_snprintf( findpath, sizeof( findpath ), "%s/%s", findbase, FindFileData.cFileName ); } return findpath; } return FS_FindNext( musthave, canthave ); }