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 */
41 LPWSTR Property
; /* NOT owned by this structure */
54 static void ACTION_VerStrToInteger(LPCWSTR verStr
, PDWORD ms
, PDWORD ls
)
57 int x1
= 0, x2
= 0, x3
= 0, x4
= 0;
60 ptr
= strchrW(verStr
, '.');
64 ptr
= strchrW(ptr
+ 1, '.');
69 ptr
= strchrW(ptr
+ 1, '.');
73 /* FIXME: byte-order dependent? */
78 /* Fills in sig with the the values from the Signature table, where name is the
79 * signature to find. Upon return, sig->File will be NULL if the record is not
80 * found, and not NULL if it is found.
81 * Warning: clears all fields in sig!
82 * Returns ERROR_SUCCESS upon success (where not finding the record counts as
83 * success), something else on error.
85 static UINT
ACTION_AppSearchGetSignature(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
90 static const WCHAR ExecSeqQuery
[] = {
91 's','e','l','e','c','t',' ','*',' ',
93 'S','i','g','n','a','t','u','r','e',' ',
94 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e',' ','=',' ',
97 TRACE("(package %p, sig %p)\n", package
, sig
);
98 memset(sig
, 0, sizeof(*sig
));
99 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, name
);
100 if (rc
== ERROR_SUCCESS
)
104 WCHAR
*minVersion
, *maxVersion
;
106 rc
= MSI_ViewExecute(view
, 0);
107 if (rc
!= ERROR_SUCCESS
)
109 TRACE("MSI_ViewExecute returned %d\n", rc
);
112 rc
= MSI_ViewFetch(view
,&row
);
113 if (rc
!= ERROR_SUCCESS
)
115 TRACE("MSI_ViewFetch returned %d\n", rc
);
121 sig
->File
= msi_dup_record_field(row
,2);
122 minVersion
= msi_dup_record_field(row
,3);
125 ACTION_VerStrToInteger(minVersion
, &sig
->MinVersionMS
,
127 msi_free( minVersion
);
129 maxVersion
= msi_dup_record_field(row
,4);
132 ACTION_VerStrToInteger(maxVersion
, &sig
->MaxVersionMS
,
134 msi_free( maxVersion
);
136 sig
->MinSize
= MSI_RecordGetInteger(row
,5);
137 if (sig
->MinSize
== MSI_NULL_INTEGER
)
139 sig
->MaxSize
= MSI_RecordGetInteger(row
,6);
140 if (sig
->MaxSize
== MSI_NULL_INTEGER
)
142 sig
->Languages
= msi_dup_record_field(row
,9);
143 time
= MSI_RecordGetInteger(row
,7);
144 if (time
!= MSI_NULL_INTEGER
)
145 DosDateTimeToFileTime(HIWORD(time
), LOWORD(time
), &sig
->MinTime
);
146 time
= MSI_RecordGetInteger(row
,8);
147 if (time
!= MSI_NULL_INTEGER
)
148 DosDateTimeToFileTime(HIWORD(time
), LOWORD(time
), &sig
->MaxTime
);
149 TRACE("Found file name %s for Signature_ %s;\n",
150 debugstr_w(sig
->File
), debugstr_w(name
));
151 TRACE("MinVersion is %d.%d.%d.%d\n", HIWORD(sig
->MinVersionMS
),
152 LOWORD(sig
->MinVersionMS
), HIWORD(sig
->MinVersionLS
),
153 LOWORD(sig
->MinVersionLS
));
154 TRACE("MaxVersion is %d.%d.%d.%d\n", HIWORD(sig
->MaxVersionMS
),
155 LOWORD(sig
->MaxVersionMS
), HIWORD(sig
->MaxVersionLS
),
156 LOWORD(sig
->MaxVersionLS
));
157 TRACE("MinSize is %ld, MaxSize is %ld;\n", sig
->MinSize
, sig
->MaxSize
);
158 TRACE("Languages is %s\n", debugstr_w(sig
->Languages
));
162 msiobj_release(&row
->hdr
);
164 msiobj_release(&view
->hdr
);
168 TRACE("MSI_OpenQuery returned %d\n", rc
);
172 TRACE("returning %d\n", rc
);
176 static UINT
ACTION_AppSearchComponents(MSIPACKAGE
*package
, BOOL
*appFound
,
181 static const WCHAR ExecSeqQuery
[] = {
182 's','e','l','e','c','t',' ','*',' ',
184 'C','o','m','p','L','o','c','a','t','o','r',' ',
185 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
186 '\'','%','s','\'',0};
188 TRACE("(package %p, appFound %p, sig %p)\n", package
, appFound
, sig
);
190 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
191 if (rc
== ERROR_SUCCESS
)
197 rc
= MSI_ViewExecute(view
, 0);
198 if (rc
!= ERROR_SUCCESS
)
200 TRACE("MSI_ViewExecute returned %d\n", rc
);
203 rc
= MSI_ViewFetch(view
,&row
);
204 if (rc
!= ERROR_SUCCESS
)
206 TRACE("MSI_ViewFetch returned %d\n", rc
);
213 sz
=sizeof(guid
)/sizeof(guid
[0]);
214 rc
= MSI_RecordGetStringW(row
,2,guid
,&sz
);
215 if (rc
!= ERROR_SUCCESS
)
217 ERR("Error is %x\n",rc
);
220 FIXME("AppSearch unimplemented for CompLocator table (GUID %s)\n",
225 msiobj_release(&row
->hdr
);
227 msiobj_release(&view
->hdr
);
231 TRACE("MSI_OpenQuery returned %d\n", rc
);
235 TRACE("returning %d\n", rc
);
239 static UINT
ACTION_AppSearchReg(MSIPACKAGE
*package
, BOOL
*appFound
,
244 static const WCHAR ExecSeqQuery
[] = {
245 's','e','l','e','c','t',' ','*',' ',
247 'R','e','g','L','o','c','a','t','o','r',' ',
248 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
249 '\'','%','s','\'',0};
250 static const WCHAR dwordFmt
[] = { '#','%','d','\0' };
251 static const WCHAR expandSzFmt
[] = { '#','%','%','%','s','\0' };
252 static const WCHAR binFmt
[] = { '#','x','%','x','\0' };
254 TRACE("(package %p, appFound %p, sig %p)\n", package
, appFound
, sig
);
256 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
257 if (rc
== ERROR_SUCCESS
)
260 LPWSTR keyPath
= NULL
, valueName
= NULL
, propertyValue
= NULL
;
262 HKEY rootKey
, key
= NULL
;
263 DWORD sz
= 0, regType
, i
;
266 rc
= MSI_ViewExecute(view
, 0);
267 if (rc
!= ERROR_SUCCESS
)
269 TRACE("MSI_ViewExecute returned %d\n", rc
);
272 rc
= MSI_ViewFetch(view
,&row
);
273 if (rc
!= ERROR_SUCCESS
)
275 TRACE("MSI_ViewFetch returned %d\n", rc
);
280 root
= MSI_RecordGetInteger(row
,2);
281 keyPath
= msi_dup_record_field(row
,3);
282 /* FIXME: keyPath needs to be expanded for properties */
283 valueName
= msi_dup_record_field(row
,4);
284 /* FIXME: valueName probably does too */
285 type
= MSI_RecordGetInteger(row
,5);
287 if ((type
& 0x0f) != msidbLocatorTypeRawValue
)
289 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
290 type
, debugstr_w(keyPath
), debugstr_w(valueName
));
296 case msidbRegistryRootClassesRoot
:
297 rootKey
= HKEY_CLASSES_ROOT
;
299 case msidbRegistryRootCurrentUser
:
300 rootKey
= HKEY_CURRENT_USER
;
302 case msidbRegistryRootLocalMachine
:
303 rootKey
= HKEY_LOCAL_MACHINE
;
305 case msidbRegistryRootUsers
:
306 rootKey
= HKEY_USERS
;
309 WARN("Unknown root key %d\n", root
);
313 rc
= RegCreateKeyW(rootKey
, keyPath
, &key
);
316 TRACE("RegCreateKeyW returned %d\n", rc
);
320 rc
= RegQueryValueExW(key
, valueName
, NULL
, NULL
, NULL
, &sz
);
323 TRACE("RegQueryValueExW returned %d\n", rc
);
327 /* FIXME: sanity-check sz before allocating (is there an upper-limit
328 * on the value of a property?)
330 value
= msi_alloc( sz
);
331 rc
= RegQueryValueExW(key
, valueName
, NULL
, ®Type
, value
, &sz
);
334 TRACE("RegQueryValueExW returned %d\n", rc
);
339 /* bail out if the registry key is empty */
349 if (*(LPWSTR
)value
== '#')
351 /* escape leading pound with another */
352 propertyValue
= msi_alloc( sz
+ sizeof(WCHAR
));
353 propertyValue
[0] = '#';
354 strcpyW(propertyValue
+ 1, (LPWSTR
)value
);
358 propertyValue
= msi_alloc( sz
);
359 strcpyW(propertyValue
, (LPWSTR
)value
);
363 /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign
366 propertyValue
= msi_alloc( 10 * sizeof(WCHAR
));
367 sprintfW(propertyValue
, dwordFmt
, *(DWORD
*)value
);
370 /* space for extra #% characters in front */
371 propertyValue
= msi_alloc( sz
+ 2 * sizeof(WCHAR
));
372 sprintfW(propertyValue
, expandSzFmt
, (LPWSTR
)value
);
375 /* 3 == length of "#x<nibble>" */
376 propertyValue
= msi_alloc( (sz
* 3 + 1) * sizeof(WCHAR
));
377 for (i
= 0; i
< sz
; i
++)
378 sprintfW(propertyValue
+ i
* 3, binFmt
, value
[i
]);
381 WARN("unimplemented for values of type %ld\n", regType
);
385 TRACE("found registry value, setting %s to %s\n",
386 debugstr_w(sig
->Property
), debugstr_w(propertyValue
));
387 rc
= MSI_SetPropertyW(package
, sig
->Property
, propertyValue
);
391 msi_free( propertyValue
);
396 msi_free( valueName
);
399 msiobj_release(&row
->hdr
);
401 msiobj_release(&view
->hdr
);
405 TRACE("MSI_OpenQuery returned %d\n", rc
);
409 TRACE("returning %d\n", rc
);
413 static UINT
ACTION_AppSearchIni(MSIPACKAGE
*package
, BOOL
*appFound
,
418 static const WCHAR ExecSeqQuery
[] = {
419 's','e','l','e','c','t',' ','*',' ',
421 'I','n','i','L','o','c','a','t','o','r',' ',
422 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
423 '\'','%','s','\'',0};
425 TRACE("(package %p, appFound %p, sig %p)\n", package
, appFound
, sig
);
427 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
428 if (rc
== ERROR_SUCCESS
)
433 rc
= MSI_ViewExecute(view
, 0);
434 if (rc
!= ERROR_SUCCESS
)
436 TRACE("MSI_ViewExecute returned %d\n", rc
);
439 rc
= MSI_ViewFetch(view
,&row
);
440 if (rc
!= ERROR_SUCCESS
)
442 TRACE("MSI_ViewFetch returned %d\n", rc
);
448 fileName
= msi_dup_record_field(row
,2);
449 FIXME("AppSearch unimplemented for IniLocator (ini file name %s)\n",
450 debugstr_w(fileName
));
455 msiobj_release(&row
->hdr
);
457 msiobj_release(&view
->hdr
);
461 TRACE("MSI_OpenQuery returned %d\n", rc
);
466 TRACE("returning %d\n", rc
);
470 /* Expands the value in src into a path without property names and only
471 * containing long path names into dst. Replaces at most len characters of dst,
472 * and always NULL-terminates dst if dst is not NULL and len >= 1.
474 * Assumes src and dst are non-overlapping.
475 * FIXME: return code probably needed:
476 * - what does AppSearch return if the table values are invalid?
477 * - what if dst is too small?
479 static void ACTION_ExpandAnyPath(MSIPACKAGE
*package
, WCHAR
*src
, WCHAR
*dst
,
485 if (!src
|| !dst
|| !len
)
488 /* Ignore the short portion of the path, don't think we can use it anyway */
489 if ((ptr
= strchrW(src
, '|')))
493 while (*ptr
&& copied
< len
- 1)
495 WCHAR
*prop
= strchrW(ptr
, '[');
499 WCHAR
*propEnd
= strchrW(prop
+ 1, ']');
503 WARN("Unterminated property name in AnyPath: %s\n",
512 propLen
= len
- copied
- 1;
513 MSI_GetPropertyW(package
, prop
+ 1, dst
+ copied
, &propLen
);
520 size_t toCopy
= min(strlenW(ptr
) + 1, len
- copied
- 1);
522 memcpy(dst
+ copied
, ptr
, toCopy
* sizeof(WCHAR
));
527 *(dst
+ copied
) = '\0';
530 /* Sets *matches to whether the file (whose path is filePath) matches the
531 * versions set in sig.
532 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
533 * something else if an install-halting error occurs.
535 static UINT
ACTION_FileVersionMatches(MSISIGNATURE
*sig
, LPCWSTR filePath
,
538 UINT rc
= ERROR_SUCCESS
;
543 FIXME(": need to check version for languages %s\n",
544 debugstr_w(sig
->Languages
));
548 DWORD zero
, size
= GetFileVersionInfoSizeW(filePath
, &zero
);
552 LPVOID buf
= msi_alloc( size
);
556 static WCHAR rootW
[] = { '\\',0 };
558 LPVOID subBlock
= NULL
;
560 if (GetFileVersionInfoW(filePath
, 0, size
, buf
))
561 VerQueryValueW(buf
, rootW
, &subBlock
, &versionLen
);
564 VS_FIXEDFILEINFO
*info
=
565 (VS_FIXEDFILEINFO
*)subBlock
;
567 TRACE("Comparing file version %d.%d.%d.%d:\n",
568 HIWORD(info
->dwFileVersionMS
),
569 LOWORD(info
->dwFileVersionMS
),
570 HIWORD(info
->dwFileVersionLS
),
571 LOWORD(info
->dwFileVersionLS
));
572 if (info
->dwFileVersionMS
< sig
->MinVersionMS
573 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
574 info
->dwFileVersionLS
< sig
->MinVersionLS
))
576 TRACE("Less than minimum version %d.%d.%d.%d\n",
577 HIWORD(sig
->MinVersionMS
),
578 LOWORD(sig
->MinVersionMS
),
579 HIWORD(sig
->MinVersionLS
),
580 LOWORD(sig
->MinVersionLS
));
582 else if (info
->dwFileVersionMS
< sig
->MinVersionMS
583 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
584 info
->dwFileVersionLS
< sig
->MinVersionLS
))
586 TRACE("Greater than minimum version %d.%d.%d.%d\n",
587 HIWORD(sig
->MaxVersionMS
),
588 LOWORD(sig
->MaxVersionMS
),
589 HIWORD(sig
->MaxVersionLS
),
590 LOWORD(sig
->MaxVersionLS
));
598 rc
= ERROR_OUTOFMEMORY
;
604 /* Sets *matches to whether the file in findData matches that in sig.
605 * fullFilePath is assumed to be the full path of the file specified in
606 * findData, which may be necessary to compare the version.
607 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
608 * something else if an install-halting error occurs.
610 static UINT
ACTION_FileMatchesSig(MSISIGNATURE
*sig
,
611 LPWIN32_FIND_DATAW findData
, LPCWSTR fullFilePath
, BOOL
*matches
)
613 UINT rc
= ERROR_SUCCESS
;
616 /* assumes the caller has already ensured the filenames match, so check
619 if (sig
->MinTime
.dwLowDateTime
|| sig
->MinTime
.dwHighDateTime
)
621 if (findData
->ftCreationTime
.dwHighDateTime
<
622 sig
->MinTime
.dwHighDateTime
||
623 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MinTime
.dwHighDateTime
624 && findData
->ftCreationTime
.dwLowDateTime
<
625 sig
->MinTime
.dwLowDateTime
))
628 if (*matches
&& (sig
->MaxTime
.dwLowDateTime
|| sig
->MaxTime
.dwHighDateTime
))
630 if (findData
->ftCreationTime
.dwHighDateTime
>
631 sig
->MaxTime
.dwHighDateTime
||
632 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MaxTime
.dwHighDateTime
633 && findData
->ftCreationTime
.dwLowDateTime
>
634 sig
->MaxTime
.dwLowDateTime
))
637 if (*matches
&& sig
->MinSize
&& findData
->nFileSizeLow
< sig
->MinSize
)
639 if (*matches
&& sig
->MaxSize
&& findData
->nFileSizeLow
> sig
->MaxSize
)
641 if (*matches
&& (sig
->MinVersionMS
|| sig
->MinVersionLS
||
642 sig
->MaxVersionMS
|| sig
->MaxVersionLS
))
643 rc
= ACTION_FileVersionMatches(sig
, fullFilePath
, matches
);
647 /* Recursively searches the directory dir for files that match the signature
648 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
649 * (and only dir). If depth is 1, searches dir and its immediate
651 * Assumes sig->File is not NULL.
652 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
653 * something else on failures which should halt the install.
655 static UINT
ACTION_RecurseSearchDirectory(MSIPACKAGE
*package
, BOOL
*appFound
,
656 MSISIGNATURE
*sig
, LPCWSTR dir
, int depth
)
658 static const WCHAR starDotStarW
[] = { '*','.','*',0 };
659 UINT rc
= ERROR_SUCCESS
;
660 size_t dirLen
= lstrlenW(dir
), fileLen
= lstrlenW(sig
->File
);
663 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir
),
664 debugstr_w(sig
->File
), depth
);
667 return ERROR_INVALID_PARAMETER
;
670 /* We need the buffer in both paths below, so go ahead and allocate it
671 * here. Add two because we might need to add a backslash if the dir name
672 * isn't backslash-terminated.
674 buf
= msi_alloc( (dirLen
+ max(fileLen
, lstrlenW(starDotStarW
)) + 2) * sizeof(WCHAR
));
677 /* a depth of 0 implies we should search dir, so go ahead and search */
679 WIN32_FIND_DATAW findData
;
681 memcpy(buf
, dir
, dirLen
* sizeof(WCHAR
));
682 if (buf
[dirLen
- 1] != '\\')
683 buf
[dirLen
++ - 1] = '\\';
684 memcpy(buf
+ dirLen
, sig
->File
, (fileLen
+ 1) * sizeof(WCHAR
));
685 hFind
= FindFirstFileW(buf
, &findData
);
686 if (hFind
!= INVALID_HANDLE_VALUE
)
690 /* assuming Signature can't contain wildcards for the file name,
691 * so don't bother with FindNextFileW here.
693 if (!(rc
= ACTION_FileMatchesSig(sig
, &findData
, buf
, &matches
))
696 TRACE("found file, setting %s to %s\n",
697 debugstr_w(sig
->Property
), debugstr_w(buf
));
698 rc
= MSI_SetPropertyW(package
, sig
->Property
, buf
);
703 if (rc
== ERROR_SUCCESS
&& !*appFound
&& depth
> 0)
706 WIN32_FIND_DATAW findData
;
708 memcpy(buf
, dir
, dirLen
* sizeof(WCHAR
));
709 if (buf
[dirLen
- 1] != '\\')
710 buf
[dirLen
++ - 1] = '\\';
711 lstrcpyW(buf
+ dirLen
, starDotStarW
);
712 hFind
= FindFirstFileW(buf
, &findData
);
713 if (hFind
!= INVALID_HANDLE_VALUE
)
715 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
716 rc
= ACTION_RecurseSearchDirectory(package
, appFound
,
717 sig
, findData
.cFileName
, depth
- 1);
718 while (rc
== ERROR_SUCCESS
&& !*appFound
&&
719 FindNextFileW(hFind
, &findData
) != 0)
721 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
722 rc
= ACTION_RecurseSearchDirectory(package
, appFound
,
723 sig
, findData
.cFileName
, depth
- 1);
731 rc
= ERROR_OUTOFMEMORY
;
736 static UINT
ACTION_CheckDirectory(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
739 UINT rc
= ERROR_SUCCESS
;
741 if (GetFileAttributesW(dir
) & FILE_ATTRIBUTE_DIRECTORY
)
743 TRACE("directory exists, setting %s to %s\n",
744 debugstr_w(sig
->Property
), debugstr_w(dir
));
745 rc
= MSI_SetPropertyW(package
, sig
->Property
, dir
);
750 static BOOL
ACTION_IsFullPath(LPCWSTR path
)
752 WCHAR first
= toupperW(path
[0]);
755 if (first
>= 'A' && first
<= 'Z' && path
[1] == ':')
757 else if (path
[0] == '\\' && path
[1] == '\\')
764 static UINT
ACTION_SearchDirectory(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
765 LPCWSTR expanded
, int depth
)
770 TRACE("%p, %p, %s, %d\n", package
, sig
, debugstr_w(expanded
), depth
);
771 if (ACTION_IsFullPath(expanded
))
774 rc
= ACTION_RecurseSearchDirectory(package
, &found
, sig
,
778 /* Recursively searching a directory makes no sense when the
779 * directory to search is the thing you're trying to find.
781 rc
= ACTION_CheckDirectory(package
, sig
, expanded
);
786 WCHAR pathWithDrive
[MAX_PATH
] = { 'C',':','\\',0 };
787 DWORD drives
= GetLogicalDrives();
792 for (i
= 0; rc
== ERROR_SUCCESS
&& !found
&& i
< 26; i
++)
793 if (drives
& (1 << drives
))
795 pathWithDrive
[0] = 'A' + i
;
796 if (GetDriveTypeW(pathWithDrive
) == DRIVE_FIXED
)
798 lstrcpynW(pathWithDrive
+ 3, expanded
,
799 sizeof(pathWithDrive
) / sizeof(pathWithDrive
[0]) - 3);
801 rc
= ACTION_RecurseSearchDirectory(package
, &found
, sig
,
802 pathWithDrive
, depth
);
804 rc
= ACTION_CheckDirectory(package
, sig
, pathWithDrive
);
808 TRACE("returning %d\n", rc
);
812 static UINT
ACTION_AppSearchDr(MSIPACKAGE
*package
, MSISIGNATURE
*sig
)
816 static const WCHAR ExecSeqQuery
[] = {
817 's','e','l','e','c','t',' ','*',' ',
819 'D','r','L','o','c','a','t','o','r',' ',
820 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
821 '\'','%','s','\'',0};
823 TRACE("(package %p, sig %p)\n", package
, sig
);
824 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
, sig
->Name
);
825 if (rc
== ERROR_SUCCESS
)
828 WCHAR buffer
[MAX_PATH
], expanded
[MAX_PATH
];
832 rc
= MSI_ViewExecute(view
, 0);
833 if (rc
!= ERROR_SUCCESS
)
835 TRACE("MSI_ViewExecute returned %d\n", rc
);
838 rc
= MSI_ViewFetch(view
,&row
);
839 if (rc
!= ERROR_SUCCESS
)
841 TRACE("MSI_ViewFetch returned %d\n", rc
);
846 /* check whether parent is set */
848 sz
=sizeof(buffer
)/sizeof(buffer
[0]);
849 rc
= MSI_RecordGetStringW(row
,2,buffer
,&sz
);
850 if (rc
!= ERROR_SUCCESS
)
852 ERR("Error is %x\n",rc
);
857 FIXME(": searching parent (%s) unimplemented\n",
861 /* no parent, now look for path */
863 sz
=sizeof(buffer
)/sizeof(buffer
[0]);
864 rc
= MSI_RecordGetStringW(row
,3,buffer
,&sz
);
865 if (rc
!= ERROR_SUCCESS
)
867 ERR("Error is %x\n",rc
);
870 if (MSI_RecordIsNull(row
,4))
873 depth
= MSI_RecordGetInteger(row
,4);
874 ACTION_ExpandAnyPath(package
, buffer
, expanded
,
875 sizeof(expanded
) / sizeof(expanded
[0]));
876 rc
= ACTION_SearchDirectory(package
, sig
, expanded
, depth
);
880 msiobj_release(&row
->hdr
);
882 msiobj_release(&view
->hdr
);
886 TRACE("MSI_OpenQuery returned %d\n", rc
);
891 TRACE("returning %d\n", rc
);
895 /* http://msdn.microsoft.com/library/en-us/msi/setup/appsearch_table.asp
896 * is the best reference for the AppSearch table and how it's used.
898 UINT
ACTION_AppSearch(MSIPACKAGE
*package
)
902 static const WCHAR ExecSeqQuery
[] = {
903 's','e','l','e','c','t',' ','*',' ',
905 'A','p','p','S','e','a','r','c','h',0};
907 rc
= MSI_OpenQuery(package
->db
, &view
, ExecSeqQuery
);
908 if (rc
== ERROR_SUCCESS
)
911 WCHAR propBuf
[0x100], sigBuf
[0x100];
914 BOOL appFound
= FALSE
;
916 rc
= MSI_ViewExecute(view
, 0);
917 if (rc
!= ERROR_SUCCESS
)
922 rc
= MSI_ViewFetch(view
,&row
);
923 if (rc
!= ERROR_SUCCESS
)
929 /* get property and signature */
931 sz
=sizeof(propBuf
)/sizeof(propBuf
[0]);
932 rc
= MSI_RecordGetStringW(row
,1,propBuf
,&sz
);
933 if (rc
!= ERROR_SUCCESS
)
935 ERR("Error is %x\n",rc
);
936 msiobj_release(&row
->hdr
);
940 sz
=sizeof(sigBuf
)/sizeof(sigBuf
[0]);
941 rc
= MSI_RecordGetStringW(row
,2,sigBuf
,&sz
);
942 if (rc
!= ERROR_SUCCESS
)
944 ERR("Error is %x\n",rc
);
945 msiobj_release(&row
->hdr
);
948 TRACE("Searching for Property %s, Signature_ %s\n",
949 debugstr_w(propBuf
), debugstr_w(sigBuf
));
950 /* This clears all the fields, so set Name and Property afterward */
951 rc
= ACTION_AppSearchGetSignature(package
, &sig
, sigBuf
);
953 sig
.Property
= propBuf
;
954 if (rc
== ERROR_SUCCESS
)
956 rc
= ACTION_AppSearchComponents(package
, &appFound
, &sig
);
957 if (rc
== ERROR_SUCCESS
&& !appFound
)
959 rc
= ACTION_AppSearchReg(package
, &appFound
, &sig
);
960 if (rc
== ERROR_SUCCESS
&& !appFound
)
962 rc
= ACTION_AppSearchIni(package
, &appFound
, &sig
);
963 if (rc
== ERROR_SUCCESS
&& !appFound
)
964 rc
= ACTION_AppSearchDr(package
, &sig
);
969 msi_free( sig
.Languages
);
970 msiobj_release(&row
->hdr
);
975 msiobj_release(&view
->hdr
);