msi: appsearch

Aric Stewart aric at codeweavers.com
Wed Jul 5 10:53:19 CDT 2006


-------------- next part --------------
>From nobody Mon Sep 17 00:00:00 2001
From: Aric Stewart <aric at codeweavers.com>
Date: Wed Jul 5 10:52:58 2006 -0500
Subject: [PATCH] add builting check for appsearch
if trying to find a DLL that is located in the system directory, also check for
a builtin version if that can be loaded as it should fill install
requirements.

---

 dlls/msi/appsearch.c |  134 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 125 insertions(+), 9 deletions(-)

01928ad4cda9a8dd0cb6d94424a7a488c8085e14
diff --git a/dlls/msi/appsearch.c b/dlls/msi/appsearch.c
index 44c5256..0893f6f 100644
--- a/dlls/msi/appsearch.c
+++ b/dlls/msi/appsearch.c
@@ -762,16 +762,15 @@ static BOOL ACTION_IsFullPath(LPCWSTR pa
 }
 
 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
- LPCWSTR expanded, int depth)
+ LPCWSTR expanded, int depth, BOOL* found)
 {
     UINT rc;
-    BOOL found;
 
     TRACE("%p, %p, %s, %d\n", package, sig, debugstr_w(expanded), depth);
     if (ACTION_IsFullPath(expanded))
     {
         if (sig->File)
-            rc = ACTION_RecurseSearchDirectory(package, &found, sig,
+            rc = ACTION_RecurseSearchDirectory(package, found, sig,
              expanded, depth);
         else
         {
@@ -788,8 +787,8 @@ static UINT ACTION_SearchDirectory(MSIPA
         int i;
 
         rc = ERROR_SUCCESS;
-        found = FALSE;
-        for (i = 0; rc == ERROR_SUCCESS && !found && i < 26; i++)
+        *found = FALSE;
+        for (i = 0; rc == ERROR_SUCCESS && !*found && i < 26; i++)
             if (drives & (1 << drives))
             {
                 pathWithDrive[0] = 'A' + i;
@@ -798,7 +797,7 @@ static UINT ACTION_SearchDirectory(MSIPA
                     lstrcpynW(pathWithDrive + 3, expanded,
                               sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
                     if (sig->File)
-                        rc = ACTION_RecurseSearchDirectory(package, &found, sig,
+                        rc = ACTION_RecurseSearchDirectory(package, found, sig,
                          pathWithDrive, depth);
                     else
                         rc = ACTION_CheckDirectory(package, sig, pathWithDrive);
@@ -809,7 +808,7 @@ static UINT ACTION_SearchDirectory(MSIPA
     return rc;
 }
 
-static UINT ACTION_AppSearchDr(MSIPACKAGE *package, MSISIGNATURE *sig)
+static UINT ACTION_AppSearchDr(MSIPACKAGE *package, BOOL *appFound, MSISIGNATURE *sig)
 {
     MSIQUERY *view;
     UINT rc;
@@ -873,7 +872,7 @@ static UINT ACTION_AppSearchDr(MSIPACKAG
             depth = MSI_RecordGetInteger(row,4);
         ACTION_ExpandAnyPath(package, buffer, expanded,
          sizeof(expanded) / sizeof(expanded[0]));
-        rc = ACTION_SearchDirectory(package, sig, expanded, depth);
+        rc = ACTION_SearchDirectory(package, sig, expanded, depth, appFound);
 
 end:
         if (row)
@@ -892,6 +891,121 @@ end:
     return rc;
 }
 
+
+static UINT ACTION_AppSearchBuiltin(MSIPACKAGE *package, MSISIGNATURE *sig)
+{
+    MSIQUERY *view;
+    UINT rc;
+	HMODULE test;
+	WCHAR systemdir[MAX_PATH];
+    static const WCHAR ExecSeqQuery[] =  {
+   's','e','l','e','c','t',' ','*',' ',
+   'f','r','o','m',' ',
+   'D','r','L','o','c','a','t','o','r',' ',
+   'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
+   '\'','%','s','\'',0};
+
+    TRACE("(package %p, sig %p)\n", package, sig);
+    rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
+    if (rc == ERROR_SUCCESS)
+    {
+        MSIRECORD *row = 0;
+        WCHAR buffer[MAX_PATH], expanded[MAX_PATH];
+        DWORD sz;
+        int depth;
+
+        rc = MSI_ViewExecute(view, 0);
+        if (rc != ERROR_SUCCESS)
+        {
+            TRACE("MSI_ViewExecute returned %d\n", rc);
+            goto end;
+        }
+        rc = MSI_ViewFetch(view,&row);
+        if (rc != ERROR_SUCCESS)
+        {
+            TRACE("MSI_ViewFetch returned %d\n", rc);
+            rc = ERROR_SUCCESS;
+            goto end;
+        }
+
+        /* check whether parent is set */
+        buffer[0] = 0;
+        sz=sizeof(buffer)/sizeof(buffer[0]);
+        rc = MSI_RecordGetStringW(row,2,buffer,&sz);
+        if (rc != ERROR_SUCCESS)
+        {
+            ERR("Error is %x\n",rc);
+            goto end;
+        }
+        else if (buffer[0])
+        {
+            FIXME(": searching parent (%s) unimplemented\n",
+             debugstr_w(buffer));
+            goto end;
+        }
+
+        /* no parent, now look for path */
+        buffer[0] = 0;
+        sz=sizeof(buffer)/sizeof(buffer[0]);
+        rc = MSI_RecordGetStringW(row,3,buffer,&sz);
+        if (rc != ERROR_SUCCESS)
+        {
+            ERR("Error is %x\n",rc);
+            goto end;
+        }
+        if (MSI_RecordIsNull(row,4))
+            depth = 0;
+        else
+            depth = MSI_RecordGetInteger(row,4);
+        ACTION_ExpandAnyPath(package, buffer, expanded,
+         sizeof(expanded) / sizeof(expanded[0]));
+
+		GetSystemDirectoryW(systemdir,MAX_PATH);
+
+		/* doctor trailing backslashes */
+		if (expanded[lstrlenW(expanded)-1]=='\\' && systemdir[lstrlenW(systemdir)-1] !='\\') 
+		{
+			int len = lstrlenW(systemdir);
+			systemdir[len]='\\';
+			systemdir[len+1]='\0';
+		}
+		else if (expanded[lstrlenW(expanded)-1]!='\\' &&
+				systemdir[lstrlenW(systemdir)-1] =='\\') 
+			systemdir[lstrlenW(systemdir)-1]='\0';
+
+		if(!expanded || !expanded[0] || lstrcmpW(systemdir,expanded)==0)
+		{
+			test = LoadLibraryW(sig->File);
+			if (test)
+			{
+				BOOL matches = TRUE;
+				FreeLibrary(test);
+				if ((sig->MinVersionMS || sig->MinVersionLS || sig->MaxVersionMS
+							|| sig->MaxVersionLS))
+				{
+					matches = FALSE;
+					ACTION_FileVersionMatches(sig, sig->File, &matches);
+				}
+				if (matches)
+        			rc = MSI_SetPropertyW(package, sig->Property, sig->File);
+			}
+		}
+end:
+        if (row)
+            msiobj_release(&row->hdr);
+        MSI_ViewClose(view);
+        msiobj_release(&view->hdr);
+    }
+    else
+    {
+        TRACE("MSI_OpenQuery returned %d\n", rc);
+        rc = ERROR_SUCCESS;
+    }
+
+    TRACE("returning %d\n", rc);
+    return rc;
+}
+
 /* http://msdn.microsoft.com/library/en-us/msi/setup/appsearch_table.asp
  * is the best reference for the AppSearch table and how it's used.
  */
@@ -961,7 +1075,9 @@ UINT ACTION_AppSearch(MSIPACKAGE *packag
                     {
                         rc = ACTION_AppSearchIni(package, &appFound, &sig);
                         if (rc == ERROR_SUCCESS && !appFound)
-                            rc = ACTION_AppSearchDr(package, &sig);
+                            rc = ACTION_AppSearchDr(package, &appFound, &sig );
+                        		if (rc == ERROR_SUCCESS && !appFound)
+                            		rc = ACTION_AppSearchBuiltin(package, &sig);
                     }
                 }
             }
-- 
1.2.4



More information about the wine-patches mailing list