-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
67 lines (47 loc) · 1.42 KB
/
main.c
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
#include <stdio.h>
#include <locale.h>
#include <sys/time.h>
#include <string.h>
#include "./test.h"
#include "defaults.h"
#include "settings/settings.h"
#include "ui/con_lib.h"
#include "ui/view/mainmenu.h"
void setupConsole();
int main(int argc, char ** argv) {
if (argc > 1 && strcmp(argv[1], "test") == 0) {
runTests();
return 0;
}
struct timeval start, end;
gettimeofday(&start, NULL);
setlocale(LC_ALL, "");
setupConsole();
UserSettings * settings = safeLoadUserSettings();
con_show_echo(false);
con_show_cursor(false);
logInfo(settings, L"Main", L"Saving default scenario");
saveDefaultScenario(settings);
mainMenuLoop(settings);
con_set_color(COLOR_RESET, COLOR_RESET);
con_clear();
gettimeofday(&end, NULL);
uint64_t delta_ms = (end.tv_sec - start.tv_sec) * 1000 + (end.tv_usec - start.tv_usec) / 1000;
uint64_t final_s = delta_ms / 1000;
uint64_t final_ms = delta_ms % 1000;
wprintf(L"Program finished in %ds %dms\n", final_s, final_ms);
logInfo(settings, L"Main", L"Program finished in %ds %dms\n", final_s, final_ms);
wprintf(L"Saving log file...\n");
freeSettings(settings);
wprintf(L"Log saved to %hs\n", LATEST_FILE);
con_show_echo(true);
con_show_cursor(true);
}
#ifdef _WIN32
#include <io.h>
void setupConsole() {
_setmode(_fileno(stdout), 0x00040000);
}
#else
void setupConsole() {}
#endif // _WIN32