bool CResourceManager::DirectoryExists(const std::string& directory) { if (PHYSFS_isInit()) { return PHYSFS_exists(CleanPath(directory).c_str()) && PHYSFS_isDirectory(CleanPath(directory).c_str()); } return false; }
CiPath::CiPath(const std::string &_text) : text(_text) { CleanPath(); if (text != WIN_HD) { DIR *d = opendir(text.c_str()); if (d) { exists = true; isDir = true; closedir(d); } else if (errno == ENOTDIR) { exists = true; isDir = false; } else { exists = false; isDir = false; } } else { exists = true; isDir = true; } }
void AddGamePath( char *path ) { int i; /* dummy check */ if( path == NULL || path[ 0 ] == '\0' || numGamePaths >= MAX_GAME_PATHS ) return; /* add it to the list */ gamePaths[ numGamePaths ] = safe_malloc( strlen( path ) + 1 ); strcpy( gamePaths[ numGamePaths ], path ); CleanPath( gamePaths[ numGamePaths ] ); numGamePaths++; /* don't add it if it's already there */ for (i = 0; i < numGamePaths - 1; i++) { if (strcmp(gamePaths[i], gamePaths[numGamePaths - 1]) == 0) { free(gamePaths[numGamePaths - 1]); gamePaths[numGamePaths - 1] = NULL; numGamePaths--; break; } } }
void AddHomeBasePath(char *path) { #ifdef Q_UNIX int i; char temp[MAX_OSPATH]; /* dummy check */ if(path == NULL || path[0] == '\0') return; /* make a hole */ for(i = (MAX_BASE_PATHS - 2); i >= 0; i--) basePaths[i + 1] = basePaths[i]; /* concatenate home dir and path */ sprintf(temp, "%s/%s", homePath, path); /* add it to the list */ basePaths[0] = safe_malloc(strlen(temp) + 1); strcpy(basePaths[0], temp); CleanPath(basePaths[0]); numBasePaths++; #endif }
int KTestCommon::CleanPath(const TCHAR cszPath[]) { int nRetCode = false; int nResult = false; TCHAR szPathName[MAX_PATH]; TCHAR szFullPathFile[MAX_PATH]; TCHAR* pszFile = NULL; HANDLE hFindFile = INVALID_HANDLE_VALUE; WIN32_FIND_DATA FindFileData; ASSERT(cszPath); nRetCode = _sntprintf(szPathName, MAX_PATH, _T("%s\\%s"), cszPath, _T("*.*")); KGLOG_PROCESS_ERROR(nRetCode != -1); szPathName[MAX_PATH - 1] = _T('\0'); hFindFile = ::FindFirstFile(szPathName, &FindFileData); KGLOG_PROCESS_ERROR(hFindFile != INVALID_HANDLE_VALUE); while (true) { pszFile = FindFileData.cFileName; if (_tcsncmp(pszFile, _T("."), MAX_PATH) != 0 && _tcsncmp(pszFile, _T("logs"), MAX_PATH) != 0 && _tcsncmp(pszFile, _T(".."), MAX_PATH) != 0) { nRetCode = _sntprintf(szFullPathFile, MAX_PATH, _T("%s\\%s"), cszPath, pszFile); KGLOG_PROCESS_ERROR(nRetCode != -1); szFullPathFile[MAX_PATH - 1] = _T('\0'); if (FindFileData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY) { nRetCode = _tremove(szFullPathFile); KGLOG_PROCESS_ERROR(nRetCode == 0); } else { nRetCode = CleanPath(szFullPathFile); KGLOG_PROCESS_ERROR(nRetCode); nRetCode = ::RemoveDirectory(szFullPathFile); KGLOG_PROCESS_ERROR(nRetCode); } } nRetCode = ::FindNextFile(hFindFile, &FindFileData); if (!nRetCode) { nRetCode = ::GetLastError(); KG_PROCESS_SUCCESS(nRetCode == ERROR_NO_MORE_FILES); } } Exit1: nResult = true; Exit0: if (hFindFile != INVALID_HANDLE_VALUE) { ::FindClose(hFindFile); hFindFile = INVALID_HANDLE_VALUE; } return nResult; }
bool CResourceManager::Exists(const std::string &filename) { if (PHYSFS_isInit()) { return PHYSFS_exists(CleanPath(filename).c_str()); } return false; }
bool CResourceManager::CreateDirectory(const std::string& directory) { if (PHYSFS_isInit()) { return PHYSFS_mkdir(CleanPath(directory).c_str()); } return false; }
long long CResourceManager::GetLastModificationTime(const std::string& filename) { if (PHYSFS_isInit()) { return PHYSFS_getLastModTime(CleanPath(filename).c_str()); } return -1; }
void AddGamePath( char *path ){ /* dummy check */ if ( path == NULL || path[ 0 ] == '\0' || numGamePaths >= MAX_GAME_PATHS ) { return; } /* add it to the list */ gamePaths[ numGamePaths ] = safe_malloc( strlen( path ) + 1 ); strcpy( gamePaths[ numGamePaths ], path ); CleanPath( gamePaths[ numGamePaths ] ); numGamePaths++; }
void AddBasePath( char *path ) { /* dummy check */ if( path == NULL || path[ 0 ] == '\0' || numBasePaths >= MAX_BASE_PATHS ) return; /* add it to the list */ basePaths[ numBasePaths ] = safe_malloc( strlen( path ) + 1 ); strcpy( basePaths[ numBasePaths ], path ); CleanPath( basePaths[ numBasePaths ] ); numBasePaths++; }
long long CResourceManager::GetFileSize(const std::string& filename) { if (PHYSFS_isInit()) { PHYSFS_File* file = PHYSFS_openRead(CleanPath(filename).c_str()); if(file == nullptr) return -1; long long size = PHYSFS_fileLength(file); PHYSFS_close(file); return size; } return -1; }
std::vector<std::string> CResourceManager::ListDirectories(const std::string &directory) { std::vector<std::string> result; if (PHYSFS_isInit()) { char **files = PHYSFS_enumerateFiles(CleanPath(directory).c_str()); for (char **i = files; *i != nullptr; i++) { std::string path = CleanPath(directory) + "/" + (*i); if (PHYSFS_isDirectory(path.c_str())) { result.push_back(*i); } } PHYSFS_freeList(files); } return result; }
void GuiFileDialog::OnListboxClick(const std::string& fullPathAndFilename) { lastPath = CleanPath(fullPathAndFilename); GuiTextEdit* text = dynamic_cast<GuiTextEdit*>(GetElementByName("fd-path-text")); Assert(text); text->SetText(lastPath); ShowPreview(); #ifdef GFD_DEBUG std::cout << "Listbox click: lastPath is now \"" << lastPath << "\"\n"; #endif }
bool CResourceManager::RemoveDirectory(const std::string& directory) { if (PHYSFS_isInit()) { std::string path = CleanPath(directory); for (auto file : ListFiles(path)) { if (PHYSFS_delete((path + "/" + file).c_str()) == 0) return false; } return PHYSFS_delete(path.c_str()) != 0; } return false; }
void AddHomeBasePath( char *path ) { int i; char temp[ MAX_OS_PATH ]; int homePathLen; if(!homePath) return; /* dummy check */ if( path == NULL || path[ 0 ] == '\0' ) return; /* strip leading dot, if homePath does not end in /. */ homePathLen = strlen(homePath); if(!strcmp(path, ".")) { /* -fs_homebase . means that -fs_home is to be used as is */ strcpy(temp, homePath); } else if(homePathLen >= 2 && !strcmp(homePath + homePathLen - 2, "/.")) { /* remove trailing /. of homePath */ homePathLen -= 2; /* concatenate home dir and path */ sprintf( temp, "%.*s/%s", homePathLen, homePath, path ); } else { /* remove leading . of path */ if(path[0] == '.') ++path; /* concatenate home dir and path */ sprintf( temp, "%s/%s", homePath, path ); } /* make a hole */ for( i = (MAX_BASE_PATHS - 2); i >= 0; i-- ) basePaths[ i + 1 ] = basePaths[ i ]; /* add it to the list */ basePaths[ 0 ] = safe_malloc( strlen( temp ) + 1 ); strcpy( basePaths[ 0 ], temp ); CleanPath( basePaths[ 0 ] ); numBasePaths++; }
void GuiFileDialog::OnPathChange() { GuiTextEdit* text = dynamic_cast<GuiTextEdit*>(GetElementByName("fd-path-text")); Assert(text); lastPath = CleanPath(text->GetText()); GuiFileListBox* fb = dynamic_cast<GuiFileListBox*>(GetElementByName("fd-file-list-box")); Assert(fb); fb->SetDir(lastPath); ShowPreview(); #ifdef GFD_DEBUG std::cout << "Path change: lastPath is now \"" << lastPath << "\"\n"; #endif }
void MonsterPath(Entity *self, Entity *target) { int p; if((self == NULL)||(target == NULL))return; p = GetPath(self->p.x/TILEW,self->p.y/TILEH,target->p.x/TILEW,target->p.y/TILEH,self->team,self->path,PATHMAX,target); if(p != -1) { CleanPath(self->path,&p,self); self->drawtrail = 1; self->pathlen = p; self->pathstep = 0; self->target = target; self->state = MS_Pathing; } else { /*no path to target....*/ /* self->target = NULL;*/ self->state = MS_Hostile; } }
void InitPaths( int *argc, char **argv ){ int i, j, k, len, len2; char temp[ MAX_OS_PATH ]; char gamePath[MAX_OS_PATH], homeBasePath[MAX_OS_PATH], game_magic[10]; strcpy( gamePath, "baseq2" ); strcpy( game_magic, "quake" ); strcpy( homeBasePath, ".quake2" ); /* note it */ Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" ); /* get the install path for backup */ LokiInitPaths( argv[ 0 ] ); /* set game to default (q3a) */ numBasePaths = 0; numGamePaths = 0; /* parse through the arguments and extract those relevant to paths */ for ( i = 0; i < *argc; i++ ) { /* check for null */ if ( argv[ i ] == NULL ) { continue; } /* -fs_basepath */ if ( strcmp( argv[ i ], "-fs_basepath" ) == 0 ) { if ( ++i >= *argc ) { Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); } argv[ i - 1 ] = NULL; AddBasePath( argv[ i ] ); argv[ i ] = NULL; } } /* remove processed arguments */ for ( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ ) { for ( j; j < *argc && argv[ j ] == NULL; j++ ) ; argv[ i ] = argv[ j ]; if ( argv[ i ] != NULL ) { k++; } } *argc = k; /* add standard game path */ AddGamePath( gamePath ); /* if there is no base path set, figure it out */ if ( numBasePaths == 0 ) { /* this is another crappy replacement for SetQdirFromPath() */ len2 = strlen( game_magic ); for ( i = 0; i < *argc && numBasePaths == 0; i++ ) { /* extract the arg */ strcpy( temp, argv[ i ] ); CleanPath( temp ); len = strlen( temp ); Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game_magic, temp, i ); /* this is slow, but only done once */ for ( j = 0; j < ( len - len2 ); j++ ) { /* check for the game's magic word */ if ( Q_strncasecmp( &temp[ j ], game_magic, len2 ) == 0 ) { /* now find the next slash and nuke everything after it */ while ( temp[ ++j ] != '/' && temp[ j ] != '\0' ) ; temp[ j ] = '\0'; /* add this as a base path */ AddBasePath( temp ); break; } } } /* add install path */ if ( numBasePaths == 0 ) { AddBasePath( installPath ); } /* check again */ if ( numBasePaths == 0 ) { Error( "Failed to find a valid base path." ); } } /* this only affects unix */ AddHomeBasePath( homeBasePath ); /* initialize vfs paths */ if ( numBasePaths > MAX_BASE_PATHS ) { numBasePaths = MAX_BASE_PATHS; } if ( numGamePaths > MAX_GAME_PATHS ) { numGamePaths = MAX_GAME_PATHS; } /* walk the list of game paths */ //for( j = 0; j < numGamePaths; j++ ) //{ /* walk the list of base paths */ // for( i = 0; i < numBasePaths; i++ ) // { /* create a full path and initialize it */ // sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] ); // vfsInitDirectory( temp ); // } //} /* done */ Sys_Printf( "\n" ); }
static void GetFileList(char *path) { struct stat stat_buf; char *last_file_ptr, *first_path, *last_path; int levels_first_file, levels_last_file, file_list_level; int sub_index; FTS *fts; FTSENT *ftsent; CleanPath(path); // Check for last_file option last_file_ptr = strchr(path, ':'); first_path = last_path = NULL; levels_first_file = levels_last_file = 0; if ( last_file_ptr ) { // make sure we have only a single ':' in path if ( strrchr(path, ':') != last_file_ptr ) { fprintf(stderr, "Multiple file separators ':' in path not allowed!\n"); exit(250); } *last_file_ptr++ = '\0'; // last_file_ptr points to last_file if ( strlen(last_file_ptr) == 0 ) { fprintf(stderr, "Missing last file option after ':'!\n"); exit(250); } CleanPath(last_file_ptr); // make sure last_file option is not a full path if ( last_file_ptr[0] == '/') { fprintf(stderr, "Last file name in -R list must not start with '/'\n"); exit(250); } // how may sub dir levels has last_file option? levels_last_file = dirlevels(last_file_ptr); // if no subdirs are given for last_file, try to find out, if the last_file // exists in any possible subdirs if ( levels_last_file == 0 ) { char s[MAXPATHLEN]; char *r = VerifyFileRange(path, last_file_ptr); if ( r != last_file_ptr && r[0] != '\0' ) { snprintf(s, MAXPATHLEN-1, "%s/%s", r, last_file_ptr); s[MAXPATHLEN-1] = '\0'; last_file_ptr = strdup(s); levels_last_file = dirlevels(last_file_ptr); } } } levels_first_file = dirlevels(path); if ( source_dirs.num_strings == 0 ) { // No multiple sources option -M // path contains the path to a file/directory // stat this entry if ( stat(path, &stat_buf) ) { fprintf(stderr, "stat() error '%s': %s\n", path, strerror(errno)); exit(250); } if ( !S_ISDIR(stat_buf.st_mode) && !S_ISREG(stat_buf.st_mode) ) { fprintf(stderr, "Not a file or directory: '%s'\n", path); exit(250); } // Check, how many levels of directory in path levels_first_file = dirlevels(path); if ( last_file_ptr ) { // path is [/]path/to/any/dir|file:last_file_ptr // make sure first_file is a file if ( S_ISDIR(stat_buf.st_mode) ) { fprintf(stderr, "Not a file: '%s'\n", path); exit(250); } if ( levels_last_file ) { // we have levels_last_file number of sub dirs // sub dir levels of first_file mus have at least the same number of levels as last_file if ( levels_first_file < levels_last_file ) { fprintf(stderr, "Number of sub dirs for sub level hierarchy for file list -R do not match\n"); exit(250); } if ( levels_first_file == levels_last_file ) { char *p, *q; // path = [/]sub1[/..]/first_file:sub1[/...]/last_file if ( path[0] == '/' ) { // this is rather strange, but strctly spoken, valid anyway InsertString(&source_dirs, "/"); path++; } else { InsertString(&source_dirs, "."); } // path = sub_first[/..]/first_file:sub_last[/...]/last_file p = strrchr(path, '/'); q = strrchr(last_file_ptr, '/'); if ( !p || !q ) { // this should never happen fprintf(stderr, "software error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) ); exit(250); } *p++ = '\0'; *q++ = '\0'; first_file = strdup(p); last_file = strdup(q); file_list_level = levels_last_file + 1; first_path = path; last_path = last_file_ptr; } else { // path = [/]path/to/sub_first[/..]/first_file:sub_last[/...]/last_file int i; char *p, *r, *s; p = strrchr(path, '/'); // levels_first_file > levels_last_file // step back the number of sub dirs in first_file for ( i=0; i<levels_last_file; i++ ) { do { p--; } while ( p >= path && *p != '/'); } *p++ = '\0'; InsertString(&source_dirs, path); r = strrchr(p, '/'); s = strrchr(last_file_ptr, '/'); if ( !r || !s ) { // this must never happen fprintf(stderr, "software error in %s line %d: %s\n", __FILE__, __LINE__, strerror(errno) ); exit(250); } *r++ = '\0'; *s++ = '\0'; first_file = strdup(r); last_file = strdup(s); // files are listed at this sub dir level file_list_level = levels_last_file + 1; first_path = p; last_path = last_file_ptr; } } else { // we have no sub dir levels given // path is [/]path/to/any/file char *p = strrchr(path, '/'); if ( p ) { // path is [/]path/to/any/first_file:last_file *p++ = '\0'; // path is the direcory containing all the files InsertString(&source_dirs, path); first_file = strdup(p); } else { // path is first_file:last_file InsertString(&source_dirs, "."); first_file = strdup(path); } // set last_file filter last_file = strdup(last_file_ptr); // in any case we list the files of directory level 1 file_list_level = 1; } } else { // path is [/]path/to/any/dir|file if ( S_ISDIR(stat_buf.st_mode) ) { // path is [/]path/to/any/dir // list all files in this directory InsertString(&source_dirs, path); first_file = NULL; file_list_level = 0; } else { // path is [/]path/to/any/file char *p = strrchr(path, '/'); if ( p ) { // path is [/]path/to/any/file *p++ = '\0'; // path is the direcory containing all the files InsertString(&source_dirs, path); first_file = strdup(p); } else { // path is file InsertString(&source_dirs, "."); first_file = strdup(path); } // in any case we list the files of directory level 1 file_list_level = 1; } // in any case, no last_file filter last_file = NULL; } } else { char pathbuff[MAXPATHLEN]; // multiple sources option -M given if ( path[0] == '/') { fprintf(stderr, "File list -R must not start with '/' when combined with a source list -M\n"); exit(250); } // special case for all files in directory if ( strcmp(path, ".") == 0 ) { first_file = NULL; last_file = NULL; file_list_level = 0; } else { // pathbuff contains the path to a file/directory, compiled using the first entry // in the source_dirs snprintf(pathbuff, MAXPATHLEN-1, "%s/%s", source_dirs.list[0], path); pathbuff[MAXPATHLEN-1] = '\0'; // pathbuff must point to a file if ( stat(pathbuff, &stat_buf) ) { if ( errno == ENOENT ) { // file not found - try to guess a possible subdir char *sub_dir = GuessSubDir(source_dirs.list[0], path); if ( sub_dir ) { // subdir found snprintf(pathbuff, MAXPATHLEN-1, "%s/%s", sub_dir, path); pathbuff[MAXPATHLEN-1] = '\0'; // update path path = strdup(pathbuff); free(sub_dir); // need guessing subdir with last_file too if ( last_file_ptr ) { sub_dir = GuessSubDir(source_dirs.list[0], last_file_ptr); if ( sub_dir ) { // subdir found snprintf(pathbuff, MAXPATHLEN-1, "%s/%s", sub_dir, last_file_ptr); pathbuff[MAXPATHLEN-1] = '\0'; last_file_ptr = strdup(pathbuff); free(sub_dir); // update dir levels of extended file path levels_last_file = dirlevels(last_file_ptr); } else { fprintf(stderr, "'%s': %s\n", last_file_ptr, "File not found!"); exit(250); } } } else { // no file in any possible subdir found fprintf(stderr, "stat() error '%s': %s\n", pathbuff, "File not found!"); exit(250); } } else { // Any other stat error fprintf(stderr, "stat() error '%s': %s\n", pathbuff, strerror(errno)); exit(250); } } else if ( !S_ISREG(stat_buf.st_mode) ) { fprintf(stderr, "Not a file : '%s'\n", pathbuff); exit(250); } // Check, how many levels of directory in path levels_first_file = dirlevels(path); if ( last_file_ptr ) { // path is path/to/any/first_file:last_file_ptr char *p, *q; // the number of sub dirs must be eqal for first_file and last_file if ( levels_first_file != levels_last_file ) { fprintf(stderr, "Number of sub dirs must agree in '%s' and '%s'\n", path, last_file_ptr); exit(250); } p = strrchr(path, '/'); if ( p ) { // path is fist_sub/to/any/first_file // recursive all files in sub dirs file_list_level = dirlevels(path) + 1; *p++ = '\0'; first_file = strdup(p); first_path = path; } else { // path is first_file first_file = strdup(path); file_list_level = 1; } q = strrchr(last_file_ptr, '/'); if ( q ) { *q++ = '\0'; last_file = strdup(q); last_path = last_file_ptr; } else { last_file = strdup(last_file_ptr); } } else { // path is path/to/any/first_file char *p = strrchr(path, '/'); if ( p ) { // path is fist_sub/to/any/first_file // recursive all files in sub dirs file_list_level = dirlevels(path) + 1; *p++ = '\0'; first_file = strdup(p); first_path = path; } else { // path is first_file first_file = strdup(path); file_list_level = 1; } last_file = NULL; } } } /* printf("first_file %s\n", first_file ? first_file : "<none>"); printf("last_file %s\n", last_file ? last_file : "<none>"); printf("first_path %s\n", first_path ? first_path : "<none>"); printf("last_path %s\n", last_path ? last_path : "<none>"); printf("file_list_level: %i\n", file_list_level); */ CreateDirListFilter(first_path, last_path, file_list_level ); // last entry must be NULL InsertString(&source_dirs, NULL); fts = fts_open(source_dirs.list, FTS_LOGICAL, compare); sub_index = 0; while ( (ftsent = fts_read(fts)) != NULL) { int fts_level = ftsent->fts_level; char *fts_path; // printf("DBG: %u %i %s %s\n", ftsent->fts_info, ftsent->fts_level, ftsent->fts_path, ftsent->fts_name); if ( fts_level == 0 ) { sub_index = ftsent->fts_pathlen + 1; continue; } if ( ftsent->fts_pathlen < sub_index ) { printf("ERROR: fts_pathlen error at %s line %d\n", __FILE__, __LINE__); exit(250); } fts_path = &ftsent->fts_path[sub_index]; /* if ( file_list_level ) printf("DGB: short fts: '%s', filer_first: '%s', filter_last: '%s'\n", fts_path, dir_entry_filter[fts_level].first_entry , dir_entry_filter[fts_level].last_entry); */ switch (ftsent->fts_info) { case FTS_D: // dir entry pre descend if ( file_list_level && file_list_level && ( ( dir_entry_filter[fts_level].first_entry && ( strcmp(fts_path, dir_entry_filter[fts_level].first_entry ) < 0 ) ) || ( dir_entry_filter[fts_level].last_entry && ( strcmp(fts_path, dir_entry_filter[fts_level].last_entry ) > 0 ) ) )) fts_set(fts, ftsent, FTS_SKIP ); break; case FTS_DP: break; case FTS_F: // file entry // printf("==> Check: %s\n", ftsent->fts_name); // skip stat file if ( strcmp(ftsent->fts_name, ".nfstat") == 0 || strncmp(ftsent->fts_name, NF_DUMPFILE , strlen(NF_DUMPFILE)) == 0) continue; if ( strstr(ftsent->fts_name, ".stat") != NULL ) continue; // skip pcap file if ( strstr(ftsent->fts_name, "pcap") != NULL ) continue; if ( file_list_level && ( ( fts_level != file_list_level ) || ( dir_entry_filter[fts_level].first_entry && ( strcmp(ftsent->fts_name, dir_entry_filter[fts_level].first_entry) < 0 ) ) || ( dir_entry_filter[fts_level].last_entry && ( strcmp(ftsent->fts_name, dir_entry_filter[fts_level].last_entry) > 0 ) ) ) ) continue; // printf("==> Listed: %s\n", ftsent->fts_path); InsertString(&file_list, ftsent->fts_path); break; } } fts_close(fts); } // End of GetFileList
void SetupInputFileSequence(char *multiple_dirs, char *single_file, char *multiple_files) { twin_first = 0; twin_last = 0xffffffff; first_file = NULL; last_file = NULL; InitStringlist(&source_dirs, NUM_PTR); InitStringlist(&file_list, 64); if ( multiple_dirs ) Getsource_dirs(multiple_dirs); if ( multiple_files ) { // use multiple files GetFileList(multiple_files); // get time window spanning all the files if ( file_list.num_strings ) { stat_record_t stat_ptr; // read the stat record if ( !GetStatRecord(file_list.list[0], &stat_ptr) ) { exit(250); } twin_first = stat_ptr.first_seen; // read the stat record of last file if ( !GetStatRecord(file_list.list[file_list.num_strings-1], &stat_ptr) ) { exit(250); } twin_last = stat_ptr.last_seen; } } else if ( single_file ) { CleanPath(single_file); if ( source_dirs.num_strings == 0 ) { InsertString(&file_list, single_file); } else { int i; if ( single_file[0] == '/' ) { fprintf(stderr, "File -r must not start with '/', when combined with a source list -M\n"); exit(250); } for ( i=0; i<source_dirs.num_strings; i++ ) { char s[MAXPATHLEN]; struct stat stat_buf; snprintf(s, MAXPATHLEN-1, "%s/%s", source_dirs.list[i], single_file); s[MAXPATHLEN-1] = '\0'; if ( stat(s, &stat_buf) ) { if ( errno == ENOENT ) { // file not found - try to guess subdir char *sub_dir = GuessSubDir(source_dirs.list[i], single_file); if ( sub_dir ) { // subdir found snprintf(s, MAXPATHLEN-1, "%s/%s/%s", source_dirs.list[i], sub_dir, single_file); s[MAXPATHLEN-1] = '\0'; InsertString(&file_list, s); } else { // no subdir found fprintf(stderr, "stat() error '%s': %s\n", s, "File not found!"); } } else { // Any other stat error fprintf(stderr, "stat() error '%s': %s\n", s, strerror(errno)); exit(250); } } else { // stat() successful if ( !S_ISREG(stat_buf.st_mode) ) { fprintf(stderr, "Skip non file entry: '%s'\n", s); } else { InsertString(&file_list, s); } } } } } else // else use stdin InsertString(&file_list, NULL); } // End of SetupInputFileSequence
std::unique_ptr<CSNDFileWrapper> CResourceManager::GetSNDFileHandler(const std::string &filename) { return MakeUnique<CSNDFileWrapper>(CleanPath(filename)); }
void InitPaths( int *argc, char **argv ) { int i, j, k, len, len2; char temp[ MAX_OS_PATH ]; /* note it */ Sys_FPrintf( SYS_VRB, "--- InitPaths ---\n" ); /* get the install path for backup */ LokiInitPaths( argv[ 0 ] ); /* set game to default (q3a) */ game = &games[ 0 ]; numBasePaths = 0; numGamePaths = 0; /* parse through the arguments and extract those relevant to paths */ for( i = 0; i < *argc; i++ ) { /* check for null */ if( argv[ i ] == NULL ) continue; /* -game */ if( strcmp( argv[ i ], "-game" ) == 0 ) { if( ++i >= *argc ) Error( "Out of arguments: No game specified after %s", argv[ i - 1 ] ); argv[ i - 1 ] = NULL; game = GetGame( argv[ i ] ); if( game == NULL ) game = &games[ 0 ]; argv[ i ] = NULL; } /* -fs_forbiddenpath */ else if( strcmp( argv[ i ], "-fs_forbiddenpath" ) == 0 ) { if( ++i >= *argc ) Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); argv[ i - 1 ] = NULL; if(g_numForbiddenDirs < VFS_MAXDIRS) { strncpy(g_strForbiddenDirs[g_numForbiddenDirs], argv[i], PATH_MAX); g_strForbiddenDirs[g_numForbiddenDirs][PATH_MAX] = 0; ++g_numForbiddenDirs; } argv[ i ] = NULL; } /* -fs_basepath */ else if( strcmp( argv[ i ], "-fs_basepath" ) == 0 ) { if( ++i >= *argc ) Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); argv[ i - 1 ] = NULL; AddBasePath( argv[ i ] ); argv[ i ] = NULL; } /* -fs_game */ else if( strcmp( argv[ i ], "-fs_game" ) == 0 ) { if( ++i >= *argc ) Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); argv[ i - 1 ] = NULL; AddGamePath( argv[ i ] ); argv[ i ] = NULL; } /* -fs_home */ else if( strcmp( argv[ i ], "-fs_home" ) == 0 ) { if( ++i >= *argc ) Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); argv[ i - 1 ] = NULL; homePath = argv[i]; argv[ i ] = NULL; } /* -fs_homebase */ else if( strcmp( argv[ i ], "-fs_homebase" ) == 0 ) { if( ++i >= *argc ) Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); argv[ i - 1 ] = NULL; homeBasePath = argv[i]; argv[ i ] = NULL; } /* -fs_homepath - sets both of them */ else if( strcmp( argv[ i ], "-fs_homepath" ) == 0 ) { if( ++i >= *argc ) Error( "Out of arguments: No path specified after %s.", argv[ i - 1 ] ); argv[ i - 1 ] = NULL; homePath = argv[i]; homeBasePath = "."; argv[ i ] = NULL; } } /* remove processed arguments */ for( i = 0, j = 0, k = 0; i < *argc && j < *argc; i++, j++ ) { for( ; j < *argc && argv[ j ] == NULL; j++ ); argv[ i ] = argv[ j ]; if( argv[ i ] != NULL ) k++; } *argc = k; /* add standard game path */ AddGamePath( game->gamePath ); /* if there is no base path set, figure it out */ if( numBasePaths == 0 ) { /* this is another crappy replacement for SetQdirFromPath() */ len2 = strlen( game->magic ); for( i = 0; i < *argc && numBasePaths == 0; i++ ) { /* extract the arg */ strcpy( temp, argv[ i ] ); CleanPath( temp ); len = strlen( temp ); Sys_FPrintf( SYS_VRB, "Searching for \"%s\" in \"%s\" (%d)...\n", game->magic, temp, i ); /* this is slow, but only done once */ for( j = 0; j < (len - len2); j++ ) { /* check for the game's magic word */ if( Q_strncasecmp( &temp[ j ], game->magic, len2 ) == 0 ) { /* now find the next slash and nuke everything after it */ while( temp[ ++j ] != '/' && temp[ j ] != '\0' ); temp[ j ] = '\0'; /* add this as a base path */ AddBasePath( temp ); break; } } } /* add install path */ if( numBasePaths == 0 ) AddBasePath( installPath ); /* check again */ if( numBasePaths == 0 ) Error( "Failed to find a valid base path." ); } /* this only affects unix */ if(homeBasePath) AddHomeBasePath( homeBasePath ); else AddHomeBasePath( game->homeBasePath ); /* initialize vfs paths */ if( numBasePaths > MAX_BASE_PATHS ) numBasePaths = MAX_BASE_PATHS; if( numGamePaths > MAX_GAME_PATHS ) numGamePaths = MAX_GAME_PATHS; /* walk the list of game paths */ for( j = 0; j < numGamePaths; j++ ) { /* walk the list of base paths */ for( i = 0; i < numBasePaths; i++ ) { /* create a full path and initialize it */ sprintf( temp, "%s/%s/", basePaths[ i ], gamePaths[ j ] ); vfsInitDirectory( temp ); } } /* done */ Sys_Printf( "\n" ); }
ImageFile *UEFileFactory::newImageFile(const std::string &initialFilePath, point initialDefaultPivot) { FString relPath = ANSI_TO_TCHAR(initialFilePath.c_str()); CleanPath(relPath); return new UEImageFile(TCHAR_TO_ANSI(*relPath), initialDefaultPivot, canvas, imagePath); }
SoundFile *UEFileFactory::newSoundFile(const std::string &initialFilePath) { FString relPath = ANSI_TO_TCHAR(initialFilePath.c_str()); CleanPath(relPath); return new UESoundFile(TCHAR_TO_ANSI(*relPath)); }