diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-10 23:44:49 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-10 23:44:49 +0200 |
commit | 6d2ca771127fb9186372566e5671c79c354b04b9 (patch) | |
tree | 5e14b30f3c6164167d25fabb38d3597a9d16a408 /apps | |
parent | 6734f09a5ac019be8a0ab3da1750bcbaf27c0bcf (diff) | |
download | mupdf-6d2ca771127fb9186372566e5671c79c354b04b9.tar.xz |
Register file type association on startup in windows.
Installs keys to add MuPDF in the "Open With" menu, but does
not take over the default association. Run "mupdf.exe -u" to
remove the registry key.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/win_main.c | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/apps/win_main.c b/apps/win_main.c index 0054ca17..1e7a24b4 100644 --- a/apps/win_main.c +++ b/apps/win_main.c @@ -39,6 +39,66 @@ static wchar_t wbuf[1024]; static char filename[1024]; /* + * Create registry keys to associate MuPDF with PDF and XPS files. + */ + +#define OPEN_KEY(parent, name, ptr) \ + RegCreateKeyExA(parent, name, 0, 0, 0, KEY_WRITE, 0, &ptr, 0) + +#define SET_KEY(parent, name, value) \ + RegSetValueExA(parent, name, 0, REG_SZ, value, strlen(value) + 1) + +void install_app(char *argv0) +{ + char buf[512]; + HKEY software, classes, mupdf, dotpdf, dotxps; + HKEY shell, open, command, supported_types; + HKEY pdf_progids, xps_progids; + + OPEN_KEY(HKEY_CURRENT_USER, "Software", software); + OPEN_KEY(software, "Classes", classes); + OPEN_KEY(classes, ".pdf", dotpdf); + OPEN_KEY(dotpdf, "OpenWithProgids", pdf_progids); + OPEN_KEY(classes, ".xps", dotxps); + OPEN_KEY(dotxps, "OpenWithProgids", xps_progids); + OPEN_KEY(classes, "MuPDF", mupdf); + OPEN_KEY(mupdf, "SupportedTypes", supported_types); + OPEN_KEY(mupdf, "shell", shell); + OPEN_KEY(shell, "open", open); + OPEN_KEY(open, "command", command); + + sprintf(buf, "\"%s\" \"%%1\"", argv0); + + SET_KEY(open, "FriendlyAppName", "MuPDF"); + SET_KEY(command, "", buf); + SET_KEY(supported_types, ".pdf", ""); + SET_KEY(supported_types, ".xps", ""); + SET_KEY(pdf_progids, "MuPDF", ""); + SET_KEY(xps_progids, "MuPDF", ""); + + RegCloseKey(dotxps); + RegCloseKey(dotpdf); + RegCloseKey(mupdf); + RegCloseKey(classes); + RegCloseKey(software); +} + +void uninstall_app(void) +{ + HKEY software, classes; + + RegOpenKeyExA(HKEY_CURRENT_USER, "Software", 0, KEY_ALL_ACCESS, &software); + RegOpenKeyExA(software, "Classes", 0, KEY_ALL_ACCESS, &classes); + + RegDeleteTreeA(classes, "MuPDF"); + + RegCloseKey(classes); + RegCloseKey(software); + + MessageBoxA(hwndframe, "MuPDF has been uninstalled.", "MuPDF", MB_ICONWARNING); +} + +/* * Dialog boxes */ @@ -788,6 +848,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow { int argc; LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc); + char argv0[256]; MSG msg; int fd; int code; @@ -796,11 +857,18 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShow pdfapp_init(&gapp); - /* associate(argv[0]); */ + GetModuleFileNameA(NULL, argv0, sizeof argv0); + install_app(argv0); + winopen(); if (argc == 2) { + if (argv[1][0] == '-' && argv[1][1] == 'u' && argv[1][2] == 0) + { + uninstall_app(); + exit(0); + } wcscpy(wbuf, argv[1]); } else |