Ejemplo n.º 1
0
bool UxMntList( wal::ccollect< MntListNode >* pList )
{
	if ( !pList ) { return false; }

	try
	{

		BFile f;
		f.Open( ( sys_char_t* )"/proc/mounts" );

		char buf[4096];

		while ( f.GetStr( buf, sizeof( buf ) ) )
		{
			char* w[3];
			int n = GetNWords( buf, w, 3 );

			if ( n < 3 ) { continue; }

			if ( !strcmp( w[0], "none" ) ) { continue; }

			if ( !strcmp( w[1], "/" ) ) { continue; }

			if ( !strcmp( w[2], "tmpfs" ) ) { continue; }

			if ( !strcmp( w[2], "sysfs" ) ) { continue; }

			if ( !strcmp( w[2], "cgroup" ) ) { continue; }


			char* p = w[1];

			if ( p[0] == '/' && p[1] == 'p' && p[2] == 'r' && p[3] == 'o' && p[4] == 'c' && ( p[5] == '/' || !p[5] ) ) { continue; } // skip /proc[/...]

			if ( p[0] == '/' && p[1] == 'd' && p[2] == 'e' && p[3] == 'v' && ( p[4] == '/' || !p[4] ) ) { continue; } //skip /dev[/...]


			MntListNode node;
			node.path = w[1];
			node.type = w[2];
			pList->append( node );

		}
	}
	catch ( cexception* ex )
	{
		ex->destroy();
		return false;
	}

	return true;
}
Ejemplo n.º 2
0
static bool LangListLoad(sys_char_t *fileName, ccollect<LangListNode> &list)
{
	list.clear();
	try {
		BFile f;
		f.Open(fileName);
		char buf[4096];
		
		while (f.GetStr(buf, sizeof(buf)))
		{
			char *s = buf;
			while (IsSpace(*s)) s++;
			if (*s == '#') 	continue;

			if (!*s) continue;
			
			ccollect<char,0x100> id;
			ccollect<char,0x100> name;
			
			while (*s && !IsSpace(*s)) {
				id.append(*s);
				s++;
			}
			
			while (IsSpace(*s)) s++;
			
			int lastNs = -1;
			for (int i = 0; *s; i++, s++) {
				if (*s == '#') break;
				if (!IsSpace(*s)) lastNs = i;
				name.append(*s);
			}
			if (id.count()<=0 || lastNs < 0) continue;
			id.append(0);
			name.append(0);
			name[lastNs + 1] = 0; 
			
			LangListNode(id.ptr(), name.ptr());
			list.append(LangListNode(id.ptr(), name.ptr()) );
		}
	} catch (cexception *ex) {
		ex->destroy();
		return false;
	}
	return true;
}
Ejemplo n.º 3
0
void MimeAliases::Refresh()
{
	time_t tim = GetMTime( fileName.data() );

	if ( tim == mtime ) { return; }

	mtime = tim;
	data.clear();

	try
	{
		BFile f;
		f.Open( fileName.data() ); //"/usr/share/mime/aliases");
		char buf[4096];

		while ( f.GetStr( buf, sizeof( buf ) ) )
		{
			char* s = SS( buf );

			if ( *s == '#' ) { continue; } //комментарий

			char* p = SNotS( s );

			if ( !p ) { continue; }

			*p = 0;
			p++;
			p = SS( p );
			char* t = SNotS( p );

			if ( t ) { *t = 0; }

			data[GetMimeID( s )] = GetMimeID( p );
		}
	}
	catch ( cexception* ex )
	{
		ex->destroy();
		return;
	}
}
Ejemplo n.º 4
0
void MimeSubclasses::Refresh()
{
	time_t tim = GetMTime( fileName.data() );

	if ( tim == mtime ) { return; }

	mtime = tim;
	hash.clear();

	try
	{
		BFile f;
		f.Open( fileName.data() ); //"/usr/share/mime/subclasses");
		char buf[4096];

		while ( f.GetStr( buf, sizeof( buf ) ) )
		{
			char* s = SS( buf );

			if ( *s == '#' ) { continue; } //комментарий

			char* parent = SNotS( s );

			if ( !parent ) { continue; }

			*parent = 0;
			parent++;
			parent = SS( parent );
			char* t = SNotS( parent );

			if ( t ) { *t = 0; }

			hash[GetMimeID( s )].append( GetMimeID( parent ) );
		}
	}
	catch ( cexception* ex )
	{
		ex->destroy();
		return;
	}
}
Ejemplo n.º 5
0
bool AppDB::ReadAppDesctopFile( const char* name )
{
	int id = GetAppID( name );

	if ( apps.find( id ) != apps.end() ) { return true; }

	clPtr<AppNode> app = new AppNode();

	try
	{
		BFile f;
		f.Open( carray_cat<char>( appDefsPrefix.data(), name ).data() );

		char buf[4096];
		bool ok = false;

		bool application = false;

		ccollect<int> mimeList;

		while ( f.GetStr( buf, sizeof( buf ) ) )
		{
			EraseLastSpaces( buf );
			char* s = buf;
			s = SS( s );

			if ( *s == '[' )
			{
				ok = !CmpNoCase( s, "[Desktop Entry]" );
				continue;
			}

			if ( !ok ) { continue; }

			char* vname = s;

			while ( *s && !IsSpace( *s ) && *s != '=' ) { s++; }

			if ( IsSpace( *s ) )
			{
				*s = 0;
				s++;
				s = SS( s );
			}

			if ( *s != '=' )
			{
				continue;
			}

			*s = 0;
			s++;
			s = SS( s );

			if ( !CmpNoCase( vname, "TYPE" ) )
			{
				if ( !CmpNoCase( s, "APPLICATION" ) ) { application = true; }

				continue;
			}


			if ( !CmpNoCase( vname, "NAME" ) )
			{

				app->name = utf8_to_unicode( s );
				continue;
			}

			if ( !CmpNoCase( vname, "EXEC" ) )
			{
				app->exec = utf8_to_unicode( s );
				continue;
			}

			if ( !CmpNoCase( vname, "TRYEXEC" ) ) //проверяем сразу, чего каждый раз проверять
			{
				if ( !ExeFileExist( s ) )
				{
					apps[id] = 0;
					return 0;
				}

				continue;
			}

			if ( !CmpNoCase( vname, "TERMINAL" ) )
			{
				if ( !CmpNoCase( s, "TRUE" ) )
				{
					app->terminal = true;
				}
				else if ( !CmpNoCase( s, "FALSE" ) )
				{
					app->terminal = false;
				}

				continue;
			}

			if ( !CmpNoCase( vname, "MIMETYPE" ) )
			{
				while ( *s )
				{
					s = SS( s );
					char* m = s;

					while ( *s && *s != ';' ) { s++; }

					if ( *s == ';' ) { *s = 0; s++; }

					if ( *m )
					{
						mimeList.append( GetMimeID( m ) );
					}
				}

				continue;
			}
		}

		if ( !app->exec.data() || !application )
		{
			apps[id] = 0;
			return false;
		}

//		AppNode* pNode = app.ptr();

//printf("read %s - ok\n", name);

		apps[id] = app;

		for ( int i = 0; i < mimeList.count(); i++ )
		{
			mimeMapHash[mimeList[i]].append( id );
		}

		return true;

	}
	catch ( cexception* ex )
	{
		ex->destroy();
	}

	apps[id] = 0;
	return false;
}
Ejemplo n.º 6
0
void AppDefListFile::Refresh()
{

	time_t tim = GetMTime( fileName.data() );

	if ( tim == mtime ) { return; }

	mtime = tim;
	hash.clear();

	try
	{
		BFile f;

		f.Open( fileName.data() );

		char buf[4096];
		bool readLine = false;

		while ( f.GetStr( buf, sizeof( buf ) ) )
		{
			EraseLastSpaces( buf );
			char* s = buf;
			s = SS( s );

			if ( *s == '[' )
			{
				readLine = !CmpNoCase( s, "[Default Applications]" ) ||
				           !CmpNoCase( s, "[Added Associations]" );
				continue;
			}

			if ( !readLine ) { continue; }

			char* mimeStr = s;

			while ( *s && !IsSpace( *s ) && *s != '=' ) { s++; }

			if ( IsSpace( *s ) )
			{

				*s = 0;
				s++;
				s = SS( s );
			}

			if ( *s != '=' )
			{
				continue;
			}

			*s = 0;
			s++;
			s = SS( s );

			int mimeId = GetMimeID( mimeStr );

			//в mint бывает несколько файлов описания приложений через ';' причем каких то файлов может не быть
			while ( *s )
			{

				char* t = SNotC( s, ';' );

				if ( *t )
				{
					*t = 0;
					t++;
				}

				hash[mimeId].append( GetAppID( s ) );
				s = t;
			}
		}

	}
	catch ( cexception* ex )
	{
		ex->destroy();
	}
}
Ejemplo n.º 7
0
void MimeGlobs::Refresh()
{
	time_t tim = GetMTime( fileName.data() );

	if ( tim == mtime ) { return; }

	mtime = tim;
	m_ExtMimeHash.clear();
	ClearMaskList();

	try
	{
		BFile f;
		f.Open( fileName.data() ); //"/usr/share/mime/glibs");
		char buf[4096];

		while ( f.GetStr( buf, sizeof( buf ) ) )
		{
			char* s = SS( buf );

			if ( *s == '#' ) { continue; } //комментарий

			//text/plain:*.doc

			char* e = SNotC( s, ':' );

			if ( !e ) { continue; }

			*e = 0;
			e++;
			e = SS( e );

			int mimeId = GetMimeID( s );

			if ( e[0] == '*' && e[1] == '.' )
			{
				e += 2;
				char* t = SNotS( e );

				if ( *t ) { *t = 0; }

				AddExt( e, mimeId );
			}
			else
			{
				char* t = SNotS( e );

				if ( *t ) { *t = 0; }

				AddMask( e, mimeId );
			}
		}
	}
	catch ( cexception* ex )
	{
		ex->destroy();
		return;
	}

	return;
}