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

Alexandre Julliard julliard at winehq.org
Tue Jan 13 10:56:44 CST 2009


Module: wine
Branch: master
Commit: d92e738f4a87a97162ea6b6356db4983398c179b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d92e738f4a87a97162ea6b6356db4983398c179b

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Tue Jan 13 17:22:11 2009 +0100

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

---

 dlls/setupapi/query.c       |   22 ++++++---
 dlls/setupapi/tests/query.c |  104 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 8 deletions(-)

diff --git a/dlls/setupapi/query.c b/dlls/setupapi/query.c
index f44826d..d6320a3 100644
--- a/dlls/setupapi/query.c
+++ b/dlls/setupapi/query.c
@@ -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;
 }
 
diff --git a/dlls/setupapi/tests/query.c b/dlls/setupapi/tests/query.c
index 932ff30..97be1a2 100644
--- a/dlls/setupapi/tests/query.c
+++ b/dlls/setupapi/tests/query.c
@@ -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)




More information about the wine-cvs mailing list