jp9000 2014-01-08 18:08:50 -07:00
commit 1b555c1c17
6 changed files with 60 additions and 1 deletions

View File

@ -75,6 +75,10 @@ if(WIN32)
elseif(APPLE)
set(obs_platform_src
platform-osx.mm)
add_definitions(-fobjc-arc)
if(BUILD_APP_BUNDLE)
add_definitions(-DOBS_OSX_BUNDLE=1)
endif()
elseif(UNIX)
set(obs_platform_src
platform-x11.cpp)

View File

@ -183,6 +183,9 @@ bool OBSApp::OnInit()
{
base_set_log_handler(do_log);
if (!InitApplicationBundle())
return false;
if (!wxApp::OnInit())
return false;
wxInitAllImageHandlers();

View File

@ -16,13 +16,15 @@
******************************************************************************/
#include <sstream>
#include <util/base.h>
#include "platform.hpp"
using namespace std;
#include <unistd.h>
#import <AppKit/AppKit.h>
using namespace std;
bool GetDataFilePath(const char *data, string &output)
{
stringstream str;
@ -41,3 +43,37 @@ void GetMonitors(vector<MonitorInfo> &monitors)
frame.size.width, frame.size.height);
}
}
bool InitApplicationBundle()
{
#ifdef OBS_OSX_BUNDLE
static bool initialized = false;
if (initialized)
return true;
try {
NSBundle *bundle = [NSBundle mainBundle];
if (!bundle)
throw "Could not find main bundle";
NSString *exe_path = [bundle executablePath];
if (!exe_path)
throw "Could not find executable path";
NSString *path = [exe_path stringByDeletingLastPathComponent];
if (chdir([path fileSystemRepresentation]))
throw "Could not change working directory to "
"bundle path";
} catch (const char* error) {
blog(LOG_ERROR, "InitBundle: %s", error);
return false;
}
return initialized = true;
#else
return true;
#endif
}

View File

@ -50,3 +50,9 @@ void GetMonitors(vector<MonitorInfo> &monitors)
monitors.clear();
EnumDisplayMonitors(NULL, NULL, OBSMonitorEnumProc, (LPARAM)&monitors);
}
bool InitApplicationBundle()
{
return true;
}

View File

@ -89,3 +89,9 @@ void GetMonitors(vector<MonitorInfo> &monitors)
XCloseDisplay(display);
}
bool InitApplicationBundle()
{
return true;
}

View File

@ -33,3 +33,7 @@ struct MonitorInfo {
/* Gets the path of obs-studio specific data files (such as locale) */
bool GetDataFilePath(const char *data, std::string &path);
void GetMonitors(std::vector<MonitorInfo> &monitors);
/* Updates the working directory for OSX application bundles */
bool InitApplicationBundle();