msi: Handle environment strings without a value.

This commit is contained in:
Hans Leidekker 2009-11-13 11:06:12 +01:00 committed by Alexandre Julliard
parent 54a01bf5bc
commit e52531ab1d
2 changed files with 32 additions and 17 deletions

View File

@ -4888,7 +4888,6 @@ static UINT ACTION_InstallODBC( MSIPACKAGE *package )
static LONG env_set_flags( LPCWSTR *name, LPCWSTR *value, DWORD *flags )
{
LPCWSTR cptr = *name;
LPCWSTR ptr = *value;
static const WCHAR prefix[] = {'[','~',']',0};
static const int prefix_len = 3;
@ -4919,18 +4918,22 @@ static LONG env_set_flags( LPCWSTR *name, LPCWSTR *value, DWORD *flags )
return ERROR_FUNCTION_FAILED;
}
if (!strncmpW(ptr, prefix, prefix_len))
if (*value)
{
*flags |= ENV_MOD_APPEND;
*value += lstrlenW(prefix);
}
else if (lstrlenW(*value) >= prefix_len)
{
ptr += lstrlenW(ptr) - prefix_len;
if (!lstrcmpW(ptr, prefix))
LPCWSTR ptr = *value;
if (!strncmpW(ptr, prefix, prefix_len))
{
*flags |= ENV_MOD_PREFIX;
/* the "[~]" will be removed by deformat_string */;
*flags |= ENV_MOD_APPEND;
*value += lstrlenW(prefix);
}
else if (lstrlenW(*value) >= prefix_len)
{
ptr += lstrlenW(ptr) - prefix_len;
if (!lstrcmpW(ptr, prefix))
{
*flags |= ENV_MOD_PREFIX;
/* the "[~]" will be removed by deformat_string */;
}
}
}
@ -4978,8 +4981,7 @@ static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
if (res != ERROR_SUCCESS)
goto done;
deformat_string(package, value, &deformatted);
if (!deformatted)
if (value && !deformat_string(package, value, &deformatted))
{
res = ERROR_OUTOFMEMORY;
goto done;
@ -5066,7 +5068,7 @@ static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
}
}
}
else
else if (value)
{
size = (lstrlenW(value) + 1) * sizeof(WCHAR);
newval = msi_alloc(size);
@ -5079,8 +5081,13 @@ static UINT ITERATE_WriteEnvironmentString( MSIRECORD *rec, LPVOID param )
lstrcpyW(newval, value);
}
TRACE("setting %s to %s\n", debugstr_w(name), debugstr_w(newval));
res = RegSetValueExW(env, name, 0, type, (LPVOID)newval, size);
if (newval)
{
TRACE("setting %s to %s\n", debugstr_w(name), debugstr_w(newval));
res = RegSetValueExW(env, name, 0, type, (LPVOID)newval, size);
}
else
res = ERROR_SUCCESS;
done:
if (env) RegCloseKey(env);

View File

@ -174,7 +174,9 @@ static const CHAR environment_dat[] = "Environment\tName\tValue\tComponent_\n"
"Var1\t=-MSITESTVAR1\t1\tOne\n"
"Var2\tMSITESTVAR2\t1\tOne\n"
"Var3\t=-MSITESTVAR3\t1\tOne\n"
"Var4\tMSITESTVAR4\t1\tOne\n";
"Var4\tMSITESTVAR4\t1\tOne\n"
"Var5\t-MSITESTVAR5\t\tOne\n"
"Var6\tMSITESTVAR6\t\tOne\n";
static const CHAR condition_dat[] = "Feature_\tLevel\tCondition\n"
"s38\ti2\tS255\n"
@ -6610,6 +6612,12 @@ static void test_envvar(void)
res = RegDeleteValueA(env, "MSITESTVAR4");
ok(res == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", res);
res = RegDeleteValueA(env, "MSITESTVAR5");
ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
res = RegDeleteValueA(env, "MSITESTVAR6");
ok(res == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %d\n", res);
RegCloseKey(env);
delete_pf("msitest\\cabout\\new\\five.txt", TRUE);