void EnlistFolders(const KString& Mask, KStrings& Folders, bool bFullPaths, bool bClearFirst) { if(bClearFirst) Folders.Clear(); KString FolderName = GetFilePath(Mask); _tfinddata_t FileInfo; int iHandle = _tfindfirst(Mask, &FileInfo); if(iHandle>=0) { for(;;) { if( (FileInfo.attrib & _A_SUBDIR) && _tcscmp(FileInfo.name, TEXT(".")) && _tcscmp(FileInfo.name, TEXT(".."))) { *Folders.AddLast() = (bFullPaths ? FolderName + FileInfo.name : FileInfo.name) + TEXT("\\"); } // To the next file if(_tfindnext(iHandle, &FileInfo)==-1) break; } _findclose(iHandle); } }
// // readdir // // Return a pointer to a dirent structure filled with the information on the // next entry in the directory. // struct dirent *readdir(DIR *dirp) { errno = 0; /* Check for valid DIR struct. */ if(!dirp) { errno = EFAULT; return (struct dirent *)0; } if(dirp->dd_stat < 0) { /* We have already returned all files in the directory * (or the structure has an invalid dd_stat). */ return (struct dirent *)0; } else if(dirp->dd_stat == 0) { /* We haven't started the search yet. */ /* Start the search */ dirp->dd_handle = _tfindfirst(dirp->dd_name, &(dirp->dd_dta)); if(dirp->dd_handle == -1) { /* Whoops! Seems there are no files in that * directory. */ dirp->dd_stat = -1; } else { dirp->dd_stat = 1; } } else { /* Get the next search entry. */ if(_tfindnext(dirp->dd_handle, &(dirp->dd_dta))) { /* We are off the end or otherwise error. _findnext sets errno to ENOENT if no more file Undo this. */ DWORD winerr = GetLastError(); if(winerr == ERROR_NO_MORE_FILES) { errno = 0; } _findclose(dirp->dd_handle); dirp->dd_handle = -1; dirp->dd_stat = -1; } else { /* Update the status to indicate the correct * number. */ dirp->dd_stat++; } } if(dirp->dd_stat > 0) { /* Successfully got an entry. Everything about the file is * already appropriately filled in except the length of the * file name. */ dirp->dd_dir.d_namlen = _tcslen(dirp->dd_dta.name); _tcscpy(dirp->dd_dir.d_name, dirp->dd_dta.name); return &dirp->dd_dir; } return (struct dirent *)0; }
int CAimProto::get_avatar_filename(HANDLE hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext) { size_t tPathLen; bool found = false; init_custom_folders(); TCHAR* path = (TCHAR*)_malloca(cbLen * sizeof(TCHAR)); if (hAvatarsFolder == NULL || FoldersGetCustomPathT(hAvatarsFolder, path, (int)cbLen, _T(""))) { TCHAR *tmpPath = Utils_ReplaceVarsT(_T("%miranda_avatarcache%")); TCHAR *tszModuleName = mir_a2t(m_szModuleName); tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%s"), tmpPath, tszModuleName); mir_free(tszModuleName); mir_free(tmpPath); } else { _tcscpy(pszDest, path); tPathLen = _tcslen(pszDest); } if (ext && _taccess(pszDest, 0)) CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)pszDest); size_t tPathLen2 = tPathLen; DBVARIANT dbv; if (getTString(hContact, AIM_KEY_AH, &dbv)) return GAIR_NOAVATAR; tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s"), dbv.ptszVal); DBFreeVariant(&dbv); if (ext == NULL) { mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T(".*")); _tfinddata_t c_file; long hFile = _tfindfirst(pszDest, &c_file); if (hFile > -1L) { do { if (_tcsrchr(c_file.name, '.')) { mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name); found = true; } } while (_tfindnext(hFile, &c_file) == 0); _findclose( hFile ); } if (!found) pszDest[0] = 0; } else { mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext); found = _taccess(pszDest, 0) == 0; } return found ? GAIR_SUCCESS : GAIR_WAITFOR; }
// ---------------- // Global routines // ---------------- void EnlistFiles(const KString& Mask, KStrings& Files, bool bFullPaths, bool bClearFirst) { if(bClearFirst) Files.Clear(); KString FolderName = GetFilePath(Mask); _tfinddata_t FileInfo; int iHandle = _tfindfirst(Mask, &FileInfo); if(iHandle>=0) { for(;;) { if(!(FileInfo.attrib & _A_SUBDIR)) *Files.AddLast() = bFullPaths ? FolderName + FileInfo.name : FileInfo.name; // To the next file if(_tfindnext(iHandle, &FileInfo)==-1) break; } _findclose(iHandle); } }
bool SmileyPackCType::LoadSmileyDir(TCHAR* dir) { bkstring dirs = dir; dirs += _T("\\*.*"); _tfinddata_t c_file; INT_PTR hFile = _tfindfirst((TCHAR*)dirs.c_str(), &c_file); if (hFile > -1L) { do { if (c_file.name[0] != '.') { bkstring fullpath = dir; fullpath = fullpath + _T("\\") + c_file.name; TCHAR* div = _tcsrchr(c_file.name, '.'); if (div) { *div = 0; SmileyCType *smlc = new SmileyCType(fullpath, c_file.name); if (smlc->GetTriggerText().empty()) delete smlc; else m_SmileyList.insert(smlc); } } } while( _tfindnext( hFile, &c_file ) == 0 ); _findclose( hFile ); AddTriggersToSmileyLookup(); return true; } return false; }
void CMsnProto::MSN_GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen, const TCHAR *ext) { size_t tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName); if (_taccess(pszDest, 0)) CreateDirectoryTreeT(pszDest); size_t tPathLen2 = tPathLen; if (hContact != NULL) { DBVARIANT dbv; if (getString(hContact, "PictContext", &dbv) == 0) { char* szAvatarHash = MSN_GetAvatarHash(dbv.pszVal); if (szAvatarHash != NULL) { TCHAR *sztAvatarHash = mir_a2t(szAvatarHash); tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s."), sztAvatarHash); mir_free(sztAvatarHash); mir_free(szAvatarHash); } else { delSetting(hContact, "PictContext"); if (cbLen) pszDest[0] = 0; } db_free(&dbv); } else if (cbLen) pszDest[0] = 0; } else { TCHAR *sztModuleName = mir_a2t(m_szModuleName); tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%s avatar."), sztModuleName); mir_free(sztModuleName); } if (ext == NULL) { mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("*")); bool found = false; _tfinddata_t c_file; long hFile = _tfindfirst(pszDest, &c_file); if (hFile > -1L) { do { if (_tcsrchr(c_file.name, '.')) { mir_sntprintf(pszDest + tPathLen2, cbLen - tPathLen2, _T("\\%s"), c_file.name); found = true; } } while(_tfindnext(hFile, &c_file) == 0); _findclose( hFile ); } if (!found) pszDest[0] = 0; } else { tPathLen--; mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, ext); } }
bool GetFileList(const tstring& mask, std::set<tstring>& files) { struct _tfinddata_t file; intptr_t hFile; tstring dirPath = ExtractFilePath(mask); size_t initialSize = files.size(); if( (hFile = _tfindfirst( mask.c_str(), &file )) != -1L ) { do { tstring fileName = dirPath + _T("\\") + file.name; files.insert(fileName); } while( _tfindnext( hFile, &file ) == 0 ); _findclose( hFile ); } return initialSize != files.size(); }
// ------------------------------------------------------------- void Actions::ParseDirectory( LPCTSTR rootPath, LPCTSTR extentionPath ) { // make sure that we do not have too many actions // this is a sign that something is broken // or that we are reading the root directory { myodd::threads::Lock guard(_mutexActions); if (_actions.size() > static_cast<size_t>(::myodd::config::Get(L"paths\\maxcommand", 2048))) { ASSERT(0); // you have reached the limit! // it is pointless to try and add more command. return; } } // make sure that the path that we have is valid. ASSERT( _tcslen( rootPath ) > 0 ); if( _tcslen( rootPath ) == 0 ) { return; } // the end path std::wstring directory = rootPath; // make sure it has a trailing back slash. myodd::files::AddTrailingBackSlash( directory ); // add the extension directory += extentionPath; // add a trailing back slash myodd::files::AddTrailingBackSlash( directory ); // // we could refine the search to // *.bat, *.exe, *.pl // but I am not sure we really need to restrict anything // it is up to the user to ensure that they have auto sPath = directory + L"*.*"; LPTSTR fullPath = NULL; if( !myodd::files::ExpandEnvironment( sPath.c_str(), fullPath ) ) { return; } _tfinddata_t fdata; const auto ffhandle = _tfindfirst( fullPath, &fdata ); if( ffhandle != -1 ) { do { if( _tcscmp(fdata.name, L"." ) == 0 || _tcscmp(fdata.name, L"..") == 0) { continue; } // .svn directories are hidden so we might as well ignore all hidden file. if( (fdata.attrib & _A_HIDDEN) == _A_HIDDEN ) { continue; } if( (fdata.attrib & _A_SUBDIR) == _A_SUBDIR ) { if( IsReservedDir( fdata.name ) ) { continue; } std::wstring subPath( extentionPath ); subPath += fdata.name; myodd::files::AddTrailingBackSlash( subPath ); ParseDirectory( rootPath, subPath.c_str() ); continue; } // ok add this command auto szFullPath( directory); szFullPath += fdata.name; std::wstring szName( fdata.name); szName = myodd::strings::lower(szName ); // if we don't want to show the extension then strip it. if( ::myodd::config::Get( L"commands\\show.extentions", 0 ) == false ) { myodd::files::StripExtension( szName ); } Add( new Action( _application ,szName, szFullPath)); }while( _tfindnext( ffhandle, &fdata ) == 0 ); _findclose( ffhandle ); } delete [] fullPath; }
void CFolderListCtrl::RefreshFileList() { std::vector<CFLCItemData *>arrListCache(m_nItemCount); int i; for (i=0;i<m_nItemCount;i++) { arrListCache[i] = reinterpret_cast<CFLCItemData *>(GetItemData(i)); arrListCache[i]->m_bFoundOnRefresh = false; } SCStringVector::iterator itExt = m_Properties.m_vsExt.begin(); CSCADString sPath; struct _tfinddata_t fd; int nLargeIconInd = 0; int nSmallIconInd = 0; int nItemCount = m_nItemCount; for( ; itExt != m_Properties.m_vsExt.end(); ++itExt ) { sPath = m_sFolderPath + _T("\\") + *itExt; intptr_t hFindHandle = _tfindfirst( sPath, &fd ); if( hFindHandle == -1 ) continue; AddFileTypeIcons(fd, nLargeIconInd, nSmallIconInd); do { bool bFileFound = false; CSCADString sFileName; if( m_sFolderPath.GetLength() && ( m_sFolderPath[m_sFolderPath.GetLength()-1] == _T('\\') || m_sFolderPath[m_sFolderPath.GetLength()-1] == _T('/') ) ) sFileName = m_sFolderPath+ fd.name; else sFileName = m_sFolderPath + ( _T("\\") ) + fd.name; for (int k=0; k<nItemCount;k++) { if (arrListCache[k]->m_sFilePath == sFileName) { bFileFound = true; arrListCache[k]->m_bFoundOnRefresh = true; if (fd.time_write != arrListCache[k]->m_tModified) { arrListCache[k]->m_bProcessed = false; if (m_strSelectedPath.CompareNoCase(arrListCache[k]->m_sFilePath)==0) { CSCAD3DMdlSettings::Get3DS()->SetViewFilePath( arrListCache[k]->m_sFilePath, arrListCache[k]->m_sExt ); } break; } } } if (!bFileFound) { AddFileItem(fd, nLargeIconInd, nSmallIconInd,*itExt); } } while( _tfindnext( hFindHandle, &fd ) != -1 ); _findclose( hFindHandle ); } m_nImageBalance = 0; for (i=0;i<m_nItemCount;i++) { CFLCItemData *pData = reinterpret_cast<CFLCItemData *>(GetItemData(i)); if (!pData->m_bFoundOnRefresh) { delete pData; CListCtrl::DeleteItem(i); m_nItemCount--; } else { if (!pData->m_bProcessed) m_nImageBalance++; } } SortItems( m_flciColumns[m_nCurColumn].m_fnCmp, m_bSortAscending ); ASSERT(m_nItemCount == GetItemCount()); UpdateFileCount(); SetRedrawItemPos( 0, true ); }
BOOL CFolderListCtrl::SetCurFolder( const CSCADString& sFolderPath, bool bForce) { if( !bForce && !m_sFolderPath.CompareNoCase( sFolderPath ) ) return TRUE; Timer.Start(); m_DirChangeListener.SetDir(sFolderPath, m_hWnd); /* SCDefProjInfo proj_info; SCADDefProj::GetInfo( m_Properties.m_DefProj, proj_info ); SCMdl3DSetCameraPos( proj_info.m_ptViewDir, proj_info.m_ptUpOrient ); */ // ReSharper disable once CppEntityAssignedButNoRead extern SCDefProjType ThumbProjection; ThumbProjection = m_Properties.m_DefProj; if(CSCAD3DMdlSettings::Get3DS()) { CSCAD3DMdlSettings::Get3DS()->CancelDraw(); CSCAD3DMdlSettings::Get3DS()->SetStartDrawPos( 0 ); } CreateImageList(); DeleteAllItemsData(); DeleteAllItems(); m_sFolderPath = sFolderPath; m_nItemCount = 0; m_nImageBalance = 0; m_nSelectedItem = -1; SetSelectionMark( 0 ); int i; for( i = m_imlLargeIcons.GetImageCount() - 1; i >= 0; i-- ) m_imlLargeIcons.Remove( i ); for( i = m_imlSmallIcons.GetImageCount() - 1; i >= 0; i-- ) m_imlSmallIcons.Remove( i ); if( _taccess( sFolderPath, 0 ) == -1 ) return TRUE; SCStringVector::iterator itExt = m_Properties.m_vsExt.begin(); CSCADString sPath; struct _tfinddata_t fd; int nLargeIconInd = 0; int nSmallIconInd = 0; for( ; itExt != m_Properties.m_vsExt.end(); ++itExt ) { sPath = m_sFolderPath + _T("\\") + *itExt; intptr_t hFindHandle = _tfindfirst( sPath, &fd ); if( hFindHandle == -1 ) continue; AddFileTypeIcons(fd, nLargeIconInd, nSmallIconInd); do { AddFileItem(fd, nLargeIconInd, nSmallIconInd, *itExt); } while( _tfindnext( hFindHandle, &fd ) != -1 ); _findclose( hFindHandle ); } SortItems( m_flciColumns[m_nCurColumn].m_fnCmp, m_bSortAscending ); m_nImageBalance = m_nItemCount; SetRedrawItemPos( 0, true ); if( AfxGetMainWnd() ) { CSCADViewerStatBar &theStatusBar = static_cast<CScadViewerFrame*>(AfxGetMainWnd())->GetStatusBar(); theStatusBar.SetFileCount( m_nItemCount ); } UpdateFileCount(); return TRUE; }
/* gets the list of mechanisms */ int _sasl_load_plugins(const add_plugin_list_t *entrypoints, const sasl_callback_t *getpath_cb, const sasl_callback_t *verifyfile_cb) { int result; TCHAR cur_dir[PATH_MAX], full_name[PATH_MAX+2], prefix[PATH_MAX+2]; /* 1 for '\\' 1 for trailing '\0' */ TCHAR * pattern; TCHAR c; int pos; int retCode = SASL_OK; char *utf8path = NULL; TCHAR *path=NULL; int position; const add_plugin_list_t *cur_ep; struct _stat statbuf; /* filesystem entry information */ intptr_t fhandle; /* file handle for _findnext function */ struct _tfinddata_t finddata; /* data returned by _findnext() */ size_t prefix_len; /* for static plugins */ add_plugin_t *add_plugin; _sasl_plug_type type; _sasl_plug_rec *p; if (! entrypoints || ! getpath_cb || getpath_cb->id != SASL_CB_GETPATH || ! getpath_cb->proc || ! verifyfile_cb || verifyfile_cb->id != SASL_CB_VERIFYFILE || ! verifyfile_cb->proc) return SASL_BADPARAM; /* do all the static plugins first */ for (cur_ep = entrypoints; cur_ep->entryname; cur_ep++) { /* What type of plugin are we looking for? */ if (!strcmp(cur_ep->entryname, "sasl_server_plug_init")) { type = SERVER; add_plugin = (add_plugin_t *)sasl_server_add_plugin; } else if (!strcmp(cur_ep->entryname, "sasl_client_plug_init")) { type = CLIENT; add_plugin = (add_plugin_t *)sasl_client_add_plugin; } else if (!strcmp(cur_ep->entryname, "sasl_auxprop_plug_init")) { type = AUXPROP; add_plugin = (add_plugin_t *)sasl_auxprop_add_plugin; } else if (!strcmp(cur_ep->entryname, "sasl_canonuser_init")) { type = CANONUSER; add_plugin = (add_plugin_t *)sasl_canonuser_add_plugin; } else { /* What are we looking for then? */ return SASL_FAIL; } for (p = _sasl_static_plugins; p->type; p++) { if (type == p->type) result = add_plugin(p->name, p->plug); } } /* get the path to the plugins */ result = ((sasl_getpath_t *)(getpath_cb->proc))(getpath_cb->context, &utf8path); if (result != SASL_OK) return result; if (!utf8path) return SASL_FAIL; if (sizeof(TCHAR) == sizeof(char)) { path = (TCHAR*)utf8path; } else { path = _sasl_utf8_to_wchar(utf8path); if (!path) return SASL_FAIL; } if (_tcslen(path) >= PATH_MAX) { /* no you can't buffer overrun */ retCode = SASL_FAIL; goto cleanup; } position=0; do { pos=0; do { c=path[position]; position++; cur_dir[pos]=c; pos++; } while ((c!=PATHS_DELIMITER) && (c!=0)); cur_dir[pos-1]='\0'; /* : check to make sure that a valid directory name was passed in */ if (_tstat (cur_dir, &statbuf) < 0) { continue; } if ((statbuf.st_mode & S_IFDIR) == 0) { continue; } _tcscpy(prefix, cur_dir); prefix_len = _tcslen (prefix); /* : Don't append trailing \ unless required */ if (prefix[prefix_len-1] != '\\') { _tcscat(prefix,_T("\\")); prefix_len++; } pattern = prefix; /* : Check that we have enough space for "*.dll" */ if ((prefix_len + DLL_MASK_LEN) > (sizeof(prefix) / sizeof(TCHAR) - 1)) { _sasl_log(NULL, SASL_LOG_WARN, "plugin search mask is too big"); continue; } _tcscat (prefix + prefix_len, _T("*") DLL_SUFFIX); fhandle = _tfindfirst (pattern, &finddata); if (fhandle == -1) { /* no matching files */ continue; } /* : Truncate "*.dll" */ prefix[prefix_len] = '\0'; do { size_t length; void *library; char *c; char plugname[PATH_MAX]; int entries; length = _tcslen(finddata.name); if (length < 5) { /* At least <Ch>.dll */ continue; /* can not possibly be what we're looking for */ } /* : Check for overflow */ if (length + prefix_len >= PATH_MAX) continue; /* too big */ if (_tcscmp(finddata.name + (length - _tcslen(DLL_SUFFIX)), DLL_SUFFIX) != 0) { continue; } /* : Check that it is not a directory */ if ((finddata.attrib & _A_SUBDIR) == _A_SUBDIR) { continue; } /* : Construct full name from prefix and name */ _tcscpy (full_name, prefix); _tcscat (full_name, finddata.name); /* cut off .dll suffix -- this only need be approximate */ if (sizeof(TCHAR) != sizeof(char)) { if (WideCharToMultiByte(CP_UTF8, 0, finddata.name, -1, plugname, sizeof(plugname), NULL, NULL) == 0) { // in case of unicode use utf8 continue; } } else { _tcscpy((TCHAR*)plugname, finddata.name); // w/o unicode local enconding is fine } c = strchr(plugname, '.'); if (c != NULL) *c = '\0'; result = _tsasl_get_plugin (full_name, verifyfile_cb, &library); if (result != SASL_OK) { continue; } entries = 0; for (cur_ep = entrypoints; cur_ep->entryname; cur_ep++) { result = _sasl_plugin_load(plugname, library, cur_ep->entryname, cur_ep->add_plugin); if (result == SASL_OK) { ++entries; } /* If this fails, it's not the end of the world */ } if (entries == 0) { _sasl_remove_last_plugin(); } } while (_tfindnext (fhandle, &finddata) == 0); _findclose (fhandle); } while ((c!='=') && (c!=0)); cleanup: if (sizeof(TCHAR) != sizeof(char)) { sasl_FREE(path); /* It's always allocated in coversion to wchar */ } return retCode; }