diff --git a/osx/boe.main.cpp b/osx/boe.main.cpp index fa14f856..10299a4e 100644 --- a/osx/boe.main.cpp +++ b/osx/boe.main.cpp @@ -154,9 +154,9 @@ bool sleep_field; void check_for_intel(); bool mac_is_intel; -int main(void) -{ +int main(int argc, char* argv[]) { try{ + init_directories(argv[0]); //data_store = (piles_of_stuff_dumping_type *) NewPtr(sizeof(piles_of_stuff_dumping_type)); init_menubar(); // Do this first of all because otherwise a default File and Window menu will be seen Initialize(); @@ -253,8 +253,6 @@ void Initialize(void) //SetQDGlobalsRandomSeed(time); srand(time(NULL)); - init_directories(); - // stored_key = open_pref_file(); // if (stored_key == -100) { // stored_key = open_pref_file(); diff --git a/osx/boe.main.h b/osx/boe.main.h index 231b4d05..11cb8763 100644 --- a/osx/boe.main.h +++ b/osx/boe.main.h @@ -1,7 +1,7 @@ #include -int main(void); +int main(int argc, char* argv[]); void Initialize(void); void Handle_One_Event(); bool handle_dialog_event() ; diff --git a/osx/pcedit/pc.main.cpp b/osx/pcedit/pc.main.cpp index 6eb0e5d4..862c1d5e 100644 --- a/osx/pcedit/pc.main.cpp +++ b/osx/pcedit/pc.main.cpp @@ -75,7 +75,7 @@ short store_flags[3]; short give_delays = 0; /* XXX this wasn't defined anywhere, is this right? -jmr */ /* Prototypes */ -int main(void); +int main(int argc, char* argv[]); void Initialize(void); void Handle_One_Event(); void Handle_Activate(); @@ -107,9 +107,9 @@ cScenario scenario; // //MW specified return type was 'void', changed to ISO C style for Carbonisation -jmr -int main(void) -{ +int main(int argc, char* argv[]) { init_menubar(); + init_directories(argv[0]); Initialize(); init_fileio(); init_main_buttons(); @@ -140,7 +140,6 @@ void Initialize(void) { check_for_intel(); - init_directories(); // // To make the Random sequences truly random, we need to make the seed start diff --git a/osx/tools/fileio.cpp b/osx/tools/fileio.cpp index 326e3197..e70d796f 100644 --- a/osx/tools/fileio.cpp +++ b/osx/tools/fileio.cpp @@ -41,27 +41,16 @@ fs::path progDir, tempDir; //extern short overall_mode; #include -// TODO: Try to find a way to get our path without using CoreFoundation, and also replace cout with printf -#include -void init_directories() { - char cPath[768]; - CFBundleRef mainBundle = CFBundleGetMainBundle(); - - CFStringRef progURL = CFURLCopyFileSystemPath(CFBundleCopyBundleURL(mainBundle), kCFURLPOSIXPathStyle); - const char* tmp = CFStringGetCStringPtr(progURL, kCFStringEncodingASCII); - if(tmp == NULL){ - bool success = CFStringGetCString(progURL, cPath, sizeof(cPath), kCFStringEncodingUTF8); - if(success) { - progDir = cPath; - std::cout << cPath << "\n\n" << progDir << "\n\n"; - } else { - std::cout << "Couldn't retrieve application path.\n"; - exit(1); - } - } else progDir = tmp; +void init_directories(const char* exec_path) { + progDir = fs::canonical(exec_path); +#ifdef __APPLE__ + // Need to back up out of the application package + // We're pointing at .app/Contents/MacOS/exec_name, so back out three steps + progDir = progDir.parent_path().parent_path().parent_path(); +#endif progDir = progDir.parent_path(); - // TODO: If this places us in the "Scenario Editor" folder, back out one more directory + if(progDir.filename() == "Scenario Editor") progDir = progDir.parent_path(); std::cout << progDir << '\n'; // Initialize the resource manager paths ResMgr::pushPath(progDir/"Scenario Editor"/"graphics.exd"/"mac"); diff --git a/osx/tools/fileio.h b/osx/tools/fileio.h index ff9a65b2..a6a383ee 100644 --- a/osx/tools/fileio.h +++ b/osx/tools/fileio.h @@ -28,4 +28,4 @@ std::vector load_strings(std::string which); bool load_party(fs::path file_to_load); bool save_party(fs::path dest_file); -void init_directories(); +void init_directories(const char* exec_path);