Mac support to get executable path from .app file

This commit is contained in:
Jake Turner
2021-04-23 06:23:26 +01:00
committed by Baldur Karlsson
parent da660cd025
commit 5b2203d9d2
2 changed files with 16 additions and 2 deletions
+12
View File
@@ -22,6 +22,8 @@
* THE SOFTWARE.
******************************************************************************/
#include "api/replay/rdcstr.h"
#import <Cocoa/Cocoa.h>
#define MAX_COUNT_KEYS (65536)
@@ -56,3 +58,13 @@ bool apple_IsKeyPressed(int appleKeyCode)
{
return s_keysPressed[appleKeyCode];
}
rdcstr apple_GetExecutablePathFromAppBundle(const char *appBundlePath)
{
NSString *path = [NSString stringWithCString:appBundlePath encoding:NSUTF8StringEncoding];
NSBundle *nsBundle = [NSBundle bundleWithPath:path];
NSString *executablePath = nsBundle.executablePath;
rdcstr result([executablePath cStringUsingEncoding:NSUTF8StringEncoding]);
return result;
}
+4 -2
View File
@@ -41,6 +41,9 @@
#include "os/os_specific.h"
#include "strings/string_utils.h"
// defined in apple_helpers.mm
extern rdcstr apple_GetExecutablePathFromAppBundle(const char *appBundlePath);
// defined in foo/foo_process.cpp
char **GetCurrentEnvironment();
int GetIdentPort(pid_t childPid);
@@ -536,8 +539,7 @@ static pid_t RunProcess(rdcstr appName, rdcstr workDir, const rdcstr &cmdLine, c
#if ENABLED(RDOC_APPLE)
if(appName.size() > 5 && appName.endsWith(".app"))
{
rdcstr realAppName = appName + "/Contents/MacOS/" + get_basename(appName);
realAppName.erase(realAppName.size() - 4, ~0U);
rdcstr realAppName = apple_GetExecutablePathFromAppBundle(appName.c_str());
if(FileIO::exists(realAppName))
{