void FSList::Append( clPtr<FSNode> p ) { p->next = 0; if ( last ) { last->next = p.ptr(); } else { first = p.ptr(); } last = p.ptr(); p.drop(); count++; }
//определяет наличие исполняемого файла в каталогах в PATH //списки кэшируются bool ExeFileExist( const char* name ) { if ( name[0] == '/' ) //абсолютный путь { struct stat sb; if ( stat( name, &sb ) ) { return false; } return true; return ( ( sb.st_mode & S_IFMT ) == S_IFREG && ( sb.st_mode & 0111 ) != 0 ); } if ( !pathExeList.ptr() ) { pathExeList = new cstrhash<bool>; const char* pl = getenv( "PATH" ); if ( !pl ) { return false; } std::vector<char> paths = new_char_str( pl ); char* s = paths.data(); while ( *s ) { char* t = s; while ( *t && *t != ':' ) { t++; } if ( *t ) { *t = 0; t++; } SearchExe( s, *( pathExeList.ptr() ) ); s = t; } } return pathExeList->exist( name ) != 0; }
static int _GetAppList( const unicode_t* fileName, ccollect<AppNode*>& list ) { if ( !mimeDb.ptr() ) { if ( FileIsExist( "/usr/share/mime/globs" ) ) { mimeDb = new MimeDB( "/usr/share/mime/" ); } else { mimeDb = new MimeDB( "/usr/local/share/mime/" ); } } if ( !appDb.ptr() ) { if ( DirIsExist( "/usr/share/applications" ) ) { appDb = new AppDB( "/usr/share/applications/" ); } else { appDb = new AppDB( "/usr/local/share/applications/" ); } } if ( !userDefApp.ptr() ) { const char* home = getenv( "HOME" ); if ( home ) { userDefApp = new AppDefListFile( carray_cat<char>( home, "/.local/share/applications/mimeapps.list" ).data() ); } } mimeDb->Refresh(); appDb->Refresh(); if ( userDefApp.ptr() ) { userDefApp->Refresh(); } ccollect<int> mimeList; if ( mimeDb->GetMimeList( fileName, mimeList ) ) { int i; std::unordered_map<int, bool> hash; for ( i = 0; i < mimeList.count(); i++ ) { ccollect<int> appList; if ( userDefApp.ptr() ) { userDefApp->GetAppList( mimeList[i], appList ); } appDb->GetAppList( mimeList[i], appList ); for ( int j = 0; j < appList.count(); j++ ) { bool Exists = hash.find( appList[j] ) != hash.end(); if ( !Exists ) { hash[appList[j]] = true; AppNode* p = appDb->GetApp( appList[j] ); if ( p && p->exec.data() ) { list.append( p ); } } } } } return list.count(); }