2 * Implementation of the AppSearch action of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
38 typedef struct tagMSISIGNATURE
40 LPWSTR Name
; /* NOT owned by this structure */
53 static void ACTION_VerStrToInteger(LPCWSTR verStr
, PDWORD ms
, PDWORD ls
)
56 int x1
= 0, x2
= 0, x3
= 0, x4
= 0;
59 ptr
= strchrW(verStr
, '.');
63 ptr
= strchrW(ptr
+ 1, '.');
68 ptr
= strchrW(ptr
+ 1, '.');
72 /* FIXME: byte-order dependent? */
77 /* Fills in sig with the the values from the Signature table, where name is the
78 * signature to find. Upon return, sig->File will be NULL if the record is not
79 * found, and not NULL if it is found.
80 * Warning: clears all fields in sig!
81 * Returns ERROR_SUCCESS upon success (where not finding the record counts as
82 * success), something else on error.
84 static UINT
ACTION_AppSearchGetSignature(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
89 static const WCHAR ExecSeqQuery
[] = {
90 's','e','l','e','c','t',' ','*',' ',
92 'S','i','g','n','a','t','u','r','e',' ',
93 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e',' ','=',' ',
96 TRACE("(package %p, sig %p)\n", package
, sig
);
97 memset(sig
, 0, sizeof(*sig
));
98 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, name
);
99 if (rc
== ERROR_SUCCESS
)
103 WCHAR
*minVersion
, *maxVersion
;
105 rc
= MSI_ViewExecute(view
, 0);
106 if (rc
!= ERROR_SUCCESS
)
108 TRACE("MSI_ViewExecute returned %d\n", rc
);
111 rc
= MSI_ViewFetch(view
,&row
);
112 if (rc
!= ERROR_SUCCESS
)
114 TRACE("MSI_ViewFetch returned %d\n", rc
);
120 sig
->File
= msi_dup_record_field(row
,2);
121 minVersion
= msi_dup_record_field(row
,3);
124 ACTION_VerStrToInteger(minVersion
, &sig
->MinVersionMS
,
126 msi_free( minVersion
);
128 maxVersion
= msi_dup_record_field(row
,4);
131 ACTION_VerStrToInteger(maxVersion
, &sig
->MaxVersionMS
,
133 msi_free( maxVersion
);
135 sig
->MinSize
= MSI_RecordGetInteger(row
,5);
136 if (sig
->MinSize
== MSI_NULL_INTEGER
)
138 sig
->MaxSize
= MSI_RecordGetInteger(row
,6);
139 if (sig
->MaxSize
== MSI_NULL_INTEGER
)
141 sig
->Languages
= msi_dup_record_field(row
,9);
142 time
= MSI_RecordGetInteger(row
,7);
143 if (time
!= MSI_NULL_INTEGER
)
144 DosDateTimeToFileTime(HIWORD(time
), LOWORD(time
), &sig
->MinTime
);
145 time
= MSI_RecordGetInteger(row
,8);
146 if (time
!= MSI_NULL_INTEGER
)
147 DosDateTimeToFileTime(HIWORD(time
), LOWORD(time
), &sig
->MaxTime
);
148 TRACE("Found file name %s for Signature_ %s;\n",
149 debugstr_w(sig
->File
), debugstr_w(name
));
150 TRACE("MinVersion is %d.%d.%d.%d\n", HIWORD(sig
->MinVersionMS
),
151 LOWORD(sig
->MinVersionMS
), HIWORD(sig
->MinVersionLS
),
152 LOWORD(sig
->MinVersionLS
));
153 TRACE("MaxVersion is %d.%d.%d.%d\n", HIWORD(sig
->MaxVersionMS
),
154 LOWORD(sig
->MaxVersionMS
), HIWORD(sig
->MaxVersionLS
),
155 LOWORD(sig
->MaxVersionLS
));
156 TRACE("MinSize is %ld, MaxSize is %ld;\n", sig
->MinSize
, sig
->MaxSize
);
157 TRACE("Languages is %s\n", debugstr_w(sig
->Languages
));
161 msiobj_release(&row
->hdr
);
163 msiobj_release(&view
->hdr
);
167 TRACE("MSI_OpenQuery returned %d\n", rc
);
171 TRACE("returning %d\n", rc
);
175 static UINT
ACTION_AppSearchComponents(MSIPACKAGE
*package
, LPWSTR
*appValue
,
180 static const WCHAR ExecSeqQuery
[] = {
181 's','e','l','e','c','t',' ','*',' ',
183 'C','o','m','p','L','o','c','a','t','o','r',' ',
184 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
185 '\'','%','s','\'',0};
187 TRACE("(package %p, appValue %p, sig %p)\n", package
, appValue
, sig
);
189 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
190 if (rc
== ERROR_SUCCESS
)
196 rc
= MSI_ViewExecute(view
, 0);
197 if (rc
!= ERROR_SUCCESS
)
199 TRACE("MSI_ViewExecute returned %d\n", rc
);
202 rc
= MSI_ViewFetch(view
,&row
);
203 if (rc
!= ERROR_SUCCESS
)
205 TRACE("MSI_ViewFetch returned %d\n", rc
);
212 sz
=sizeof(guid
)/sizeof(guid
[0]);
213 rc
= MSI_RecordGetStringW(row
,2,guid
,&sz
);
214 if (rc
!= ERROR_SUCCESS
)
216 ERR("Error is %x\n",rc
);
219 FIXME("AppSearch unimplemented for CompLocator table (GUID %s)\n",
224 msiobj_release(&row
->hdr
);
226 msiobj_release(&view
->hdr
);
230 TRACE("MSI_OpenQuery returned %d\n", rc
);
234 TRACE("returning %d\n", rc
);
238 static void ACTION_ConvertRegValue(DWORD regType
, const BYTE
*value
, DWORD sz
,
241 static const WCHAR dwordFmt
[] = { '#','%','d','\0' };
242 static const WCHAR expandSzFmt
[] = { '#','%','%','%','s','\0' };
243 static const WCHAR binFmt
[] = { '#','x','%','x','\0' };
249 if (*(LPWSTR
)value
== '#')
251 /* escape leading pound with another */
252 *appValue
= msi_alloc(sz
+ sizeof(WCHAR
));
253 (*appValue
)[0] = '#';
254 strcpyW(*appValue
+ 1, (LPCWSTR
)value
);
258 *appValue
= msi_alloc(sz
);
259 strcpyW(*appValue
, (LPCWSTR
)value
);
263 /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign
266 *appValue
= msi_alloc(10 * sizeof(WCHAR
));
267 sprintfW(*appValue
, dwordFmt
, *(const DWORD
*)value
);
270 /* space for extra #% characters in front */
271 *appValue
= msi_alloc(sz
+ 2 * sizeof(WCHAR
));
272 sprintfW(*appValue
, expandSzFmt
, (LPCWSTR
)value
);
275 /* 3 == length of "#x<nibble>" */
276 *appValue
= msi_alloc((sz
* 3 + 1) * sizeof(WCHAR
));
277 for (i
= 0; i
< sz
; i
++)
278 sprintfW(*appValue
+ i
* 3, binFmt
, value
[i
]);
281 WARN("unimplemented for values of type %ld\n", regType
);
286 static UINT
ACTION_AppSearchReg(MSIPACKAGE
*package
, LPWSTR
*appValue
,
291 static const WCHAR ExecSeqQuery
[] = {
292 's','e','l','e','c','t',' ','*',' ',
294 'R','e','g','L','o','c','a','t','o','r',' ',
295 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
296 '\'','%','s','\'',0};
298 TRACE("(package %p, appValue %p, sig %p)\n", package
, appValue
, sig
);
300 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
301 if (rc
== ERROR_SUCCESS
)
304 LPWSTR keyPath
= NULL
, valueName
= NULL
;
306 HKEY rootKey
, key
= NULL
;
307 DWORD sz
= 0, regType
;
310 rc
= MSI_ViewExecute(view
, 0);
311 if (rc
!= ERROR_SUCCESS
)
313 TRACE("MSI_ViewExecute returned %d\n", rc
);
316 rc
= MSI_ViewFetch(view
,&row
);
317 if (rc
!= ERROR_SUCCESS
)
319 TRACE("MSI_ViewFetch returned %d\n", rc
);
324 root
= MSI_RecordGetInteger(row
,2);
325 keyPath
= msi_dup_record_field(row
,3);
326 /* FIXME: keyPath needs to be expanded for properties */
327 valueName
= msi_dup_record_field(row
,4);
328 /* FIXME: valueName probably does too */
329 type
= MSI_RecordGetInteger(row
,5);
331 if ((type
& 0x0f) != msidbLocatorTypeRawValue
)
333 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
334 type
, debugstr_w(keyPath
), debugstr_w(valueName
));
340 case msidbRegistryRootClassesRoot
:
341 rootKey
= HKEY_CLASSES_ROOT
;
343 case msidbRegistryRootCurrentUser
:
344 rootKey
= HKEY_CURRENT_USER
;
346 case msidbRegistryRootLocalMachine
:
347 rootKey
= HKEY_LOCAL_MACHINE
;
349 case msidbRegistryRootUsers
:
350 rootKey
= HKEY_USERS
;
353 WARN("Unknown root key %d\n", root
);
357 rc
= RegOpenKeyW(rootKey
, keyPath
, &key
);
360 TRACE("RegCreateKeyW returned %d\n", rc
);
364 rc
= RegQueryValueExW(key
, valueName
, NULL
, NULL
, NULL
, &sz
);
367 TRACE("RegQueryValueExW returned %d\n", rc
);
371 /* FIXME: sanity-check sz before allocating (is there an upper-limit
372 * on the value of a property?)
374 value
= msi_alloc( sz
);
375 rc
= RegQueryValueExW(key
, valueName
, NULL
, ®Type
, value
, &sz
);
378 TRACE("RegQueryValueExW returned %d\n", rc
);
383 /* bail out if the registry key is empty */
390 ACTION_ConvertRegValue(regType
, value
, sz
, appValue
);
397 msi_free( valueName
);
400 msiobj_release(&row
->hdr
);
402 msiobj_release(&view
->hdr
);
406 TRACE("MSI_OpenQuery returned %d\n", rc
);
410 TRACE("returning %d\n", rc
);
414 static UINT
ACTION_AppSearchIni(MSIPACKAGE
*package
, LPWSTR
*appValue
,
419 static const WCHAR ExecSeqQuery
[] = {
420 's','e','l','e','c','t',' ','*',' ',
422 'I','n','i','L','o','c','a','t','o','r',' ',
423 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
424 '\'','%','s','\'',0};
426 TRACE("(package %p, appValue %p, sig %p)\n", package
, appValue
, sig
);
428 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
429 if (rc
== ERROR_SUCCESS
)
434 rc
= MSI_ViewExecute(view
, 0);
435 if (rc
!= ERROR_SUCCESS
)
437 TRACE("MSI_ViewExecute returned %d\n", rc
);
440 rc
= MSI_ViewFetch(view
,&row
);
441 if (rc
!= ERROR_SUCCESS
)
443 TRACE("MSI_ViewFetch returned %d\n", rc
);
449 fileName
= msi_dup_record_field(row
,2);
450 FIXME("AppSearch unimplemented for IniLocator (ini file name %s)\n",
451 debugstr_w(fileName
));
456 msiobj_release(&row
->hdr
);
458 msiobj_release(&view
->hdr
);
462 TRACE("MSI_OpenQuery returned %d\n", rc
);
467 TRACE("returning %d\n", rc
);
471 /* Expands the value in src into a path without property names and only
472 * containing long path names into dst. Replaces at most len characters of dst,
473 * and always NULL-terminates dst if dst is not NULL and len >= 1.
475 * Assumes src and dst are non-overlapping.
476 * FIXME: return code probably needed:
477 * - what does AppSearch return if the table values are invalid?
478 * - what if dst is too small?
480 static void ACTION_ExpandAnyPath(MSIPACKAGE
*package
, WCHAR
*src
, WCHAR
*dst
,
486 if (!src
|| !dst
|| !len
)
489 /* Ignore the short portion of the path, don't think we can use it anyway */
490 if ((ptr
= strchrW(src
, '|')))
494 while (*ptr
&& copied
< len
- 1)
496 WCHAR
*prop
= strchrW(ptr
, '[');
500 WCHAR
*propEnd
= strchrW(prop
+ 1, ']');
504 WARN("Unterminated property name in AnyPath: %s\n",
513 propLen
= len
- copied
- 1;
514 MSI_GetPropertyW(package
, prop
+ 1, dst
+ copied
, &propLen
);
521 size_t toCopy
= min(strlenW(ptr
) + 1, len
- copied
- 1);
523 memcpy(dst
+ copied
, ptr
, toCopy
* sizeof(WCHAR
));
528 *(dst
+ copied
) = '\0';
531 /* Sets *matches to whether the file (whose path is filePath) matches the
532 * versions set in sig.
533 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
534 * something else if an install-halting error occurs.
536 static UINT
ACTION_FileVersionMatches(MSISIGNATURE
*sig
, LPCWSTR filePath
,
539 UINT rc
= ERROR_SUCCESS
;
544 FIXME(": need to check version for languages %s\n",
545 debugstr_w(sig
->Languages
));
549 DWORD zero
, size
= GetFileVersionInfoSizeW(filePath
, &zero
);
553 LPVOID buf
= msi_alloc( size
);
557 static WCHAR rootW
[] = { '\\',0 };
559 LPVOID subBlock
= NULL
;
561 if (GetFileVersionInfoW(filePath
, 0, size
, buf
))
562 VerQueryValueW(buf
, rootW
, &subBlock
, &versionLen
);
565 VS_FIXEDFILEINFO
*info
=
566 (VS_FIXEDFILEINFO
*)subBlock
;
568 TRACE("Comparing file version %d.%d.%d.%d:\n",
569 HIWORD(info
->dwFileVersionMS
),
570 LOWORD(info
->dwFileVersionMS
),
571 HIWORD(info
->dwFileVersionLS
),
572 LOWORD(info
->dwFileVersionLS
));
573 if (info
->dwFileVersionMS
< sig
->MinVersionMS
574 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
575 info
->dwFileVersionLS
< sig
->MinVersionLS
))
577 TRACE("Less than minimum version %d.%d.%d.%d\n",
578 HIWORD(sig
->MinVersionMS
),
579 LOWORD(sig
->MinVersionMS
),
580 HIWORD(sig
->MinVersionLS
),
581 LOWORD(sig
->MinVersionLS
));
583 else if (info
->dwFileVersionMS
< sig
->MinVersionMS
584 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
585 info
->dwFileVersionLS
< sig
->MinVersionLS
))
587 TRACE("Greater than minimum version %d.%d.%d.%d\n",
588 HIWORD(sig
->MaxVersionMS
),
589 LOWORD(sig
->MaxVersionMS
),
590 HIWORD(sig
->MaxVersionLS
),
591 LOWORD(sig
->MaxVersionLS
));
599 rc
= ERROR_OUTOFMEMORY
;
605 /* Sets *matches to whether the file in findData matches that in sig.
606 * fullFilePath is assumed to be the full path of the file specified in
607 * findData, which may be necessary to compare the version.
608 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
609 * something else if an install-halting error occurs.
611 static UINT
ACTION_FileMatchesSig(MSISIGNATURE
*sig
,
612 LPWIN32_FIND_DATAW findData
, LPCWSTR fullFilePath
, BOOL
*matches
)
614 UINT rc
= ERROR_SUCCESS
;
617 /* assumes the caller has already ensured the filenames match, so check
620 if (sig
->MinTime
.dwLowDateTime
|| sig
->MinTime
.dwHighDateTime
)
622 if (findData
->ftCreationTime
.dwHighDateTime
<
623 sig
->MinTime
.dwHighDateTime
||
624 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MinTime
.dwHighDateTime
625 && findData
->ftCreationTime
.dwLowDateTime
<
626 sig
->MinTime
.dwLowDateTime
))
629 if (*matches
&& (sig
->MaxTime
.dwLowDateTime
|| sig
->MaxTime
.dwHighDateTime
))
631 if (findData
->ftCreationTime
.dwHighDateTime
>
632 sig
->MaxTime
.dwHighDateTime
||
633 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MaxTime
.dwHighDateTime
634 && findData
->ftCreationTime
.dwLowDateTime
>
635 sig
->MaxTime
.dwLowDateTime
))
638 if (*matches
&& sig
->MinSize
&& findData
->nFileSizeLow
< sig
->MinSize
)
640 if (*matches
&& sig
->MaxSize
&& findData
->nFileSizeLow
> sig
->MaxSize
)
642 if (*matches
&& (sig
->MinVersionMS
|| sig
->MinVersionLS
||
643 sig
->MaxVersionMS
|| sig
->MaxVersionLS
))
644 rc
= ACTION_FileVersionMatches(sig
, fullFilePath
, matches
);
648 /* Recursively searches the directory dir for files that match the signature
649 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
650 * (and only dir). If depth is 1, searches dir and its immediate
652 * Assumes sig->File is not NULL.
653 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
654 * something else on failures which should halt the install.
656 static UINT
ACTION_RecurseSearchDirectory(MSIPACKAGE
*package
, LPWSTR
*appValue
,
657 MSISIGNATURE
*sig
, LPCWSTR dir
, int depth
)
659 static const WCHAR starDotStarW
[] = { '*','.','*',0 };
660 UINT rc
= ERROR_SUCCESS
;
661 size_t dirLen
= lstrlenW(dir
), fileLen
= lstrlenW(sig
->File
);
664 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir
),
665 debugstr_w(sig
->File
), depth
);
668 return ERROR_INVALID_PARAMETER
;
671 /* We need the buffer in both paths below, so go ahead and allocate it
672 * here. Add two because we might need to add a backslash if the dir name
673 * isn't backslash-terminated.
675 buf
= msi_alloc( (dirLen
+ max(fileLen
, lstrlenW(starDotStarW
)) + 2) * sizeof(WCHAR
));
678 /* a depth of 0 implies we should search dir, so go ahead and search */
680 WIN32_FIND_DATAW findData
;
682 memcpy(buf
, dir
, dirLen
* sizeof(WCHAR
));
683 if (buf
[dirLen
- 1] != '\\')
684 buf
[dirLen
++ - 1] = '\\';
685 memcpy(buf
+ dirLen
, sig
->File
, (fileLen
+ 1) * sizeof(WCHAR
));
686 hFind
= FindFirstFileW(buf
, &findData
);
687 if (hFind
!= INVALID_HANDLE_VALUE
)
691 /* assuming Signature can't contain wildcards for the file name,
692 * so don't bother with FindNextFileW here.
694 if (!(rc
= ACTION_FileMatchesSig(sig
, &findData
, buf
, &matches
))
697 TRACE("found file, returning %s\n", debugstr_w(buf
));
702 if (rc
== ERROR_SUCCESS
&& !*appValue
&& depth
> 0)
705 WIN32_FIND_DATAW findData
;
707 memcpy(buf
, dir
, dirLen
* sizeof(WCHAR
));
708 if (buf
[dirLen
- 1] != '\\')
709 buf
[dirLen
++ - 1] = '\\';
710 lstrcpyW(buf
+ dirLen
, starDotStarW
);
711 hFind
= FindFirstFileW(buf
, &findData
);
712 if (hFind
!= INVALID_HANDLE_VALUE
)
714 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
715 rc
= ACTION_RecurseSearchDirectory(package
, appValue
, sig
,
716 findData
.cFileName
, depth
- 1);
717 while (rc
== ERROR_SUCCESS
&& !*appValue
&&
718 FindNextFileW(hFind
, &findData
) != 0)
720 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
721 rc
= ACTION_RecurseSearchDirectory(package
, appValue
,
722 sig
, findData
.cFileName
, depth
- 1);
731 rc
= ERROR_OUTOFMEMORY
;
736 static UINT
ACTION_CheckDirectory(MSIPACKAGE
*package
, LPCWSTR dir
,
739 UINT rc
= ERROR_SUCCESS
;
741 if (GetFileAttributesW(dir
) & FILE_ATTRIBUTE_DIRECTORY
)
743 TRACE("directory exists, returning %s\n", debugstr_w(dir
));
744 *appValue
= strdupW(dir
);
751 static BOOL
ACTION_IsFullPath(LPCWSTR path
)
753 WCHAR first
= toupperW(path
[0]);
756 if (first
>= 'A' && first
<= 'Z' && path
[1] == ':')
758 else if (path
[0] == '\\' && path
[1] == '\\')
765 static UINT
ACTION_SearchDirectory(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
766 LPCWSTR path
, int depth
, LPWSTR
*appValue
)
770 TRACE("%p, %p, %s, %d, %p\n", package
, sig
, debugstr_w(path
), depth
,
772 if (ACTION_IsFullPath(path
))
775 rc
= ACTION_RecurseSearchDirectory(package
, appValue
, sig
,
779 /* Recursively searching a directory makes no sense when the
780 * directory to search is the thing you're trying to find.
782 rc
= ACTION_CheckDirectory(package
, path
, appValue
);
787 WCHAR pathWithDrive
[MAX_PATH
] = { 'C',':','\\',0 };
788 DWORD drives
= GetLogicalDrives();
793 for (i
= 0; rc
== ERROR_SUCCESS
&& !*appValue
&& i
< 26; i
++)
794 if (drives
& (1 << drives
))
796 pathWithDrive
[0] = 'A' + i
;
797 if (GetDriveTypeW(pathWithDrive
) == DRIVE_FIXED
)
799 lstrcpynW(pathWithDrive
+ 3, path
,
800 sizeof(pathWithDrive
) / sizeof(pathWithDrive
[0]) - 3);
802 rc
= ACTION_RecurseSearchDirectory(package
, appValue
,
803 sig
, pathWithDrive
, depth
);
805 rc
= ACTION_CheckDirectory(package
, pathWithDrive
,
810 TRACE("returning %d\n", rc
);
814 static UINT
ACTION_AppSearchDr(MSIPACKAGE
*package
, LPWSTR
*appValue
,
819 static const WCHAR ExecSeqQuery
[] = {
820 's','e','l','e','c','t',' ','*',' ',
822 'D','r','L','o','c','a','t','o','r',' ',
823 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
824 '\'','%','s','\'',0};
826 TRACE("(package %p, sig %p)\n", package
, sig
);
827 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
828 if (rc
== ERROR_SUCCESS
)
831 WCHAR buffer
[MAX_PATH
], expanded
[MAX_PATH
];
835 rc
= MSI_ViewExecute(view
, 0);
836 if (rc
!= ERROR_SUCCESS
)
838 TRACE("MSI_ViewExecute returned %d\n", rc
);
841 rc
= MSI_ViewFetch(view
,&row
);
842 if (rc
!= ERROR_SUCCESS
)
844 TRACE("MSI_ViewFetch returned %d\n", rc
);
849 /* check whether parent is set */
851 sz
=sizeof(buffer
)/sizeof(buffer
[0]);
852 rc
= MSI_RecordGetStringW(row
,2,buffer
,&sz
);
853 if (rc
!= ERROR_SUCCESS
)
855 ERR("Error is %x\n",rc
);
860 FIXME(": searching parent (%s) unimplemented\n",
864 /* no parent, now look for path */
866 sz
=sizeof(buffer
)/sizeof(buffer
[0]);
867 rc
= MSI_RecordGetStringW(row
,3,buffer
,&sz
);
868 if (rc
!= ERROR_SUCCESS
)
870 ERR("Error is %x\n",rc
);
873 if (MSI_RecordIsNull(row
,4))
876 depth
= MSI_RecordGetInteger(row
,4);
877 ACTION_ExpandAnyPath(package
, buffer
, expanded
,
878 sizeof(expanded
) / sizeof(expanded
[0]));
879 rc
= ACTION_SearchDirectory(package
, sig
, expanded
, depth
, appValue
);
883 msiobj_release(&row
->hdr
);
885 msiobj_release(&view
->hdr
);
889 TRACE("MSI_OpenQuery returned %d\n", rc
);
894 TRACE("returning %d\n", rc
);
898 /* http://msdn.microsoft.com/library/en-us/msi/setup/appsearch_table.asp
899 * is the best reference for the AppSearch table and how it's used.
901 UINT
ACTION_AppSearch(MSIPACKAGE
*package
)
905 static const WCHAR ExecSeqQuery
[] = {
906 's','e','l','e','c','t',' ','*',' ',
908 'A','p','p','S','e','a','r','c','h',0};
910 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
);
911 if (rc
== ERROR_SUCCESS
)
914 WCHAR propBuf
[0x100], sigBuf
[0x100];
917 rc
= MSI_ViewExecute(view
, 0);
918 if (rc
!= ERROR_SUCCESS
)
926 rc
= MSI_ViewFetch(view
,&row
);
927 if (rc
!= ERROR_SUCCESS
)
933 /* get property and signature */
935 sz
=sizeof(propBuf
)/sizeof(propBuf
[0]);
936 rc
= MSI_RecordGetStringW(row
,1,propBuf
,&sz
);
937 if (rc
!= ERROR_SUCCESS
)
939 ERR("Error is %x\n",rc
);
940 msiobj_release(&row
->hdr
);
944 sz
=sizeof(sigBuf
)/sizeof(sigBuf
[0]);
945 rc
= MSI_RecordGetStringW(row
,2,sigBuf
,&sz
);
946 if (rc
!= ERROR_SUCCESS
)
948 ERR("Error is %x\n",rc
);
949 msiobj_release(&row
->hdr
);
952 TRACE("Searching for Property %s, Signature_ %s\n",
953 debugstr_w(propBuf
), debugstr_w(sigBuf
));
954 /* This clears all the fields, so set Name and Property afterward */
955 rc
= ACTION_AppSearchGetSignature(package
, &sig
, sigBuf
);
957 if (rc
== ERROR_SUCCESS
)
959 rc
= ACTION_AppSearchComponents(package
, &value
, &sig
);
960 if (rc
== ERROR_SUCCESS
&& !value
)
962 rc
= ACTION_AppSearchReg(package
, &value
, &sig
);
963 if (rc
== ERROR_SUCCESS
&& !value
)
965 rc
= ACTION_AppSearchIni(package
, &value
, &sig
);
966 if (rc
== ERROR_SUCCESS
&& !value
)
967 rc
= ACTION_AppSearchDr(package
, &value
, &sig
);
973 MSI_SetPropertyW(package
, propBuf
, value
);
977 msi_free( sig
.Languages
);
978 msiobj_release(&row
->hdr
);
983 msiobj_release(&view
->hdr
);