summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorDidier 'OdyX' Raboud <didier@raboud.com>2013-10-31 10:35:43 +0100
committerDidier 'OdyX' Raboud <didier@raboud.com>2013-11-13 09:35:32 +0100
commite78d2cce18b50ed86933d05ac5bccdf4ef13d6e3 (patch)
tree6492888cf316514449ec08e4f1b004777eec541d /src/app
parent17ad3e5a906c59e8d108b75a6d51cc7528dfa44d (diff)
downloadcolobot-e78d2cce18b50ed86933d05ac5bccdf4ef13d6e3.tar.gz
colobot-e78d2cce18b50ed86933d05ac5bccdf4ef13d6e3.tar.bz2
colobot-e78d2cce18b50ed86933d05ac5bccdf4ef13d6e3.zip
On MacOSX, define the DataPath as being the Resources path in the bundle
Diffstat (limited to 'src/app')
-rw-r--r--src/app/system_macosx.cpp53
-rw-r--r--src/app/system_macosx.h1
2 files changed, 54 insertions, 0 deletions
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 <stdlib.h>
+// MacOS-specific headers
+#include <CoreFoundation/CFBundle.h>
#include <CoreServices/CoreServices.h>
#include <boost/filesystem.hpp>
+inline std::string CFStringRefToStdString(CFStringRef str) {
+
+ std::string stdstr;
+
+ char *fullPath;
+ CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
+
+ // 1st try for English system
+ fullPath = const_cast<char*>(CFStringGetCStringPtr(str, encodingMethod));
+ if( fullPath == NULL )
+ {
+ // 2nd try for Japanese system
+ encodingMethod = kCFStringEncodingUTF8;
+ fullPath = const_cast<char*>(CFStringGetCStringPtr(str, encodingMethod));
+ }
+
+ // for safer operation.
+ if( fullPath == NULL )
+ {
+ CFIndex length = CFStringGetLength(str);
+ fullPath = static_cast<char *>(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: