Explorar el Código

fix osx bundle loading of required resources

Palana hace 11 años
padre
commit
642d0dfca7
Se han modificado 6 ficheros con 60 adiciones y 1 borrados
  1. 4 0
      obs/CMakeLists.txt
  2. 3 0
      obs/obs-app.cpp
  3. 37 1
      obs/platform-osx.mm
  4. 6 0
      obs/platform-windows.cpp
  5. 6 0
      obs/platform-x11.cpp
  6. 4 0
      obs/platform.hpp

+ 4 - 0
obs/CMakeLists.txt

@@ -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)

+ 3 - 0
obs/obs-app.cpp

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

+ 37 - 1
obs/platform-osx.mm

@@ -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
+}
+

+ 6 - 0
obs/platform-windows.cpp

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

+ 6 - 0
obs/platform-x11.cpp

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

+ 4 - 0
obs/platform.hpp

@@ -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();
+