Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJocelyn Turcotte <jturcotte@woboq.com>2015-02-04 21:55:15 +0300
committerJocelyn Turcotte <turcotte.j@gmail.com>2015-02-05 17:15:05 +0300
commitaf0001a149a9e243ff079703fd96697bd539e066 (patch)
tree477e34feb191530bcbef2194af3917143e2fc380 /shell_integration
parent2debd5a1984efeb7a06d50daea30ed9c720b0d1d (diff)
[shell_integration] Remove the usage of Win32 APIs not available on XP
Diffstat (limited to 'shell_integration')
-rw-r--r--shell_integration/windows/OCContextMenu/OCContextMenu.vcxproj1
-rw-r--r--shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp5
-rw-r--r--shell_integration/windows/OCContextMenu/RegDelnode.h114
-rw-r--r--shell_integration/windows/OCContextMenu/targetver.h2
-rw-r--r--shell_integration/windows/OCOverlays/stdafx.h2
-rw-r--r--shell_integration/windows/OCUtil/stdafx.h2
6 files changed, 124 insertions, 2 deletions
diff --git a/shell_integration/windows/OCContextMenu/OCContextMenu.vcxproj b/shell_integration/windows/OCContextMenu/OCContextMenu.vcxproj
index 535ae5282..3b9bbcbb3 100644
--- a/shell_integration/windows/OCContextMenu/OCContextMenu.vcxproj
+++ b/shell_integration/windows/OCContextMenu/OCContextMenu.vcxproj
@@ -146,6 +146,7 @@
<ClInclude Include="OCContextMenuFactory.h" />
<ClInclude Include="OCContextMenuRegHandler.h" />
<ClInclude Include="OCContextMenu.h" />
+ <ClInclude Include="RegDelnode.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
diff --git a/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp b/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp
index 20af1245e..126816d91 100644
--- a/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp
+++ b/shell_integration/windows/OCContextMenu/OCContextMenuRegHandler.cpp
@@ -15,6 +15,7 @@
#include "stdafx.h"
#include "OCContextMenuRegHandler.h"
+#include "RegDelnode.h"
#include <strsafe.h>
#include <objbase.h>
@@ -125,7 +126,7 @@ HRESULT OCContextMenuRegHandler::UnregisterInprocServer(const CLSID& clsid)
hr = StringCchPrintf(szSubkey, ARRAYSIZE(szSubkey), L"CLSID\\%s", szCLSID);
if (SUCCEEDED(hr))
{
- hr = HRESULT_FROM_WIN32(RegDeleteTree(HKEY_CLASSES_ROOT, szSubkey));
+ hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey));
}
return hr;
@@ -210,7 +211,7 @@ HRESULT OCContextMenuRegHandler::UnregisterShellExtContextMenuHandler(
L"%s\\shellex\\ContextMenuHandlers\\%s", pszFileType, pszFriendlyName);
if (SUCCEEDED(hr))
{
- hr = HRESULT_FROM_WIN32(RegDeleteTree(HKEY_CLASSES_ROOT, szSubkey));
+ hr = HRESULT_FROM_WIN32(RegDelnode(HKEY_CLASSES_ROOT, szSubkey));
}
return hr;
diff --git a/shell_integration/windows/OCContextMenu/RegDelnode.h b/shell_integration/windows/OCContextMenu/RegDelnode.h
new file mode 100644
index 000000000..28b375dda
--- /dev/null
+++ b/shell_integration/windows/OCContextMenu/RegDelnode.h
@@ -0,0 +1,114 @@
+#pragma once
+
+#include <windows.h>
+#include <stdio.h>
+#include <strsafe.h>
+
+// Stolen from the "Deleting a Key with Subkeys" example to replace
+// RegDeleteTree which isn't available on WinXP.
+// https://msdn.microsoft.com/en-us/library/ms724235(VS.85).aspx
+
+//*************************************************************
+//
+// RegDelnodeRecurse()
+//
+// Purpose: Deletes a registry key and all its subkeys / values.
+//
+// Parameters: hKeyRoot - Root key
+// lpSubKey - SubKey to delete
+//
+// Return: TRUE if successful.
+// FALSE if an error occurs.
+//
+//*************************************************************
+
+HRESULT RegDelnodeRecurse(HKEY hKeyRoot, LPTSTR lpSubKey)
+{
+ LPTSTR lpEnd;
+ LONG lResult;
+ DWORD dwSize;
+ TCHAR szName[MAX_PATH];
+ HKEY hKey;
+ FILETIME ftWrite;
+
+ // First, see if we can delete the key without having
+ // to recurse.
+
+ lResult = RegDeleteKey(hKeyRoot, lpSubKey);
+
+ if (lResult == ERROR_SUCCESS)
+ return lResult;
+
+ lResult = RegOpenKeyEx(hKeyRoot, lpSubKey, 0, KEY_READ, &hKey);
+
+ if (lResult != ERROR_SUCCESS)
+ return lResult;
+
+ // Check for an ending slash and add one if it is missing.
+
+ lpEnd = lpSubKey + lstrlen(lpSubKey);
+
+ if (*(lpEnd - 1) != TEXT('\\'))
+ {
+ *lpEnd = TEXT('\\');
+ lpEnd++;
+ *lpEnd = TEXT('\0');
+ }
+
+ // Enumerate the keys
+
+ dwSize = MAX_PATH;
+ lResult = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL,
+ NULL, NULL, &ftWrite);
+
+ if (lResult == ERROR_SUCCESS)
+ {
+ do {
+
+ StringCchCopy(lpEnd, MAX_PATH * 2, szName);
+
+ if (!RegDelnodeRecurse(hKeyRoot, lpSubKey)) {
+ break;
+ }
+
+ dwSize = MAX_PATH;
+
+ lResult = RegEnumKeyEx(hKey, 0, szName, &dwSize, NULL,
+ NULL, NULL, &ftWrite);
+
+ } while (lResult == ERROR_SUCCESS);
+ }
+
+ lpEnd--;
+ *lpEnd = TEXT('\0');
+
+ RegCloseKey(hKey);
+
+ // Try again to delete the key.
+
+ lResult = RegDeleteKey(hKeyRoot, lpSubKey);
+ return lResult;
+}
+
+//*************************************************************
+//
+// RegDelnode()
+//
+// Purpose: Deletes a registry key and all its subkeys / values.
+//
+// Parameters: hKeyRoot - Root key
+// lpSubKey - SubKey to delete
+//
+// Return: TRUE if successful.
+// FALSE if an error occurs.
+//
+//*************************************************************
+
+HRESULT RegDelnode(HKEY hKeyRoot, LPTSTR lpSubKey)
+{
+ TCHAR szDelKey[MAX_PATH * 2];
+
+ StringCchCopy(szDelKey, MAX_PATH * 2, lpSubKey);
+ return RegDelnodeRecurse(hKeyRoot, szDelKey);
+
+}
diff --git a/shell_integration/windows/OCContextMenu/targetver.h b/shell_integration/windows/OCContextMenu/targetver.h
index 87c0086de..ce2bc7493 100644
--- a/shell_integration/windows/OCContextMenu/targetver.h
+++ b/shell_integration/windows/OCContextMenu/targetver.h
@@ -5,4 +5,6 @@
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
+#define WINVER 0x0501
+#define _WIN32_WINNT 0x0501
#include <SDKDDKVer.h>
diff --git a/shell_integration/windows/OCOverlays/stdafx.h b/shell_integration/windows/OCOverlays/stdafx.h
index 81121202b..3d94fc641 100644
--- a/shell_integration/windows/OCOverlays/stdafx.h
+++ b/shell_integration/windows/OCOverlays/stdafx.h
@@ -13,6 +13,8 @@
*/
#define WIN32_LEAN_AND_MEAN
+#define WINVER 0x0501
+#define _WIN32_WINNT 0x0501
#include "CommunicationSocket.h"
#include "RegistryUtil.h"
diff --git a/shell_integration/windows/OCUtil/stdafx.h b/shell_integration/windows/OCUtil/stdafx.h
index e468ce291..e46161544 100644
--- a/shell_integration/windows/OCUtil/stdafx.h
+++ b/shell_integration/windows/OCUtil/stdafx.h
@@ -1,5 +1,7 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
+#define WINVER 0x0501
+#define _WIN32_WINNT 0x0501
#include <windows.h>