| 90 | } |
| 91 | |
| 92 | bool parseOptions(int argc, const char *const argv[]) |
| 93 | { |
| 94 | if (this->parsed) |
| 95 | { |
| 96 | LogError("Already parsed options"); |
| 97 | return true; |
| 98 | } |
| 99 | fs::path programPath(argv[0]); |
| 100 | // Remove extension (if any) and path |
| 101 | programName = programPath.filename().string(); |
| 102 | if (ends_with(programName, ".exe")) |
| 103 | { |
| 104 | programName = programName.substr(0, programName.length() - 4); |
| 105 | } |
| 106 | if (!PHYSFS_isInit()) |
| 107 | { |
| 108 | PHYSFS_init(programName.c_str()); |
| 109 | } |
| 110 | UString settingsPath; |
| 111 | // If a file called 'portable.txt' exists in $(PWD), use a local config folder instead of a |
| 112 | // system one. |
| 113 | // This can't go through the normal settings system, as it's used by the normal settings |
| 114 | // system... |
| 115 | std::ifstream portableFile("./portable.txt"); |
| 116 | if (portableFile) |
| 117 | { |
| 118 | LogInfo("portable mode set"); |
| 119 | settingsPath = programName + "_"; |
| 120 | } |
| 121 | else |
| 122 | { |
| 123 | settingsPath = PHYSFS_getPrefDir("OpenApoc", programName.c_str()); |
| 124 | } |
| 125 | settingsPath += "settings.conf"; |
| 126 | // Setup some config-related options |
| 127 | this->addOption("", "help", "h", "Show help text and exit"); |
| 128 | this->addOptionTyped<UString>("Config", "File", "", "Path to config file", settingsPath); |
| 129 | this->addOptionTyped<bool>("Config", "Read", "", "Read the config file at startup", true); |
| 130 | this->addOptionTyped<bool>("Config", "Save", "", "Save the config file at exit", true); |
| 131 | |
| 132 | po::options_description allOptions; |
| 133 | for (auto &optPair : this->optionSections) |
| 134 | allOptions.add(optPair.second); |
| 135 | |
| 136 | try |
| 137 | { |
| 138 | auto parsed = po::command_line_parser(argc, argv) |
| 139 | .positional(posDesc) |
| 140 | .options(allOptions) |
| 141 | .allow_unregistered() |
| 142 | .run(); |
| 143 | po::store(parsed, vm); |
| 144 | auto unknown_options = po::collect_unrecognized(parsed.options, po::include_positional); |
| 145 | for (const auto &unknown : unknown_options) |
| 146 | { |
| 147 | LogWarning("Ignoring option \"%s\"", unknown); |
| 148 | } |
| 149 | } |