forked from TanninOne/modorganizer-lootcli
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (78 loc) · 2.82 KB
/
main.cpp
File metadata and controls
95 lines (78 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "lootthread.h"
#include <lootcli/lootcli.h>
using namespace std;
template <typename T>
T getParameter(const std::vector<std::string>& arguments, const std::string& key)
{
auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
if ((iter != arguments.end()) && ((iter + 1) != arguments.end())) {
return boost::lexical_cast<T>(*(iter + 1));
} else {
throw std::runtime_error(std::string("argument missing " + key));
}
}
template <>
bool getParameter<bool>(const std::vector<std::string>& arguments,
const std::string& key)
{
auto iter = std::find(arguments.begin(), arguments.end(), std::string("--") + key);
if (iter != arguments.end()) {
return true;
} else {
return false;
}
}
template <typename T>
T getOptionalParameter(const std::vector<std::string>& arguments,
const std::string& key, T def)
{
try {
return getParameter<T>(arguments, key);
} catch (std::runtime_error&) {
return def;
}
}
loot::LogLevel getLogLevel(const std::vector<std::string>& arguments)
{
const auto s = getOptionalParameter<std::string>(arguments, "logLevel", "");
const auto level = lootcli::logLevelFromString(s);
return lootcli::toLootLogLevel(level);
}
int wWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
_setmode(_fileno(stdout), _O_BINARY);
setlocale(LC_ALL, "en.UTF-8");
std::vector<std::string> arguments;
int argc;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argv) {
for (int i = 0; i < argc; ++i) {
size_t num_converted;
std::vector<char> arg(wcslen(argv[i]) * sizeof(wchar_t) + 1);
wcstombs_s(&num_converted, &(arg[0]), arg.size(), argv[i], arg.size() - 1);
arguments.push_back(&(arg[0]));
}
}
// design rationale: this was designed to have the actual loot stuff run in a separate
// thread. That turned out to be unnecessary atm.
try {
lootcli::LOOTWorker worker;
worker.setUpdateMasterlist(!getParameter<bool>(arguments, "skipUpdateMasterlist"));
worker.setGame(getParameter<std::string>(arguments, "game"));
worker.setGamePath(getParameter<std::string>(arguments, "gamePath"));
const auto pluginListPath = getParameter<std::string>(arguments, "pluginListPath");
worker.setPluginListPath(pluginListPath);
worker.setReportOutputPath(getParameter<std::string>(arguments, "out"));
worker.setSortedPluginListOutputPath(getOptionalParameter<std::string>(
arguments, "pluginListOutputPath", pluginListPath));
worker.setLogLevel(getLogLevel(arguments));
const auto lang = getOptionalParameter<std::string>(arguments, "language", "");
if (!lang.empty()) {
worker.setLanguageCode(lang);
}
return worker.run();
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what();
return 1;
}
}