Sync to trunk r40610
[reactos.git] / reactos / dll / win32 / setupapi / query.c
index ef9e837..5bf4d77 100644 (file)
@@ -563,19 +563,25 @@ 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;
-    INT size;
+    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;
-
-    size = lstrlenW( dir ) + 1;
+    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;
 
     if (buffer)
@@ -589,7 +595,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;
 }