d3d11: Implement d3d11_device_context_ClearUnorderedAccessViewFloat().
[wine.git] / programs / reg / delete.c
blob8804e16e52f31da02c51e73152c58ebbcf8953d6
1 /*
2 * Copyright 2016-2017, 2021 Hugh McMaster
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "reg.h"
21 static BOOL op_delete_key = TRUE;
23 static void output_error(LONG rc)
25 if (rc == ERROR_FILE_NOT_FOUND)
27 if (op_delete_key)
28 output_message(STRING_KEY_NONEXIST);
29 else
30 output_message(STRING_VALUE_NONEXIST);
32 else
34 output_message(STRING_ACCESS_DENIED);
38 static int run_delete(HKEY root, WCHAR *path, WCHAR *key_name, WCHAR *value_name,
39 BOOL value_empty, BOOL value_all, BOOL force)
41 LONG rc;
42 HKEY hkey;
44 if (!force)
46 BOOL ret;
48 if (value_name || value_empty)
49 ret = ask_confirm(STRING_DELETE_VALUE, value_name);
50 else if (value_all)
51 ret = ask_confirm(STRING_DELETE_VALUEALL, key_name);
52 else
53 ret = ask_confirm(STRING_DELETE_SUBKEY, key_name);
55 if (!ret)
57 output_message(STRING_CANCELLED);
58 return 0;
62 /* Delete registry key if no /v* option is given */
63 if (!value_name && !value_empty && !value_all)
65 if ((rc = RegDeleteTreeW(root, path)))
67 output_error(rc);
68 return 1;
71 output_message(STRING_SUCCESS);
72 return 0;
75 if ((rc = RegOpenKeyExW(root, path, 0, KEY_READ|KEY_SET_VALUE, &hkey)))
77 output_error(rc);
78 return 1;
81 op_delete_key = FALSE;
83 if (value_all)
85 DWORD max_value_len = 256, value_len;
86 WCHAR *value_name;
88 value_name = malloc(max_value_len * sizeof(WCHAR));
90 while (1)
92 value_len = max_value_len;
93 rc = RegEnumValueW(hkey, 0, value_name, &value_len, NULL, NULL, NULL, NULL);
94 if (rc == ERROR_SUCCESS)
96 rc = RegDeleteValueW(hkey, value_name);
97 if (rc != ERROR_SUCCESS)
99 free(value_name);
100 RegCloseKey(hkey);
101 output_message(STRING_VALUEALL_FAILED, key_name);
102 output_error(rc);
103 return 1;
106 else if (rc == ERROR_MORE_DATA)
108 max_value_len *= 2;
109 value_name = realloc(value_name, max_value_len * sizeof(WCHAR));
111 else break;
113 free(value_name);
115 else if (value_name || value_empty)
117 if ((rc = RegDeleteValueW(hkey, value_name)))
119 RegCloseKey(hkey);
120 output_error(rc);
121 return 1;
125 RegCloseKey(hkey);
126 output_message(STRING_SUCCESS);
127 return 0;
130 int reg_delete(int argc, WCHAR *argvW[])
132 HKEY root;
133 WCHAR *path, *key_name, *value_name = NULL;
134 BOOL value_all = FALSE, value_empty = FALSE, force = FALSE;
135 int i;
137 if (!parse_registry_key(argvW[2], &root, &path))
138 return 1;
140 for (i = 3; i < argc; i++)
142 WCHAR *str;
144 if (argvW[i][0] != '/' && argvW[i][0] != '-')
145 goto invalid;
147 str = &argvW[i][1];
149 if (!lstrcmpiW(str, L"va"))
151 if (value_all) goto invalid;
152 value_all = TRUE;
153 continue;
155 else if (!lstrcmpiW(str, L"ve"))
157 if (value_empty) goto invalid;
158 value_empty = TRUE;
159 continue;
161 else if (!lstrcmpiW(str, L"reg:32") || !lstrcmpiW(str, L"reg:64"))
162 continue;
163 else if (!str[0] || str[1])
164 goto invalid;
166 switch (towlower(*str))
168 case 'v':
169 if (value_name || !(value_name = argvW[++i]))
170 goto invalid;
171 break;
172 case 'f':
173 if (force) goto invalid;
174 force = TRUE;
175 break;
176 default:
177 goto invalid;
181 if ((value_name && value_empty) || (value_name && value_all) || (value_empty && value_all))
182 goto invalid;
184 key_name = get_long_key(root, path);
186 return run_delete(root, path, key_name, value_name, value_empty, value_all, force);
188 invalid:
189 output_message(STRING_INVALID_SYNTAX);
190 output_message(STRING_FUNC_HELP, wcsupr(argvW[1]));
191 return 1;