This repository was archived by the owner on Oct 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·68 lines (54 loc) · 1.49 KB
/
main.cpp
File metadata and controls
executable file
·68 lines (54 loc) · 1.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
#include <iostream>
#include <string>
#include <cstring>
#include <unistd.h>
#include <QtWidgets/QApplication>
#include "utils/config.hpp"
#include "utils/console.hpp"
#include "components/download.hpp"
#include "components/check.hpp"
#define CMD_NA 0
#define CMD_DOWNLOAD 1
#define CMD_CHECK 2
using namespace std;
void help(char *exe_name) {
cout << "Usage: " << endl;
cout << "\t" << exe_name << " download -c [path to config.ini]" << endl;
cout << "\t" << exe_name << " check -c [path to config.ini]" << endl;
cout << "* c option is optional. The default value is ./config.ini." << endl;
exit(0);
}
int main(int argc, char **argv) {
int mode = CMD_NA;
string ini_path = "./config.ini";
if (argc < 2)
help(argv[0]);
/* command check */
if (!strcmp(argv[1], "download"))
mode = CMD_DOWNLOAD;
else if (!strcmp(argv[1], "check"))
mode = CMD_CHECK;
else
help(argv[0]);
/* option check */
int ret = getopt(argc, argv, "c:");
if (ret == 'c')
ini_path = optarg;
/* ini file check */
auto c = Config();
if (c.parse(ini_path) < 0) {
fd_error("failed to parse ini file", ini_path);
exit(1);
}
c.print();
/* handle each command */
if (mode == CMD_DOWNLOAD)
Downloader(c).download();
if (mode == CMD_CHECK) {
QApplication app(argc, argv);
CheckWidget widget(c);
widget.show();
return app.exec();
}
return 0;
}