gl-win32.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright (C) 2004-2021 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #ifdef _WIN32
  23. #define WIN32_LEAN_AND_MEAN
  24. #define _CRT_SECURE_NO_WARNINGS
  25. #include <windows.h>
  26. #include <commdlg.h>
  27. #include <shellapi.h>
  28. #include <stdio.h>
  29. #define OPEN_KEY(parent, name, ptr) \
  30. RegCreateKeyExA(parent, name, 0, 0, 0, KEY_WRITE, 0, ptr, 0)
  31. #define SET_VALUE(parent, name, value) \
  32. RegSetValueExA(parent, name, 0, REG_SZ, (const BYTE *)(value), (DWORD)strlen(value) + 1)
  33. void win_install(void)
  34. {
  35. char command_str[2048], argv0[2048];
  36. HKEY software, classes, mupdf;
  37. HKEY supported_types, shell, open, command;
  38. HKEY dotpdf, dotxps, dotcbz, dotepub, dotfb2;
  39. HKEY pdf_progids, xps_progids, cbz_progids, epub_progids, fb2_progids;
  40. GetModuleFileNameA(NULL, argv0, sizeof argv0);
  41. _snprintf(command_str, sizeof command_str, "\"%s\" \"%%1\"", argv0);
  42. OPEN_KEY(HKEY_CURRENT_USER, "Software", &software);
  43. OPEN_KEY(software, "Classes", &classes);
  44. {
  45. OPEN_KEY(classes, "MuPDF", &mupdf);
  46. {
  47. OPEN_KEY(mupdf, "SupportedTypes", &supported_types);
  48. {
  49. SET_VALUE(supported_types, ".pdf", "");
  50. SET_VALUE(supported_types, ".xps", "");
  51. SET_VALUE(supported_types, ".cbz", "");
  52. SET_VALUE(supported_types, ".epub", "");
  53. SET_VALUE(supported_types, ".fb2", "");
  54. }
  55. RegCloseKey(supported_types);
  56. OPEN_KEY(mupdf, "shell", &shell);
  57. OPEN_KEY(shell, "open", &open);
  58. OPEN_KEY(open, "command", &command);
  59. {
  60. SET_VALUE(open, "FriendlyAppName", "MuPDF");
  61. SET_VALUE(command, "", command_str);
  62. }
  63. RegCloseKey(command);
  64. RegCloseKey(open);
  65. RegCloseKey(shell);
  66. }
  67. RegCloseKey(mupdf);
  68. OPEN_KEY(classes, ".pdf", &dotpdf);
  69. OPEN_KEY(classes, ".xps", &dotxps);
  70. OPEN_KEY(classes, ".cbz", &dotcbz);
  71. OPEN_KEY(classes, ".epub", &dotepub);
  72. OPEN_KEY(classes, ".fb2", &dotfb2);
  73. {
  74. OPEN_KEY(dotpdf, "OpenWithProgids", &pdf_progids);
  75. OPEN_KEY(dotxps, "OpenWithProgids", &xps_progids);
  76. OPEN_KEY(dotcbz, "OpenWithProgids", &cbz_progids);
  77. OPEN_KEY(dotepub, "OpenWithProgids", &epub_progids);
  78. OPEN_KEY(dotfb2, "OpenWithProgids", &fb2_progids);
  79. {
  80. SET_VALUE(pdf_progids, "MuPDF", "");
  81. SET_VALUE(xps_progids, "MuPDF", "");
  82. SET_VALUE(cbz_progids, "MuPDF", "");
  83. SET_VALUE(epub_progids, "MuPDF", "");
  84. SET_VALUE(fb2_progids, "MuPDF", "");
  85. }
  86. RegCloseKey(pdf_progids);
  87. RegCloseKey(xps_progids);
  88. RegCloseKey(cbz_progids);
  89. RegCloseKey(epub_progids);
  90. RegCloseKey(fb2_progids);
  91. }
  92. RegCloseKey(dotpdf);
  93. RegCloseKey(dotxps);
  94. RegCloseKey(dotcbz);
  95. RegCloseKey(dotepub);
  96. RegCloseKey(dotfb2);
  97. }
  98. RegCloseKey(classes);
  99. RegCloseKey(software);
  100. }
  101. #endif