Commit c23da6c3 authored by Alexander Nicolaysen Sørnes's avatar Alexander Nicolaysen Sørnes Committed by Alexandre Julliard

regedit: Use RegSetValueExW when importing data.

parent f4c3e0f4
...@@ -202,11 +202,11 @@ static DWORD getDataType(LPSTR *lpValue, DWORD* parse_type) ...@@ -202,11 +202,11 @@ static DWORD getDataType(LPSTR *lpValue, DWORD* parse_type)
/****************************************************************************** /******************************************************************************
* Replaces escape sequences with the characters. * Replaces escape sequences with the characters.
*/ */
static void REGPROC_unescape_string(LPSTR str) static void REGPROC_unescape_string(WCHAR* str)
{ {
int str_idx = 0; /* current character under analysis */ int str_idx = 0; /* current character under analysis */
int val_idx = 0; /* the last character of the unescaped string */ int val_idx = 0; /* the last character of the unescaped string */
int len = strlen(str); int len = lstrlenW(str);
for (str_idx = 0; str_idx < len; str_idx++, val_idx++) { for (str_idx = 0; str_idx < len; str_idx++, val_idx++) {
if (str[str_idx] == '\\') { if (str[str_idx] == '\\') {
str_idx++; str_idx++;
...@@ -328,7 +328,7 @@ static HKEY currentKeyHandle = NULL; ...@@ -328,7 +328,7 @@ static HKEY currentKeyHandle = NULL;
* val_name - name of the registry value * val_name - name of the registry value
* val_data - registry value data * val_data - registry value data
*/ */
static LONG setValue(LPSTR val_name, LPSTR val_data) static LONG setValue(WCHAR* val_name, LPSTR val_data)
{ {
LONG res; LONG res;
DWORD dwDataType, dwParseType; DWORD dwDataType, dwParseType;
...@@ -340,7 +340,7 @@ static LONG setValue(LPSTR val_name, LPSTR val_data) ...@@ -340,7 +340,7 @@ static LONG setValue(LPSTR val_name, LPSTR val_data)
if (strcmp(val_data, "-") == 0) if (strcmp(val_data, "-") == 0)
{ {
res=RegDeleteValue(currentKeyHandle,val_name); res=RegDeleteValueW(currentKeyHandle,val_name);
return (res == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : res); return (res == ERROR_FILE_NOT_FOUND ? ERROR_SUCCESS : res);
} }
...@@ -349,19 +349,21 @@ static LONG setValue(LPSTR val_name, LPSTR val_data) ...@@ -349,19 +349,21 @@ static LONG setValue(LPSTR val_name, LPSTR val_data)
if (dwParseType == REG_SZ) /* no conversion for string */ if (dwParseType == REG_SZ) /* no conversion for string */
{ {
REGPROC_unescape_string(val_data); WCHAR* val_dataW = GetWideString(val_data, lstrlenA(val_data)+1);
REGPROC_unescape_string(val_dataW);
/* Compute dwLen after REGPROC_unescape_string because it may /* Compute dwLen after REGPROC_unescape_string because it may
* have changed the string length and we don't want to store * have changed the string length and we don't want to store
* the extra garbage in the registry. * the extra garbage in the registry.
*/ */
dwLen = strlen(val_data); dwLen = lstrlenW(val_dataW);
if (dwLen>0 && val_data[dwLen-1]=='"') if (dwLen>0 && val_dataW[dwLen-1]=='"')
{ {
dwLen--; dwLen--;
val_data[dwLen]='\0'; val_dataW[dwLen]='\0';
} }
lpbData = (BYTE*) val_data; lpbData = (BYTE*) val_dataW;
dwLen++; /* include terminating null */ dwLen++; /* include terminating null */
dwLen = dwLen * sizeof(WCHAR); /* size is in bytes */
} }
else if (dwParseType == REG_DWORD) /* Convert the dword types */ else if (dwParseType == REG_DWORD) /* Convert the dword types */
{ {
...@@ -382,14 +384,14 @@ static LONG setValue(LPSTR val_name, LPSTR val_data) ...@@ -382,14 +384,14 @@ static LONG setValue(LPSTR val_name, LPSTR val_data)
return ERROR_INVALID_DATA; return ERROR_INVALID_DATA;
} }
res = RegSetValueEx( res = RegSetValueExW(
currentKeyHandle, currentKeyHandle,
val_name, val_name,
0, /* Reserved */ 0, /* Reserved */
dwDataType, dwDataType,
lpbData, lpbData,
dwLen); dwLen);
if (dwParseType == REG_BINARY) if (dwParseType == REG_BINARY || dwParseType == REG_SZ)
HeapFree(GetProcessHeap(), 0, lpbData); HeapFree(GetProcessHeap(), 0, lpbData);
return res; return res;
} }
...@@ -465,6 +467,7 @@ static void processSetValue(LPSTR line) ...@@ -465,6 +467,7 @@ static void processSetValue(LPSTR line)
{ {
LPSTR val_name; /* registry value name */ LPSTR val_name; /* registry value name */
LPSTR val_data; /* registry value data */ LPSTR val_data; /* registry value data */
WCHAR* val_nameW;
int line_idx = 0; /* current character under analysis */ int line_idx = 0; /* current character under analysis */
LONG res; LONG res;
...@@ -504,8 +507,10 @@ static void processSetValue(LPSTR line) ...@@ -504,8 +507,10 @@ static void processSetValue(LPSTR line)
line_idx++; /* skip the '=' character */ line_idx++; /* skip the '=' character */
val_data = line + line_idx; val_data = line + line_idx;
REGPROC_unescape_string(val_name); val_nameW = GetWideString(val_name, lstrlenA(val_name)+1);
res = setValue(val_name, val_data); REGPROC_unescape_string(val_nameW);
res = setValue(val_nameW, val_data);
HeapFree(GetProcessHeap(), 0, val_nameW);
if ( res != ERROR_SUCCESS ) if ( res != ERROR_SUCCESS )
fprintf(stderr,"%s: ERROR Key %s not created. Value: %s, Data: %s\n", fprintf(stderr,"%s: ERROR Key %s not created. Value: %s, Data: %s\n",
getAppName(), getAppName(),
......
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