Aric Stewart : reg.exe: Implement DELETE.
Alexandre Julliard
julliard at winehq.org
Wed Jan 28 08:03:25 CST 2009
Module: wine
Branch: master
Commit: 45824821ff4d68459dc31219e820f2a53466f701
URL: http://source.winehq.org/git/wine.git/?a=commit;h=45824821ff4d68459dc31219e820f2a53466f701
Author: Aric Stewart <aric at codeweavers.com>
Date: Wed Jan 28 07:14:18 2009 -0600
reg.exe: Implement DELETE.
---
programs/reg/En.rc | 1 +
programs/reg/reg.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++-
programs/reg/reg.h | 1 +
3 files changed, 121 insertions(+), 1 deletions(-)
diff --git a/programs/reg/En.rc b/programs/reg/En.rc
index 5a3945a..e713416 100644
--- a/programs/reg/En.rc
+++ b/programs/reg/En.rc
@@ -31,4 +31,5 @@ STRINGTABLE
STRING_INVALID_KEY, "Error: Invalid key name\n"
STRING_INVALID_CMDLINE, "Error: Invalid command line parameters\n"
STRING_NO_REMOTE, "Error: Unable to add keys to remote machine\n"
+ STRING_CANNOT_FIND, "Error: The system was unable to find the specified registry key or value\n"
}
diff --git a/programs/reg/reg.c b/programs/reg/reg.c
index ff87a2d..4a278d4 100644
--- a/programs/reg/reg.c
+++ b/programs/reg/reg.c
@@ -209,11 +209,129 @@ static int reg_add(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
static int reg_delete(WCHAR *key_name, WCHAR *value_name, BOOL value_empty,
BOOL value_all, BOOL force)
{
- static const WCHAR stubW[] = {'S','T','U','B',' ','D','E','L','E','T','E',
+ LPWSTR p;
+ HKEY root,subkey;
+
+ static const WCHAR stubW[] = {'D','E','L','E','T','E',
' ','-',' ','%','s',' ','%','s',' ','%','d',' ','%','d',' ','%','d','\n'
,0};
reg_printfW(stubW, key_name, value_name, value_empty, value_all, force);
+ if (key_name[0]=='\\' && key_name[1]=='\\')
+ {
+ reg_message(STRING_NO_REMOTE);
+ return 0;
+ }
+
+ p = strchrW(key_name,'\\');
+ if (!p)
+ {
+ reg_message(STRING_INVALID_KEY);
+ return 0;
+ }
+ p++;
+
+ root = get_rootkey(key_name);
+ if (!root)
+ {
+ reg_message(STRING_INVALID_KEY);
+ return 0;
+ }
+
+ if (value_name && value_empty)
+ {
+ RegCloseKey(subkey);
+ reg_message(STRING_INVALID_CMDLINE);
+ return 0;
+ }
+
+ if (value_empty && value_all)
+ {
+ RegCloseKey(subkey);
+ reg_message(STRING_INVALID_CMDLINE);
+ return 0;
+ }
+
+ if (!force)
+ {
+ /* FIXME: Prompt for delete */
+ }
+
+ if (!value_name)
+ {
+ if (RegDeleteTreeW(root,p)!=ERROR_SUCCESS)
+ {
+ reg_message(STRING_CANNOT_FIND);
+ return 0;
+ }
+ reg_message(STRING_SUCCESS);
+ return 1;
+ }
+
+ if(RegOpenKeyW(root,p,&subkey)!=ERROR_SUCCESS)
+ {
+ reg_message(STRING_CANNOT_FIND);
+ return 0;
+ }
+
+ if (value_all)
+ {
+ LPWSTR szValue;
+ DWORD maxValue;
+ DWORD count;
+ LONG rc;
+
+ if (value_name)
+ {
+ RegCloseKey(subkey);
+ reg_message(STRING_INVALID_CMDLINE);
+ return 0;
+ }
+
+ rc = RegQueryInfoKeyW(subkey, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ &maxValue, NULL, NULL, NULL);
+ if (rc != ERROR_SUCCESS)
+ {
+ /* FIXME: failure */
+ RegCloseKey(subkey);
+ return 0;
+ }
+ maxValue++;
+ szValue = HeapAlloc(GetProcessHeap(),0,maxValue*sizeof(WCHAR));
+
+ while (1)
+ {
+ count = maxValue;
+ rc = RegEnumValueW(subkey, 0, value_name, &count, NULL, NULL, NULL, NULL);
+ if (rc == ERROR_SUCCESS)
+ {
+ rc = RegDeleteValueW(subkey,value_name);
+ if (rc != ERROR_SUCCESS)
+ break;
+ }
+ else break;
+ }
+ if (rc != ERROR_SUCCESS)
+ {
+ /* FIXME delete failed */
+ }
+ }
+ else if (value_name)
+ {
+ if (RegDeleteValueW(subkey,value_name) != ERROR_SUCCESS)
+ {
+ RegCloseKey(subkey);
+ reg_message(STRING_CANNOT_FIND);
+ return 0;
+ }
+ }
+ else if (value_empty)
+ {
+ RegSetValueExW(subkey,NULL,0,REG_SZ,NULL,0);
+ }
+
+ RegCloseKey(subkey);
+ reg_message(STRING_SUCCESS);
return 1;
}
diff --git a/programs/reg/reg.h b/programs/reg/reg.h
index f1d4020..6d4ae47 100644
--- a/programs/reg/reg.h
+++ b/programs/reg/reg.h
@@ -27,3 +27,4 @@
#define STRING_INVALID_KEY 106
#define STRING_INVALID_CMDLINE 107
#define STRING_NO_REMOTE 108
+#define STRING_CANNOT_FIND 109
More information about the wine-cvs
mailing list