Windows shell extensions: Rename all files and classes from OC* to NC*, update version info

This also ensures a clear separation in the system registry.

SelfReg is not recommended by Microsoft and will be handled by the MSI package to allow proper Repair and Uninstall.
However, we keep it for backward compatibility with the NSIS installer.

For details see:
https://stackoverflow.com/questions/364187/how-do-you-register-a-win32-com-dll-file-in-wix-3#364210
https://docs.microsoft.com/en-us/windows/win32/msi/selfreg-table#remarks

Another fix by this commit:
The "Version" registry value in the NCOverlays self reg should be a key and not a value.

Details: https://wixtoolset.org/documentation/manual/v3/xsd/wix/class.html

Example:

  [HKCR\CLSID\{01234567-89AB-CDEF-0123-456789ABCDEF}\Version]
  @="1.0.0.0"

Signed-off-by: Michael Schuster <michael@schuster.ms>
This commit is contained in:
Michael Schuster 2020-08-18 19:11:08 +02:00
parent 8ce13b7bdb
commit 0ba5df597f
No known key found for this signature in database
GPG key ID: 00819E3BF4177B28
46 changed files with 227 additions and 208 deletions

View file

@ -9,7 +9,7 @@ include_directories(
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)
add_subdirectory(NCContextMenu)
add_subdirectory(NCOverlays)
add_subdirectory(NCUtil)

View file

