juce_WindowsRegistry.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_WINDOWSREGISTRY_H_INCLUDED
  22. #define JUCE_WINDOWSREGISTRY_H_INCLUDED
  23. #if JUCE_WINDOWS || DOXYGEN
  24. /**
  25. Contains some static helper functions for manipulating the MS Windows registry
  26. (Only available on Windows, of course!)
  27. */
  28. class JUCE_API WindowsRegistry
  29. {
  30. public:
  31. /** These values can be used to specify whether the 32- or 64-bit registry should be used.
  32. When running on a 32-bit OS, there is no 64-bit registry, so the mode will be ignored.
  33. */
  34. enum WoW64Mode
  35. {
  36. /** Default handling: 32-bit apps will use the 32-bit registry, and 64-bit apps
  37. will use the 64-bit registry. */
  38. WoW64_Default = 0,
  39. /** Always use the 64-bit registry store. (KEY_WOW64_64KEY). */
  40. WoW64_64bit = 0x100,
  41. /** Always use the 32-bit registry store. (KEY_WOW64_32KEY). */
  42. WoW64_32bit = 0x200
  43. };
  44. //==============================================================================
  45. /** Returns a string from the registry.
  46. The path is a string for the entire path of a value in the registry,
  47. e.g. "HKEY_CURRENT_USER\Software\foo\bar"
  48. */
  49. static String JUCE_CALLTYPE getValue (const String& regValuePath,
  50. const String& defaultValue = String::empty,
  51. WoW64Mode mode = WoW64_Default);
  52. /** Reads a binary block from the registry.
  53. The path is a string for the entire path of a value in the registry,
  54. e.g. "HKEY_CURRENT_USER\Software\foo\bar"
  55. @returns a DWORD indicating the type of the key.
  56. */
  57. static uint32 JUCE_CALLTYPE getBinaryValue (const String& regValuePath, MemoryBlock& resultData, WoW64Mode mode = WoW64_Default);
  58. /** Sets a registry value as a string.
  59. This will take care of creating any groups needed to get to the given registry value.
  60. */
  61. static bool JUCE_CALLTYPE setValue (const String& regValuePath, const String& value, WoW64Mode mode = WoW64_Default);
  62. /** Sets a registry value as a DWORD.
  63. This will take care of creating any groups needed to get to the given registry value.
  64. */
  65. static bool JUCE_CALLTYPE setValue (const String& regValuePath, uint32 value, WoW64Mode mode = WoW64_Default);
  66. /** Sets a registry value as a QWORD.
  67. This will take care of creating any groups needed to get to the given registry value.
  68. */
  69. static bool JUCE_CALLTYPE setValue (const String& regValuePath, uint64 value, WoW64Mode mode = WoW64_Default);
  70. /** Sets a registry value as a binary block.
  71. This will take care of creating any groups needed to get to the given registry value.
  72. */
  73. static bool JUCE_CALLTYPE setValue (const String& regValuePath, const MemoryBlock& value, WoW64Mode mode = WoW64_Default);
  74. /** Returns true if the given value exists in the registry. */
  75. static bool JUCE_CALLTYPE valueExists (const String& regValuePath, WoW64Mode mode = WoW64_Default);
  76. /** Returns true if the given key exists in the registry. */
  77. static bool JUCE_CALLTYPE keyExists (const String& regValuePath, WoW64Mode mode = WoW64_Default);
  78. /** Deletes a registry value. */
  79. static void JUCE_CALLTYPE deleteValue (const String& regValuePath, WoW64Mode mode = WoW64_Default);
  80. /** Deletes a registry key (which is registry-talk for 'folder'). */
  81. static void JUCE_CALLTYPE deleteKey (const String& regKeyPath, WoW64Mode mode = WoW64_Default);
  82. /** Creates a file association in the registry.
  83. This lets you set the executable that should be launched by a given file extension.
  84. @param fileExtension the file extension to associate, including the
  85. initial dot, e.g. ".txt"
  86. @param symbolicDescription a space-free short token to identify the file type
  87. @param fullDescription a human-readable description of the file type
  88. @param targetExecutable the executable that should be launched
  89. @param iconResourceNumber the icon that gets displayed for the file type will be
  90. found by looking up this resource number in the
  91. executable. Pass 0 here to not use an icon
  92. @param registerForCurrentUserOnly if false, this will try to register the association
  93. for all users (you might not have permission to do this
  94. unless running in an installer). If true, it will register the
  95. association in HKEY_CURRENT_USER.
  96. @param mode the WoW64 mode to use for choosing the database
  97. */
  98. static bool JUCE_CALLTYPE registerFileAssociation (const String& fileExtension,
  99. const String& symbolicDescription,
  100. const String& fullDescription,
  101. const File& targetExecutable,
  102. int iconResourceNumber,
  103. bool registerForCurrentUserOnly,
  104. WoW64Mode mode = WoW64_Default);
  105. // DEPRECATED: use the other methods with a WoW64Mode parameter of WoW64_64bit instead.
  106. JUCE_DEPRECATED (static String getValueWow64 (const String&, const String& defaultValue = String::empty));
  107. JUCE_DEPRECATED (static bool valueExistsWow64 (const String&));
  108. JUCE_DEPRECATED (static bool keyExistsWow64 (const String&));
  109. private:
  110. WindowsRegistry() JUCE_DELETED_FUNCTION;
  111. JUCE_DECLARE_NON_COPYABLE (WindowsRegistry)
  112. };
  113. #endif
  114. #endif // JUCE_WINDOWSREGISTRY_H_INCLUDED