mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-24 14:05:58 +03:00
0ba5df597f
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>
114 lines
2.5 KiB
C
114 lines
2.5 KiB
C
#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, nullptr,
|
|
nullptr, nullptr, &ftWrite);
|
|
|
|
if (lResult == ERROR_SUCCESS)
|
|
{
|
|
do {
|
|
|
|
StringCchCopy(lpEnd, MAX_PATH * 2, szName);
|
|
|
|
if (RegDelnodeRecurse(hKeyRoot, lpSubKey) != ERROR_SUCCESS) {
|
|
break;
|
|
}
|
|
|
|
dwSize = MAX_PATH;
|
|
|
|
lResult = RegEnumKeyEx(hKey, 0, szName, &dwSize, nullptr,
|
|
nullptr, nullptr, &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);
|
|
|
|
}
|