Skip to content

Commit 26adfda

Browse files
committed
[REGEDIT]
- Katayama Hirofumi: Unicodify regedit, add support for import/export of v5 reg files. Based on Wine regedit. svn path=/trunk/; revision=48933
1 parent 2191371 commit 26adfda

File tree

11 files changed

+1193
-1133
lines changed

11 files changed

+1193
-1133
lines changed

reactos/base/applications/regedit/childwnd.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
227227
bFound = FALSE;
228228

229229
/* Check default key */
230-
if (RegQueryStringValue(hRootKey, pszKeyPath, NULL,
231-
szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
230+
if (QueryStringValue(hRootKey, pszKeyPath, NULL,
231+
szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS)
232232
{
233233
/* Sanity check this key; it cannot be empty, nor can it be a
234234
* loop back */
@@ -259,8 +259,8 @@ static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions
259259
/* Check CLSID key */
260260
if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS)
261261
{
262-
if (RegQueryStringValue(hSubKey, TEXT("CLSID"), NULL,
263-
szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
262+
if (QueryStringValue(hSubKey, TEXT("CLSID"), NULL, szBuffer,
263+
COUNT_OF(szBuffer)) == ERROR_SUCCESS)
264264
{
265265
lstrcpyn(pszSuggestions, TEXT("HKCR\\CLSID\\"), (int) iSuggestionsLength);
266266
i = _tcslen(pszSuggestions);
@@ -535,8 +535,8 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa
535535
}
536536
else
537537
{
538-
if (RegRenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS)
539-
lResult = FALSE;
538+
if (RenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS)
539+
lResult = FALSE;
540540
}
541541
return lResult;
542542
}

reactos/base/applications/regedit/edit.c

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,91 @@ BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName, BOOL EditBin)
702702
return result;
703703
}
704704

705+
static LONG CopyKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey)
706+
{
707+
LONG lResult;
708+
DWORD dwDisposition;
709+
HKEY hDestSubKey = NULL;
710+
HKEY hSrcSubKey = NULL;
711+
DWORD dwIndex, dwType, cbName, cbData;
712+
TCHAR szSubKey[256];
713+
TCHAR szValueName[256];
714+
BYTE szValueData[512];
715+
716+
FILETIME ft;
717+
718+
/* open the source subkey, if specified */
719+
if (lpSrcSubKey)
720+
{
721+
lResult = RegOpenKeyEx(hSrcKey, lpSrcSubKey, 0, KEY_ALL_ACCESS, &hSrcSubKey);
722+
if (lResult)
723+
goto done;
724+
hSrcKey = hSrcSubKey;
725+
}
726+
727+
/* create the destination subkey */
728+
lResult = RegCreateKeyEx(hDestKey, lpDestSubKey, 0, NULL, 0, KEY_WRITE, NULL,
729+
&hDestSubKey, &dwDisposition);
730+
if (lResult)
731+
goto done;
732+
733+
/* copy all subkeys */
734+
dwIndex = 0;
735+
do
736+
{
737+
cbName = sizeof(szSubKey) / sizeof(szSubKey[0]);
738+
lResult = RegEnumKeyEx(hSrcKey, dwIndex++, szSubKey, &cbName, NULL, NULL, NULL, &ft);
739+
if (lResult == ERROR_SUCCESS)
740+
{
741+
lResult = CopyKey(hDestSubKey, szSubKey, hSrcKey, szSubKey);
742+
if (lResult)
743+
goto done;
744+
}
745+
}
746+
while(lResult == ERROR_SUCCESS);
747+
748+
/* copy all subvalues */
749+
dwIndex = 0;
750+
do
751+
{
752+
cbName = sizeof(szValueName) / sizeof(szValueName[0]);
753+
cbData = sizeof(szValueData) / sizeof(szValueData[0]);
754+
lResult = RegEnumValue(hSrcKey, dwIndex++, szValueName, &cbName, NULL, &dwType, szValueData, &cbData);
755+
if (lResult == ERROR_SUCCESS)
756+
{
757+
lResult = RegSetValueEx(hDestSubKey, szValueName, 0, dwType, szValueData, cbData);
758+
if (lResult)
759+
goto done;
760+
}
761+
}
762+
while(lResult == ERROR_SUCCESS);
763+
764+
lResult = ERROR_SUCCESS;
765+
766+
done:
767+
if (hSrcSubKey)
768+
RegCloseKey(hSrcSubKey);
769+
if (hDestSubKey)
770+
RegCloseKey(hDestSubKey);
771+
if (lResult != ERROR_SUCCESS)
772+
SHDeleteKey(hDestKey, lpDestSubKey);
773+
return lResult;
774+
}
775+
776+
static LONG MoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey)
777+
{
778+
LONG lResult;
779+
780+
if (!lpSrcSubKey)
781+
return ERROR_INVALID_FUNCTION;
782+
783+
lResult = CopyKey(hDestKey, lpDestSubKey, hSrcKey, lpSrcSubKey);
784+
if (lResult == ERROR_SUCCESS)
785+
SHDeleteKey(hSrcKey, lpSrcSubKey);
786+
787+
return lResult;
788+
}
789+
705790
BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
706791
{
707792
TCHAR msg[128], caption[128];
@@ -732,3 +817,128 @@ BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath)
732817
RegCloseKey(hKey);
733818
return result;
734819
}
820+
821+
LONG RenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName)
822+
{
823+
LPCTSTR s;
824+
LPTSTR lpNewSubKey = NULL;
825+
LONG Ret = 0;
826+
827+
if (!lpSubKey)
828+
return Ret;
829+
830+
s = _tcsrchr(lpSubKey, _T('\\'));
831+
if (s)
832+
{
833+
s++;
834+
lpNewSubKey = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (s - lpSubKey + _tcslen(lpNewName) + 1) * sizeof(TCHAR));
835+
if (lpNewSubKey != NULL)
836+
{
837+
memcpy(lpNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(TCHAR));
838+
lstrcpy(lpNewSubKey + (s - lpSubKey), lpNewName);
839+
lpNewName = lpNewSubKey;
840+
}
841+
else
842+
return ERROR_NOT_ENOUGH_MEMORY;
843+
}
844+
845+
Ret = MoveKey(hKey, lpNewName, hKey, lpSubKey);
846+
847+
if (lpNewSubKey)
848+
{
849+
HeapFree(GetProcessHeap(), 0, lpNewSubKey);
850+
}
851+
return Ret;
852+
}
853+
854+
LONG RenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lpSrcValue)
855+
{
856+
LONG lResult;
857+
HKEY hSubKey = NULL;
858+
DWORD dwType, cbData;
859+
BYTE data[512];
860+
861+
if (lpSubKey)
862+
{
863+
lResult = RegOpenKey(hKey, lpSubKey, &hSubKey);
864+
if (lResult != ERROR_SUCCESS)
865+
goto done;
866+
hKey = hSubKey;
867+
}
868+
869+
cbData = sizeof(data);
870+
lResult = RegQueryValueEx(hKey, lpSrcValue, NULL, &dwType, data, &cbData);
871+
if (lResult != ERROR_SUCCESS)
872+
goto done;
873+
874+
lResult = RegSetValueEx(hKey, lpDestValue, 0, dwType, data, cbData);
875+
if (lResult != ERROR_SUCCESS)
876+
goto done;
877+
878+
RegDeleteValue(hKey, lpSrcValue);
879+
880+
done:
881+
if (hSubKey)
882+
RegCloseKey(hSubKey);
883+
return lResult;
884+
}
885+
886+
LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen)
887+
{
888+
LONG lResult;
889+
HKEY hSubKey = NULL;
890+
DWORD cbData, dwType;
891+
892+
if (lpSubKey)
893+
{
894+
lResult = RegOpenKey(hKey, lpSubKey, &hSubKey);
895+
if (lResult != ERROR_SUCCESS)
896+
goto done;
897+
hKey = hSubKey;
898+
}
899+
900+
cbData = (dwBufferLen - 1) * sizeof(*pszBuffer);
901+
lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE) pszBuffer, &cbData);
902+
if (lResult != ERROR_SUCCESS)
903+
goto done;
904+
if (dwType != REG_SZ)
905+
{
906+
lResult = -1;
907+
goto done;
908+
}
909+
910+
pszBuffer[cbData / sizeof(*pszBuffer)] = _T('\0');
911+
912+
done:
913+
if (lResult != ERROR_SUCCESS)
914+
pszBuffer[0] = _T('\0');
915+
if (hSubKey)
916+
RegCloseKey(hSubKey);
917+
return lResult;
918+
}
919+
920+
BOOL GetKeyName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey)
921+
{
922+
LPCTSTR pszRootKey;
923+
924+
if (hRootKey == HKEY_CLASSES_ROOT)
925+
pszRootKey = TEXT("HKEY_CLASSES_ROOT");
926+
else if (hRootKey == HKEY_CURRENT_USER)
927+
pszRootKey = TEXT("HKEY_CURRENT_USER");
928+
else if (hRootKey == HKEY_LOCAL_MACHINE)
929+
pszRootKey = TEXT("HKEY_LOCAL_MACHINE");
930+
else if (hRootKey == HKEY_USERS)
931+
pszRootKey = TEXT("HKEY_USERS");
932+
else if (hRootKey == HKEY_CURRENT_CONFIG)
933+
pszRootKey = TEXT("HKEY_CURRENT_CONFIG");
934+
else if (hRootKey == HKEY_DYN_DATA)
935+
pszRootKey = TEXT("HKEY_DYN_DATA");
936+
else
937+
return FALSE;
938+
939+
if (lpSubKey[0])
940+
_sntprintf(pszDest, iDestLength, TEXT("%s\\%s"), pszRootKey, lpSubKey);
941+
else
942+
_sntprintf(pszDest, iDestLength, TEXT("%s"), pszRootKey);
943+
return TRUE;
944+
}

reactos/base/applications/regedit/find.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919

2020
#include <regedit.h>
2121

22+
#define RSF_WHOLESTRING 0x00000001
23+
#define RSF_LOOKATKEYS 0x00000002
24+
#define RSF_LOOKATVALUES 0x00000004
25+
#define RSF_LOOKATDATA 0x00000008
26+
#define RSF_MATCHCASE 0x00010000
27+
2228
static TCHAR s_szFindWhat[256];
2329
static const TCHAR s_szFindFlags[] = _T("FindFlags");
2430
static const TCHAR s_szFindFlagsR[] = _T("FindFlagsReactOS");
@@ -677,7 +683,7 @@ BOOL FindNext(HWND hWnd)
677683

678684
if (fSuccess)
679685
{
680-
RegKeyGetName(szFullKey, COUNT_OF(szFullKey), hKeyRoot, pszFoundSubKey);
686+
GetKeyName(szFullKey, COUNT_OF(szFullKey), hKeyRoot, pszFoundSubKey);
681687
SelectNode(g_pChildWnd->hTreeWnd, szFullKey);
682688
SetValueName(g_pChildWnd->hListWnd, pszFoundValueName);
683689
free(pszFoundSubKey);

0 commit comments

Comments
 (0)