@ -0,0 +1,17 @@
add_library(NCContextMenu MODULE
dllmain.cpp
NCClientInterface.cpp
NCContextMenu.cpp
NCContextMenuFactory.cpp
NCContextMenuRegHandler.cpp
NCContextMenu.rc
NCContextMenu.def
)
target_link_libraries(NCContextMenu
NCUtil)
install(TARGETS NCContextMenu
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View file

@ -12,7 +12,7 @@
* details.
*/
#include "OCClientInterface.h"
#include "NCClientInterface.h"
#include "CommunicationSocket.h"
#include "StringUtil.h"
@ -31,7 +31,7 @@ using namespace std;
#define PIPE_TIMEOUT 5*1000 //ms
OCClientInterface::ContextMenuInfo OCClientInterface::FetchInfo(const std::wstring &files)
NCClientInterface::ContextMenuInfo NCClientInterface::FetchInfo(const std::wstring &files)
{
auto pipename = CommunicationSocket::DefaultPipePath();
@ -77,7 +77,7 @@ OCClientInterface::ContextMenuInfo OCClientInterface::FetchInfo(const std::wstri
return info;
}
void OCClientInterface::SendRequest(const wchar_t *verb, const std::wstring &path)
void NCClientInterface::SendRequest(const wchar_t *verb, const std::wstring &path)
{
auto pipename = CommunicationSocket::DefaultPipePath();

View file

@ -40,7 +40,7 @@
class CommunicationSocket;
class OCClientInterface
class NCClientInterface
{
public:
struct ContextMenuInfo {

View file

@ -12,8 +12,8 @@
* details.
*/
#include "OCContextMenu.h"
#include "OCClientInterface.h"
#include "NCContextMenu.h"
#include "NCClientInterface.h"
#include <shobjidl.h>
#include <shlwapi.h>
@ -23,13 +23,13 @@
extern long g_cDllRef;
OCContextMenu::OCContextMenu(void)
NCContextMenu::NCContextMenu(void)
: m_cRef(1)
{
InterlockedIncrement(&g_cDllRef);
}
OCContextMenu::~OCContextMenu(void)
NCContextMenu::~NCContextMenu(void)
{
InterlockedDecrement(&g_cDllRef);
}
@ -37,25 +37,25 @@ OCContextMenu::~OCContextMenu(void)
#pragma region IUnknown
// Query to the interface the component supported.
IFACEMETHODIMP OCContextMenu::QueryInterface(REFIID riid, void **ppv)
IFACEMETHODIMP NCContextMenu::QueryInterface(REFIID riid, void **ppv)
{
static const QITAB qit[] =
{
QITABENT(OCContextMenu, IContextMenu),
QITABENT(OCContextMenu, IShellExtInit),
QITABENT(NCContextMenu, IContextMenu),
QITABENT(NCContextMenu, IShellExtInit),
{ 0 },
};
return QISearch(this, qit, riid, ppv);
}
// Increase the reference count for an interface on an object.
IFACEMETHODIMP_(ULONG) OCContextMenu::AddRef()
IFACEMETHODIMP_(ULONG) NCContextMenu::AddRef()
{
return InterlockedIncrement(&m_cRef);
}
// Decrease the reference count for an interface on an object.
IFACEMETHODIMP_(ULONG) OCContextMenu::Release()
IFACEMETHODIMP_(ULONG) NCContextMenu::Release()
{
ULONG cRef = InterlockedDecrement(&m_cRef);
if (0 == cRef) {
@ -71,7 +71,7 @@ IFACEMETHODIMP_(ULONG) OCContextMenu::Release()
#pragma region IShellExtInit
// Initialize the context menu handler.
IFACEMETHODIMP OCContextMenu::Initialize(
IFACEMETHODIMP NCContextMenu::Initialize(
LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID)
{
m_selectedFiles.clear();
@ -127,7 +127,7 @@ void InsertSeperator(HMENU hMenu, UINT indexMenu)
InsertMenuItem(hMenu, indexMenu, TRUE, &sep);
}
IFACEMETHODIMP OCContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
IFACEMETHODIMP NCContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
// If uFlags include CMF_DEFAULTONLY then we should not do anything.
if (CMF_DEFAULTONLY & uFlags)
@ -135,7 +135,7 @@ IFACEMETHODIMP OCContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0));
}
m_info = OCClientInterface::FetchInfo(m_selectedFiles);
m_info = NCClientInterface::FetchInfo(m_selectedFiles);
if (m_info.menuItems.empty()) {
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0));
}
@ -177,7 +177,7 @@ IFACEMETHODIMP OCContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(indexSubMenu));
}
IFACEMETHODIMP OCContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
IFACEMETHODIMP NCContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
{
std::wstring command;
@ -215,11 +215,11 @@ IFACEMETHODIMP OCContextMenu::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
return E_FAIL;
}
OCClientInterface::SendRequest(command.data(), m_selectedFiles);
NCClientInterface::SendRequest(command.data(), m_selectedFiles);
return S_OK;
}
IFACEMETHODIMP OCContextMenu::GetCommandString(UINT_PTR idCommand,
IFACEMETHODIMP NCContextMenu::GetCommandString(UINT_PTR idCommand,
UINT uFlags, UINT *pwReserved, LPSTR pszName, UINT cchMax)
{
if (idCommand < m_info.menuItems.size() && uFlags == GCS_VERBW) {

View file

@ -12,15 +12,15 @@
* details.
*/
#ifndef OCCONTEXTMENU_H
#define OCCONTEXTMENU_H
#ifndef NCCONTEXTMENU_H
#define NCCONTEXTMENU_H
#pragma once
#include <shlobj.h> // For IShellExtInit and IContextMenu
#include <string>
#include "OCClientInterface.h"
#include "NCClientInterface.h"
class OCContextMenu : public IShellExtInit, public IContextMenu
class NCContextMenu : public IShellExtInit, public IContextMenu
{
public:
// IUnknown
@ -36,10 +36,10 @@ public:
IFACEMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO pici);
IFACEMETHODIMP GetCommandString(UINT_PTR idCommand, UINT uFlags, UINT *pwReserved, LPSTR pszName, UINT cchMax);
OCContextMenu();
NCContextMenu();
protected:
~OCContextMenu();
~NCContextMenu();
private:
// Reference count of component.
@ -47,7 +47,7 @@ private:
// The name of the selected files (separated by '\x1e')
std::wstring m_selectedFiles;
OCClientInterface::ContextMenuInfo m_info;
NCClientInterface::ContextMenuInfo m_info;
};
#endif //OCCONTEXTMENU_H
#endif //NCCONTEXTMENU_H

View file

@ -12,8 +12,8 @@
* details.
*/
#include "OCContextMenuFactory.h"
#include "OCContextMenu.h"
#include "NCContextMenuFactory.h"
#include "NCContextMenu.h"
#include <new>
#include <Shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
@ -22,12 +22,12 @@
extern long g_cDllRef;
OCContextMenuFactory::OCContextMenuFactory() : m_cRef(1)
NCContextMenuFactory::NCContextMenuFactory() : m_cRef(1)
{
InterlockedIncrement(&g_cDllRef);
}
OCContextMenuFactory::~OCContextMenuFactory()
NCContextMenuFactory::~NCContextMenuFactory()
{
InterlockedDecrement(&g_cDllRef);
}
@ -35,18 +35,18 @@ OCContextMenuFactory::~OCContextMenuFactory()
// IUnknown methods
IFACEMETHODIMP OCContextMenuFactory::QueryInterface(REFIID riid, void **ppv)
IFACEMETHODIMP NCContextMenuFactory::QueryInterface(REFIID riid, void **ppv)
{
static const QITAB qit[] = { QITABENT(OCContextMenuFactory, IClassFactory), { 0 }, };
static const QITAB qit[] = { QITABENT(NCContextMenuFactory, IClassFactory), { 0 }, };
return QISearch(this, qit, riid, ppv);
}
IFACEMETHODIMP_(ULONG) OCContextMenuFactory::AddRef()
IFACEMETHODIMP_(ULONG) NCContextMenuFactory::AddRef()
{
return InterlockedIncrement(&m_cRef);
}
IFACEMETHODIMP_(ULONG) OCContextMenuFactory::Release()
IFACEMETHODIMP_(ULONG) NCContextMenuFactory::Release()
{
ULONG cRef = InterlockedDecrement(&m_cRef);
if (0 == cRef) {
@ -58,7 +58,7 @@ IFACEMETHODIMP_(ULONG) OCContextMenuFactory::Release()
// IClassFactory methods
IFACEMETHODIMP OCContextMenuFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv)
IFACEMETHODIMP NCContextMenuFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv)
{
HRESULT hr = CLASS_E_NOAGGREGATION;
@ -67,7 +67,7 @@ IFACEMETHODIMP OCContextMenuFactory::CreateInstance(IUnknown *pUnkOuter, REFIID
hr = E_OUTOFMEMORY;
// Create the COM component.
OCContextMenu *pExt = new (std::nothrow) OCContextMenu();
NCContextMenu *pExt = new (std::nothrow) NCContextMenu();
if (pExt) {
// Query the specified interface.
hr = pExt->QueryInterface(riid, ppv);
@ -78,7 +78,7 @@ IFACEMETHODIMP OCContextMenuFactory::CreateInstance(IUnknown *pUnkOuter, REFIID
return hr;
}
IFACEMETHODIMP OCContextMenuFactory::LockServer(BOOL fLock)
IFACEMETHODIMP NCContextMenuFactory::LockServer(BOOL fLock)
{
if (fLock) {
InterlockedIncrement(&g_cDllRef);

View file

@ -13,14 +13,14 @@
*/
#ifndef OCCONTEXTMENUFACTORY_H
#define OCCONTEXTMENUFACTORY_H
#ifndef NCCONTEXTMENUFACTORY_H
#define NCCONTEXTMENUFACTORY_H
#pragma once
#include <unknwn.h> // For IClassFactory
class OCContextMenuFactory : public IClassFactory
class NCContextMenuFactory : public IClassFactory
{
public:
// IUnknown
@ -32,11 +32,11 @@ public:
IFACEMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv);
IFACEMETHODIMP LockServer(BOOL fLock);
OCContextMenuFactory();
NCContextMenuFactory();
private:
~OCContextMenuFactory();
~NCContextMenuFactory();
long m_cRef;
};
#endif //OCCONTEXTMENUFACTORY_H
#endif //NCCONTEXTMENUFACTORY_H

View file

@ -12,7 +12,7 @@
* details.
*/
#include "OCContextMenuRegHandler.h"
#include "NCContextMenuRegHandler.h"
#include "RegDelnode.h"
#include <strsafe.h>
#include <objbase.h>
@ -68,7 +68,7 @@ HRESULT GetHKCRRegistryKeyAndValue(PCWSTR pszSubKey, PCWSTR pszValueName, PWSTR
}
HRESULT OCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CLSID& clsid, PCWSTR pszFriendlyName, PCWSTR pszThreadModel)
HRESULT NCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CLSID& clsid, PCWSTR pszFriendlyName, PCWSTR pszThreadModel)
{
if (!pszModule || !pszThreadModel)
{
@ -111,7 +111,7 @@ HRESULT OCContextMenuRegHandler::RegisterInprocServer(PCWSTR pszModule, const CL
return hr;
}
HRESULT OCContextMenuRegHandler::UnregisterInprocServer(const CLSID& clsid)
HRESULT NCContextMenuRegHandler::UnregisterInprocServer(const CLSID& clsid)
{
HRESULT hr = S_OK;
@ -131,7 +131,7 @@ HRESULT OCContextMenuRegHandler::UnregisterInprocServer(const CLSID& clsid)
}
HRESULT OCContextMenuRegHandler::RegisterShellExtContextMenuHandler(
HRESULT NCContextMenuRegHandler::RegisterShellExtContextMenuHandler(
PCWSTR pszFileType, const CLSID& clsid, PCWSTR pszFriendlyName)
{
if (!pszFileType)
@ -175,7 +175,7 @@ HRESULT OCContextMenuRegHandler::RegisterShellExtContextMenuHandler(
return hr;
}
HRESULT OCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(
HRESULT NCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(
PCWSTR pszFileType, PCWSTR pszFriendlyName)
{
if (!pszFileType)

View file

@ -13,14 +13,14 @@
*/
#ifndef OCCONTEXTMENUREGHANDLER_H
#define OCCONTEXTMENUREGHANDLER_H
#ifndef NCCONTEXTMENUREGHANDLER_H
#define NCCONTEXTMENUREGHANDLER_H
#pragma once
#include <windows.h>
class __declspec(dllexport) OCContextMenuRegHandler
class __declspec(dllexport) NCContextMenuRegHandler
{
public:
static HRESULT MakeRegistryEntries(const CLSID& clsid, PCWSTR fileType);
@ -35,4 +35,4 @@ public:
static HRESULT UnregisterShellExtContextMenuHandler(PCWSTR pszFileType, PCWSTR pszFriendlyName);
};
#endif //OCCONTEXTMENUREGHANDLER_H
#endif //NCCONTEXTMENUREGHANDLER_H

View file

@ -14,8 +14,8 @@
#include <windows.h>
#include <Guiddef.h>
#include "OCContextMenuRegHandler.h"
#include "OCContextMenuFactory.h"
#include "NCContextMenuRegHandler.h"
#include "NCContextMenuFactory.h"
#include "WinShellExtConstants.h"
HINSTANCE g_hInst = nullptr;
@ -41,7 +41,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
{
HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
HRESULT hr;
GUID guid;
hr = CLSIDFromString(CONTEXT_MENU_GUID, (LPCLSID)&guid);
@ -49,10 +49,12 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
return hr;
}
hr = CLASS_E_CLASSNOTAVAILABLE;
if (IsEqualCLSID(guid, rclsid)) {
hr = E_OUTOFMEMORY;
OCContextMenuFactory *pClassFactory = new OCContextMenuFactory();
NCContextMenuFactory *pClassFactory = new NCContextMenuFactory();
if (pClassFactory) {
hr = pClassFactory->QueryInterface(riid, ppv);
pClassFactory->Release();
@ -70,6 +72,12 @@ STDAPI DllCanUnloadNow(void)
STDAPI DllRegisterServer(void)
{
HRESULT hr;
GUID guid;
hr = CLSIDFromString(CONTEXT_MENU_GUID, (LPCLSID)&guid);
if (!SUCCEEDED(hr)) {
return hr;
}
wchar_t szModule[MAX_PATH];
if (GetModuleFileName(g_hInst, szModule, ARRAYSIZE(szModule)) == 0) {
@ -78,12 +86,12 @@ STDAPI DllRegisterServer(void)
}
// Register the component.
hr = OCContextMenuRegHandler::RegisterInprocServer(szModule, CLSID_FileContextMenuExt,
L"OCContextMenuHandler Class", L"Apartment");
hr = NCContextMenuRegHandler::RegisterInprocServer(szModule, guid,
CONTEXT_MENU_DESCRIPTION, L"Apartment");
if (SUCCEEDED(hr)) {
// Register the context menu handler. The context menu handler is
// associated with the .cpp file class.
hr = OCContextMenuRegHandler::RegisterShellExtContextMenuHandler(L"AllFileSystemObjects", CLSID_FileContextMenuExt, L"OCContextMenuHandler");
hr = NCContextMenuRegHandler::RegisterShellExtContextMenuHandler(L"AllFileSystemObjects", guid, CONTEXT_MENU_REGKEY_NAME);
}
return hr;
@ -92,6 +100,12 @@ STDAPI DllRegisterServer(void)
STDAPI DllUnregisterServer(void)
{
HRESULT hr = S_OK;
GUID guid;
hr = CLSIDFromString(CONTEXT_MENU_GUID, (LPCLSID)&guid);
if (!SUCCEEDED(hr)) {
return hr;
}
wchar_t szModule[MAX_PATH];
if (GetModuleFileName(g_hInst, szModule, ARRAYSIZE(szModule)) == 0) {
@ -100,10 +114,10 @@ STDAPI DllUnregisterServer(void)
}
// Unregister the component.
hr = OCContextMenuRegHandler::UnregisterInprocServer(CLSID_FileContextMenuExt);
hr = NCContextMenuRegHandler::UnregisterInprocServer(guid);
if (SUCCEEDED(hr)) {
// Unregister the context menu handler.
hr = OCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(L"AllFileSystemObjects", L"OCContextMenuHandler");
hr = NCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(L"AllFileSystemObjects", CONTEXT_MENU_REGKEY_NAME);
}
return hr;

View file

@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by OCContextMenu.rc
// Used by NCContextMenu.rc
// Next default values for new objects
//

View file

@ -0,0 +1,16 @@
add_library(NCOverlays MODULE
DllMain.cpp
NCOverlay.cpp
NCOverlayFactory.cpp
NCOverlayRegistrationHandler.cpp
NCOverlay.rc
NCOverlays.def
)
target_link_libraries(NCOverlays
NCUtil)
install(TARGETS NCOverlays
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View file

@ -12,8 +12,8 @@
* details.
*/
#include "OCOverlayRegistrationHandler.h"
#include "OCOverlayFactory.h"
#include "NCOverlayRegistrationHandler.h"
#include "NCOverlayFactory.h"
#include "WinShellExtConstants.h"
HINSTANCE instanceHandle = nullptr;
@ -41,11 +41,11 @@ HRESULT CreateFactory(REFIID riid, void **ppv, int state)
{
HRESULT hResult = E_OUTOFMEMORY;
OCOverlayFactory* ocOverlayFactory = new OCOverlayFactory(state);
NCOverlayFactory* ncOverlayFactory = new NCOverlayFactory(state);
if (ocOverlayFactory) {
hResult = ocOverlayFactory->QueryInterface(riid, ppv);
ocOverlayFactory->Release();
if (ncOverlayFactory) {
hResult = ncOverlayFactory->QueryInterface(riid, ppv);
ncOverlayFactory->Release();
}
return hResult;
}
@ -94,13 +94,13 @@ HRESULT RegisterCLSID(LPCOLESTR guidStr, PCWSTR overlayStr, PCWSTR szModule)
return hResult;
}
hResult = OCOverlayRegistrationHandler::RegisterCOMObject(szModule, OVERLAY_GENERIC_NAME, guid);
hResult = NCOverlayRegistrationHandler::RegisterCOMObject(szModule, OVERLAY_DESCRIPTION, guid);
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = OCOverlayRegistrationHandler::MakeRegistryEntries(guid, overlayStr);
hResult = NCOverlayRegistrationHandler::MakeRegistryEntries(guid, overlayStr);
return hResult;
}
@ -116,13 +116,13 @@ HRESULT UnregisterCLSID(LPCOLESTR guidStr, PCWSTR overlayStr)
return hResult;
}
hResult = OCOverlayRegistrationHandler::UnregisterCOMObject(guid);
hResult = NCOverlayRegistrationHandler::UnregisterCOMObject(guid);
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = OCOverlayRegistrationHandler::RemoveRegistryEntries(overlayStr);
hResult = NCOverlayRegistrationHandler::RemoveRegistryEntries(overlayStr);
return hResult;
}
@ -138,13 +138,6 @@ HRESULT _stdcall DllRegisterServer(void)
return hResult;
}
// Unregister any obsolete CLSID when we register here
// Those CLSID were removed in 2.1, but we need to make sure to prevent any previous version
// of the extension on the system from loading at the same time as a new version to avoid crashing explorer.
UnregisterCLSID(OVERLAY_GUID_ERROR_SHARED, OVERLAY_NAME_ERROR_SHARED);
UnregisterCLSID(OVERLAY_GUID_SYNC_SHARED, OVERLAY_NAME_SYNC_SHARED);
UnregisterCLSID(OVERLAY_GUID_WARNING_SHARED, OVERLAY_NAME_WARNING_SHARED);
hResult = RegisterCLSID(OVERLAY_GUID_ERROR, OVERLAY_NAME_ERROR, szModule);
if (!SUCCEEDED(hResult)) { return hResult; }
hResult = RegisterCLSID(OVERLAY_GUID_OK, OVERLAY_NAME_OK, szModule);

View file

@ -12,12 +12,9 @@
* details.
*/
#include "OCOverlay.h"
#include "OCOverlayFactory.h"
#include "NCOverlay.h"
#include "NCOverlayFactory.h"
#include "StringUtil.h"
#include "UtilConstants.h"
#include "RemotePathChecker.h"
#include <algorithm>
@ -50,23 +47,23 @@ RemotePathChecker *getGlobalChecker()
}
}
OCOverlay::OCOverlay(int state)
NCOverlay::NCOverlay(int state)
: _referenceCount(1)
, _state(state)
{
}
OCOverlay::~OCOverlay(void)
NCOverlay::~NCOverlay(void)
{
}
IFACEMETHODIMP_(ULONG) OCOverlay::AddRef()
IFACEMETHODIMP_(ULONG) NCOverlay::AddRef()
{
return InterlockedIncrement(&_referenceCount);
}
IFACEMETHODIMP OCOverlay::QueryInterface(REFIID riid, void **ppv)
IFACEMETHODIMP NCOverlay::QueryInterface(REFIID riid, void **ppv)
{
HRESULT hr = S_OK;
@ -88,7 +85,7 @@ IFACEMETHODIMP OCOverlay::QueryInterface(REFIID riid, void **ppv)
return hr;
}
IFACEMETHODIMP_(ULONG) OCOverlay::Release()
IFACEMETHODIMP_(ULONG) NCOverlay::Release()
{
ULONG cRef = InterlockedDecrement(&_referenceCount);
if (0 == cRef)
@ -99,7 +96,7 @@ IFACEMETHODIMP_(ULONG) OCOverlay::Release()
return cRef;
}
IFACEMETHODIMP OCOverlay::GetPriority(int *pPriority)
IFACEMETHODIMP NCOverlay::GetPriority(int *pPriority)
{
// this defines which handler has prededence, so
// we order this in terms of likelyhood
@ -121,7 +118,7 @@ IFACEMETHODIMP OCOverlay::GetPriority(int *pPriority)
return S_OK;
}
IFACEMETHODIMP OCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib)
IFACEMETHODIMP NCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib)
{
RemotePathChecker* checker = getGlobalChecker();
std::shared_ptr<const std::vector<std::wstring>> watchedDirectories = checker->WatchedDirectories();
@ -149,7 +146,7 @@ IFACEMETHODIMP OCOverlay::IsMemberOf(PCWSTR pwszPath, DWORD dwAttrib)
return MAKE_HRESULT(state == _state ? S_OK : S_FALSE, 0, 0);
}
IFACEMETHODIMP OCOverlay::GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)
IFACEMETHODIMP NCOverlay::GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)
{
*pIndex = 0;
*pdwFlags = ISIOI_ICONFILE | ISIOI_ICONINDEX;

View file

@ -12,18 +12,18 @@
* details.
*/
#ifndef OCOVERLAY_H
#define OCOVERLAY_H
#ifndef NCOVERLAY_H
#define NCOVERLAY_H
#pragma once
#include <shlobj.h>
class OCOverlay : public IShellIconOverlayIdentifier
class NCOverlay : public IShellIconOverlayIdentifier
{
public:
OCOverlay(int state);
NCOverlay(int state);
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP GetOverlayInfo(PWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags);
@ -33,7 +33,7 @@ public:
IFACEMETHODIMP_(ULONG) Release();
protected:
~OCOverlay();
~NCOverlay();
private:
long _referenceCount;

View file

@ -15,23 +15,23 @@
#include <windows.h>
#include <new>
#include "OCOverlayFactory.h"
#include "OCOverlay.h"
#include "NCOverlayFactory.h"
#include "NCOverlay.h"
extern long dllReferenceCount;
OCOverlayFactory::OCOverlayFactory(int state)
NCOverlayFactory::NCOverlayFactory(int state)
: _referenceCount(1), _state(state)
{
InterlockedIncrement(&dllReferenceCount);
}
OCOverlayFactory::~OCOverlayFactory()
NCOverlayFactory::~NCOverlayFactory()
{
InterlockedDecrement(&dllReferenceCount);
}
IFACEMETHODIMP OCOverlayFactory::QueryInterface(REFIID riid, void **ppv)
IFACEMETHODIMP NCOverlayFactory::QueryInterface(REFIID riid, void **ppv)
{
HRESULT hResult = S_OK;
@ -50,12 +50,12 @@ IFACEMETHODIMP OCOverlayFactory::QueryInterface(REFIID riid, void **ppv)
return hResult;
}
IFACEMETHODIMP_(ULONG) OCOverlayFactory::AddRef()
IFACEMETHODIMP_(ULONG) NCOverlayFactory::AddRef()
{
return InterlockedIncrement(&_referenceCount);
}
IFACEMETHODIMP_(ULONG) OCOverlayFactory::Release()
IFACEMETHODIMP_(ULONG) NCOverlayFactory::Release()
{
ULONG cRef = InterlockedDecrement(&_referenceCount);
@ -66,7 +66,7 @@ IFACEMETHODIMP_(ULONG) OCOverlayFactory::Release()
return cRef;
}
IFACEMETHODIMP OCOverlayFactory::CreateInstance(
IFACEMETHODIMP NCOverlayFactory::CreateInstance(
IUnknown *pUnkOuter, REFIID riid, void **ppv)
{
HRESULT hResult = CLASS_E_NOAGGREGATION;
@ -74,7 +74,7 @@ IFACEMETHODIMP OCOverlayFactory::CreateInstance(
if (pUnkOuter) { return hResult; }
hResult = E_OUTOFMEMORY;
OCOverlay *lrOverlay = new (std::nothrow) OCOverlay(_state);
NCOverlay *lrOverlay = new (std::nothrow) NCOverlay(_state);
if (!lrOverlay) { return hResult; }
hResult = lrOverlay->QueryInterface(riid, ppv);
@ -83,7 +83,7 @@ IFACEMETHODIMP OCOverlayFactory::CreateInstance(
return hResult;
}
IFACEMETHODIMP OCOverlayFactory::LockServer(BOOL fLock)
IFACEMETHODIMP NCOverlayFactory::LockServer(BOOL fLock)
{
if (fLock) {
InterlockedIncrement(&dllReferenceCount);

View file

@ -12,8 +12,8 @@
* details.
*/
#ifndef OCOVERLAYFACTORY_H
#define OCOVERLAYFACTORY_H
#ifndef NCOVERLAYFACTORY_H
#define NCOVERLAYFACTORY_H
#pragma once
@ -26,10 +26,10 @@ enum State {
State_Warning
};
class OCOverlayFactory : public IClassFactory
class NCOverlayFactory : public IClassFactory
{
public:
OCOverlayFactory(int state);
NCOverlayFactory(int state);
IFACEMETHODIMP_(ULONG) AddRef();
IFACEMETHODIMP CreateInstance(IUnknown *pUnkOuter, REFIID riid, void **ppv);
@ -38,7 +38,7 @@ public:
IFACEMETHODIMP_(ULONG) Release();
protected:
~OCOverlayFactory();
~NCOverlayFactory();
private:
long _referenceCount;

View file

@ -12,17 +12,24 @@
* details.
*/
#include "OCOverlayRegistrationHandler.h"
#include "OverlayConstants.h"
#include "NCOverlayRegistrationHandler.h"
#include <windows.h>
#include <objbase.h>
#include <iostream>
#include <fstream>
#define REGISTRY_OVERLAY_KEY LR"(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"
using namespace std;
HRESULT OCOverlayRegistrationHandler::MakeRegistryEntries(const CLSID& clsid, PCWSTR friendlyName)
HRESULT NCOverlayRegistrationHandler::MakeRegistryEntries(const CLSID& clsid, PCWSTR friendlyName)
{
HRESULT hResult;
HKEY shellOverlayKey = nullptr;
@ -53,7 +60,7 @@ HRESULT OCOverlayRegistrationHandler::MakeRegistryEntries(const CLSID& clsid, PC
return hResult;
}
HRESULT OCOverlayRegistrationHandler::RemoveRegistryEntries(PCWSTR friendlyName)
HRESULT NCOverlayRegistrationHandler::RemoveRegistryEntries(PCWSTR friendlyName)
{
HRESULT hResult;
HKEY shellOverlayKey = nullptr;
@ -72,7 +79,7 @@ HRESULT OCOverlayRegistrationHandler::RemoveRegistryEntries(PCWSTR friendlyName)
return hResult;
}
HRESULT OCOverlayRegistrationHandler::RegisterCOMObject(PCWSTR modulePath, PCWSTR friendlyName, const CLSID& clsid)
HRESULT NCOverlayRegistrationHandler::RegisterCOMObject(PCWSTR modulePath, PCWSTR friendlyName, const CLSID& clsid)
{
if (!modulePath) {
return E_FAIL;
@ -90,7 +97,7 @@ HRESULT OCOverlayRegistrationHandler::RegisterCOMObject(PCWSTR modulePath, PCWST
HKEY clsidKey = nullptr;
hResult = HRESULT_FROM_WIN32(RegCreateKeyEx(hKey, stringCLSID, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &clsidKey, nullptr));
if(!SUCCEEDED(hResult)) {
if (!SUCCEEDED(hResult)) {
return hResult;
}
@ -98,30 +105,36 @@ HRESULT OCOverlayRegistrationHandler::RegisterCOMObject(PCWSTR modulePath, PCWST
HKEY inprocessKey = nullptr;
hResult = HRESULT_FROM_WIN32(RegCreateKeyEx(clsidKey, REGISTRY_IN_PROCESS, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &inprocessKey, nullptr));
if(!SUCCEEDED(hResult)) {
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = HRESULT_FROM_WIN32(RegSetValue(inprocessKey, nullptr, REG_SZ, modulePath, (DWORD) wcslen(modulePath)));
if(!SUCCEEDED(hResult)) {
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = HRESULT_FROM_WIN32(RegSetValueEx(inprocessKey, REGISTRY_THREADING, 0, REG_SZ, (LPBYTE)REGISTRY_APARTMENT, (DWORD)((wcslen(REGISTRY_APARTMENT)+1) * sizeof(TCHAR))));
if(!SUCCEEDED(hResult)) {
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = HRESULT_FROM_WIN32(RegSetValueEx(inprocessKey, REGISTRY_VERSION, 0, REG_SZ, (LPBYTE)REGISTRY_VERSION_NUMBER, (DWORD)(wcslen(REGISTRY_VERSION_NUMBER)+1) * sizeof(TCHAR)));
if(!SUCCEEDED(hResult)) {
HKEY versionKey = nullptr;
hResult = HRESULT_FROM_WIN32(RegCreateKeyEx(clsidKey, REGISTRY_VERSION, 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_WRITE, nullptr, &versionKey, nullptr));
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = HRESULT_FROM_WIN32(RegSetValueEx(versionKey, nullptr, 0, REG_SZ, (LPBYTE)REGISTRY_VERSION_NUMBER, (DWORD)(wcslen(REGISTRY_VERSION_NUMBER)+1) * sizeof(TCHAR)));
if (!SUCCEEDED(hResult)) {
return hResult;
}
return S_OK;
}
HRESULT OCOverlayRegistrationHandler::UnregisterCOMObject(const CLSID& clsid)
HRESULT NCOverlayRegistrationHandler::UnregisterCOMObject(const CLSID& clsid)
{
wchar_t stringCLSID[MAX_PATH];
@ -135,17 +148,22 @@ HRESULT OCOverlayRegistrationHandler::UnregisterCOMObject(const CLSID& clsid)
HKEY clsidKey = nullptr;
hResult = HRESULT_FROM_WIN32(RegOpenKeyEx(hKey, stringCLSID, 0, DELETE, &clsidKey));
if(!SUCCEEDED(hResult)) {
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = HRESULT_FROM_WIN32(RegDeleteKey(clsidKey, REGISTRY_IN_PROCESS));
if(!SUCCEEDED(hResult)) {
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = HRESULT_FROM_WIN32(RegDeleteKey(clsidKey, REGISTRY_VERSION));
if (!SUCCEEDED(hResult)) {
return hResult;
}
hResult = HRESULT_FROM_WIN32(RegDeleteKey(hKey, stringCLSID));
if(!SUCCEEDED(hResult)) {
if (!SUCCEEDED(hResult)) {
return hResult;
}

View file

@ -12,14 +12,14 @@
* details.
*/
#ifndef OCOVERLAYREGISTRATIONHANDLER_H
#define OCOVERLAYREGISTRATIONHANDLER_H
#ifndef NCOVERLAYREGISTRATIONHANDLER_H
#define NCOVERLAYREGISTRATIONHANDLER_H
#pragma once
#include <windows.h>
class __declspec(dllexport) OCOverlayRegistrationHandler
class __declspec(dllexport) NCOverlayRegistrationHandler
{
public:
static HRESULT MakeRegistryEntries(const CLSID& clsid, PCWSTR fileType);

View file

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View file

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View file

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -1,11 +1,11 @@
add_library(OCUtil STATIC
add_library(NCUtil STATIC
CommunicationSocket.cpp
RemotePathChecker.cpp
StringUtil.cpp
OCUtil.rc
NCUtil.rc
)
target_include_directories(OCUtil
target_include_directories(NCUtil
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}"
)

View file

@ -13,7 +13,6 @@
*/
#include "CommunicationSocket.h"
#include "UtilConstants.h"
#include "StringUtil.h"
#include <iostream>

View file

@ -29,7 +29,7 @@
class __declspec(dllexport) RemotePathChecker {
public:
enum FileState {
// Order synced with OCOverlay
// Order synced with NCOverlay
StateError = 0,
StateOk, StateOkSWM,
StateSync,
@ -53,7 +53,7 @@ private:
std::queue<std::wstring> _pending;
std::unordered_map<std::wstring, FileState> _cache;
// The vector is const since it will be accessed from multiple threads through OCOverlay::IsMemberOf.
// The vector is const since it will be accessed from multiple threads through NCOverlay::IsMemberOf.
// Each modification needs to be made onto a copy and then atomically replaced in the shared_ptr.
std::shared_ptr<const std::vector<std::wstring>> _watchedDirectories;
bool _connected;

View file

@ -2,10 +2,10 @@
// This is the number that will end up in the version window of the DLLs.
// Increment this version before committing a new build if you are today's shell_integration build master.
#define OCEXT_BUILD_NUM 46
#define NCEXT_BUILD_NUM 47
#define STRINGIZE2(s) #s
#define STRINGIZE(s) STRINGIZE2(s)
#define OCEXT_VERSION 1,0,0,OCEXT_BUILD_NUM
#define OCEXT_VERSION_STRING STRINGIZE(OCEXT_VERSION)
#define NCEXT_VERSION 3,0,0,NCEXT_BUILD_NUM
#define NCEXT_VERSION_STRING STRINGIZE(NCEXT_VERSION)

View file

@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by OCContextMenu.rc
// Used by NCContextMenu.rc
// Next default values for new objects
//

View file

@ -1,17 +0,0 @@
add_library(OCContextMenu MODULE
dllmain.cpp
OCClientInterface.cpp
OCContextMenu.cpp
OCContextMenuFactory.cpp
OCContextMenuRegHandler.cpp
OCContextMenu.rc
OCContextMenu.def
)
target_link_libraries(OCContextMenu
OCUtil)
install(TARGETS OCContextMenu
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View file

@ -1,16 +0,0 @@
add_library(OCOverlays MODULE
DllMain.cpp
OCOverlay.cpp
OCOverlayFactory.cpp
OCOverlayRegistrationHandler.cpp
OCOverlay.rc
OCOverlays.def
)
target_link_libraries(OCOverlays
OCUtil)
install(TARGETS OCOverlays
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View file

@ -1,30 +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 PLUG_IN_SOCKET_ADDRESS "127.0.0.1"
#define BACK_SLASH L"\\"
#define CLOSE_BRACE L"]"
#define CLOSE_CURLY_BRACE L"}"
#define COLON L":"
#define COMMAND L"command"
#define COMMA L","
#define OPEN_BRACE L"["
#define OPEN_CURLY_BRACE L"{"
#define QUOTE L"\""
#define VALUE L"value"
#define REGISTRY_ROOT_KEY L"SOFTWARE\\ownCloud Inc\\ownCloud"
#define REGISTRY_ENABLE_OVERLAY L"EnableOverlay"
#define REGISTRY_FILTER_FOLDER L"FilterFolder"

View file

@ -14,8 +14,13 @@
#pragma once
// IMPORTANT: Keep this file in sync with WinShellExtConstants.wxi.in
// Context Menu
#define CONTEXT_MENU_GUID L"@WIN_SHELLEXT_CONTEXT_MENU_GUID@"
#define CONTEXT_MENU_REGKEY_NAME L"@APPLICATION_SHORTNAME@ContextMenuHandler"
#define CONTEXT_MENU_DESCRIPTION L"@APPLICATION_SHORTNAME@ context menu handler"
// Overlays
#define OVERLAY_GUID_ERROR L"@WIN_SHELLEXT_OVERLAY_GUID_ERROR@"
@ -23,3 +28,17 @@
#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@"
//
// Preceeding spaces are intended, two spaces to put us ahead of the competition :/
//
// There is a limit in Windows (oh wonder^^) so that only the first 15 extensions get invoked, this is why to use that dirty little trick to get ahead ;)
// See: https://docs.microsoft.com/en-us/windows/win32/shell/context-menu-handlers?redirectedfrom=MSDN#employing-the-verb-selection-model
//
#define OVERLAY_NAME_ERROR L" @APPLICATION_SHORTNAME@Error"
#define OVERLAY_NAME_OK L" @APPLICATION_SHORTNAME@OK"
#define OVERLAY_NAME_OK_SHARED L" @APPLICATION_SHORTNAME@OKShared"
#define OVERLAY_NAME_SYNC L" @APPLICATION_SHORTNAME@Sync"
#define OVERLAY_NAME_WARNING L" @APPLICATION_SHORTNAME@Warning"
#define OVERLAY_DESCRIPTION L"@APPLICATION_SHORTNAME@ overlay handler"

View file

@ -16,6 +16,10 @@
-->
<Include>
<!--
IMPORTANT: Keep this file in sync with WinShellExtConstants.h.in
-->
<!-- Context Menu -->
<?define ContextMenuGuid = "@WIN_SHELLEXT_CONTEXT_MENU_GUID@" ?>
<?define ContextMenuRegKeyName = "@APPLICATION_SHORTNAME@ContextMenuHandler" ?>
@ -29,7 +33,12 @@
<?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 :/ -->
<!--
Preceeding spaces are intended, two spaces to put us ahead of the competition :/
There is a limit in Windows (oh wonder^^) so that only the first 15 extensions get invoked, this is why to use that dirty little trick to get ahead ;)
See: https://docs.microsoft.com/en-us/windows/win32/shell/context-menu-handlers?redirectedfrom=MSDN#employing-the-verb-selection-model
-->
<?define OverlayNameError = " @APPLICATION_SHORTNAME@Error" ?>
<?define OverlayNameOK = " @APPLICATION_SHORTNAME@OK" ?>
<?define OverlayNameOKShared = " @APPLICATION_SHORTNAME@OKShared" ?>