From e78d2cce18b50ed86933d05ac5bccdf4ef13d6e3 Mon Sep 17 00:00:00 2001 From: Didier 'OdyX' Raboud Date: Thu, 31 Oct 2013 10:35:43 +0100 Subject: On MacOSX, define the DataPath as being the Resources path in the bundle --- src/app/system_macosx.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/app/system_macosx.h | 1 + 2 files changed, 54 insertions(+) (limited to 'src/app') diff --git a/src/app/system_macosx.cpp b/src/app/system_macosx.cpp index 8e9608c..d452fe6 100644 --- a/src/app/system_macosx.cpp +++ b/src/app/system_macosx.cpp @@ -21,10 +21,47 @@ #include +// MacOS-specific headers +#include #include #include +inline std::string CFStringRefToStdString(CFStringRef str) { + + std::string stdstr; + + char *fullPath; + CFStringEncoding encodingMethod = CFStringGetSystemEncoding(); + + // 1st try for English system + fullPath = const_cast(CFStringGetCStringPtr(str, encodingMethod)); + if( fullPath == NULL ) + { + // 2nd try for Japanese system + encodingMethod = kCFStringEncodingUTF8; + fullPath = const_cast(CFStringGetCStringPtr(str, encodingMethod)); + } + + // for safer operation. + if( fullPath == NULL ) + { + CFIndex length = CFStringGetLength(str); + fullPath = static_cast(malloc( length + 1 )); + + // TODO: Check boolean result of that conversion + CFStringGetCString(str, fullPath, length, kCFStringEncodingUTF8 ); + + stdstr = fullPath; + + free( fullPath ); + } + else + stdstr = fullPath; + + return stdstr; +} + void CSystemUtilsMacOSX::Init() { // These functions are a deprecated way to get the 'Application Support' folder, but they do work, in plain C++ @@ -41,6 +78,22 @@ void CSystemUtilsMacOSX::Init() boost::filesystem::create_directories(m_ASPath.c_str()); } +std::string CSystemUtilsMacOSX::GetDataPath() +{ + std::string dataPath; + // Get the Resources bundle URL + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle); + CFStringRef str = CFURLCopyFileSystemPath( resourcesURL, kCFURLPOSIXPathStyle ); + CFRelease(resourcesURL); + + dataPath = CFStringRefToStdString(str); + dataPath += "/Contents/Resources"; + GetLogger()->Trace("dataPath is %s\n", dataPath.c_str()); + + return dataPath; +} + std::string CSystemUtilsMacOSX::GetProfileFileLocation() { std::string profileFile = m_ASPath + "/colobot.ini"; diff --git a/src/app/system_macosx.h b/src/app/system_macosx.h index a5c1150..c2b9a41 100644 --- a/src/app/system_macosx.h +++ b/src/app/system_macosx.h @@ -28,6 +28,7 @@ class CSystemUtilsMacOSX : public CSystemUtilsOther public: virtual void Init() override; + virtual std::string GetDataPath() override; virtual std::string GetProfileFileLocation() override; virtual std::string GetSavegameDirectoryLocation() override; private: -- cgit v1.2.3-1-g7c22