-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
64 lines (51 loc) · 1.29 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
#include "Config.h"
#include "Dialog.h"
#include "Layout.h"
#include <string.h>
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
int main()
{
// Prevent LoadKeyboardLayout() from loading the layout DLL from the application directory.
// https://github.com/MicrosoftDocs/sdk-api/pull/711
if (!SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32)) {
showSysError("main()", "SetDefaultDllDirectories() failed!", GetLastError());
return -1;
}
Config config = {0};
if (!loadConfig(&config, "kli.ini")) {
return 1;
}
int ret = 0;
Layouts *layouts = getLayouts();
if (!layouts) {
ret = 2;
goto FINAL;
}
for (DWORD i = 0; i < layouts->num; ++i) {
const Layout *layout = &layouts->list[i];
if (!layout->product_code || strcmp(layout->product_code, config.product_code) != 0) {
continue;
}
if (!showPrompt("main()", "This layout already appears to be installed.\n\nDo you want to uninstall it?")) {
goto FINAL;
}
if (!uninstallLayout(layout)) {
ret = 4;
goto FINAL;
}
showInfo("main()", "Layout successfully uninstalled!");
goto FINAL;
}
if (!installLayout(&config, layouts)) {
ret = 3;
goto FINAL;
}
showInfo("main()", "Layout successfully installed!");
FINAL:
freeLayouts(layouts);
freeConfig(&config);
return ret;
}