Set up working directory, file paths, Windows console
| 52 | |
| 53 | // Set up working directory, file paths, Windows console |
| 54 | void SetUpEnvironment(char* program_path, const char* overloaded_write_dir, const char* overloaded_working_dir) { |
| 55 | #if PLATFORM_UNIX |
| 56 | // Force numeric locale so numbers parse correctly |
| 57 | setenv("LC_NUMERIC", "en_US.utf8", 1); |
| 58 | if (strlen(overloaded_working_dir) > 0) { |
| 59 | chdir(overloaded_working_dir); |
| 60 | } |
| 61 | char* dirn = dirname(program_path); |
| 62 | AddPath(dirn, kDataPaths); |
| 63 | char cwd[kPathSize]; |
| 64 | getcwd(cwd, kPathSize); |
| 65 | int len = strlen(cwd); |
| 66 | if (len < kPathSize - 1) { |
| 67 | cwd[len] = '/'; |
| 68 | cwd[len + 1] = '\0'; |
| 69 | } |
| 70 | |
| 71 | if (false == areSame(cwd, dirn)) { |
| 72 | AddPath(cwd, kDataPaths); |
| 73 | } else { |
| 74 | LOGI << "Not adding " << cwd << " to FindPath list as it's the same as ./" << std::endl; |
| 75 | } |
| 76 | char write_dir[kPathSize]; |
| 77 | initWriteDir(write_dir, kPathSize); |
| 78 | |
| 79 | if (strcmp(overloaded_write_dir, "") != 0) { |
| 80 | AddPath(overloaded_write_dir, kWriteDir); |
| 81 | } else { |
| 82 | AddPath(write_dir, kWriteDir); |
| 83 | } |
| 84 | |
| 85 | #elif defined(_WIN32) |
| 86 | std::string cwd; |
| 87 | if (strlen(overloaded_working_dir) > 0) { |
| 88 | SetWorkingDir(overloaded_working_dir); |
| 89 | WorkingDir(&cwd); |
| 90 | AddPath(ApplicationPathSeparators(cwd).c_str(), kDataPaths); |
| 91 | } else { |
| 92 | // TODO: Consider if we actually want to include the default working dir as a data path, it seems unecessary |
| 93 | WorkingDir(&cwd); |
| 94 | AddPath(ApplicationPathSeparators(cwd).c_str(), kDataPaths); |
| 95 | #ifdef _DEPLOY |
| 96 | char path[] = ""; |
| 97 | chdirToBasePath(path); // Set working directory to .exe location (so shortcuts work) |
| 98 | WorkingDir(&cwd); |
| 99 | AddPath(ApplicationPathSeparators(cwd).c_str(), kDataPaths); |
| 100 | #endif |
| 101 | } |
| 102 | char write_path[kPathSize]; |
| 103 | int err = initWriteDir(write_path, kPathSize); |
| 104 | if (err != 0) { |
| 105 | FatalError("Error", win_compat_err_str[err]); |
| 106 | } |
| 107 | |
| 108 | if (strcmp(overloaded_write_dir, "") != 0) { |
| 109 | AddPath(overloaded_write_dir, kWriteDir); |
| 110 | } else { |
| 111 | AddPath(write_path, kWriteDir); |