Windows shell extensions: Use custom GUIDs via CMake and prepare MSI reg
authorMichael Schuster <michael@schuster.ms>
Tue, 18 Aug 2020 16:12:29 +0000 (18:12 +0200)
committerMichael Schuster <michael@schuster.ms>
Thu, 20 Aug 2020 16:50:05 +0000 (18:50 +0200)
Previously side by side installation with ownCloud or other NC custom builds would break the shell integration because the same GUIDs and registry keys were used.

Now we specify our custom GUIDs in NEXTCLOUD.cmake and use CMake to generate a header file and WiX (MSI) include file with these constants.

Note: Using generators like "guidgen" or "uuidgen" ensures that GUIDs are unique, as manual changes are not guaranteed to be.

Signed-off-by: Michael Schuster <michael@schuster.ms>
NEXTCLOUD.cmake
shell_integration/windows/CMakeLists.txt
shell_integration/windows/OCContextMenu/dllmain.cpp
shell_integration/windows/OCOverlays/DllMain.cpp
shell_integration/windows/OCOverlays/OverlayConstants.h [deleted file]
shell_integration/windows/WinShellExtConstants.h.in [new file with mode: 0644]
shell_integration/windows/WinShellExtConstants.wxi.in [new file with mode: 0644]

index d5a64488bb1853dd13ba04c03fe08351f1356ddf..15b4eb46f8352aa4e69f4b0d73024b54ead3b791 100644 (file)
@@ -35,3 +35,17 @@ set( APPLICATION_WIZARD_HEADER_BACKGROUND_COLOR "#0082c9" CACHE STRING "Hex colo
 set( APPLICATION_WIZARD_HEADER_TITLE_COLOR "#ffffff" CACHE STRING "Hex color of the text in the wizard header")
 option( APPLICATION_WIZARD_USE_CUSTOM_LOGO "Use the logo from ':/client/theme/colored/wizard_logo.png' else the default application icon is used" ON )
 
+
+#
+## Windows Shell Extensions - IMPORTANT: Generate new GUIDs for custom builds with "guidgen" or "uuidgen"
+#
+
+# Context Menu
+set( WIN_SHELLEXT_CONTEXT_MENU_GUID      "{BC6988AB-ACE2-4B81-84DC-DC34F9B24401}" )
+
+# Overlays
+set( WIN_SHELLEXT_OVERLAY_GUID_ERROR     "{E0342B74-7593-4C70-9D61-22F294AAFE05}" )
+set( WIN_SHELLEXT_OVERLAY_GUID_OK        "{E1094E94-BE93-4EA2-9639-8475C68F3886}" )
+set( WIN_SHELLEXT_OVERLAY_GUID_OK_SHARED "{E243AD85-F71B-496B-B17E-B8091CBE93D2}" )
+set( WIN_SHELLEXT_OVERLAY_GUID_SYNC      "{E3D6DB20-1D83-4829-B5C9-941B31C0C35A}" )
+set( WIN_SHELLEXT_OVERLAY_GUID_WARNING   "{E4977F33-F93A-4A0A-9D3C-83DEA0EE8483}" )
index 2c004fd6728a56d74845c321c99fc189ef2dad00..068c8b1d1637f3b0827144df40331efe1715f334 100644 (file)
@@ -3,6 +3,12 @@ foreach(buildType "" "_DEBUG" "_MINSIZEREL" "_RELEASE" "_RELWITHDEBINFO")
     string(REPLACE "/MD" "/MT" "CMAKE_CXX_FLAGS${buildType}" "${CMAKE_CXX_FLAGS${buildType}}")
 endforeach()
 
+include_directories(
+    ${CMAKE_CURRENT_BINARY_DIR}
+)
+configure_file(WinShellExtConstants.h.in ${CMAKE_CURRENT_BINARY_DIR}/WinShellExtConstants.h)
+configure_file(WinShellExtConstants.wxi.in ${CMAKE_CURRENT_BINARY_DIR}/WinShellExtConstants.wxi)
+
 add_subdirectory(OCContextMenu)
 add_subdirectory(OCOverlays)
 add_subdirectory(OCUtil)
index 924f3a4e524d2fdd51667ffa465ab4df6b316d2f..b6f1a11db1a98b0af0cc5826e12d613f30bff250 100644 (file)
@@ -16,9 +16,7 @@
 #include <Guiddef.h>
 #include "OCContextMenuRegHandler.h"
 #include "OCContextMenuFactory.h"
-
-// {841A0AAD-AA11-4B50-84D9-7F8E727D77D7}
-static const GUID CLSID_FileContextMenuExt = { 0x841a0aad, 0xaa11, 0x4b50, { 0x84, 0xd9, 0x7f, 0x8e, 0x72, 0x7d, 0x77, 0xd7 } };
+#include "WinShellExtConstants.h"
 
 HINSTANCE   g_hInst = nullptr;
 long        g_cDllRef = 0;
@@ -44,8 +42,14 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
 {
        HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
+    GUID guid;
+
+    hr = CLSIDFromString(CONTEXT_MENU_GUID, (LPCLSID)&guid);
+    if (!SUCCEEDED(hr)) {
+        return hr;
+    }
 
-       if (IsEqualCLSID(CLSID_FileContextMenuExt, rclsid))     {
+       if (IsEqualCLSID(guid, rclsid)) {
                hr = E_OUTOFMEMORY;
 
                OCContextMenuFactory *pClassFactory = new OCContextMenuFactory();
index c52f367f5759aedbfe8f2c994cdee9997f037cd6..8f6cff4978b5ec7f552edceba047dfc1ac40c6bc 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "OCOverlayRegistrationHandler.h"
 #include "OCOverlayFactory.h"
-#include "OverlayConstants.h"
+#include "WinShellExtConstants.h"
 
 HINSTANCE instanceHandle = nullptr;
 
diff --git a/shell_integration/windows/OCOverlays/OverlayConstants.h b/shell_integration/windows/OCOverlays/OverlayConstants.h
deleted file mode 100644 (file)
index 06c58ac..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
-* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
-*
-* This library is free software; you can redistribute it and/or modify it under
-* the terms of the GNU Lesser General Public License as published by the Free
-* Software Foundation; either version 2.1 of the License, or (at your option)
-* any later version.
-*
-* This library is distributed in the hope that it will be useful, but WITHOUT
-* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-* details.
-*/
-
-
-#define OVERLAY_GUID_ERROR          L"{0960F090-F328-48A3-B746-276B1E3C3722}"
-#define OVERLAY_GUID_ERROR_SHARED   L"{0960F091-F328-48A3-B746-276B1E3C3722}"
-#define OVERLAY_GUID_OK             L"{0960F092-F328-48A3-B746-276B1E3C3722}"
-#define OVERLAY_GUID_OK_SHARED      L"{0960F093-F328-48A3-B746-276B1E3C3722}"
-#define OVERLAY_GUID_SYNC           L"{0960F094-F328-48A3-B746-276B1E3C3722}"
-#define OVERLAY_GUID_SYNC_SHARED    L"{0960F095-F328-48A3-B746-276B1E3C3722}"
-#define OVERLAY_GUID_WARNING        L"{0960F096-F328-48A3-B746-276B1E3C3722}"
-#define OVERLAY_GUID_WARNING_SHARED L"{0960F097-F328-48A3-B746-276B1E3C3722}"
-
-#define OVERLAY_GENERIC_NAME        L"ownCloud overlay handler"
-
-// two spaces to put us ahead of the competition :/
-#define OVERLAY_NAME_ERROR          L"  OCError"
-#define OVERLAY_NAME_ERROR_SHARED   L"  OCErrorShared"
-#define OVERLAY_NAME_OK             L"  OCOK"
-#define OVERLAY_NAME_OK_SHARED      L"  OCOKShared"
-#define OVERLAY_NAME_SYNC           L"  OCSync"
-#define OVERLAY_NAME_SYNC_SHARED    L"  OCSyncShared"
-#define OVERLAY_NAME_WARNING        L"  OCWarning"
-#define OVERLAY_NAME_WARNING_SHARED L"  OCWarningShared"
-
-#define REGISTRY_OVERLAY_KEY        L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers"
-#define REGISTRY_CLSID              L"CLSID"
-#define REGISTRY_IN_PROCESS         L"InprocServer32"
-#define REGISTRY_THREADING          L"ThreadingModel"
-#define REGISTRY_APARTMENT          L"Apartment"
-#define REGISTRY_VERSION            L"Version"
-#define REGISTRY_VERSION_NUMBER     L"1.0"
-
-//Registry values for running
-#define REGISTRY_ENABLE_OVERLAY     L"EnableOverlay"
-
-#define GET_FILE_OVERLAY_ID     L"getFileIconId"
-
-#define PORT                34001
diff --git a/shell_integration/windows/WinShellExtConstants.h.in b/shell_integration/windows/WinShellExtConstants.h.in
new file mode 100644 (file)
index 0000000..4c8a165
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#pragma once
+
+// Context Menu
+#define CONTEXT_MENU_GUID           L"@WIN_SHELLEXT_CONTEXT_MENU_GUID@"
+
+// Overlays
+#define OVERLAY_GUID_ERROR          L"@WIN_SHELLEXT_OVERLAY_GUID_ERROR@"
+#define OVERLAY_GUID_OK             L"@WIN_SHELLEXT_OVERLAY_GUID_OK@"
+#define OVERLAY_GUID_OK_SHARED      L"@WIN_SHELLEXT_OVERLAY_GUID_OK_SHARED@"
+#define OVERLAY_GUID_SYNC           L"@WIN_SHELLEXT_OVERLAY_GUID_SYNC@"
+#define OVERLAY_GUID_WARNING        L"@WIN_SHELLEXT_OVERLAY_GUID_WARNING@"
diff --git a/shell_integration/windows/WinShellExtConstants.wxi.in b/shell_integration/windows/WinShellExtConstants.wxi.in
new file mode 100644 (file)
index 0000000..788ca32
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ *
+ * Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+-->
+<Include>
+
+    <!-- Context Menu -->
+    <?define ContextMenuGuid        = "@WIN_SHELLEXT_CONTEXT_MENU_GUID@" ?>
+    <?define ContextMenuRegKeyName  = "@APPLICATION_SHORTNAME@ContextMenuHandler" ?>
+
+    <?define ContextMenuDescription = "@APPLICATION_SHORTNAME@ context menu handler" ?>
+
+    <!-- Overlays -->
+    <?define OverlayGuidError       = "@WIN_SHELLEXT_OVERLAY_GUID_ERROR@" ?>
+    <?define OverlayGuidOK          = "@WIN_SHELLEXT_OVERLAY_GUID_OK@" ?>
+    <?define OverlayGuidOKShared    = "@WIN_SHELLEXT_OVERLAY_GUID_OK_SHARED@" ?>
+    <?define OverlayGuidSync        = "@WIN_SHELLEXT_OVERLAY_GUID_SYNC@" ?>
+    <?define OverlayGuidWarning     = "@WIN_SHELLEXT_OVERLAY_GUID_WARNING@" ?>
+
+    <!-- Preceeding spaces are intended, two spaces to put us ahead of the competition :/ -->
+    <?define OverlayNameError       = "  @APPLICATION_SHORTNAME@Error" ?>
+    <?define OverlayNameOK          = "  @APPLICATION_SHORTNAME@OK" ?>
+    <?define OverlayNameOKShared    = "  @APPLICATION_SHORTNAME@OKShared" ?>
+    <?define OverlayNameSync        = "  @APPLICATION_SHORTNAME@Sync" ?>
+    <?define OverlayNameWarning     = "  @APPLICATION_SHORTNAME@Warning" ?>
+
+    <?define OverlayDescription     = "@APPLICATION_SHORTNAME@ overlay handler" ?>
+
+</Include>