Commit d92e738f authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

setupapi: Fix resolving target path when given a section. Default to the system directory.

parent c6144893
......@@ -579,18 +579,24 @@ BOOL WINAPI SetupGetTargetPathW( HINF hinf, PINFCONTEXT context, PCWSTR section,
{'D','e','f','a','u','l','t','D','e','s','t','D','i','r',0};
INFCONTEXT ctx;
WCHAR *dir;
WCHAR *dir, systemdir[MAX_PATH];
unsigned int size;
BOOL ret = FALSE;
TRACE("%p, %p, %s, %p, 0x%08x, %p\n", hinf, context, debugstr_w(section), buffer,
buffer_size, required_size);
if (context && !SetupFindFirstLineW( hinf, destination_dirs, NULL, context )) return FALSE;
else if (section && !SetupFindFirstLineW( hinf, section, NULL, &ctx )) return FALSE;
else if (!SetupFindFirstLineW( hinf, destination_dirs, default_dest_dir, &ctx )) return FALSE;
if (!(dir = PARSER_get_dest_dir( context ? context : &ctx ))) return FALSE;
if (context) ret = SetupFindFirstLineW( hinf, destination_dirs, NULL, context );
else if (section)
{
if (!(ret = SetupFindFirstLineW( hinf, destination_dirs, section, &ctx )))
ret = SetupFindFirstLineW( hinf, destination_dirs, default_dest_dir, &ctx );
}
if (!ret || !(dir = PARSER_get_dest_dir( context ? context : &ctx )))
{
GetSystemDirectoryW( systemdir, MAX_PATH );
dir = systemdir;
}
size = strlenW( dir ) + 1;
if (required_size) *required_size = size;
......@@ -605,7 +611,7 @@ BOOL WINAPI SetupGetTargetPathW( HINF hinf, PINFCONTEXT context, PCWSTR section,
return FALSE;
}
}
HeapFree( GetProcessHeap(), 0, dir );
if (dir != systemdir) HeapFree( GetProcessHeap(), 0, dir );
return TRUE;
}
......
......@@ -68,6 +68,37 @@ static const char inf_data2[] =
"sp1qfe\\winhttp.dll=3EC6F518114606CA59D4160322077437,000500010A280615,331776,SP1QFE\n"
"sp1qfe\\xpob2res.dll=DB83156B9F496F20D1EA70E4ABEC0166,000500010A280622,158720,SP1QFE\n";
static const char inf_data3[] =
"[Version]\n"
"Signature = \"$Windows NT$\"\n"
"[DestinationDirs]\n"
"CopyAlways.Windir.files = 10\n"
"[CopyAlways.Windir.Files]\n"
"WindowsCodecs.dll\n";
static const char inf_data4[] =
"[Version]\n"
"Signature = \"$Windows NT$\"\n"
"[CopyAlways.System32.Files]\n"
"WindowsCodecs.dll\n";
static const char inf_data5[] =
"[Version]\n"
"Signature = \"$Windows NT$\"\n"
"[DestinationDirs]\n"
"DefaultDestDir = 11\n"
"CopyAlways.Windir.files = 10\n"
"[CopyAlways.Windir.Files]\n"
"WindowsCodecs.dll\n";
static const char inf_data6[] =
"[Version]\n"
"Signature = \"$Windows NT$\"\n"
"[DestinationDirs]\n"
"DefaultDestDir = 10\n"
"[CopyAlways.Windir.Files]\n"
"WindowsCodecs.dll\n";
static void create_inf_file(LPSTR filename, const char *data, DWORD size)
{
DWORD dwNumberOfBytesWritten;
......@@ -398,6 +429,79 @@ static void test_SetupGetTargetPath(void)
SetupCloseInfFile(hinf);
DeleteFileA(inf_filename);
create_inf_file(inf_filename, inf_data3, sizeof(inf_data3) - 1);
hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
required = 0;
ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
ok(ret, "SetupGetTargetPathA failed\n");
lstrcpyA(destfile, WIN_DIR);
ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
SetupCloseInfFile(hinf);
DeleteFileA(inf_filename);
create_inf_file(inf_filename, inf_data4, sizeof(inf_data4) - 1);
hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
required = 0;
ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.System32.Files", buffer, sizeof(buffer), &required);
ok(ret, "SetupGetTargetPathA failed\n");
lstrcpyA(destfile, WIN_DIR);
lstrcatA(destfile, "\\system32");
ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
SetupCloseInfFile(hinf);
DeleteFileA(inf_filename);
create_inf_file(inf_filename, inf_data5, sizeof(inf_data5) - 1);
hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
required = 0;
ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
ok(ret, "SetupGetTargetPathA failed\n");
lstrcpyA(destfile, WIN_DIR);
ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
SetupCloseInfFile(hinf);
DeleteFileA(inf_filename);
create_inf_file(inf_filename, inf_data6, sizeof(inf_data6) - 1);
hinf = SetupOpenInfFileA(inf_filename, NULL, INF_STYLE_WIN4, NULL);
ok(hinf != INVALID_HANDLE_VALUE, "could not open inf file\n");
required = 0;
ret = SetupGetTargetPathA(hinf, NULL, "CopyAlways.Windir.Files", buffer, sizeof(buffer), &required);
ok(ret, "SetupGetTargetPathA failed\n");
lstrcpyA(destfile, WIN_DIR);
ok(required == lstrlenA(destfile) + 1, "unexpected required size: %d\n", required);
ok(!lstrcmpiA(buffer, destfile), "unexpected path: %s\n", buffer);
SetupCloseInfFile(hinf);
DeleteFileA(inf_filename);
}
START_TEST(query)
......
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