On MacOSX, define the DataPath as being the Resources path in the bundle
parent
17ad3e5a90
commit
e78d2cce18
|
@ -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";
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue