chdir to data directory on mac

May change this later if I decide to go back to using objective-c (or swift?) later to reimplement the rest of the mac features
This commit is contained in:
jacob1
2019-01-12 12:08:18 -05:00
parent cc93479c4b
commit 655f4bb6d0

View File

@@ -28,6 +28,10 @@
#ifndef WIN #ifndef WIN
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef MACOSX
#include <CoreServices/CoreServices.h>
#include <sys/stat.h>
#endif
#include "Format.h" #include "Format.h"
@@ -546,6 +550,23 @@ void SigHandler(int signal)
} }
} }
void ChdirToDataDirectory()
{
#ifdef MACOSX
FSRef ref;
OSType folderType = kApplicationSupportFolderType;
char path[PATH_MAX];
FSFindFolder( kUserDomain, folderType, kCreateFolder, &ref );
FSRefMakePath( &ref, (UInt8*)&path, PATH_MAX );
const char *tptPath = (std::string(path) + "/The Powder Toy").c_str();
mkdir(tptPath, 0755);
chdir(tptPath);
#endif
}
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
#if defined(_DEBUG) && defined(_MSC_VER) #if defined(_DEBUG) && defined(_MSC_VER)
@@ -563,6 +584,8 @@ int main(int argc, char * argv[])
#else #else
chdir(arguments["ddir"].c_str()); chdir(arguments["ddir"].c_str());
#endif #endif
else
ChdirToDataDirectory();
scale = Client::Ref().GetPrefInteger("Scale", 1); scale = Client::Ref().GetPrefInteger("Scale", 1);
resizable = Client::Ref().GetPrefBool("Resizable", false); resizable = Client::Ref().GetPrefBool("Resizable", false);