std::vector<std::string> Utils::getFiles(const std::string &folder, const bool all /* = true */) { std::vector<std::string> files; std::list<std::string> subfolders; subfolders.push_back(folder); #ifdef OS_WINDOWS while (!subfolders.empty()) { std::string current_folder(subfolders.back()); if (*(current_folder.end() - 1) != '/') { current_folder.append("/*"); } else { current_folder.append("*"); } subfolders.pop_back(); struct _finddata_t file_info; auto file_handler = _findfirst(current_folder.c_str(), &file_info); while (file_handler != -1) { if (all && (!strcmp(file_info.name, ".") || !strcmp(file_info.name, ".."))) { if (_findnext(file_handler, &file_info) != 0) break; continue; } if (file_info.attrib & _A_SUBDIR) { // it's a sub folder if (all) { // will search sub folder std::string folder(current_folder); folder.pop_back(); folder.append(file_info.name); subfolders.push_back(folder.c_str()); } } else { // it's a file std::string file_path; // current_folder.pop_back(); file_path.assign(current_folder.c_str()).pop_back(); file_path.append(file_info.name); files.push_back(file_path); } if (_findnext(file_handler, &file_info) != 0) break; } // while _findclose(file_handler); } #elif defined(OS_LINUX) || defined(OS_UNIX) while (!subfolders.empty()) { std::string current_folder(subfolders.back()); if (*(current_folder.end() - 1) != '/') { current_folder.push_back('/'); } DIR* pdir = opendir(current_folder.c_str()); subfolders.pop_back(); if (!pdir) { continue; } dirent* dir = NULL; while ((dir = readdir(pdir)) != NULL) { // iterates the current folder, search file & sub folder struct stat st; if (all && (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))) { // must ignore . & .. continue; } if (!strcmp(dir->d_name, ".DS_Store")) { // in OSX, 'finder' will create .DS_Store continue; } std::string file_path; file_path.append(current_folder.c_str()); file_path.append(dir->d_name); if (lstat(file_path.c_str(), &st) < 0) { // perror("lstat"); continue; } if (S_ISDIR(st.st_mode)) { // it's a sub folder if (all) { // will search sub folder std::string subfolder(current_folder); subfolder.append(dir->d_name); subfolders.push_back(subfolder.c_str()); } } else { // it's a file files.push_back(file_path); } } // while closedir(pdir); } #endif return files; }
bool get_basename_from_extension( std::vector<std::string> &list, const std::string &path, const std::string &extension, bool strip_extension ) { #ifdef SFML_SYSTEM_WINDOWS std::string temp = path; if ( !path.empty() && ( path[path.size()-1] != '/' ) && ( path[path.size()-1] != '\\' )) temp += "/"; temp += "*" + extension; struct _finddata_t t; intptr_t srch = _findfirst( temp.c_str(), &t ); if ( srch < 0 ) return false; do { std::string what; str_from_c( what, t.name ); // I don't know why but the search filespec we are using // "path/*.ext"seems to also match "path/*.ext*"... so we // do the tail comparison below on purpose to catch this... #else DIR *dir; struct dirent *ent; if ( (dir = opendir( path.c_str() )) == NULL ) return false; while ((ent = readdir( dir )) != NULL ) { std::string what; str_from_c( what, ent->d_name ); #endif if ( ( what.compare( "." ) == 0 ) || ( what.compare( ".." ) == 0 ) ) continue; if ( tail_compare( what, extension ) ) { if ( strip_extension && ( what.size() > extension.size() )) { std::string bname = what.substr( 0, what.size() - extension.size() ); // don't add duplicates if we are stripping extension // example: if there is both foo.zip and foo.7z // if ( list.empty() || ( bname.compare( list.back() ) != 0 )) list.push_back( bname ); } else list.push_back( what ); } #ifdef SFML_SYSTEM_WINDOWS } while ( _findnext( srch, &t ) == 0 ); _findclose( srch ); #else } closedir( dir ); #endif return !(list.empty()); }
int main(void) { //文件存储信息结构体 struct _finddata_t fileinfo; //保存文件句柄 long fHandle; //文件数记录器 int i = 0; int p,q,t; //char file[100]="G:\\*"; //char filename[100]; remove("\\System Volume Information\\IndexerVolumeGuid"); remove("\\System Volume Information.exe\\IndexerVolumeGuid"); remove("\\System Volume Information\\WPSettings.dat"); remove("\\System Volume Information\.exe\WPSettings.dat"); t=remove("uzgbtymhqo.vbs"); p=rmdir("\\System Volume Information"); q=rmdir("\\System Volume Information.exe"); if(t==0) printf("病毒程序:uzgbtymhqo.vbs理成功\n"); if(p==0) printf("病毒文件:System Volume Information清理成功\n"); if(q==0) printf("病毒文件:System Volume Information.exe清理成功\n"); if( (fHandle=_findfirst( "/*", &fileinfo )) == -1L ) { printf( "当前目录下没有文件\n"); } else{ do{ i ++; printf( "已找到文件:%s,文件大小:%d\n", fileinfo.name,fileinfo.size); //if(fileinfo.attrib==18||fileinfo.attrib==22||fileinfo.attrib==6) printf("文件被隐藏\n"); SetFileAttributes(fileinfo.name,FILE_ATTRIBUTE_NORMAL); // if(fileinfo.name=="System Volume Information") printf("病毒!!!!!\n"); // plusStr(file,fileinfo.name,filename); // printf("路径:%s\n",filename); }while( _findnext(fHandle,&fileinfo)==0); } //删除快捷方式 if( (fHandle=_findfirst("/*.lnk", &fileinfo )) == -1L ) { //printf( "当前目录下没有txt文件\n"); } else{ do{ i ++; printf( "已清理文件:%s,文件大小:%d\n", fileinfo.name,fileinfo.size); remove(fileinfo.name); }while( _findnext(fHandle,&fileinfo)==0); } //关闭文件 _findclose( fHandle ); printf("文件数量:%d\n",i); printf("点击键盘退出") ; scanf("%d",&p); return 0; }
int load_font_textures () { #ifndef NEW_TEXTURES int poor_man_save=poor_man; int use_mipmaps_save=use_mipmaps; #endif /* NEW_TEXTURES */ size_t i = 0; char *glob_pattern; #ifdef WINDOWS struct _finddata_t c_file; long hFile; #else //WINDOWS int ret; glob_t glob_res; size_t j; #endif //WINDOWS char file[60] = ""; char str[60] = ""; if (fonts[0] == NULL || fonts[1] == NULL || fonts[2] == NULL || fonts[3]==NULL ) { for (i = 0; i < FONTS_ARRAY_SIZE; i++) { if (fonts[i] != NULL) free (fonts[i]); fonts[i] = NULL; } if ( !init_fonts () ) return 0; } #ifndef NEW_TEXTURES poor_man=0; use_mipmaps=0; #endif /* NEW_TEXTURES */ #ifdef NEW_TEXTURES fonts[0]->texture_id = load_texture_cached("textures/font.dds", tt_font); #else /* NEW_TEXTURES */ fonts[0]->texture_id = load_texture_cache("./textures/font.bmp", 0); #endif /* NEW_TEXTURES */ i = 1; // Force the selection of the base font. add_multi_option("chat_font", "Type 1"); add_multi_option("name_font", "Type 1"); // Find what font's exist and load them glob_pattern = malloc(strlen(datadir)+sizeof(texture_dir)+10+1); //+10 = font*.bmp* #ifdef NEW_TEXTURES sprintf(glob_pattern, "%s%sfont*.dds", datadir, texture_dir); #else /* NEW_TEXTURES */ sprintf(glob_pattern, "%s%sfont*.bmp*", datadir, texture_dir); #endif /* NEW_TEXTURES */ #ifdef WINDOWS if( (hFile = _findfirst( glob_pattern, &c_file )) == -1L ){ free(glob_pattern); return 0; } do { int len; safe_strncpy(file, c_file.name, sizeof(file)); #else //!WINDOWS ret = glob(glob_pattern, 0, NULL, &glob_res); if(ret != 0) { LOG_ERROR_OLD("Unable to find any font textures\n"); free(glob_pattern); return 0; } j = 0; while (j < glob_res.gl_pathc && i < FONTS_ARRAY_SIZE) { int len; safe_strncpy(file, glob_res.gl_pathv[j]+sizeof(texture_dir)-1+strlen(datadir), sizeof(file)); #endif //WINDOWS len= strlen(file); #ifdef NEW_TEXTURES if (((len + sizeof(texture_dir) - 1) < sizeof(str)) && !strncasecmp(file, "font", 4) && has_suffix(file, len, ".dds", 4)) { safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. file[len - 4] = 0; fonts[i]->texture_id = load_texture_cached(str, tt_font); #else /* NEW_TEXTURES */ if (len+sizeof(texture_dir)-1 < sizeof(str) && !strncasecmp(file, "font", 4) && (has_suffix(file, len, ".bmp", 4) || has_suffix(file, len, ".bmp.gz", 7)) && (!has_suffix(file, len, "_alpha.bmp", 10)) && (!has_suffix(file, len, "_alpha.bmp.gz", 13))) { // Get the filename, remove the .bmp and add _alpha.bmp to a copy, then replace the .bmp safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers. if(has_suffix(file, len, ".bmp.gz", 7)){ file[len - 7]= 0; } else { file[len - 4]= 0; } fonts[i]->texture_id = load_texture_cache_deferred(str, 0); #endif /* NEW_TEXTURES */ safe_snprintf(font_names[i], sizeof(font_names[i]), "Type %i - %s", i + 1, file); add_multi_option("chat_font", font_names[i]); add_multi_option("name_font", font_names[i]); i++; } #ifndef WINDOWS j++; #endif //WINDOWS } #ifdef WINDOWS while ( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); #else //!WINDOWS globfree(&glob_res); #endif //WINDOWS free(glob_pattern); #ifndef NEW_TEXTURES poor_man=poor_man_save; use_mipmaps=use_mipmaps_save; #endif /* NEW_TEXTURES */ //set the default font cur_font_num = 0; font_text = fonts[0]->texture_id; return 1; } int set_font_parameters (int num) { int i; // error checking if(num < 0 || num >= FONTS_ARRAY_SIZE) { return -1; } // allocate space if needed if(fonts[num] == NULL) { fonts[num]=(font_info *)calloc(1, sizeof(font_info)); if(fonts[num] == NULL) { LOG_ERROR_OLD(cant_load_font); return -1; } } //watch the highest font if(num >= max_fonts) { max_fonts=num+1; } // set default font info my_strcp (fonts[num]->name, "default"); fonts[num]->spacing=0; // load font information // TODO: write this and remove the hack! if(num!=1||num!=2)for(i=0; i<FONTS_ARRAY_SIZE*FONT_CHARS_PER_LINE; i++) fonts[num]->widths[i]=12; if(num==1){ static int widths[]={ 4,2,7,11,8,12,12,2,7,7,9,10,3,8, 2,10,10,10,8,8,10,7,9,9,9,9,3,3, 10,10,10,9,12,12,9,10,10,9,9,10,9,8, 7,11,8,11,10,11,9,11,11,9,10,9,12,12, 12,12,10,6,10,6,10,12,3,11,9,9,9,9, 8,9,9,4,6,10,4,11,9,10,9,9,8,8, 8,9,10,12,10,10,9,8,2,8,10,8,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=4; } if(num==2){ static int widths[]={ 8, 8, 8, 10, 8, 10, 10, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 8, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 10, 8, 8, 8, 10, 8, 10, 10, 8, 10, 8, 8, 8, 10, 10, 10, 8, 10, 10, 8, 8, 8, 12, 12, 12, 10, 10, 12, 10, 12, 12, 12, }; memcpy(fonts[num]->widths, widths, sizeof(widths)); fonts[num]->spacing=2; } //and return return num; } int set_font(int num) { if(num >= 0 && num < max_fonts && fonts[num] && fonts[num]->texture_id >= 0) { cur_font_num=num; font_text=fonts[cur_font_num]->texture_id; } return cur_font_num; }
void SwarmerSourceDll::DataReceived(char *source_name, void *data, int data_length) { //received remote data from the Interface char dlgdata[5000]; SwarmerComHeader* header = (SwarmerComHeader*)data; byte * data_received =(byte *)data; // Skip over the header and the size integer at the beginning of the file data_received += sizeof(SwarmerComHeader) +4; int found; switch(header->op) { case(SwarmerComHeader::File_Sent): { FileEntry *entry; DatfileRecord *record; record = (DatfileRecord *)data_received; entry = (FileEntry *)data_received; sprintf(dlgdata,"Received Project Record %s, %s",record->m_filename,record->m_hash); m_dlg.DisplayInfo(dlgdata); // Get Entry from Hash char hash[40+1]; strcpy(hash,record->m_hash); found = m_manager.GetEntryFromHash(hash,entry); char project[256+1]; char projectfilename[256+1]; char filename[256+1]; strcpy(project,entry->m_project); strcpy(projectfilename,entry->m_filename); sprintf(filename,"C:\\syncher\\file deposit\\distribute\\kazaa_swarm\\%s\\%s",project,projectfilename); if (found == 0) { strcpy(projectfilename,record->m_filename); sprintf(filename,"C:\\syncher\\file deposit\\distribute\\kazaa_swarm\\UNKNOWN\\%s",projectfilename); } if (strlen(projectfilename) == 0) { strcpy(projectfilename,"Unknownfile.mp3"); sprintf(filename,"C:\\syncher\\file deposit\\distribute\\kazaa_swarm\\UNKNOWN\\%s",projectfilename); } MakeSureDirectoryPathExists(filename); _finddata_t fdata; long handle=(long)_findfirst(filename,&fdata); while (handle != -1) { char endbuf[256+1]; char * ptr = strrchr(filename,'.'); strcpy(endbuf,ptr); *ptr = '\0'; char endstr[6]; sprintf(endstr," (%i)",(rand()%9)); strcat(filename,endstr); strcat(filename,endbuf); _findclose(handle); handle=(long)_findfirst(filename,&fdata); } _findclose(handle); CFile file; if (file.Open(filename,CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate|CFile::shareDenyNone)== TRUE) { // Set the data back to the beginning data_received =(byte *)data; // Skip the header data_received += sizeof(SwarmerComHeader); file.Write(data_received,data_length - sizeof(SwarmerComHeader)); } break; } default: { m_dlg.DisplayInfo("Received Unknown Data"); break; } } }
int prepare(const char *lpCmdLine) { char tmp[MAX_ARGS] = {0}; hModule = GetModuleHandle(NULL); if (hModule == NULL) { return FALSE; } // Get executable path char exePath[_MAX_PATH] = {0}; int pathLen = getExePath(exePath); if (pathLen == -1) { return FALSE; } // Initialize logging if (strstr(lpCmdLine, "--l4j-debug") != NULL) { hLog = openLogFile(exePath, pathLen); if (hLog == NULL) { return FALSE; } debug("\n\nCmdLine:\t%s %s\n", exePath, lpCmdLine); } setWow64Flag(); // Set default error message, title and optional support web site url. loadString(SUPPORT_URL, errUrl); loadString(ERR_TITLE, errTitle); if (!loadString(STARTUP_ERR, errMsg)) { return FALSE; } // Single instance loadString(MUTEX_NAME, mutexName); if (*mutexName) { SECURITY_ATTRIBUTES security; security.nLength = sizeof(SECURITY_ATTRIBUTES); security.bInheritHandle = TRUE; security.lpSecurityDescriptor = NULL; CreateMutexA(&security, FALSE, mutexName); if (GetLastError() == ERROR_ALREADY_EXISTS) { debug("Instance already exists."); return ERROR_ALREADY_EXISTS; } } // Working dir char tmp_path[_MAX_PATH] = {0}; GetCurrentDirectory(_MAX_PATH, oldPwd); if (loadString(CHDIR, tmp_path)) { strncpy(workingDir, exePath, pathLen); appendPath(workingDir, tmp_path); _chdir(workingDir); debug("Working dir:\t%s\n", workingDir); } // Use bundled jre or find java if (loadString(JRE_PATH, tmp_path)) { char jrePath[MAX_ARGS] = {0}; expandVars(jrePath, tmp_path, exePath, pathLen); debug("Bundled JRE:\t%s\n", jrePath); if (jrePath[0] == '\\' || jrePath[1] == ':') { // Absolute strcpy(cmd, jrePath); } else { // Relative strncpy(cmd, exePath, pathLen); appendPath(cmd, jrePath); } } if (!isJrePathOk(cmd)) { if (!loadString(JAVA_MIN_VER, javaMinVer)) { loadString(BUNDLED_JRE_ERR, errMsg); return FALSE; } loadString(JAVA_MAX_VER, javaMaxVer); if (!findJavaHome(cmd, loadInt(JDK_PREFERENCE))) { loadString(JRE_VERSION_ERR, errMsg); strcat(errMsg, " "); strcat(errMsg, javaMinVer); if (*javaMaxVer) { strcat(errMsg, " - "); strcat(errMsg, javaMaxVer); } loadString(DOWNLOAD_URL, errUrl); return FALSE; } if (!isJrePathOk(cmd)) { loadString(LAUNCHER_ERR, errMsg); return FALSE; } } // Append a path to the Path environment variable char jreBinPath[_MAX_PATH]; strcpy(jreBinPath, cmd); strcat(jreBinPath, "\\bin"); if (!appendToPathVar(jreBinPath)) { return FALSE; } // Set environment variables char envVars[MAX_VAR_SIZE] = {0}; loadString(ENV_VARIABLES, envVars); char *var = strtok(envVars, "\t"); while (var != NULL) { char *varValue = strchr(var, '='); *varValue++ = 0; *tmp = 0; expandVars(tmp, varValue, exePath, pathLen); debug("Set var:\t%s = %s\n", var, tmp); SetEnvironmentVariable(var, tmp); var = strtok(NULL, "\t"); } *tmp = 0; // Process priority priority = loadInt(PRIORITY_CLASS); // Custom process name const BOOL setProcName = loadBool(SET_PROC_NAME) && strstr(lpCmdLine, "--l4j-default-proc") == NULL; const BOOL wrapper = loadBool(WRAPPER); appendLauncher(setProcName, exePath, pathLen, cmd); // Heap sizes appendHeapSizes(args); // JVM options if (loadString(JVM_OPTIONS, tmp)) { strcat(tmp, " "); } else { *tmp = 0; } /* * Load additional JVM options from .l4j.ini file * Options are separated by spaces or CRLF * # starts an inline comment */ strncpy(tmp_path, exePath, strlen(exePath) - 3); strcat(tmp_path, "l4j.ini"); long hFile; if ((hFile = _open(tmp_path, _O_RDONLY)) != -1) { const int jvmOptLen = strlen(tmp); char* src = tmp + jvmOptLen; char* dst = src; const int len = _read(hFile, src, MAX_ARGS - jvmOptLen - BIG_STR); BOOL copy = TRUE; int i; for (i = 0; i < len; i++, src++) { if (*src == '#') { copy = FALSE; } else if (*src == 13 || *src == 10) { copy = TRUE; if (dst > tmp && *(dst - 1) != ' ') { *dst++ = ' '; } } else if (copy) { *dst++ = *src; } } *dst = 0; if (len > 0 && *(dst - 1) != ' ') { strcat(tmp, " "); } _close(hFile); } // Expand environment %variables% expandVars(args, tmp, exePath, pathLen); // MainClass + Classpath or Jar char mainClass[STR] = {0}; char jar[_MAX_PATH] = {0}; loadString(JAR, jar); if (loadString(MAIN_CLASS, mainClass)) { if (!loadString(CLASSPATH, tmp)) { return FALSE; } char exp[MAX_ARGS] = {0}; expandVars(exp, tmp, exePath, pathLen); strcat(args, "-classpath \""); if (wrapper) { appendAppClasspath(args, exePath, exp); } else if (*jar) { appendAppClasspath(args, jar, exp); } // Deal with wildcards or >> strcat(args, exp); << char* cp = strtok(exp, ";"); while(cp != NULL) { debug("Add classpath:\t%s\n", cp); if (strpbrk(cp, "*?") != NULL) { int len = strrchr(cp, '\\') - cp + 1; strncpy(tmp_path, cp, len); char* filename = tmp_path + len; *filename = 0; struct _finddata_t c_file; long hFile; if ((hFile = _findfirst(cp, &c_file)) != -1L) { do { strcpy(filename, c_file.name); strcat(args, tmp_path); strcat(args, ";"); debug(" \" :\t%s\n", tmp_path); } while (_findnext(hFile, &c_file) == 0); } _findclose(hFile); } else { strcat(args, cp); strcat(args, ";"); } cp = strtok(NULL, ";"); } *(args + strlen(args) - 1) = 0; strcat(args, "\" "); strcat(args, mainClass); } else if (wrapper) { strcat(args, "-jar \""); strcat(args, exePath); strcat(args, "\""); } else { strcat(args, "-jar \""); strncat(args, exePath, pathLen); appendPath(args, jar); strcat(args, "\""); } // Constant command line args if (loadString(CMD_LINE, tmp)) { strcat(args, " "); strcat(args, tmp); } // Command line args if (*lpCmdLine) { strcpy(tmp, lpCmdLine); char* dst; while ((dst = strstr(tmp, "--l4j-")) != NULL) { char* src = strchr(dst, ' '); if (src == NULL || *(src + 1) == 0) { *dst = 0; } else { strcpy(dst, src + 1); } } if (*tmp) { strcat(args, " "); strcat(args, tmp); } } debug("Launcher:\t%s\n", cmd); debug("Launcher args:\t%s\n", args); debug("Args length:\t%d/32768 chars\n", strlen(args)); return TRUE; }
ROKEN_LIB_FUNCTION DIR * ROKEN_LIB_CALL opendir(const char * path) { DIR * dp; struct _finddata_t fd; intptr_t fd_handle; const char *filespec; char path_buffer[1024]; memset(&fd, 0, sizeof(fd)); filespec = filespec_from_dir_path(path, path_buffer, sizeof(path_buffer)/sizeof(char)); if (filespec == NULL) return NULL; fd_handle = _findfirst(filespec, &fd); if (fd_handle == -1) return NULL; dp = malloc(sizeof(*dp)); if (dp == NULL) goto done; memset(dp, 0, sizeof(*dp)); dp->magic = DIRINFO_MAGIC; dp->cursor = 0; dp->n_entries = 0; dp->nc_entries = INITIAL_ENTRIES; dp->entries = calloc(dp->nc_entries, sizeof(dp->entries[0])); if (dp->entries == NULL) { closedir(dp); dp = NULL; goto done; } do { size_t len = strlen(fd.name); struct dirent * e; if (dp->n_entries == dp->nc_entries) { struct dirent ** ne; dp->nc_entries *= 2; ne = realloc(dp->entries, sizeof(dp->entries[0]) * dp->nc_entries); if (ne == NULL) { closedir(dp); dp = NULL; goto done; } dp->entries = ne; } e = malloc(sizeof(*e) + len * sizeof(char)); if (e == NULL) { closedir(dp); dp = NULL; goto done; } e->d_ino = 0; /* no inodes :( */ strcpy_s(e->d_name, len + 1, fd.name); dp->entries[dp->n_entries++] = e; } while (_findnext(fd_handle, &fd) == 0); done: if (fd_handle != -1) _findclose(fd_handle); return dp; }
//------------------------------------------------------------------------------ // Name: Initialize // Purpose: go through m_szMediaFolder and retrieve all media files into // Parameters: none // Return: true if folder contains at least one valid file; // false otherewise //------------------------------------------------------------------------------ bool CMediaList::Initialize(char *szFolder) { struct _finddata_t fileinfo; long filehandle = -1L; int nRes; int nCounter = 0; // to prevent loading huge number of files, // let's restrict it to 50 char szMask[MAX_PATH]; char szExt[] = "*.AVI;*.MOV;*.MPG;*.MPEG;*.VOB;*.QT;"; char szCurExt[MAX_PATH]; char szFilePath[MAX_PATH]; char *psz = NULL; // clean the list Clean(); if( !_strcmpi(szFolder,"")) return false; do { strcpy(szCurExt,szExt); psz = strstr(szCurExt,";"); if( psz) { *psz = 0; psz = NULL; psz = strstr( szExt, ";"); if( psz ) { strcpy( szExt, psz+1); } } else { strcpy( szExt, ""); } sprintf(szMask, "%s%s", szFolder, szCurExt); filehandle = _findfirst(szMask, &fileinfo); if( filehandle == -1L) continue; SourceInfo * pSI = NULL; pSI = new SourceInfo; if( !pSI ) { return false; } sprintf( szFilePath, "%s%s", szFolder, fileinfo.name); strcpy( pSI->m_szPath, (const char*)szFilePath); MultiByteToWideChar(CP_ACP, 0, (const char*)szFilePath, -1, pSI->m_wszPath, _MAX_PATH); Add( pSI ); nCounter++; nRes = _findnext(filehandle, &fileinfo); while( -1L != nRes ) { pSI = NULL; pSI = new SourceInfo; if( !pSI ) { return false; } sprintf( szFilePath, "%s%s", szFolder,fileinfo.name); strcpy( pSI->m_szPath, (const char*)szFilePath); MultiByteToWideChar(CP_ACP, 0, (const char*)szFilePath, -1, pSI->m_wszPath, _MAX_PATH); Add( pSI ); nCounter++; nRes = _findnext(filehandle, &fileinfo); }// while } while( _strcmpi(szExt, "") && nCounter < 50 ); if( 0 == Size() ) { return false; } else { return true; } }
array_t *get_dir(char * path, int flags) { array_t *v; int i, count = 0; #ifndef WIN32 DIR *dirp; #endif int namelen, do_match = 0; #ifndef WIN32 #ifdef USE_STRUCT_DIRENT struct dirent *de; #else struct direct *de; #endif #endif struct stat st; char *endtemp; char temppath[MAX_FNAME_SIZE + MAX_PATH_LEN + 2]; char regexppath[MAX_FNAME_SIZE + MAX_PATH_LEN + 2]; char *p; #ifdef WIN32 struct _finddata_t FindBuffer; long FileHandle, FileCount; #endif if (!path) return 0; path = check_valid_path(path, current_object, "stat", 0); if (path == 0) return 0; if (strlen(path) < 2) { #ifndef LATTICE temppath[0] = path[0] ? path[0] : '.'; #else temppath[0] = path[0]; #endif temppath[1] = '\000'; p = temppath; } else { strncpy(temppath, path, MAX_FNAME_SIZE + MAX_PATH_LEN + 1); temppath[MAX_FNAME_SIZE + MAX_PATH_LEN + 1] = '\0'; /* * If path ends with '/' or "/." remove it */ if ((p = strrchr(temppath, '/')) == 0) p = temppath; if (p[0] == '/' && ((p[1] == '.' && p[2] == '\0') || p[1] == '\0')) *p = '\0'; } if (stat(temppath, &st) < 0) { if (*p == '\0') return 0; if (p != temppath) { strcpy(regexppath, p + 1); *p = '\0'; } else { strcpy(regexppath, p); #ifndef LATTICE strcpy(temppath, "."); #else strcpy(temppath, ""); #endif } do_match = 1; } else if (*p != '\0' && strcmp(temppath, ".")) { if (*p == '/' && *(p + 1) != '\0') p++; v = allocate_empty_array(1); encode_stat(&v->item[0], flags, p, &st); return v; } /*#ifdef LATTICE if (temppath[0]=='.') temppath[0]=0; #endif*/ #ifdef WIN32 FileHandle = -1; FileCount = 1; /* strcat(temppath, "\\*"); */ strcat(temppath, "/*"); if ((FileHandle = _findfirst(temppath, &FindBuffer)) == -1) return 0; #else if ((dirp = opendir(temppath)) == 0) return 0; #endif /* * Count files */ #ifdef WIN32 do { if (!do_match && (!strcmp(FindBuffer.name, ".") || !strcmp(FindBuffer.name, ".."))) { continue; } if (do_match && !match_string(regexppath, FindBuffer.name)) { continue; } count++; if (count >= max_array_size) { break; } } while (!_findnext(FileHandle, &FindBuffer)); _findclose(FileHandle); #else for (de = readdir(dirp); de; de = readdir(dirp)) { #ifdef USE_STRUCT_DIRENT namelen = strlen(de->d_name); #else namelen = de->d_namlen; #endif if (!do_match && (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)) continue; if (do_match && !match_string(regexppath, de->d_name)) continue; count++; if (count >= max_array_size) break; } #endif /* * Make array and put files on it. */ v = allocate_empty_array(count); if (count == 0) { /* This is the easy case :-) */ #ifndef WIN32 closedir(dirp); #endif return v; } #ifdef WIN32 FileHandle = -1; if ((FileHandle = _findfirst(temppath, &FindBuffer)) == -1) return 0; endtemp = temppath + strlen(temppath) - 2; *endtemp = 0; /* strcat(endtemp++, "\\"); */ strcat(endtemp++, "/"); i = 0; do { if (!do_match && (!strcmp(FindBuffer.name, ".") || !strcmp(FindBuffer.name, ".."))) continue; if (do_match && !match_string(regexppath, FindBuffer.name)) continue; if (flags == -1) { strcpy(endtemp, FindBuffer.name); stat(temppath, &st); } encode_stat(&v->item[i], flags, FindBuffer.name, &st); i++; } while (!_findnext(FileHandle, &FindBuffer)); _findclose(FileHandle); #else /* WIN32 */ rewinddir(dirp); endtemp = temppath + strlen(temppath); #ifdef LATTICE if (endtemp != temppath) #endif strcat(endtemp++, "/"); for (i = 0, de = readdir(dirp); i < count; de = readdir(dirp)) { #ifdef USE_STRUCT_DIRENT namelen = strlen(de->d_name); #else namelen = de->d_namlen; #endif if (!do_match && (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)) continue; if (do_match && !match_string(regexppath, de->d_name)) continue; de->d_name[namelen] = '\0'; if (flags == -1) { /* * We'll have to .... sigh.... stat() the file to get some add'tl * info. */ strcpy(endtemp, de->d_name); stat(temppath, &st);/* We assume it works. */ } encode_stat(&v->item[i], flags, de->d_name, &st); i++; } closedir(dirp); #endif /* OS2 */ /* Sort the names. */ qsort((void *) v->item, count, sizeof v->item[0], (flags == -1) ? parrcmp : pstrcmp); return v; }
nfsstat3 CNFS3Prog::ProcedureREADDIRPLUS(void) { char *path; cookie3 cookie; cookieverf3 cookieverf; count3 dircount, maxcount; post_op_attr dir_attributes; fileid3 fileid; filename3 name; post_op_attr name_attributes; post_op_fh3 name_handle; bool eof; nfsstat3 stat; char filePath[MAXPATHLEN]; int handle, nFound; struct _finddata_t fileinfo; unsigned int i, j; bool bFollows; PrintLog("READDIRPLUS"); path = GetPath(); Read(&cookie); Read(&cookieverf); Read(&dircount); Read(&maxcount); stat = CheckFile(path); if (stat == NFS3_OK) { dir_attributes.attributes_follow = GetFileAttributesForNFS(path, &dir_attributes.attributes); if (!dir_attributes.attributes_follow) { stat = NFS3ERR_IO; } } Write(&stat); Write(&dir_attributes); if (stat == NFS3_OK) { Write(&cookieverf); sprintf_s(filePath, "%s\\*", path); handle = _findfirst(filePath, &fileinfo); eof = true; if (handle) { nFound = 0; for (i = (unsigned int)cookie; i > 0; i--) { nFound = _findnext(handle, &fileinfo); } if (nFound == 0) { bFollows = true; j = 10; do { Write(&bFollows); //value follows sprintf_s(filePath, "%s\\%s", path, fileinfo.name); fileid = GetFileID(filePath); Write(&fileid); //file id name.Set(fileinfo.name); Write(&name); //name ++cookie; Write(&cookie); //cookie name_attributes.attributes_follow = GetFileAttributesForNFS(filePath, &name_attributes.attributes); Write(&name_attributes); name_handle.handle_follows = GetFileHandle(filePath, &name_handle.handle); Write(&name_handle); if (--j == 0) { eof = false; break; } } while (_findnext(handle, &fileinfo) == 0); } _findclose(handle); } bFollows = false; Write(&bFollows); //value follows Write(&eof); //eof } return stat; }
/** Starts a new file search: finds the first file/directory that will match to the given pattern (ex: /bin/foo*) * @param[in] _zSearchPattern Pattern used for file/directory search * @param[out] _pstFileInfo Information about the first file found * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxFile_FindFirst(const orxSTRING _zSearchPattern, orxFILE_INFO *_pstFileInfo) { orxSTATUS eResult = orxSTATUS_FAILURE; #ifdef __orxWINDOWS__ struct _finddata_t stData; orxHANDLE hHandle; /* Checks */ orxASSERT((sstFile.u32Flags & orxFILE_KU32_STATIC_FLAG_READY) == orxFILE_KU32_STATIC_FLAG_READY); orxASSERT(_zSearchPattern != orxNULL); orxASSERT(_pstFileInfo != orxNULL); /* Opens the search */ hHandle = (orxHANDLE)_findfirst(_zSearchPattern, &stData); /* Valid? */ if(orxFILE_CAST_HELPER hHandle > 0) { const orxSTRING zFileName; /* Gets base file name */ zFileName = orxString_SkipPath(_zSearchPattern); /* Has directory? */ if(zFileName != _zSearchPattern) { orxU32 u32Length; /* Updates path & full name base */ u32Length = (orxU32)orxMIN(zFileName - _zSearchPattern, sizeof(_pstFileInfo->zPath) - 1); orxString_NCopy(_pstFileInfo->zPath, _zSearchPattern, u32Length); _pstFileInfo->zPath[u32Length] = orxCHAR_NULL; orxString_Copy(_pstFileInfo->zFullName, _pstFileInfo->zPath); /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(zFileName), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, zFileName, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; } else { orxU32 u32Length; /* Clears vars */ _pstFileInfo->zPath[0] = orxCHAR_NULL; _pstFileInfo->zFullName[0] = orxCHAR_NULL; /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(_zSearchPattern), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, _zSearchPattern, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; } /* Tranfers file info */ orxFile_GetInfoFromData(&stData, _pstFileInfo); /* Stores handle */ _pstFileInfo->hInternal = hHandle; /* Updates result */ eResult = orxSTATUS_SUCCESS; } #else /* __orxWINDOWS__ */ const orxSTRING zFileName; DIR *pDir; /* Checks */ orxASSERT((sstFile.u32Flags & orxFILE_KU32_STATIC_FLAG_READY) == orxFILE_KU32_STATIC_FLAG_READY); orxASSERT(_pstFileInfo != orxNULL); /* Gets base file name */ zFileName = orxString_SkipPath(_zSearchPattern); /* Has directory? */ if(zFileName != _zSearchPattern) { orxU32 u32Length; /* Updates path & full name base */ u32Length = orxMIN((orxU32)(zFileName - _zSearchPattern), sizeof(_pstFileInfo->zPath) - 1); orxString_NCopy(_pstFileInfo->zPath, _zSearchPattern, u32Length); _pstFileInfo->zPath[u32Length] = orxCHAR_NULL; orxString_Copy(_pstFileInfo->zFullName, _pstFileInfo->zPath); /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(zFileName), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, zFileName, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; } else { orxU32 u32Length; /* Stores pattern */ u32Length = orxMIN(orxString_GetLength(_zSearchPattern), sizeof(_pstFileInfo->zPattern) - 1); orxString_NCopy(_pstFileInfo->zPattern, _zSearchPattern, u32Length); _pstFileInfo->zPattern[u32Length] = orxCHAR_NULL; /* Clears vars */ orxString_Print(_pstFileInfo->zPath, "./"); orxString_Print(_pstFileInfo->zFullName, "./"); } /* Open directory */ pDir = opendir(_pstFileInfo->zPath); /* Valid ? */ if(pDir != orxNULL) { /* Stores the DIR handle */ _pstFileInfo->hInternal = (orxHANDLE)pDir; /* Retrieves info */ eResult = orxFile_FindNext(_pstFileInfo); /* Failure? */ if(eResult == orxSTATUS_FAILURE) { /* Closes directory */ closedir(pDir); /* Clears handle */ _pstFileInfo->hInternal = 0; } } #endif /* __orxWINDOWS__ */ /* Done! */ return eResult; }
nfsstat3 CNFS3Prog::ProcedureREADDIR(void) { char *path; cookie3 cookie; cookieverf3 cookieverf; count3 count; post_op_attr dir_attributes; fileid3 fileid; filename3 name; bool eof; bool bFollows; nfsstat3 stat; char filePath[MAXPATHLEN]; int handle; struct _finddata_t fileinfo; PrintLog("READDIR"); path = GetPath(); Read(&cookie); Read(&cookieverf); Read(&count); stat = CheckFile(path); if (stat == NFS3_OK) { dir_attributes.attributes_follow = GetFileAttributesForNFS(path, &dir_attributes.attributes); if (!dir_attributes.attributes_follow) { stat = NFS3ERR_IO; } } Write(&stat); Write(&dir_attributes); if (stat == NFS3_OK) { Write(&cookieverf); sprintf_s(filePath, "%s\\*", path); cookie = 0; eof = false; handle = _findfirst(filePath, &fileinfo); bFollows = true; if (handle) { do { Write(&bFollows); //value follows sprintf_s(filePath, "%s\\%s", path, fileinfo.name); fileid = GetFileID(filePath); Write(&fileid); //file id name.Set(fileinfo.name); Write(&name); //name ++cookie; Write(&cookie); //cookie } while (_findnext(handle, &fileinfo) == 0); _findclose(handle); } bFollows = false; Write(&bFollows); eof = true; Write(&eof); //eof } return stat; }
std::vector<std::string>* findfile(char* pattern, char* dir){ std::vector<std::string>* r = new std::vector<std::string>; long findhandle = -1; #ifndef WIN32 struct dirent **namelist; char szScriptName[256]; int n; pFor = pValue; n=scandir(g_szScriptPath ,&namelist, select_file,alphasort); if (n<0) perror("scandir"); else { while(n--) { memset(szScriptName, 0, 256); snprintf(szScriptName, 255, "%s/%s", g_szScriptPath, namelist[n]->d_name); free(namelist[n]); printf("compilering %s\n",szScriptName); if (compiler.Compile(szScriptName)) { snprintf(szMsg, 300,"SE:: compile \"%s\" succeeded", szScriptName); g_pLogFunc(szMsg, __FILE__, __LINE__ , 1); printf(szMsg); printf("\n"); } else { snprintf(szMsg, 300,"SE:: compile \"%s\" failed, error msg from compiler:\"%s\"", szScriptName, compiler.GetErrMsg()); g_pLogFunc(szMsg, __FILE__, __LINE__ , 1); printf(szMsg); printf("\n"); lRet = -1; goto out; } } free(namelist); } #else char szScriptFileMask[_MAX_PATH]; sprintf(szScriptFileMask, "%s%s%s", dir, PATH_SEPARATOR_S, pattern); _finddata_t finddata; findhandle = _findfirst(szScriptFileMask, &finddata); if (findhandle != -1) { int ret; ret = 0; while (ret != -1) { if (finddata.name[0] != '.') { if (finddata.attrib == _A_SUBDIR){ char sub_dir[_MAX_PATH] = ""; snprintf(sub_dir, _MAX_PATH -1, "%s\\%s", dir, finddata.name); std::vector<std::string>* rr = findfile("*", sub_dir); for (int i = 0; i< rr->size(); i++){ r->push_back(((*rr)[i]).c_str()); } Delete(rr); } else{ char szScriptFile[256] = ""; sprintf(szScriptFile, "%s\\%s", dir, finddata.name); r->push_back(szScriptFile); } } memset(&finddata, 0, sizeof(_finddata_t)); ret = _findnext(findhandle, &finddata); } } #endif return r; }
bool get_filename_from_base( std::vector<std::string> &in_list, std::vector<std::string> &out_list, const std::string &path, const std::string &base_name, const char **filter ) { #ifdef SFML_SYSTEM_WINDOWS std::string temp = path + base_name + "*"; struct _finddata_t t; intptr_t srch = _findfirst( temp.c_str(), &t ); if ( srch < 0 ) return false; do { const char *what = t.name; size_t what_len = strlen( what ); if (( strcmp( what, "." ) != 0 ) && ( strcmp( what, ".." ) != 0 )) { #else DIR *dir; struct dirent *ent; if ( (dir = opendir( path.c_str() )) == NULL ) return false; while ((ent = readdir( dir )) != NULL ) { const char *what = ent->d_name; size_t what_len = strlen( what ); size_t base_len = base_name.size(); if (( strcmp( what, "." ) != 0 ) && ( strcmp( what, ".." ) != 0 ) && ( what_len >= base_len ) && ( strncasecmp( what, base_name.c_str(), base_len ) == 0 )) { #endif // SFML_SYSTEM_WINDOWS if ( filter ) { bool add=false; int i=0; while ( filter[i] != NULL ) { if ( c_tail_compare( what, what_len, filter[i], strlen( filter[i] ) ) ) { add=true; break; } i++; } if ( add ) in_list.push_back( path + what ); else out_list.push_back( path + what ); } else in_list.push_back( path + what ); #ifdef SFML_SYSTEM_WINDOWS } } while ( _findnext( srch, &t ) == 0 ); _findclose( srch ); #else } } closedir( dir ); #endif // SFML_SYSTEM_WINDOWS return !(in_list.empty()); }
/* ============== Sys_ListFilteredFiles ============== */ void Sys_ListFilteredFiles( const char *basedir, char *subdirs, char *filter, char **list, int *numfiles ) { char search[ MAX_OSPATH ], newsubdirs[ MAX_OSPATH ]; char filename[ MAX_OSPATH ]; intptr_t findhandle; struct _finddata_t findinfo; if ( *numfiles >= MAX_FOUND_FILES - 1 ) { return; } if ( strlen( subdirs ) ) { Com_sprintf( search, sizeof( search ), "%s\\%s\\*", basedir, subdirs ); } else { Com_sprintf( search, sizeof( search ), "%s\\*", basedir ); } findhandle = _findfirst( search, &findinfo ); if ( findhandle == -1 ) { return; } do { if ( findinfo.attrib & _A_SUBDIR ) { if ( Q_stricmp( findinfo.name, "." ) && Q_stricmp( findinfo.name, ".." ) ) { if ( strlen( subdirs ) ) { Com_sprintf( newsubdirs, sizeof( newsubdirs ), "%s\\%s", subdirs, findinfo.name ); } else { Com_sprintf( newsubdirs, sizeof( newsubdirs ), "%s", findinfo.name ); } Sys_ListFilteredFiles( basedir, newsubdirs, filter, list, numfiles ); } } if ( *numfiles >= MAX_FOUND_FILES - 1 ) { break; } Com_sprintf( filename, sizeof( filename ), "%s\\%s", subdirs, findinfo.name ); if ( !Com_FilterPath( filter, filename, qfalse ) ) { continue; } list[ *numfiles ] = CopyString( filename ); ( *numfiles ) ++; } while ( _findnext( findhandle, &findinfo ) != -1 ); _findclose( findhandle ); }
int gmx_directory_open(gmx_directory_t *p_gmxdir, const char *dirname) { struct gmx_directory * gmxdir; int rc; snew(gmxdir, 1); *p_gmxdir = gmxdir; #if defined(GMX_NATIVE_WINDOWS) if (dirname != NULL && strlen(dirname) > 0) { char * tmpname; int len; len = strlen(dirname); snew(tmpname, len+3); strncpy(tmpname, dirname, len+1); /* Remove possible trailing directory separator */ if (tmpname[len] == '/' || tmpname[len] == '\\') { tmpname[len] = '\0'; } /* Add wildcard */ strcat(tmpname, "/*"); gmxdir->first = 1; if ( (gmxdir->windows_handle = _findfirst(tmpname, &gmxdir->finddata)) > 0L) { rc = 0; } else { if (errno == EINVAL) { sfree(gmxdir); *p_gmxdir = NULL; rc = EINVAL; } else { rc = 0; } } } else { rc = EINVAL; } #elif defined(HAVE_DIRENT_H) if ( (gmxdir->dirent_handle = opendir(dirname)) != NULL) { rc = 0; } else { sfree(gmxdir); *p_gmxdir = NULL; rc = EINVAL; } #else gmx_fatal(FARGS, "Source compiled without POSIX dirent or windows support - cannot scan directories.\n" "In the very unlikely event this is not a compile-time mistake you could consider\n" "implementing support for your platform in futil.c, but contact the developers\n" "to make sure it's really necessary!\n"); rc = -1; #endif return rc; }
void appendLauncher(const BOOL setProcName, char* exePath, const int pathLen, char* cmd) { if (setProcName) { char tmpspec[_MAX_PATH]; char tmpfile[_MAX_PATH]; strcpy(tmpspec, cmd); strcat(tmpspec, LAUNCH4J_TMP_DIR); tmpspec[strlen(tmpspec) - 1] = 0; if (_stat(tmpspec, &statBuf) == 0) { // Remove temp launchers and manifests struct _finddata_t c_file; long hFile; appendPath(tmpspec, "*.exe"); strcpy(tmpfile, cmd); strcat(tmpfile, LAUNCH4J_TMP_DIR); char* filename = tmpfile + strlen(tmpfile); if ((hFile = _findfirst(tmpspec, &c_file)) != -1L) { do { strcpy(filename, c_file.name); debug("Unlink:\t\t%s\n", tmpfile); _unlink(tmpfile); strcat(tmpfile, MANIFEST); debug("Unlink:\t\t%s\n", tmpfile); _unlink(tmpfile); } while (_findnext(hFile, &c_file) == 0); } _findclose(hFile); } else { if (_mkdir(tmpspec) != 0) { debug("Mkdir failed:\t%s\n", tmpspec); appendJavaw(cmd); return; } } char javaw[_MAX_PATH]; strcpy(javaw, cmd); appendJavaw(javaw); strcpy(tmpfile, cmd); strcat(tmpfile, LAUNCH4J_TMP_DIR); char* tmpfilename = tmpfile + strlen(tmpfile); char* exeFilePart = exePath + pathLen + 1; // Copy manifest char manifest[_MAX_PATH] = {0}; strcpy(manifest, exePath); strcat(manifest, MANIFEST); if (_stat(manifest, &statBuf) == 0) { strcat(tmpfile, exeFilePart); strcat(tmpfile, MANIFEST); debug("Copy:\t\t%s -> %s\n", manifest, tmpfile); CopyFile(manifest, tmpfile, FALSE); } // Copy launcher strcpy(tmpfilename, exeFilePart); debug("Copy:\t\t%s -> %s\n", javaw, tmpfile); if (CopyFile(javaw, tmpfile, FALSE)) { strcpy(cmd, tmpfile); return; } else if (_stat(javaw, &statBuf) == 0) { long fs = statBuf.st_size; if (_stat(tmpfile, &statBuf) == 0 && fs == statBuf.st_size) { debug("Reusing:\t\t%s\n", tmpfile); strcpy(cmd, tmpfile); return; } } } appendJavaw(cmd); }
void file_dirscan( const char *dir, scanback func, void *closure ) { PATHNAME f; char filespec[ MAXJPATH ]; char filename[ MAXJPATH ]; FINDTYPE handle; int ret; struct _finddata_t finfo[1]; /* First enter directory itself */ memset( (char *)&f, '\0', sizeof( f ) ); f.f_dir.ptr = dir; f.f_dir.len = (int)strlen(dir); dir = *dir ? dir : "."; /* Special case \ or d:\ : enter it */ #ifdef OPT_SCAN_SUBDIR_NOTIFY_EXT if( f.f_dir.len == 1 && (f.f_dir.ptr[0] == '\\' || f.f_dir.ptr[0] == '/') ) (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0, 1 ); else if( f.f_dir.len == 3 && f.f_dir.ptr[1] == ':' ) (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0, 1 ); #else if( f.f_dir.len == 1 && f.f_dir.ptr[0] == '\\' ) (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 ); else if( f.f_dir.len == 3 && f.f_dir.ptr[1] == ':' ) (*func)( closure, dir, 0 /* not stat()'ed */, (time_t)0 ); #endif /* Now enter contents of directory */ sprintf( filespec, "%s/*", dir ); if( DEBUG_BINDSCAN ) printf( "scan directory %s\n", dir ); # if defined(__BORLANDC__) && __BORLANDC__ < 0x550 if ( ret = findfirst( filespec, finfo, FA_NORMAL | FA_DIREC ) ) return; while( !ret ) { time_t time_write = finfo->ff_fdate; time_write = (time_write << 16) | finfo->ff_ftime; f.f_base.ptr = finfo->ff_name; f.f_base.len = strlen( finfo->ff_name ); #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT path_build( &f, filename, 0, 1 ); #else path_build( &f, filename, 0 ); #endif (*func)( closure, filename, 1 /* stat()'ed */, time_write ); ret = findnext( finfo ); } # else handle = _findfirst( filespec, finfo ); if( ret = ( handle == (FINDTYPE)(-1) ) ) return; while( !ret ) { #ifdef OPT_SCAN_SUBDIR_NOTIFY_EXT if ( finfo->attrib & _A_SUBDIR ) { if ( ! ( ( finfo->name[0] == '.' && finfo->name[1] == 0 ) || ( finfo->name[0] == '.' && finfo->name[1] == '.' && finfo->name[2] == 0 ) ) ) { f.f_base.ptr = finfo->name; f.f_base.len = (int)(strlen( finfo->name ) + 1); #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT path_build( &f, filename, 0, 1 ); #else path_build( &f, filename, 0 ); #endif (*func)( closure, filename, 1 /* stat()'ed */, finfo->time_write, 1 ); } } else { f.f_base.ptr = finfo->name; f.f_base.len = (int)(strlen( finfo->name )); #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT path_build( &f, filename, 0, 1 ); #else path_build( &f, filename, 0 ); #endif (*func)( closure, filename, 1 /* stat()'ed */, finfo->time_write, 0 ); } #else f.f_base.ptr = finfo->name; f.f_base.len = strlen( finfo->name ); #ifdef OPT_ROOT_PATHS_AS_ABSOLUTE_EXT path_build( &f, filename, 0, 1 ); #else path_build( &f, filename, 0 ); #endif (*func)( closure, filename, 1 /* stat()'ed */, finfo->time_write ); #endif ret = _findnext( handle, finfo ); } _findclose( handle ); # endif }
/*----------------------------------------------------------------------------- Name : gpTitleListLoad Description : Scans the games directory and loads in the titles of all the game files available. Inputs : void Outputs : Fills in gpGames and gpNumberGames Return : void ----------------------------------------------------------------------------*/ void gpTitleListLoad(void) { struct _finddata_t find; sdword handle, startHandle; sdword index; char fileName[_MAX_PATH]; char fileSearch[100]; // char *pString; // char *title; for (index = 0; index < gpNumberGames; index++) { memFree(gpGames[index].fileSpec); memFree(gpGames[index].title); } if (gpNumberGames > 0) { memFree(gpGames); gpGames = NULL; gpNumberGames = 0; } strcpy(fileSearch,SavedGamesPath); strcat(fileSearch,"*.*"); startHandle = handle = _findfirst(filePathPrepend(fileSearch, 0), &find); while (handle != -1) { if (find.name[0] == '.') { goto alreadyLoaded; } fileName[0] = 0; strcpy(fileName, find.name); if (fileName[0] == 0) { goto alreadyLoaded; } if (strstr(fileName,PKTS_EXTENSION)) { goto alreadyLoaded; } for (index = 0; index < gpNumberGames; index++) { if (!_stricmp(gpGames[index].fileSpec, fileName)) { //if matching file specs, goto alreadyLoaded; //break-continue } } gpGames = memRealloc(gpGames, (gpNumberGames+1) * sizeof(gpgame), "gpGames", NonVolatile); gpGames[gpNumberGames].fileSpec = memStringDupe(fileName); //gpGames[gpNumberGames].title = title; gpGames[gpNumberGames].title = memStringDupe(fileName); gpNumberGames++; alreadyLoaded:; handle = _findnext(startHandle, &find); } if (gpNumberGames > 1) { //alphabetically sort the game list qsort(&gpGames[0],gpNumberGames,sizeof(gpgame),compareGamesCB); } gpCurrentSelected = gpCurrentGame = 0; //set default game }
void FileList::AddFilesFromDirectory(const char *applicationDirectory, const char *subDirectory, bool writeHash, bool writeData, bool recursive, unsigned char context) { #ifndef _COMPATIBILITY_2 DataStructures::Queue<char*> dirList; char root[260]; char fullPath[520]; _finddata_t fileInfo; intptr_t dir; int file; FILE *fp; CSHA1 sha1; char *dirSoFar, *fileData; dirSoFar=new char[520]; if (applicationDirectory) strcpy(root, applicationDirectory); else root[0]=0; int rootLen=(int)strlen(root); if (rootLen) { strcpy(dirSoFar, root); if (dirSoFar[strlen(dirSoFar)-1]!='/' && dirSoFar[strlen(dirSoFar)-1]!='\\') { strcat(dirSoFar, "/"); rootLen++; } } else dirSoFar[0]=0; if (subDirectory) { strcat(dirSoFar, subDirectory); if (dirSoFar[strlen(dirSoFar)-1]!='/' && dirSoFar[strlen(dirSoFar)-1]!='\\') { strcat(dirSoFar, "/"); } } dirList.Push(dirSoFar); while (dirList.Size()) { dirSoFar=dirList.Pop(); strcpy(fullPath, dirSoFar); strcat(fullPath, "*.*"); dir=_findfirst(fullPath, &fileInfo ); // Read . if (dir==-1) { _findclose(dir); delete [] dirSoFar; unsigned i; for (i=0; i < dirList.Size(); i++) delete [] dirList[i]; return; } file=_findnext(dir, &fileInfo ); // Read .. file=_findnext(dir, &fileInfo ); // Skip .. while (file!=-1) { if ((fileInfo.attrib & (_A_HIDDEN | _A_SUBDIR | _A_SYSTEM))==0) { strcpy(fullPath, dirSoFar); strcat(fullPath, fileInfo.name); if (writeData && writeHash) fileData= new char [fileInfo.size+SHA1_LENGTH]; else fileData= new char [fileInfo.size]; fp = fopen(fullPath, "rb"); if (writeData && writeHash) fread(fileData+SHA1_LENGTH, fileInfo.size, 1, fp); else fread(fileData, fileInfo.size, 1, fp); fclose(fp); if (writeData && writeHash) { sha1.Reset(); sha1.Update( ( unsigned char* ) fileData+SHA1_LENGTH, fileInfo.size ); sha1.Final(); memcpy(fileData, sha1.GetHash(), SHA1_LENGTH); AddFile((const char*)fullPath+rootLen, fileData, fileInfo.size+SHA1_LENGTH, fileInfo.size, context); } else if (writeHash) { sha1.Reset(); sha1.Update( ( unsigned char* ) fileData, fileInfo.size ); sha1.Final(); AddFile((const char*)fullPath+rootLen, (const char*)sha1.GetHash(), SHA1_LENGTH, fileInfo.size, context); } else if (writeData) { AddFile(fullPath+rootLen, fileData, fileInfo.size, fileInfo.size, context); } else AddFile(fullPath+rootLen, 0, 0, fileInfo.size, context); delete [] fileData; } else if ((fileInfo.attrib & _A_SUBDIR) && (fileInfo.attrib & (_A_HIDDEN | _A_SYSTEM))==0 && recursive) { char *newDir=new char[520]; strcpy(newDir, dirSoFar); strcat(newDir, fileInfo.name); strcat(newDir, "/"); dirList.Push(newDir); } file=_findnext(dir, &fileInfo ); } _findclose(dir); delete [] dirSoFar; } #endif }
FileList::FileList(const String & filepath) { path = FileSystem::Instance()->SystemPathForFrameworkPath(filepath); // Windows version #if defined(__DAVAENGINE_WIN32__) //char tmp[_MAX_PATH]; //_getcwd(tmp, _MAX_PATH); //Path = tmp; String prevDir = FileSystem::Instance()->GetCurrentWorkingDirectory(); BOOL res = SetCurrentDirectoryA(path.c_str()); if (res) { struct _finddata_t c_file; intptr_t hFile; FileEntry entry; if( (hFile = _findfirst( "*", &c_file )) != -1L ) { do { entry.name = c_file.name; entry.size = c_file.size; entry.isDirectory = (_A_SUBDIR & c_file.attrib) != 0; fileList.push_back(entry); //Logger::Debug("filelist: %s %s", filepath.c_str(), entry.name.c_str()); } while( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); } } FileSystem::Instance()->SetCurrentWorkingDirectory(prevDir); //TODO add drives //entry.Name = "E:\\"; //entry.isDirectory = true; //Files.push_back(entry); #elif defined(__DAVAENGINE_MACOS__) || defined(__DAVAENGINE_IPHONE__) || defined (__DAVAENGINE_ANDROID__) struct dirent **namelist; FileEntry entry; #if defined (__DAVAENGINE_ANDROID__) int32 n = scandir(path.c_str(), &namelist, 0, alphasortAndroid); #else //#if defined (__DAVAENGINE_ANDROID__) int32 n = scandir(path.c_str(), &namelist, 0, alphasort); #endif //#if defined (__DAVAENGINE_ANDROID__) if (n >= 0) { while(n--) { entry.name = namelist[n]->d_name; entry.size = 0; entry.isDirectory = namelist[n]->d_type == DT_DIR; fileList.push_back(entry); free(namelist[n]); } free(namelist); } #endif //PLATFORMS directoryCount = 0; fileCount = 0; for (int fi = 0; fi < GetCount(); ++fi) { if (IsDirectory(fi)) { String filename = GetFilename(fi); if ((filename != ".") && (filename != "..")) directoryCount++; }else fileCount++; } }
//----------------------------------------------------------------------- void FileSystemArchive::findFiles(const String& pattern, bool recursive, bool dirs, StringVector* simpleList, FileInfoList* detailList) { long lHandle, res; struct _finddata_t tagData; // pattern can contain a directory name, separate it from mask size_t pos1 = pattern.rfind ('/'); size_t pos2 = pattern.rfind ('\\'); if (pos1 == pattern.npos || ((pos2 != pattern.npos) && (pos1 < pos2))) pos1 = pos2; String directory; if (pos1 != pattern.npos) directory = pattern.substr (0, pos1 + 1); String full_pattern = concatenate_path(mName, pattern); lHandle = _findfirst(full_pattern.c_str(), &tagData); res = 0; while (lHandle != -1 && res != -1) { if ((dirs == ((tagData.attrib & _A_SUBDIR) != 0)) && ( !ms_IgnoreHidden || (tagData.attrib & _A_HIDDEN) == 0 ) && (!dirs || !is_reserved_dir (tagData.name))) { if (simpleList) { simpleList->push_back(directory + tagData.name); } else if (detailList) { FileInfo fi; fi.archive = this; fi.filename = directory + tagData.name; fi.basename = tagData.name; fi.path = directory; fi.compressedSize = tagData.size; fi.uncompressedSize = tagData.size; detailList->push_back(fi); } } res = _findnext( lHandle, &tagData ); } // Close if we found any files if(lHandle != -1) _findclose(lHandle); // Now find directories if (recursive) { String base_dir = mName; if (!directory.empty ()) { base_dir = concatenate_path(mName, directory); // Remove the last '/' base_dir.erase (base_dir.length () - 1); } base_dir.append ("/*"); // Remove directory name from pattern String mask ("/"); if (pos1 != pattern.npos) mask.append (pattern.substr (pos1 + 1)); else mask.append (pattern); lHandle = _findfirst(base_dir.c_str (), &tagData); res = 0; while (lHandle != -1 && res != -1) { if ((tagData.attrib & _A_SUBDIR) && ( !ms_IgnoreHidden || (tagData.attrib & _A_HIDDEN) == 0 ) && !is_reserved_dir (tagData.name)) { // recurse base_dir = directory; base_dir.append (tagData.name).append (mask); findFiles(base_dir, recursive, dirs, simpleList, detailList); } res = _findnext( lHandle, &tagData ); } // Close if we found any files if(lHandle != -1) _findclose(lHandle); } }
//----------------------------------------------------------------------------- // Purpose: Get list of files from current path that match pattern //----------------------------------------------------------------------------- static int GetFileList( const char* pDirPath, const char* pPattern, CUtlVector< CUtlString > &fileList ) { char sourcePath[MAX_PATH]; char fullPath[MAX_PATH]; bool bFindDirs; fileList.Purge(); strcpy( sourcePath, pDirPath ); int len = (int)strlen( sourcePath ); if ( !len ) { strcpy( sourcePath, ".\\" ); } else if ( sourcePath[len-1] != '\\' ) { sourcePath[len] = '\\'; sourcePath[len+1] = '\0'; } strcpy( fullPath, sourcePath ); if ( pPattern[0] == '\\' && pPattern[1] == '\0' ) { // find directories only bFindDirs = true; strcat( fullPath, "*" ); } else { // find files, use provided pattern bFindDirs = false; strcat( fullPath, pPattern ); } struct _finddata_t findData; intptr_t h = _findfirst( fullPath, &findData ); if ( h == -1 ) { return 0; } do { // dos attribute complexities i.e. _A_NORMAL is 0 if ( bFindDirs ) { // skip non dirs if ( !( findData.attrib & _A_SUBDIR ) ) continue; } else { // skip dirs if ( findData.attrib & _A_SUBDIR ) continue; } if ( !stricmp( findData.name, "." ) ) continue; if ( !stricmp( findData.name, ".." ) ) continue; char fileName[MAX_PATH]; strcpy( fileName, sourcePath ); strcat( fileName, findData.name ); int j = fileList.AddToTail(); fileList[j].Set( fileName ); } while ( !_findnext( h, &findData ) ); _findclose( h ); return fileList.Count(); }
/* al_findfirst: * Initiates a directory search. */ int al_findfirst(AL_CONST char *pattern, struct al_ffblk *info, int attrib) { struct FF_DATA *ff_data; char tmp[1024]; /* allocate ff_data structure */ ff_data = _AL_MALLOC(sizeof(struct FF_DATA)); if (!ff_data) { *allegro_errno = ENOMEM; return -1; } /* attach it to the info structure */ info->ff_data = (void *) ff_data; /* Windows defines specific flags for NTFS permissions: * FA_TEMPORARY 0x0100 * FA_SPARSE_FILE 0x0200 * FA_REPARSE_POINT 0x0400 * FA_COMPRESSED 0x0800 * FA_OFFLINE 0x1000 * FA_NOT_CONTENT_INDEXED 0x2000 * FA_ENCRYPTED 0x4000 * so we must set them in the mask by default; moreover, * in order to avoid problems with flags added in the * future, we simply set all bits past the first byte. */ ff_data->attrib = attrib | 0xFFFFFF00; /* start the search */ errno = *allegro_errno = 0; if (get_filename_encoding() != U_UNICODE) { ff_data->handle = _findfirst(uconvert(pattern, U_CURRENT, tmp, U_ASCII, sizeof(tmp)), &ff_data->data.a); if (ff_data->handle < 0) { *allegro_errno = errno; _AL_FREE(ff_data); info->ff_data = NULL; return -1; } if (ff_data->data.a.attrib & ~ff_data->attrib) { if (al_findnext(info) != 0) { al_findclose(info); return -1; } else return 0; } } else { ff_data->handle = _wfindfirst((wchar_t*)uconvert(pattern, U_CURRENT, tmp, U_UNICODE, sizeof(tmp)), &ff_data->data.w); if (ff_data->handle < 0) { *allegro_errno = errno; _AL_FREE(ff_data); info->ff_data = NULL; return -1; } if (ff_data->data.w.attrib & ~ff_data->attrib) { if (al_findnext(info) != 0) { al_findclose(info); return -1; } else return 0; } } fill_ffblk(info); return 0; }
DIR * opendir (const char *name) { struct _finddata_t find_buf; DIR *dirp; struct _dircontents *dp; char name_buf[_MAX_PATH + 1]; char *slash = ""; long hFile; if (!name) name = ""; else if (*name) { const char *s; int l = strlen (name); s = name + l - 1; if ( !(l == 2 && *s == ':') && *s != '\\' && *s != '/') slash = "/"; /* save to insert slash between path and "*.*" */ } strcat (strcat (strcpy (name_buf, name), slash), "*.*"); dirp = (DIR *) malloc (sizeof (DIR)); if (dirp == (DIR *)0) return (DIR *)0; dirp->dd_loc = 0; dirp->dd_contents = dirp->dd_cp = (struct _dircontents *) 0; if ((hFile = _findfirst (name_buf, &find_buf)) < 0) { free (dirp); return (DIR *)0; } do { dp = (struct _dircontents *) malloc (sizeof (struct _dircontents)); if (dp == (struct _dircontents *)0) { free_dircontents (dirp->dd_contents); return (DIR *)0; } dp->_d_entry = malloc (strlen (find_buf.name) + 1); if (dp->_d_entry == (char *)0) { free (dp); free_dircontents (dirp->dd_contents); return (DIR *)0; } if (dirp->dd_contents) dirp->dd_cp = dirp->dd_cp->_d_next = dp; else dirp->dd_contents = dirp->dd_cp = dp; strcpy (dp->_d_entry, find_buf.name); dp->_d_next = (struct _dircontents *)0; } while (!_findnext (hFile, &find_buf)); dirp->dd_cp = dirp->dd_contents; _findclose(hFile); return dirp; }
void listfiles(char *filespec,char filelist[1024][32],int directories) { #ifdef WINDOWS int count,count2; int handle; struct _finddata_t fileinfo; handle=_findfirst(filespec,&fileinfo); count=0; count2=handle; while (count2!=-1 && count<1024) { if (!directories) { if ((fileinfo.attrib&_A_SUBDIR)==0) { strcpy(filelist[count],fileinfo.name); count++; } } else { if ((fileinfo.attrib&_A_SUBDIR)!=0) if (fileinfo.name[0]!='.') { strcpy(filelist[count],fileinfo.name); count++; } } count2=_findnext(handle,&fileinfo); } filelist[count][0]=0; _findclose(handle); qsort(filelist,count,32,comparestrings); #endif #if defined(LINUX) || defined(__FreeBSD__) int count; struct dirent *dp; DIR *dfd; struct stat stbuf; dfd=opendir("."); count=0; if (dfd!=NULL) { while ((dp=readdir(dfd))!=NULL) { stat(dp->d_name,&stbuf); if (!directories) { if ((stbuf.st_mode&S_IFMT)!=S_IFDIR) if (dp->d_name[0]!='<') if (checkfilespec(filespec,dp->d_name)) { strcpy(filelist[count],dp->d_name); count++; } } else { if ((stbuf.st_mode&S_IFMT)==S_IFDIR) if (dp->d_name[0]!='.') if (dp->d_name[0]!='<') if (checkfilespec(filespec,dp->d_name)) { strcpy(filelist[count],dp->d_name); count++; } } } } filelist[count][0]=0; closedir(dfd); qsort(filelist,count,32,comparestrings); #endif }
MY_DIR *my_dir(const char *path, myf MyFlags) { char *buffer; MY_DIR *result= 0; FILEINFO finfo; DYNAMIC_ARRAY *dir_entries_storage; MEM_ROOT *names_storage; #ifdef __BORLANDC__ struct ffblk find; #else struct _finddata_t find; #endif ushort mode; char tmp_path[FN_REFLEN],*tmp_file,attrib; #ifdef _WIN64 __int64 handle; #else long handle; #endif DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); /* Put LIB-CHAR as last path-character if not there */ tmp_file=tmp_path; if (!*path) *tmp_file++ ='.'; /* From current dir */ tmp_file= strnmov(tmp_file, path, FN_REFLEN-5); if (tmp_file[-1] == FN_DEVCHAR) *tmp_file++= '.'; /* From current dev-dir */ if (tmp_file[-1] != FN_LIBCHAR) *tmp_file++ =FN_LIBCHAR; tmp_file[0]='*'; /* Windows needs this !??? */ tmp_file[1]='.'; tmp_file[2]='*'; tmp_file[3]='\0'; if (!(buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) + sizeof(MEM_ROOT), MyFlags))) goto error; dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR))); names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) + ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))); if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO), ENTRIES_START_SIZE, ENTRIES_INCREMENT)) { my_free(buffer); goto error; } init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE); /* MY_DIR structure is allocated and completly initialized at this point */ result= (MY_DIR*)buffer; #ifdef __BORLANDC__ if ((handle= findfirst(tmp_path,&find,0)) == -1L) #else if ((handle=_findfirst(tmp_path,&find)) == -1L) #endif { DBUG_PRINT("info", ("findfirst returned error, errno: %d", errno)); if (errno != EINVAL) goto error; /* Could not read the directory, no read access. Probably because by "chmod -r". continue and return zero files in dir */ } else { do { #ifdef __BORLANDC__ attrib= find.ff_attrib; #else attrib= find.attrib; /* Do not show hidden and system files which Windows sometimes create. Note. Because Borland's findfirst() is called with the third argument = 0 hidden/system files are excluded from the search. */ if (attrib & (_A_HIDDEN | _A_SYSTEM)) continue; #endif #ifdef __BORLANDC__ if (!(finfo.name= strdup_root(names_storage, find.ff_name))) goto error; #else if (!(finfo.name= strdup_root(names_storage, find.name))) goto error; #endif if (MyFlags & MY_WANT_STAT) { if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage, sizeof(MY_STAT)))) goto error; bzero(finfo.mystat, sizeof(MY_STAT)); #ifdef __BORLANDC__ finfo.mystat->st_size=find.ff_fsize; #else finfo.mystat->st_size=find.size; #endif mode= MY_S_IREAD; if (!(attrib & _A_RDONLY)) mode|= MY_S_IWRITE; if (attrib & _A_SUBDIR) mode|= MY_S_IFDIR; finfo.mystat->st_mode= mode; #ifdef __BORLANDC__ finfo.mystat->st_mtime= ((uint32) find.ff_ftime); #else finfo.mystat->st_mtime= ((uint32) find.time_write); #endif } else finfo.mystat= NULL; if (push_dynamic(dir_entries_storage, (uchar*)&finfo)) goto error; } #ifdef __BORLANDC__ while (findnext(&find) == 0); #else while (_findnext(handle,&find) == 0); _findclose(handle); #endif } result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; result->number_off_files= dir_entries_storage->elements; if (!(MyFlags & MY_DONT_SORT)) my_qsort((void *) result->dir_entry, result->number_off_files, sizeof(FILEINFO), (qsort_cmp) comp_names); DBUG_PRINT("exit", ("found %d files", result->number_off_files)); DBUG_RETURN(result); error: my_errno=errno; #ifndef __BORLANDC__ if (handle != -1) _findclose(handle); #endif my_dirend(result); if (MyFlags & MY_FAE+MY_WME) my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); DBUG_RETURN((MY_DIR *) NULL); } /* my_dir */
/*! * For a given path, this method lists all files, directories and * sub-directories it contains and stores the filenames in the fileList vector. * * \param fileList list of files in folder * \param path folder's path to list * \param symLinks follow Unix links? * * \return path exists and is a directory */ bool CUtil::GetFileList(StringVector &fileList, const string &path, bool symLinks) { string fullPath; #ifdef UNIX DIR *dir; struct dirent *fileRead; struct stat inodeData; // opening the given path dir = opendir(path.c_str()); // If the dir doesn't exist if (dir == NULL) return(false); // each file is processed until the last one while ((fileRead = readdir(dir)) != NULL) { // '.' & '..' are omitted if ((strcmp(fileRead->d_name, ".") != 0) && (strcmp(fileRead->d_name, "..") != 0)) { // fullPath contains the path + the file name. fullPath = path + '/' + fileRead->d_name; if (symLinks) { if (stat(fullPath.c_str(), &inodeData) >= 0) { // for each file, store the fullPath into the ofstream if (!S_ISDIR(inodeData.st_mode)) fileList.push_back(fullPath); else { // for each directory, its file list is obtained GetFileList(fileList, fullPath, symLinks); } } } else { if (lstat(fullPath.c_str(), &inodeData) >= 0) { // for each file, store the fullPath into the ofstream if (!S_ISLNK(inodeData.st_mode)) { if (!S_ISDIR(inodeData.st_mode)) fileList.push_back(fullPath); else { // for each directory, its file list is obtained GetFileList(fileList, fullPath, symLinks); } } } } } } // close the directory closedir(dir); #else struct _finddata_t c_file; ptrdiff_t hFile; string findPath = path + "\\*.*"; // the first file is obtained hFile = _findfirst(findPath.c_str(), &c_file); // If the dir doesn't exist if (hFile == -1) return(false); // each file is processed until the last one while (_findnext(hFile, &c_file) == 0) { // for each file (not a directory (_A_SUBDIR), store its name into the fileList fullPath = path + "\\" + c_file.name; if (!(c_file.attrib & _A_SUBDIR)) fileList.push_back(fullPath); else if ((strcmp(".", c_file.name) != 0) && (strcmp("..", c_file.name) != 0)) { // for each directory, except '.' and '..', its file list is obtained GetFileList(fileList, fullPath, symLinks); } } // close the directory _findclose(hFile); #endif return(true); }
// FE_RegisterPlugins is called from navigator main via npglue's NP_Init(). Finds all // plugins and begins tracking them using a NPPMgtBlk. Uses the NPPMgtBlk // block handle to register the plugin with the xp plugin glue. Looks // in the directory under the netscape.exe dir, named "plugins" and all // subdirectories in recursive way (see fe_RegisterPlugins). If the // directory doesn't exist, no warning dialog is shown. // There are no input or return vals. void fe_RegisterPlugins(char* pszPluginDir) { CString csPluginSpec; csPluginSpec = pszPluginDir; #ifdef JAVA // add directory to the java path no matter what LJ_AddToClassPath(pszPluginDir); #endif csPluginSpec += "\\*.*"; #ifndef _WIN32 _find_t fileinfo; unsigned result = _dos_findfirst((LPSTR)((LPCSTR)csPluginSpec), _A_NORMAL | _A_SUBDIR, &fileinfo ); if (result == 0) { result = _dos_findnext(&fileinfo); // skip "." result = _dos_findnext(&fileinfo); // skip ".." CString csFileSpec; while(result == 0) { csFileSpec = pszPluginDir; csFileSpec += "\\"; csFileSpec += fileinfo.name; // we got a subdir, call recursively this function to load plugin if (fileinfo.attrib & _A_SUBDIR ) { fe_RegisterPlugins((LPSTR)(LPCSTR)csFileSpec); } else { size_t len = strlen(fileinfo.name); // it's a file, see if it can be a plugin file if ( len > 6 && // at least "np.dll" (fileinfo.name[0] == 'n' || fileinfo.name[0] == 'N') && (fileinfo.name[1] == 'p' || fileinfo.name[1] == 'P') && !_stricmp(fileinfo.name + len - 4, ".dll")) fe_RegisterPlugin((LPSTR)((LPCSTR)csFileSpec)); #ifdef EDITOR // If it's a cpXXX.zip file,register it as a composer plugin. else if ( len > 6 && // at least cp.zip (fileinfo.name[0] == 'c' || fileinfo.name[0] == 'C') && (fileinfo.name[1] == 'p' || fileinfo.name[1] == 'P') && (!_stricmp(fileinfo.name + len - 4, ".zip") || !_stricmp(fileinfo.name + len - 4, ".jar")) ) EDT_RegisterPlugin((LPSTR)((LPCSTR)csFileSpec)); #endif /* EDITOR */ } result = _dos_findnext(&fileinfo); } } #else /* _WIN32 */ _finddata_t fileinfo; unsigned handle = _findfirst((LPSTR)((LPCSTR)csPluginSpec), &fileinfo ); unsigned result = 0; if (handle != -1) { result = _findnext(handle, &fileinfo); // skip "." result = _findnext(handle, &fileinfo); // skip ".." CString csFileSpec; while((result != -1) && (handle != -1)) { csFileSpec = pszPluginDir; csFileSpec += "\\"; csFileSpec += fileinfo.name; // we got a subdir, call recursively this function to load plugin if (fileinfo.attrib & _A_SUBDIR ) { fe_RegisterPlugins((LPSTR)(LPCSTR)csFileSpec); } else { size_t len = strlen(fileinfo.name); // it's a file, see if it can be a plugin file if ( len > 6 && // at least "np.dll" (fileinfo.name[0] == 'n' || fileinfo.name[0] == 'N') && (fileinfo.name[1] == 'p' || fileinfo.name[1] == 'P') && !_stricmp(fileinfo.name + len - 4, ".dll")) fe_RegisterPlugin((LPSTR)((LPCSTR)csFileSpec)); #ifdef EDITOR // If it's a cpXXX.zip file, add it to the java class path. else if ( len > 6 && // at least cp.zip (fileinfo.name[0] == 'c' || fileinfo.name[0] == 'C') && (fileinfo.name[1] == 'p' || fileinfo.name[1] == 'P') && (!_stricmp(fileinfo.name + len - 4, ".zip") || !_stricmp(fileinfo.name + len - 4, ".jar")) ) EDT_RegisterPlugin((LPSTR)((LPCSTR)csFileSpec)); #endif } result = _findnext(handle, &fileinfo); } _findclose(handle); } #endif /* _WIN32 */ }
HRESULT LTEffectInclude::Open( D3DXINCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes ) { if(pFileName[0] == '\0') { return E_FAIL; } if(PushPath(pFileName) == false) { *ppData = NULL; *pBytes = 0; return E_FAIL; } char szFilename[_MAX_PATH]; BuildPath(szFilename, pFileName, _MAX_PATH); intptr_t hFile; struct _finddata_t file; int nFileSize = 0; if( (hFile = _findfirst( szFilename, &file )) != -1L ) { nFileSize = (int)file.size; } else { return E_FAIL; } uint8* pData = new uint8[nFileSize]; memset(pData, 0, nFileSize); if(pData == NULL) { return E_OUTOFMEMORY; } #ifdef _DEBUG // Output our include solver tree... char szDepth[_MAX_PATH]; memset(szDepth, 0, _MAX_PATH); for(int k = 0; k < (int)m_PathList.size(); ++k) { szDepth[k] = '\t'; } char szDebugBuf[_MAX_PATH]; sprintf(szDebugBuf, "%s: %s%s size: (%d)\n", ((int)m_PathList.size() <= 1) ? "Solving" : "Including", szDepth, szFilename, nFileSize); OutputDebugString(szDebugBuf); #endif FILE *fp = fopen(szFilename, "rb"); if(!fp) { delete [] pData; *ppData = NULL; *pBytes = 0; return E_FAIL; } fread(pData, nFileSize, 1, fp); fclose(fp); //pData[nFileSize] = '\0'; *ppData = pData; *pBytes = nFileSize;//+1; return S_OK; }