Commit b3130b9f authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Add new value support. Misc improvements and cleanups.

parent ccd74968
...@@ -218,7 +218,8 @@ BEGIN ...@@ -218,7 +218,8 @@ BEGIN
IDS_TOO_BIG_VALUE "Value is too big (%ld)" IDS_TOO_BIG_VALUE "Value is too big (%ld)"
IDS_DELETE_BOX_TITLE "Confirm Value Delete" IDS_DELETE_BOX_TITLE "Confirm Value Delete"
IDS_DELETE_BOX_TEXT "Are you sure you want to delete value '%s'?" IDS_DELETE_BOX_TEXT "Are you sure you want to delete value '%s'?"
IDS_NEWKEY "New Key" IDS_NEWKEY "New Key #%d"
IDS_NEWVALUE "New Value #%d"
END END
/*****************************************************************/ /*****************************************************************/
......
...@@ -127,36 +127,31 @@ INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l ...@@ -127,36 +127,31 @@ INT_PTR CALLBACK modify_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l
BOOL CreateKey(HKEY hKey) BOOL CreateKey(HKEY hKey)
{ {
LONG lRet; LONG lRet = ERROR_SUCCESS;
HKEY retKey; HKEY retKey;
TCHAR keyName[32]; TCHAR keyName[32];
static TCHAR newKey[28] = ""; /* should be max keyName len - 4 */ TCHAR newKey[COUNT_OF(keyName) - 4];
HINSTANCE hInstance; int keyNum;
unsigned int keyNum = 1;
/* If we have illegal parameter return with operation failure */ /* If we have illegal parameter return with operation failure */
if (!hKey) return FALSE; if (!hKey) return FALSE;
/* Load localized "new key" string. -4 is because we need max 4 character if (!LoadString(GetModuleHandle(0), IDS_NEWKEY, newKey, COUNT_OF(newKey))) return FALSE;
to numbering. */
if (newKey[0] == 0) {
hInstance = GetModuleHandle(0);
if (!LoadString(hInstance, IDS_NEWKEY, newKey, COUNT_OF(newKey)))
lstrcpy(newKey, "New Key");
}
lstrcpy(keyName, newKey);
/* try to find out a name for the newly create key. /* try to find out a name for the newly create key (max 100 times) */
We try it max 100 times. */ for (keyNum = 1; keyNum < 100; keyNum++) {
lRet = RegOpenKey(hKey, keyName, &retKey); wsprintf(keyName, newKey, keyNum);
while (lRet == ERROR_SUCCESS && keyNum < 100) {
wsprintf(keyName, "%s %u", newKey, ++keyNum);
lRet = RegOpenKey(hKey, keyName, &retKey); lRet = RegOpenKey(hKey, keyName, &retKey);
if (lRet != ERROR_SUCCESS) break;
RegCloseKey(retKey);
} }
if (lRet == ERROR_SUCCESS) return FALSE; if (lRet == ERROR_SUCCESS) return FALSE;
lRet = RegCreateKey(hKey, keyName, &retKey); lRet = RegCreateKey(hKey, keyName, &retKey);
return lRet == ERROR_SUCCESS; if (lRet != ERROR_SUCCESS) return FALSE;
RegCloseKey(retKey);
return TRUE;
} }
BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName) BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
...@@ -226,3 +221,30 @@ BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName) ...@@ -226,3 +221,30 @@ BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName)
} }
return lRet == ERROR_SUCCESS; return lRet == ERROR_SUCCESS;
} }
BOOL CreateValue(HWND hwnd, HKEY hKey, DWORD valueType)
{
LONG lRet = ERROR_SUCCESS;
TCHAR valueName[32];
TCHAR newValue[COUNT_OF(valueName) - 4];
DWORD valueDword = 0;
int valueNum;
/* If we have illegal parameter return with operation failure */
if (!hKey) return FALSE;
if (!LoadString(GetModuleHandle(0), IDS_NEWVALUE, newValue, COUNT_OF(newValue))) return FALSE;
/* try to find out a name for the newly create key (max 100 times) */
for (valueNum = 1; valueNum < 100; valueNum++) {
wsprintf(valueName, newValue, valueNum);
lRet = RegQueryValueEx(hKey, valueName, 0, 0, 0, 0);
if (lRet != ERROR_SUCCESS) break;
}
if (lRet == ERROR_SUCCESS) return FALSE;
lRet = RegSetValueEx(hKey, valueName, 0, valueType, (BYTE*)&valueDword, sizeof(DWORD));
if (lRet != ERROR_SUCCESS) return FALSE;
return TRUE;
}
...@@ -440,6 +440,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -440,6 +440,7 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
LPCTSTR valueName; LPCTSTR valueName;
BOOL result = TRUE; BOOL result = TRUE;
LONG lRet; LONG lRet;
DWORD valueType;
if ((keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot))) { if ((keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot))) {
lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_ALL_ACCESS, &hKey); lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_ALL_ACCESS, &hKey);
...@@ -475,6 +476,19 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) ...@@ -475,6 +476,19 @@ static BOOL _CmdWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case ID_EDIT_NEW_KEY: case ID_EDIT_NEW_KEY:
CreateKey(hKey); CreateKey(hKey);
break; break;
case ID_EDIT_NEW_STRINGVALUE:
valueType = REG_SZ;
goto create_value;
case ID_EDIT_NEW_BINARYVALUE:
valueType = REG_BINARY;
goto create_value;
case ID_EDIT_NEW_DWORDVALUE:
valueType = REG_DWORD;
/* fall through */
create_value:
if (CreateValue(hWnd, hKey, valueType))
RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath);
break;
case ID_REGISTRY_PRINTERSETUP: case ID_REGISTRY_PRINTERSETUP:
/*PRINTDLG pd;*/ /*PRINTDLG pd;*/
/*PrintDlg(&pd);*/ /*PrintDlg(&pd);*/
......
...@@ -94,6 +94,7 @@ extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey); ...@@ -94,6 +94,7 @@ extern LPCTSTR GetItemPath(HWND hwndTV, HTREEITEM hItem, HKEY* phRootKey);
/* edit.c */ /* edit.c */
extern BOOL CreateKey(HKEY hKey); extern BOOL CreateKey(HKEY hKey);
extern BOOL CreateValue(HWND hwnd, HKEY hKey, DWORD valueType);
extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName); extern BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName); extern BOOL DeleteValue(HWND hwnd, HKEY hKey, LPCTSTR valueName);
......
...@@ -113,6 +113,7 @@ ...@@ -113,6 +113,7 @@
#define IDC_DWORD_HEX 32853 #define IDC_DWORD_HEX 32853
#define IDC_DWORD_DEC 32854 #define IDC_DWORD_DEC 32854
#define IDS_NEWKEY 32860 #define IDS_NEWKEY 32860
#define IDS_NEWVALUE 32861
#define IDD_EDIT_STRING 2000 #define IDD_EDIT_STRING 2000
#define IDC_VALUE_NAME 2001 #define IDC_VALUE_NAME 2001
......
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