-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (66 loc) · 2.74 KB
/
Copy pathmain.cpp
File metadata and controls
84 lines (66 loc) · 2.74 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
#include "painter_pch.h"
// Main-only Libraries
#include <argparse/argparse.hpp>
// Project headers
#include "utils/logger.h"
#include "launch/launch.h"
#include "optimization_adapters/utils.h"
int main(int argc, char *argv[]) {
set_utf8_in_console();
Logger::SetLogFile(std::filesystem::current_path() / "log" / "logs.txt");
Logger::SetLoggingLevel(LogLevel::Info);
argparse::ArgumentParser program("Painter");
program.add_argument("path")
.required()
.help("Path to target image");
program.add_argument("--params")
.required()
.help("Path to common stroking params");
try {
program.parse_args(argc, argv);
} catch (const std::runtime_error& err) {
ConsoleError("Main") << "Failed to parse command line arguments: " << err.what();
Console() << program;
Logger::Stop();
exit(0);
}
Console() << console_colors::green << "Welcome to Painter™!" << console_colors::remove_all_colors;
if (std::thread::hardware_concurrency() <= 1) {
LogConsoleWarning("Main") << "StrongNishebrodWarning: YOU HAVE ONLY ONE THREAD! Hopefully, you won't try multithreading mode…";
}
else if (std::thread::hardware_concurrency() <= 2) {
LogConsoleWarning("Main")
<< "NishebrodWarning: do you seriously have only " << std::thread::hardware_concurrency() << " threads in >= 2021?! "
<< "Buying a new computer strongly recommended.";
}
LogConsoleInfo("Main") << "Using up to " << std::thread::hardware_concurrency() - 1 << " threads of "
<< std::thread::hardware_concurrency();
auto image_path = program.get("path");
try {
if (not fs::exists(image_path)) {
throw std::runtime_error("Image path doesn't exist: " + image_path);
} else if (not fs::is_regular_file(image_path)) {
throw std::runtime_error("Image path you specified doesn't correspond to regular file: " + image_path);
}
LogConsoleInfo("Main") << "Image path: " << image_path;
CommonStrokingParams params;
auto params_path = program.get("--params");
if (not fs::exists(params_path)) {
throw std::runtime_error("Parameters path you provided doesn't exist: " + params_path);
} else if (fs::path(params_path).extension().string() != ".json") {
throw std::runtime_error(
"Parameters path has inappropriate extension: \"" + fs::path(params_path).extension().string() + R"(" (".json" expected))"
);
}
params = load_params(params_path);
LogConsoleSuccess("Main") << "Parameters loaded from: " << params_path;
Packer::params = params;
launch_stroking(image_path, params);
} catch (const std::exception& ex) {
LogConsoleError("Exception") << ex.what();
Logger::Stop();
exit(1);
}
Logger::Stop();
return 0;
}