-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (109 loc) · 2.63 KB
/
main.cpp
File metadata and controls
123 lines (109 loc) · 2.63 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <boost/program_options.hpp>
#include <Windows.h>
#include "wil/result.h"
#include "exit_code.h"
#include "event_log.h"
#include "task_scheduler.h"
#include "transition_fixer.h"
#include "utils.h"
namespace po = boost::program_options;
int main(int argc, char* argv[])
{
po::options_description opts("Allowed Options");
opts.add_options()
("help", "Show this help message")
#ifdef _DEBUG
("break", po::bool_switch(), "Break as soon as the program starts")
#endif
("mode",
po::value<std::string>()
->default_value("run")
->required(),
"The mode the program will run as. Valid modes are:\n"
"- run (default)\n"
"- install-event-log\n"
"- uninstall-event-log\n"
"- install-task\n"
"- uninstall-task");
po::positional_options_description pos;
pos.add("mode", 1);
try {
po::variables_map vm;
po::store(
po::command_line_parser(argc, argv)
.options(opts)
.positional(pos)
.run(),
vm);
po::notify(vm);
if (vm.count("help")) {
std::cout << opts << std::endl;
return ExitCode::ERR_SUCCESS;
}
#ifdef _DEBUG
// Do we need to start breaking?
bool breakOnStart = vm["break"].as<bool>();
if (breakOnStart) {
DebugBreak();
}
#endif
// What are we trying to do?
bool succeeded = false;
std::string mode = vm["mode"].as<std::string>();
if (mode == "install-event-log") {
succeeded = InstallEventLogSource();
if (succeeded) {
LogInfo(L"Successfully installed Event Log source");
}
}
else if (mode == "install-task") {
succeeded = InstallTask();
if (succeeded) {
LogInfo(L"Successfully installed task into Windows Task Scheduler");
}
}
else if (mode == "run") {
succeeded = ApplyFadeFix();
if (succeeded) {
LogInfo(L"Successfully enabled Active Desktop");
}
}
else if (mode == "uninstall-event-log") {
succeeded = UninstallEventLogSource();
if (succeeded) {
LogInfo(L"Successfully removed Event Log source");
}
}
else if (mode == "uninstall-task") {
succeeded = UninstallTask();
if (succeeded) {
LogInfo(L"Successfully removed task from Windows Task Scheduler");
}
}
else {
std::cerr
<< "Error: Unrecognized mode '" << mode << "'\n"
<< opts
<< std::endl;
return ExitCode::ERR_CMDLINE_ERROR;
}
if (succeeded) {
return ExitCode::ERR_SUCCESS;
}
else {
return ExitCode::ERR_FAILURE;
}
}
catch (const wil::ResultException& ex) {
std::cerr << ex.what() << std::endl;
return ExitCode::ERR_FAILURE;
}
catch (const po::error& ex) {
std::cerr
<< "Error: " << ex.what() << "\n"
<< opts
<< std::endl;
return ExitCode::ERR_CMDLINE_ERROR;
}
}