-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
90 lines (80 loc) · 2.49 KB
/
Copy pathmain.cpp
File metadata and controls
90 lines (80 loc) · 2.49 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
///*****************************************************************************
/// @date Feb 2021
/// @copyright GPL-3.0-or-later
/// @author Thomas Lepoix <[email protected]>
///*****************************************************************************
#include <QApplication>
#include <cstdlib>
#include <iostream>
#include <format>
#include "app/openemsh.hpp"
#include "ui/cli/cli.hpp"
#include "ui/cli/logger.hpp"
#include "ui/cli/progress.hpp"
#include "ui/qt/main_window.hpp"
//******************************************************************************
int main(int argc, char* argv[]) {
app::OpenEMSH oemsh(ui::cli::cli(argc, argv));
if(oemsh.get_params().verbose)
Progress::singleton().register_impl_builder(
[&oemsh](std::size_t max, std::string const& message) {
return std::make_unique<ui::cli::ProgressBar>(max,
std::format("{}/{} {}",
app::index(oemsh.get_current_step()),
app::index_max(),
message));
});
Logger::singleton().register_sink(Logger::id("Cli"), std::make_unique<ui::cli::LoggerSink>(oemsh.get_params().verbose));
if(!oemsh.get_params().gui) {
if(auto res = oemsh.parse(); !res.has_value()) {
log({
.level = Logger::Level::ERROR,
.message = std::format(
"Failed to parse file \"{}\" : {}",
oemsh.get_params().input.generic_string(),
res.error())
});
return EXIT_FAILURE;
}
if(oemsh.is_about_overwriting()) {
log({
.level = Logger::Level::ERROR,
.message = std::format(
"You are about overwriting the file \"{}\", "
"use --force if that is what you want.",
oemsh.get_params().output.generic_string())
});
return EXIT_FAILURE;
}
oemsh.run_all_steps();
if(auto res = oemsh.write(); !res.has_value()) {
log({
.level = Logger::Level::ERROR,
.message = std::format(
"Failed to save file \"{}\" : {}",
oemsh.get_params().output.generic_string(),
res.error())
});
return EXIT_FAILURE;
} else {
log({
.level = Logger::Level::INFO,
.message = std::format(
"Saved file \"{}\"",
oemsh.get_params().output.generic_string())
});
}
} else {
QApplication a(argc, argv);
#ifdef OEMSH_PORTABILITY_TWEAKS
a.setAttribute(Qt::AA_DontUseNativeDialogs);
#endif // OEMSH_PORTABILITY_TWEAKS
// Avoid a stold() bug introduced by QApplication() performing setlocale(LC_ALL, "")
setlocale(LC_NUMERIC, "C");
ui::qt::MainWindow w(oemsh);
w.show();
w.parse_and_display();
return QApplication::exec();
}
return EXIT_SUCCESS;
}