mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-10 22:22:10 +08:00
platform: move Sys_ShellExecute implementation to platform backends
This commit is contained in:
+1
-74
@@ -138,54 +138,6 @@ char *Sys_GetCurrentUser( void )
|
||||
return "Player";
|
||||
}
|
||||
|
||||
#if (defined(__linux__) && !defined(__ANDROID__)) || defined (__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
|
||||
static qboolean Sys_FindExecutable( const char *baseName, char *buf, size_t size )
|
||||
{
|
||||
char *envPath;
|
||||
char *part;
|
||||
size_t length;
|
||||
size_t baseNameLength;
|
||||
size_t needTrailingSlash;
|
||||
|
||||
if( !baseName || !baseName[0] )
|
||||
return false;
|
||||
|
||||
envPath = getenv( "PATH" );
|
||||
if( !envPath )
|
||||
return false;
|
||||
|
||||
baseNameLength = Q_strlen( baseName );
|
||||
while( *envPath )
|
||||
{
|
||||
part = Q_strchr( envPath, ':' );
|
||||
if( part )
|
||||
length = part - envPath;
|
||||
else
|
||||
length = Q_strlen( envPath );
|
||||
|
||||
if( length > 0 )
|
||||
{
|
||||
needTrailingSlash = ( envPath[length - 1] == '/' ) ? 0 : 1;
|
||||
if( length + baseNameLength + needTrailingSlash < size )
|
||||
{
|
||||
Q_strncpy( buf, envPath, length + 1 );
|
||||
if( needTrailingSlash )
|
||||
Q_strcpy( buf + length, "/" );
|
||||
Q_strcpy( buf + length + needTrailingSlash, baseName );
|
||||
buf[length + needTrailingSlash + baseNameLength] = '\0';
|
||||
if( access( buf, X_OK ) == 0 )
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
envPath += length;
|
||||
if( *envPath == ':' )
|
||||
envPath++;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
=================
|
||||
Sys_ShellExecute
|
||||
@@ -193,32 +145,7 @@ Sys_ShellExecute
|
||||
*/
|
||||
void Sys_ShellExecute( const char *path, const char *parms, int shouldExit )
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if( !Q_strcmp( path, GENERIC_UPDATE_PAGE ) || !Q_strcmp( path, PLATFORM_UPDATE_PAGE ))
|
||||
path = DEFAULT_UPDATE_PAGE;
|
||||
|
||||
ShellExecute( NULL, "open", path, parms, NULL, SW_SHOW );
|
||||
#elif (defined(__linux__) && !defined (__ANDROID__)) || defined (__FreeBSD__) || defined (__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
|
||||
|
||||
if( !Q_strcmp( path, GENERIC_UPDATE_PAGE ) || !Q_strcmp( path, PLATFORM_UPDATE_PAGE ))
|
||||
path = DEFAULT_UPDATE_PAGE;
|
||||
|
||||
char xdgOpen[128];
|
||||
if( Sys_FindExecutable( OPEN_COMMAND, xdgOpen, sizeof( xdgOpen ) ) )
|
||||
{
|
||||
const char *argv[] = {xdgOpen, path, NULL};
|
||||
pid_t id = fork( );
|
||||
if( id == 0 )
|
||||
{
|
||||
execv( xdgOpen, (char **)argv );
|
||||
fprintf( stderr, "error opening %s %s", xdgOpen, path );
|
||||
_exit( 1 );
|
||||
}
|
||||
}
|
||||
else Con_Reportf( S_WARN "Could not find "OPEN_COMMAND" utility\n" );
|
||||
#elif defined(__ANDROID__) && !defined(XASH_DEDICATED)
|
||||
Android_ShellExecute( path, parms );
|
||||
#endif
|
||||
Platform_ShellExecute( path, parms );
|
||||
|
||||
if( shouldExit )
|
||||
Sys_Quit();
|
||||
|
||||
Reference in New Issue
Block a user