Commit 3e3ed6f4 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

shlwapi: Forward SHCopyKey() to shcore.

parent 454264f0
......@@ -1994,139 +1994,6 @@ HKEY WINAPI SHRegDuplicateHKey(HKEY hKey)
return newKey;
}
/*************************************************************************
* SHCopyKeyA [SHLWAPI.@]
*
* Copy a key and its values/sub keys to another location.
*
* PARAMS
* hKeySrc [I] Source key to copy from
* lpszSrcSubKey [I] Sub key under hKeySrc, or NULL to use hKeySrc directly
* hKeyDst [I] Destination key
* dwReserved [I] Reserved, must be 0
*
* RETURNS
* Success: ERROR_SUCCESS. The key is copied to the destination key.
* Failure: A standard windows error code.
*
* NOTES
* If hKeyDst is a key under hKeySrc, this function will misbehave
* (It will loop until out of stack, or the registry is full). This
* bug is present in Win32 also.
*/
DWORD WINAPI SHCopyKeyA(HKEY hKeySrc, LPCSTR lpszSrcSubKey, HKEY hKeyDst, DWORD dwReserved)
{
WCHAR szSubKeyW[MAX_PATH];
TRACE("(hkey=%p,%s,%p08x,%d)\n", hKeySrc, debugstr_a(lpszSrcSubKey), hKeyDst, dwReserved);
if (lpszSrcSubKey)
MultiByteToWideChar(CP_ACP, 0, lpszSrcSubKey, -1, szSubKeyW, MAX_PATH);
return SHCopyKeyW(hKeySrc, lpszSrcSubKey ? szSubKeyW : NULL, hKeyDst, dwReserved);
}
/*************************************************************************
* SHCopyKeyW [SHLWAPI.@]
*
* See SHCopyKeyA.
*/
DWORD WINAPI SHCopyKeyW(HKEY hKeySrc, LPCWSTR lpszSrcSubKey, HKEY hKeyDst, DWORD dwReserved)
{
DWORD dwKeyCount = 0, dwValueCount = 0, dwMaxKeyLen = 0;
DWORD dwMaxValueLen = 0, dwMaxDataLen = 0, i;
BYTE buff[1024];
LPVOID lpBuff = buff;
WCHAR szName[MAX_PATH], *lpszName = szName;
DWORD dwRet = S_OK;
TRACE("hkey=%p,%s,%p08x,%d)\n", hKeySrc, debugstr_w(lpszSrcSubKey), hKeyDst, dwReserved);
if(!hKeyDst || !hKeySrc)
dwRet = ERROR_INVALID_PARAMETER;
else
{
/* Open source key */
if(lpszSrcSubKey)
dwRet = RegOpenKeyExW(hKeySrc, lpszSrcSubKey, 0, KEY_ALL_ACCESS, &hKeySrc);
if(dwRet)
hKeyDst = NULL; /* Don't close this key since we didn't open it */
else
{
/* Get details about sub keys and values */
dwRet = RegQueryInfoKeyW(hKeySrc, NULL, NULL, NULL, &dwKeyCount, &dwMaxKeyLen,
NULL, &dwValueCount, &dwMaxValueLen, &dwMaxDataLen,
NULL, NULL);
if(!dwRet)
{
if (dwMaxValueLen > dwMaxKeyLen)
dwMaxKeyLen = dwMaxValueLen; /* Get max size for key/value names */
if (dwMaxKeyLen++ > MAX_PATH - 1)
lpszName = HeapAlloc(GetProcessHeap(), 0, dwMaxKeyLen * sizeof(WCHAR));
if (dwMaxDataLen > sizeof(buff))
lpBuff = HeapAlloc(GetProcessHeap(), 0, dwMaxDataLen);
if (!lpszName || !lpBuff)
dwRet = ERROR_NOT_ENOUGH_MEMORY;
}
}
}
/* Copy all the sub keys */
for(i = 0; i < dwKeyCount && !dwRet; i++)
{
HKEY hSubKeySrc, hSubKeyDst;
DWORD dwSize = dwMaxKeyLen;
dwRet = RegEnumKeyExW(hKeySrc, i, lpszName, &dwSize, NULL, NULL, NULL, NULL);
if(!dwRet)
{
/* Open source sub key */
dwRet = RegOpenKeyExW(hKeySrc, lpszName, 0, KEY_READ, &hSubKeySrc);
if(!dwRet)
{
/* Create destination sub key */
dwRet = RegCreateKeyW(hKeyDst, lpszName, &hSubKeyDst);
if(!dwRet)
{
/* Recursively copy keys and values from the sub key */
dwRet = SHCopyKeyW(hSubKeySrc, NULL, hSubKeyDst, 0);
RegCloseKey(hSubKeyDst);
}
}
RegCloseKey(hSubKeySrc);
}
}
/* Copy all the values in this key */
for (i = 0; i < dwValueCount && !dwRet; i++)
{
DWORD dwNameSize = dwMaxKeyLen, dwType, dwLen = dwMaxDataLen;
dwRet = RegEnumValueW(hKeySrc, i, lpszName, &dwNameSize, NULL, &dwType, lpBuff, &dwLen);
if (!dwRet)
dwRet = SHSetValueW(hKeyDst, NULL, lpszName, dwType, lpBuff, dwLen);
}
/* Free buffers if allocated */
if (lpszName != szName)
HeapFree(GetProcessHeap(), 0, lpszName);
if (lpBuff != buff)
HeapFree(GetProcessHeap(), 0, lpBuff);
if (lpszSrcSubKey && hKeyDst)
RegCloseKey(hKeyDst);
return dwRet;
}
/*
* The following functions are ORDINAL ONLY:
*/
......
......@@ -680,8 +680,8 @@
@ stdcall PathUnquoteSpacesA (str)
@ stdcall PathUnquoteSpacesW (wstr)
@ stdcall SHAutoComplete(ptr long)
@ stdcall SHCopyKeyA(long str long long)
@ stdcall SHCopyKeyW(long wstr long long)
@ stdcall SHCopyKeyA(long str long long) shcore.SHCopyKeyA
@ stdcall SHCopyKeyW(long wstr long long) shcore.SHCopyKeyW
@ stdcall SHCreateShellPalette(long)
@ stdcall SHCreateStreamOnFileA(str long ptr) shcore.SHCreateStreamOnFileA
@ stdcall SHCreateStreamOnFileEx(wstr long long long ptr ptr) shcore.SHCreateStreamOnFileEx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment