MCPcopy Create free account
hub / github.com/AbyssEngine/AbyssEngineOld / process

Function process

src/Abyss/Common/CommandLineOpts.cpp:8–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6namespace Abyss::Common::CommandLineOpts {
7
8void process(int argc, char **argv, bool &quitOnRun, Configuration &config) {
9 cxxopts::Options options("Abyss", "Abyss Engine");
10 options.add_options() //
11 ("d,mpqdir", "Path to MPQ files", cxxopts::value<std::string>()) //
12 ("cascdir", "Path to CASC dir", cxxopts::value<std::string>()) //
13 ("direct", "Path to dir", cxxopts::value<std::string>()) //
14 ("o,loadorder", "Comma separated list of MPQ files to load", cxxopts::value<std::string>())("h,help", "Print usage");
15
16 auto result = options.parse(argc, argv);
17
18 if (result.count("help") != 0U) {
19 Log::info("{}", options.help());
20 quitOnRun = true;
21 return;
22 }
23
24 auto checkDir = [](const std::string& s) {
25 if (!std::filesystem::exists(s)) {
26 Log::error("Directory does not exist: {}", s);
27 exit(1);
28 }
29
30 if (!std::filesystem::is_directory(s)) {
31 Log::error("Directory is not a directory: {}", s);
32 exit(1);
33 }
34 };
35
36 if (result.count("direct") != 0U) {
37 const auto dir = result["direct"].as<std::string>();
38 checkDir(dir);
39 config.setDirectDir(dir);
40 Log::info("Using directory: {}", dir);
41 }
42
43 if (result.count("cascdir") != 0U) {
44 const auto cascDir = result["cascdir"].as<std::string>();
45 checkDir(cascDir);
46 config.setCASCDir(cascDir);
47 Log::info("Using CASC directory: {}", cascDir);
48 }
49
50 if (result.count("mpqdir") != 0U) {
51 const auto mpqDir = result["mpqdir"].as<std::string>();
52 checkDir(mpqDir);
53 config.setMPQDir(mpqDir);
54 Log::info("Using MPQ directory: {}", mpqDir);
55 } else {
56#ifdef _WIN32
57 if (std::filesystem::is_directory("C:/Program Files (x86)/Diablo II")) {
58 config.setMPQDir("C:/Program Files (x86)/Diablo II");
59 }
60#endif // _WIN32
61 }
62
63 if (result.count("loadorder") == 0U) {
64 Log::info("Using default MPQ load order");
65 } else {

Callers 1

Calls 6

infoFunction · 0.85
errorFunction · 0.85
setDirectDirMethod · 0.80
setCASCDirMethod · 0.80
setMPQDirMethod · 0.80
setLoadOrderMethod · 0.80

Tested by

no test coverage detected