diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index 73a4a634fa..8f7b5ce753 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -13,6 +13,8 @@ #if defined(WIN32) && !defined(XBOX) #include +#elif defined(UNIX) || defined(MACOSX) +#include #endif RageFileManager *FILEMAN = NULL; @@ -203,10 +205,38 @@ static RString GetDirOfExecutable( RString argv0 ) if( !bIsAbsolutePath ) { +#if defined(UNIX) || defined(MACOSX) + if( sPath.empty() ) + { + // This is in our path so look for it. + const char *path = getenv( "PATH" ); + + if( !path ) + path = _PATH_DEFPATH; + + vector vPath; + split( path, ":", vPath ); + FOREACH( RString, vPath, i ) + { + if( access(*i + "/" + argv0, X_OK|R_OK) ) + continue; + sPath = *i; + break; + } + if( sPath.empty() ) + sPath = GetCwd(); // What? + else if( sPath[0] != '/' ) // For example, if . is in $PATH. + sPath = GetCwd() + "/" + sPath; + } + else + { + sPath = GetCwd() + "/" + sPath; + } +#else sPath = GetCwd() + "/" + sPath; sPath.Replace( "\\", "/" ); +#endif } - return sPath; #endif } @@ -225,6 +255,7 @@ static void ChangeToDirOfExecutable( const RString &argv0 ) * through a symlink. Assume this is the case and change to the dir of the symlink. */ if( Basename(RageFileManagerUtil::sDirOfExecutable) == "MacOS" ) CollapsePath( RageFileManagerUtil::sDirOfExecutable += "/../../.." ); + puts( RageFileManagerUtil::sDirOfExecutable ); chdir( RageFileManagerUtil::sDirOfExecutable ); #endif }