/** * Determine the base (personal dir and game data dir) paths * @param exe the path to the executable */ void DetermineBasePaths(const char *exe) { char tmp[MAX_PATH]; #if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR) _searchpaths[SP_PERSONAL_DIR] = NULL; #else #ifdef __HAIKU__ BPath path; find_directory(B_USER_SETTINGS_DIRECTORY, &path); const char *homedir = path.Path(); #else const char *homedir = getenv("HOME"); if (homedir == NULL) { const struct passwd *pw = getpwuid(getuid()); homedir = (pw == NULL) ? "" : pw->pw_dir; } #endif snprintf(tmp, MAX_PATH, "%s" PATHSEP "%s", homedir, PERSONAL_DIR); AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_PERSONAL_DIR] = strdup(tmp); #endif #if defined(WITH_SHARED_DIR) snprintf(tmp, MAX_PATH, "%s", SHARED_DIR); AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_SHARED_DIR] = strdup(tmp); #else _searchpaths[SP_SHARED_DIR] = NULL; #endif #if defined(__MORPHOS__) || defined(__AMIGA__) _searchpaths[SP_WORKING_DIR] = NULL; #else if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_WORKING_DIR] = strdup(tmp); #endif _do_scan_working_directory = DoScanWorkingDirectory(); /* Change the working directory to that one of the executable */ if (ChangeWorkingDirectoryToExecutable(exe)) { if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_BINARY_DIR] = strdup(tmp); } else { _searchpaths[SP_BINARY_DIR] = NULL; } if (_searchpaths[SP_WORKING_DIR] != NULL) { /* Go back to the current working directory. */ if (chdir(_searchpaths[SP_WORKING_DIR]) != 0) { DEBUG(misc, 0, "Failed to return to working directory!"); } } #if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) _searchpaths[SP_INSTALLATION_DIR] = NULL; #else snprintf(tmp, MAX_PATH, "%s", GLOBAL_DATA_DIR); AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_INSTALLATION_DIR] = strdup(tmp); #endif #ifdef WITH_COCOA extern void cocoaSetApplicationBundleDir(); cocoaSetApplicationBundleDir(); #else _searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL; #endif }
/** * Determine the base (personal dir and game data dir) paths * @param exe the path to the executable */ void DetermineBasePaths(const char *exe) { char tmp[MAX_PATH]; #if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) || !defined(WITH_PERSONAL_DIR) _searchpaths[SP_PERSONAL_DIR] = NULL; #else #if !defined(__APPLE__) && !defined(__arm__) const char *homedir = getenv("HOME"); if (homedir == NULL) { const struct passwd *pw = getpwuid(getuid()); homedir = (pw == NULL) ? "" : pw->pw_dir; } snprintf(tmp, MAX_PATH, "%s" PATHSEP "%s", homedir, PERSONAL_DIR); #else snprintf(tmp, MAX_PATH, "%s", PERSONAL_DIR); #endif AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_PERSONAL_DIR] = strdup(tmp); #endif #if defined(WITH_SHARED_DIR) snprintf(tmp, MAX_PATH, "%s", SHARED_DIR); AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_SHARED_DIR] = strdup(tmp); #else _searchpaths[SP_SHARED_DIR] = NULL; #endif #if defined(__MORPHOS__) || defined(__AMIGA__) _searchpaths[SP_WORKING_DIR] = NULL; #else if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_WORKING_DIR] = strdup(tmp); #endif /* Change the working directory to that one of the executable */ ChangeWorkingDirectory(exe); if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_BINARY_DIR] = strdup(tmp); if (_searchpaths[SP_WORKING_DIR] != NULL) { /* Go back to the current working directory. */ ChangeWorkingDirectory(_searchpaths[SP_WORKING_DIR]); } #if defined(__MORPHOS__) || defined(__AMIGA__) || defined(DOS) || defined(OS2) _searchpaths[SP_INSTALLATION_DIR] = NULL; #else snprintf(tmp, MAX_PATH, "%s", GLOBAL_DATA_DIR); AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_INSTALLATION_DIR] = strdup(tmp); #endif #ifdef WITH_COCOA extern void cocoaSetApplicationBundleDir(); cocoaSetApplicationBundleDir(); #else _searchpaths[SP_APPLICATION_BUNDLE_DIR] = NULL; #endif }