1 | #ifdef _WIN32 |
2 | #define WIN32_LEAN_AND_MEAN |
3 | #define _CRT_SECURE_NO_WARNINGS |
4 | #include <windows.h> |
5 | #include <commdlg.h> |
6 | #include <shellapi.h> |
7 | #include <stdio.h> |
8 | |
9 | #define OPEN_KEY(parent, name, ptr) \ |
10 | RegCreateKeyExA(parent, name, 0, 0, 0, KEY_WRITE, 0, ptr, 0) |
11 | #define SET_VALUE(parent, name, value) \ |
12 | RegSetValueExA(parent, name, 0, REG_SZ, (const BYTE *)(value), (DWORD)strlen(value) + 1) |
13 | |
14 | void win_install(void) |
15 | { |
16 | char command_str[2048], argv0[2048]; |
17 | HKEY software, classes, mupdf; |
18 | HKEY supported_types, shell, open, command; |
19 | HKEY dotpdf, dotxps, dotcbz, dotepub, dotfb2; |
20 | HKEY pdf_progids, xps_progids, cbz_progids, epub_progids, fb2_progids; |
21 | |
22 | GetModuleFileNameA(NULL, argv0, sizeof argv0); |
23 | _snprintf(command_str, sizeof command_str, "\"%s\" \"%%1\"" , argv0); |
24 | |
25 | OPEN_KEY(HKEY_CURRENT_USER, "Software" , &software); |
26 | OPEN_KEY(software, "Classes" , &classes); |
27 | { |
28 | OPEN_KEY(classes, "MuPDF" , &mupdf); |
29 | { |
30 | OPEN_KEY(mupdf, "SupportedTypes" , &supported_types); |
31 | { |
32 | SET_VALUE(supported_types, ".pdf" , "" ); |
33 | SET_VALUE(supported_types, ".xps" , "" ); |
34 | SET_VALUE(supported_types, ".cbz" , "" ); |
35 | SET_VALUE(supported_types, ".epub" , "" ); |
36 | SET_VALUE(supported_types, ".fb2" , "" ); |
37 | } |
38 | RegCloseKey(supported_types); |
39 | OPEN_KEY(mupdf, "shell" , &shell); |
40 | OPEN_KEY(shell, "open" , &open); |
41 | OPEN_KEY(open, "command" , &command); |
42 | { |
43 | SET_VALUE(open, "FriendlyAppName" , "MuPDF" ); |
44 | SET_VALUE(command, "" , command_str); |
45 | } |
46 | RegCloseKey(command); |
47 | RegCloseKey(open); |
48 | RegCloseKey(shell); |
49 | } |
50 | RegCloseKey(mupdf); |
51 | |
52 | OPEN_KEY(classes, ".pdf" , &dotpdf); |
53 | OPEN_KEY(classes, ".xps" , &dotxps); |
54 | OPEN_KEY(classes, ".cbz" , &dotcbz); |
55 | OPEN_KEY(classes, ".epub" , &dotepub); |
56 | OPEN_KEY(classes, ".fb2" , &dotfb2); |
57 | { |
58 | OPEN_KEY(dotpdf, "OpenWithProgids" , &pdf_progids); |
59 | OPEN_KEY(dotxps, "OpenWithProgids" , &xps_progids); |
60 | OPEN_KEY(dotcbz, "OpenWithProgids" , &cbz_progids); |
61 | OPEN_KEY(dotepub, "OpenWithProgids" , &epub_progids); |
62 | OPEN_KEY(dotfb2, "OpenWithProgids" , &fb2_progids); |
63 | { |
64 | SET_VALUE(pdf_progids, "MuPDF" , "" ); |
65 | SET_VALUE(xps_progids, "MuPDF" , "" ); |
66 | SET_VALUE(cbz_progids, "MuPDF" , "" ); |
67 | SET_VALUE(epub_progids, "MuPDF" , "" ); |
68 | SET_VALUE(fb2_progids, "MuPDF" , "" ); |
69 | } |
70 | RegCloseKey(pdf_progids); |
71 | RegCloseKey(xps_progids); |
72 | RegCloseKey(cbz_progids); |
73 | RegCloseKey(epub_progids); |
74 | RegCloseKey(fb2_progids); |
75 | } |
76 | RegCloseKey(dotpdf); |
77 | RegCloseKey(dotxps); |
78 | RegCloseKey(dotcbz); |
79 | RegCloseKey(dotepub); |
80 | RegCloseKey(dotfb2); |
81 | } |
82 | RegCloseKey(classes); |
83 | RegCloseKey(software); |
84 | } |
85 | |
86 | #endif |
87 | |