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

Hans Leidekker hans at codeweavers.com
Mon Jan 12 15:08:15 CST 2009


Fixes http://bugs.winehq.org/show_bug.cgi?id=16875

 -Hans

diff --git a/dlls/setupapi/query.c b/dlls/setupapi/query.c
index f44826d..21f65a5 100644
--- a/dlls/setupapi/query.c
+++ b/dlls/setupapi/query.c
@@ -579,18 +579,22 @@ 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;
 
     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) ret = SetupFindFirstLineW( hinf, destination_dirs, section, &ctx );
+    else 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 +609,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;
 }
 
diff --git a/dlls/setupapi/tests/query.c b/dlls/setupapi/tests/query.c
index 932ff30..ca031dd 100644
--- a/dlls/setupapi/tests/query.c
+++ b/dlls/setupapi/tests/query.c
@@ -68,6 +68,20 @@ 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.System32.files = 11\n"
+    "[CopyAlways.System32.Files]\n"
+    "WindowsCodecs.dll\n";
+
+static const char inf_data4[] =
+    "[Version]\n"
+    "Signature = \"$Windows NT$\"\n"
+    "[CopyAlways.System32.Files]\n"
+    "WindowsCodecs.dll\n";
+
 static void create_inf_file(LPSTR filename, const char *data, DWORD size)
 {
     DWORD dwNumberOfBytesWritten;
@@ -398,6 +412,44 @@ 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.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_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);
 }
 
 START_TEST(query)



More information about the wine-patches mailing list