-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwmain.cpp
106 lines (83 loc) · 1.56 KB
/
wmain.cpp
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
/*
* This file is a part of the "Nullboard Backup Agent" source
* code and it is distributed under the terms of 2-clause BSD
* license.
*
* Copyright (c) 2022 Alexander Pankratov, [email protected].
* All rights reserved.
*/
#include "types.h"
#include "socket_io.h"
#include "http_request.h"
#include "utils.h"
#include "trace.h"
#include "config.h"
#include "console.h"
#include "engine.h"
#include "ui.h"
//
BOOL __stdcall on_console_event(dword ctrl)
{
if (ctrl == CTRL_C_EVENT)
{
trace_v("Ctrl-C\n");
stop_ui();
return TRUE;
}
if (ctrl == CTRL_CLOSE_EVENT)
{
stop_ui();
return TRUE;
}
return FALSE;
}
//
int wmain_alt(int argc, wchar_t ** argv)
{
HANDLE en = NULL;
HANDLE ui = NULL;
if (! open_console()) // hidden by default
return 10;
SetConsoleCtrlHandler(on_console_event, TRUE);
if (! init_conf()) // conf.path = %LocalAppData%\Nullboard
return 20;
if (! parse_args(argc, argv))
return 30;
if (! load_ini())
return 40;
if (! make_path(conf.path))
return 50;
if (! init_engine())
return 60;
en = start_engine();
ui = start_ui();
for (;;)
{
HANDLE foo[2] = { en, ui };
auto rc = WaitForMultipleObjects(2, foo, FALSE, 100);
if (rc == WAIT_OBJECT_0 + 1)
{
trace_v("UI stopped\n");
stop_engine();
break;
}
if (rc == WAIT_OBJECT_0)
{
trace_v("Engine stopped\n");
stop_ui();
return 70;
}
}
return 0;
}
int wmain_app(int argc, wchar_t ** argv)
{
int rc = wmain_alt(argc, argv);
if (rc != 0)
{
show_console(true);
printf("\nPress Enter to exit...");
getchar();
}
return rc;
}