From c6936984b42e92c10f0175d0416eee34231f83f8 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 14 Aug 2006 15:31:52 +0000 Subject: [PATCH] Allow launching through a symlink. It doesn't work quite like normal applications. Menus don't show up, it doesn't really seem to know where it is. Still, most people just would use the Finder and never encounter this behavior. --- stepmania/src/RageFileManager.cpp | 7 ++++++- .../src/arch/ArchHooks/ArchHooks_darwin.cpp | 16 +++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index b4bbe0666b..a1388b4db5 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -221,7 +221,12 @@ static void ChangeToDirOfExecutable( const RString &argv0 ) #if defined(_WINDOWS) chdir( RageFileManagerUtil::sDirOfExecutable + "/.." ); #elif defined(MACOSX) - chdir( RageFileManagerUtil::sDirOfExecutable + "/../../.." ); + /* If the basename is not MacOS, then we've likely been launched via the command line + * through a symlink. Assume this is the case and change to the dir of the symlink. */ + puts( RageFileManagerUtil::sDirOfExecutable ); + if( Basename(RageFileManagerUtil::sDirOfExecutable) == "MacOS" ) + CollapsePath( RageFileManagerUtil::sDirOfExecutable += "/../../.." ); + chdir( RageFileManagerUtil::sDirOfExecutable ); #endif } diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp index 08143607e5..dcfbdaa01f 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp @@ -83,10 +83,15 @@ void ArchHooks_darwin::Init() CFBundleRef bundle = CFBundleGetMainBundle(); CFStringRef appID = CFBundleGetIdentifier( bundle ); + if( appID == NULL ) + { + // We were probably launched through a symlink. Don't bother hunting down the real path. + return; + } CFStringRef version = CFStringRef( CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey) ); + CFPropertyListRef old = CFPreferencesCopyAppValue( key, appID ); CFURLRef path = CFBundleCopyBundleURL( bundle ); CFPropertyListRef value = CFURLCopyFileSystemPath( path, kCFURLPOSIXPathStyle ); - CFPropertyListRef old = CFPreferencesCopyAppValue( key, appID ); CFMutableDictionaryRef newDict = NULL; if( old && CFGetTypeID(old) != CFDictionaryGetTypeID() ) @@ -437,16 +442,9 @@ static void PathForFolderType( char dir[PATH_MAX], OSType folderType ) void ArchHooks::MountInitialFilesystems( const RString &sDirOfExecutable ) { - CFBundleRef bundle = CFBundleGetMainBundle(); - CFURLRef bundleURL = CFBundleCopyBundleURL( bundle ); - CFURLRef dirURL = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault, bundleURL ); char dir[PATH_MAX]; - if( !CFURLGetFileSystemRepresentation(dirURL, true, (UInt8 *)dir, sizeof(dir)) ) - FAIL_M( "CFURLGetFileSystemRepresentation() failed." ); - CFRelease( bundleURL ); - CFRelease( dirURL ); - FILEMAN->Mount( "dir", dir, "/" ); + FILEMAN->Mount( "dir", sDirOfExecutable, "/" ); // /Save -> ~/Library/Application Support/PRODUCT_ID PathForFolderType( dir, kPreferencesFolderType );