Get progDir from argv[0] instead of using CoreFoundation

This commit is contained in:
2014-04-20 00:47:43 -04:00
parent edf37f3291
commit 277dd6c208
5 changed files with 15 additions and 29 deletions

View File

@@ -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();

View File

@@ -1,7 +1,7 @@
#include <SFML/Graphics.hpp>
int main(void);
int main(int argc, char* argv[]);
void Initialize(void);
void Handle_One_Event();
bool handle_dialog_event() ;

View File

@@ -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

View File

@@ -41,27 +41,16 @@ fs::path progDir, tempDir;
//extern short overall_mode;
#include <stdexcept>
// TODO: Try to find a way to get our path without using CoreFoundation, and also replace cout with printf
#include <CoreFoundation/CoreFoundation.h>
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<ImageRsrc>(progDir/"Scenario Editor"/"graphics.exd"/"mac");

View File

@@ -28,4 +28,4 @@ std::vector<std::string> 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);