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
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
38 typedef struct tagMSISIGNATURE
40 LPCWSTR 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 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
, LPCWSTR name
)
86 static const WCHAR query
[] = {
87 's','e','l','e','c','t',' ','*',' ',
89 'S','i','g','n','a','t','u','r','e',' ',
90 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e',' ','=',' ',
92 LPWSTR minVersion
, maxVersion
;
96 TRACE("package %p, sig %p\n", package
, sig
);
98 memset(sig
, 0, sizeof(*sig
));
100 row
= MSI_QueryGetRecord( package
->db
, query
, name
);
103 TRACE("failed to query signature for %s\n", debugstr_w(name
));
104 return ERROR_SUCCESS
;
108 sig
->File
= msi_dup_record_field(row
,2);
109 minVersion
= msi_dup_record_field(row
,3);
112 ACTION_VerStrToInteger(minVersion
, &sig
->MinVersionMS
, &sig
->MinVersionLS
);
113 msi_free( minVersion
);
115 maxVersion
= msi_dup_record_field(row
,4);
118 ACTION_VerStrToInteger(maxVersion
, &sig
->MaxVersionMS
, &sig
->MaxVersionLS
);
119 msi_free( maxVersion
);
121 sig
->MinSize
= MSI_RecordGetInteger(row
,5);
122 if (sig
->MinSize
== MSI_NULL_INTEGER
)
124 sig
->MaxSize
= MSI_RecordGetInteger(row
,6);
125 if (sig
->MaxSize
== MSI_NULL_INTEGER
)
127 sig
->Languages
= msi_dup_record_field(row
,9);
128 time
= MSI_RecordGetInteger(row
,7);
129 if (time
!= MSI_NULL_INTEGER
)
130 DosDateTimeToFileTime(HIWORD(time
), LOWORD(time
), &sig
->MinTime
);
131 time
= MSI_RecordGetInteger(row
,8);
132 if (time
!= MSI_NULL_INTEGER
)
133 DosDateTimeToFileTime(HIWORD(time
), LOWORD(time
), &sig
->MaxTime
);
135 TRACE("Found file name %s for Signature_ %s;\n",
136 debugstr_w(sig
->File
), debugstr_w(name
));
137 TRACE("MinVersion is %d.%d.%d.%d\n", HIWORD(sig
->MinVersionMS
),
138 LOWORD(sig
->MinVersionMS
), HIWORD(sig
->MinVersionLS
),
139 LOWORD(sig
->MinVersionLS
));
140 TRACE("MaxVersion is %d.%d.%d.%d\n", HIWORD(sig
->MaxVersionMS
),
141 LOWORD(sig
->MaxVersionMS
), HIWORD(sig
->MaxVersionLS
),
142 LOWORD(sig
->MaxVersionLS
));
143 TRACE("MinSize is %d, MaxSize is %d;\n", sig
->MinSize
, sig
->MaxSize
);
144 TRACE("Languages is %s\n", debugstr_w(sig
->Languages
));
146 msiobj_release( &row
->hdr
);
148 return ERROR_SUCCESS
;
151 /* Frees any memory allocated in sig */
152 static void ACTION_FreeSignature(MSISIGNATURE
*sig
)
155 msi_free(sig
->Languages
);
158 static UINT
ACTION_AppSearchComponents(MSIPACKAGE
*package
, LPWSTR
*appValue
, MSISIGNATURE
*sig
)
160 static const WCHAR query
[] = {
161 'S','E','L','E','C','T',' ','*',' ',
163 '`','C','o','m','p','L','o','c','a','t','o','r','`',' ',
164 'W','H','E','R','E',' ','`','S','i','g','n','a','t','u','r','e','_','`',' ','=',' ',
165 '\'','%','s','\'',0};
166 static const WCHAR sigquery
[] = {
167 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
168 '`','S','i','g','n','a','t','u','r','e','`',' ',
169 'W','H','E','R','E',' ','`','S','i','g','n','a','t','u','r','e','`',' ','=',' ',
170 '\'','%','s','\'',0};
172 MSIRECORD
*row
, *rec
;
173 LPCWSTR signature
, guid
;
174 BOOL sigpresent
= TRUE
;
177 WCHAR path
[MAX_PATH
];
178 DWORD size
= MAX_PATH
;
182 TRACE("%s\n", debugstr_w(sig
->Name
));
186 row
= MSI_QueryGetRecord(package
->db
, query
, sig
->Name
);
189 TRACE("failed to query CompLocator for %s\n", debugstr_w(sig
->Name
));
190 return ERROR_SUCCESS
;
193 signature
= MSI_RecordGetString(row
, 1);
194 guid
= MSI_RecordGetString(row
, 2);
195 type
= MSI_RecordGetInteger(row
, 3);
197 rec
= MSI_QueryGetRecord(package
->db
, sigquery
, signature
);
202 MsiLocateComponentW(guid
, path
, &size
);
206 attr
= GetFileAttributesW(path
);
207 if (attr
== INVALID_FILE_ATTRIBUTES
)
210 isdir
= (attr
& FILE_ATTRIBUTE_DIRECTORY
);
212 if (type
!= msidbLocatorTypeDirectory
&& sigpresent
&& !isdir
)
214 *appValue
= strdupW(path
);
216 else if (!sigpresent
&& (type
!= msidbLocatorTypeDirectory
|| isdir
))
218 if (type
== msidbLocatorTypeFileName
)
220 ptr
= strrchrW(path
, '\\');
224 PathAddBackslashW(path
);
226 *appValue
= strdupW(path
);
230 if (rec
) msiobj_release(&rec
->hdr
);
231 msiobj_release(&row
->hdr
);
232 return ERROR_SUCCESS
;
235 static void ACTION_ConvertRegValue(DWORD regType
, const BYTE
*value
, DWORD sz
,
238 static const WCHAR dwordFmt
[] = { '#','%','d','\0' };
239 static const WCHAR expandSzFmt
[] = { '#','%','%','%','s','\0' };
240 static const WCHAR binFmt
[] = { '#','x','%','x','\0' };
246 if (*(LPCWSTR
)value
== '#')
248 /* escape leading pound with another */
249 *appValue
= msi_alloc(sz
+ sizeof(WCHAR
));
250 (*appValue
)[0] = '#';
251 strcpyW(*appValue
+ 1, (LPCWSTR
)value
);
255 *appValue
= msi_alloc(sz
);
256 strcpyW(*appValue
, (LPCWSTR
)value
);
260 /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign
263 *appValue
= msi_alloc(10 * sizeof(WCHAR
));
264 sprintfW(*appValue
, dwordFmt
, *(const DWORD
*)value
);
267 /* space for extra #% characters in front */
268 *appValue
= msi_alloc(sz
+ 2 * sizeof(WCHAR
));
269 sprintfW(*appValue
, expandSzFmt
, (LPCWSTR
)value
);
272 /* 3 == length of "#x<nibble>" */
273 *appValue
= msi_alloc((sz
* 3 + 1) * sizeof(WCHAR
));
274 for (i
= 0; i
< sz
; i
++)
275 sprintfW(*appValue
+ i
* 3, binFmt
, value
[i
]);
278 WARN("unimplemented for values of type %d\n", regType
);
283 static UINT
ACTION_SearchDirectory(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
284 LPCWSTR path
, int depth
, LPWSTR
*appValue
);
286 static UINT
ACTION_AppSearchReg(MSIPACKAGE
*package
, LPWSTR
*appValue
, MSISIGNATURE
*sig
)
288 static const WCHAR query
[] = {
289 's','e','l','e','c','t',' ','*',' ',
291 'R','e','g','L','o','c','a','t','o','r',' ',
292 'w','h','e','r','e',' ',
293 'S','i','g','n','a','t','u','r','e','_',' ','=',' ', '\'','%','s','\'',0};
294 LPWSTR keyPath
= NULL
, valueName
= NULL
;
295 LPWSTR deformatted
= NULL
;
297 HKEY rootKey
, key
= NULL
;
298 DWORD sz
= 0, regType
;
303 TRACE("%s\n", debugstr_w(sig
->Name
));
307 row
= MSI_QueryGetRecord( package
->db
, query
, sig
->Name
);
310 TRACE("failed to query RegLocator for %s\n", debugstr_w(sig
->Name
));
311 return ERROR_SUCCESS
;
314 root
= MSI_RecordGetInteger(row
,2);
315 keyPath
= msi_dup_record_field(row
,3);
316 valueName
= msi_dup_record_field(row
,4);
317 type
= MSI_RecordGetInteger(row
,5);
319 deformat_string(package
, keyPath
, &deformatted
);
323 case msidbRegistryRootClassesRoot
:
324 rootKey
= HKEY_CLASSES_ROOT
;
326 case msidbRegistryRootCurrentUser
:
327 rootKey
= HKEY_CURRENT_USER
;
329 case msidbRegistryRootLocalMachine
:
330 rootKey
= HKEY_LOCAL_MACHINE
;
332 case msidbRegistryRootUsers
:
333 rootKey
= HKEY_USERS
;
336 WARN("Unknown root key %d\n", root
);
340 rc
= RegOpenKeyW(rootKey
, deformatted
, &key
);
343 TRACE("RegOpenKeyW returned %d\n", rc
);
347 rc
= RegQueryValueExW(key
, valueName
, NULL
, NULL
, NULL
, &sz
);
350 TRACE("RegQueryValueExW returned %d\n", rc
);
353 /* FIXME: sanity-check sz before allocating (is there an upper-limit
354 * on the value of a property?)
356 value
= msi_alloc( sz
);
357 rc
= RegQueryValueExW(key
, valueName
, NULL
, ®Type
, value
, &sz
);
360 TRACE("RegQueryValueExW returned %d\n", rc
);
364 /* bail out if the registry key is empty */
370 case msidbLocatorTypeDirectory
:
371 rc
= ACTION_SearchDirectory(package
, sig
, (LPWSTR
)value
, 0, appValue
);
373 case msidbLocatorTypeFileName
:
374 *appValue
= strdupW((LPWSTR
)value
);
376 case msidbLocatorTypeRawValue
:
377 ACTION_ConvertRegValue(regType
, value
, sz
, appValue
);
380 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
381 type
, debugstr_w(keyPath
), debugstr_w(valueName
));
388 msi_free( valueName
);
389 msi_free( deformatted
);
391 msiobj_release(&row
->hdr
);
393 return ERROR_SUCCESS
;
396 static UINT
ACTION_AppSearchIni(MSIPACKAGE
*package
, LPWSTR
*appValue
,
399 static const WCHAR query
[] = {
400 's','e','l','e','c','t',' ','*',' ',
402 'I','n','i','L','o','c','a','t','o','r',' ',
403 'w','h','e','r','e',' ',
404 'S','i','g','n','a','t','u','r','e','_',' ','=',' ','\'','%','s','\'',0};
406 LPWSTR fileName
, section
, key
;
410 TRACE("%s\n", debugstr_w(sig
->Name
));
414 row
= MSI_QueryGetRecord( package
->db
, query
, sig
->Name
);
417 TRACE("failed to query IniLocator for %s\n", debugstr_w(sig
->Name
));
418 return ERROR_SUCCESS
;
421 fileName
= msi_dup_record_field(row
, 2);
422 section
= msi_dup_record_field(row
, 3);
423 key
= msi_dup_record_field(row
, 4);
424 field
= MSI_RecordGetInteger(row
, 5);
425 type
= MSI_RecordGetInteger(row
, 6);
426 if (field
== MSI_NULL_INTEGER
)
428 if (type
== MSI_NULL_INTEGER
)
431 GetPrivateProfileStringW(section
, key
, NULL
, buf
, MAX_PATH
, fileName
);
436 case msidbLocatorTypeDirectory
:
437 FIXME("unimplemented for Directory (%s)\n", debugstr_w(buf
));
439 case msidbLocatorTypeFileName
:
440 FIXME("unimplemented for File (%s)\n", debugstr_w(buf
));
442 case msidbLocatorTypeRawValue
:
443 *appValue
= strdupW(buf
);
452 msiobj_release(&row
->hdr
);
454 return ERROR_SUCCESS
;
457 /* Expands the value in src into a path without property names and only
458 * containing long path names into dst. Replaces at most len characters of dst,
459 * and always NULL-terminates dst if dst is not NULL and len >= 1.
461 * Assumes src and dst are non-overlapping.
462 * FIXME: return code probably needed:
463 * - what does AppSearch return if the table values are invalid?
464 * - what if dst is too small?
466 static void ACTION_ExpandAnyPath(MSIPACKAGE
*package
, WCHAR
*src
, WCHAR
*dst
,
472 if (!src
|| !dst
|| !len
)
474 if (dst
) *dst
= '\0';
478 /* Ignore the short portion of the path, don't think we can use it anyway */
479 if ((ptr
= strchrW(src
, '|')))
483 while (*ptr
&& copied
< len
- 1)
485 WCHAR
*prop
= strchrW(ptr
, '[');
489 WCHAR
*propEnd
= strchrW(prop
+ 1, ']');
493 WARN("Unterminated property name in AnyPath: %s\n",
502 propLen
= len
- copied
- 1;
503 MSI_GetPropertyW(package
, prop
+ 1, dst
+ copied
, &propLen
);
510 size_t toCopy
= min(strlenW(ptr
) + 1, len
- copied
- 1);
512 memcpy(dst
+ copied
, ptr
, toCopy
* sizeof(WCHAR
));
517 *(dst
+ copied
) = '\0';
520 /* Sets *matches to whether the file (whose path is filePath) matches the
521 * versions set in sig.
522 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
523 * something else if an install-halting error occurs.
525 static UINT
ACTION_FileVersionMatches(const MSISIGNATURE
*sig
, LPCWSTR filePath
,
528 UINT rc
= ERROR_SUCCESS
;
533 FIXME(": need to check version for languages %s\n",
534 debugstr_w(sig
->Languages
));
538 DWORD zero
, size
= GetFileVersionInfoSizeW(filePath
, &zero
);
542 LPVOID buf
= msi_alloc( size
);
546 static const WCHAR rootW
[] = { '\\',0 };
548 LPVOID subBlock
= NULL
;
550 if (GetFileVersionInfoW(filePath
, 0, size
, buf
))
551 VerQueryValueW(buf
, rootW
, &subBlock
, &versionLen
);
554 VS_FIXEDFILEINFO
*info
=
555 (VS_FIXEDFILEINFO
*)subBlock
;
557 TRACE("Comparing file version %d.%d.%d.%d:\n",
558 HIWORD(info
->dwFileVersionMS
),
559 LOWORD(info
->dwFileVersionMS
),
560 HIWORD(info
->dwFileVersionLS
),
561 LOWORD(info
->dwFileVersionLS
));
562 if (info
->dwFileVersionMS
< sig
->MinVersionMS
563 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
564 info
->dwFileVersionLS
< sig
->MinVersionLS
))
566 TRACE("Less than minimum version %d.%d.%d.%d\n",
567 HIWORD(sig
->MinVersionMS
),
568 LOWORD(sig
->MinVersionMS
),
569 HIWORD(sig
->MinVersionLS
),
570 LOWORD(sig
->MinVersionLS
));
572 else if (info
->dwFileVersionMS
< sig
->MinVersionMS
573 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
574 info
->dwFileVersionLS
< sig
->MinVersionLS
))
576 TRACE("Greater than minimum version %d.%d.%d.%d\n",
577 HIWORD(sig
->MaxVersionMS
),
578 LOWORD(sig
->MaxVersionMS
),
579 HIWORD(sig
->MaxVersionLS
),
580 LOWORD(sig
->MaxVersionLS
));
588 rc
= ERROR_OUTOFMEMORY
;
594 /* Sets *matches to whether the file in findData matches that in sig.
595 * fullFilePath is assumed to be the full path of the file specified in
596 * findData, which may be necessary to compare the version.
597 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
598 * something else if an install-halting error occurs.
600 static UINT
ACTION_FileMatchesSig(const MSISIGNATURE
*sig
,
601 const WIN32_FIND_DATAW
*findData
, LPCWSTR fullFilePath
, BOOL
*matches
)
603 UINT rc
= ERROR_SUCCESS
;
606 /* assumes the caller has already ensured the filenames match, so check
609 if (sig
->MinTime
.dwLowDateTime
|| sig
->MinTime
.dwHighDateTime
)
611 if (findData
->ftCreationTime
.dwHighDateTime
<
612 sig
->MinTime
.dwHighDateTime
||
613 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MinTime
.dwHighDateTime
614 && findData
->ftCreationTime
.dwLowDateTime
<
615 sig
->MinTime
.dwLowDateTime
))
618 if (*matches
&& (sig
->MaxTime
.dwLowDateTime
|| sig
->MaxTime
.dwHighDateTime
))
620 if (findData
->ftCreationTime
.dwHighDateTime
>
621 sig
->MaxTime
.dwHighDateTime
||
622 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MaxTime
.dwHighDateTime
623 && findData
->ftCreationTime
.dwLowDateTime
>
624 sig
->MaxTime
.dwLowDateTime
))
627 if (*matches
&& sig
->MinSize
&& findData
->nFileSizeLow
< sig
->MinSize
)
629 if (*matches
&& sig
->MaxSize
&& findData
->nFileSizeLow
> sig
->MaxSize
)
631 if (*matches
&& (sig
->MinVersionMS
|| sig
->MinVersionLS
||
632 sig
->MaxVersionMS
|| sig
->MaxVersionLS
))
633 rc
= ACTION_FileVersionMatches(sig
, fullFilePath
, matches
);
637 /* Recursively searches the directory dir for files that match the signature
638 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
639 * (and only dir). If depth is 1, searches dir and its immediate
641 * Assumes sig->File is not NULL.
642 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
643 * something else on failures which should halt the install.
645 static UINT
ACTION_RecurseSearchDirectory(MSIPACKAGE
*package
, LPWSTR
*appValue
,
646 MSISIGNATURE
*sig
, LPCWSTR dir
, int depth
)
648 static const WCHAR starDotStarW
[] = { '*','.','*',0 };
649 UINT rc
= ERROR_SUCCESS
;
650 size_t dirLen
= lstrlenW(dir
), fileLen
= lstrlenW(sig
->File
);
653 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir
),
654 debugstr_w(sig
->File
), depth
);
657 return ERROR_INVALID_PARAMETER
;
660 /* We need the buffer in both paths below, so go ahead and allocate it
661 * here. Add two because we might need to add a backslash if the dir name
662 * isn't backslash-terminated.
664 buf
= msi_alloc( (dirLen
+ max(fileLen
, lstrlenW(starDotStarW
)) + 2) * sizeof(WCHAR
));
667 /* a depth of 0 implies we should search dir, so go ahead and search */
669 WIN32_FIND_DATAW findData
;
671 memcpy(buf
, dir
, dirLen
* sizeof(WCHAR
));
672 if (buf
[dirLen
- 1] != '\\')
673 buf
[dirLen
++ - 1] = '\\';
674 memcpy(buf
+ dirLen
, sig
->File
, (fileLen
+ 1) * sizeof(WCHAR
));
675 hFind
= FindFirstFileW(buf
, &findData
);
676 if (hFind
!= INVALID_HANDLE_VALUE
)
680 /* assuming Signature can't contain wildcards for the file name,
681 * so don't bother with FindNextFileW here.
683 if (!(rc
= ACTION_FileMatchesSig(sig
, &findData
, buf
, &matches
))
686 TRACE("found file, returning %s\n", debugstr_w(buf
));
691 if (rc
== ERROR_SUCCESS
&& !*appValue
&& depth
> 0)
694 WIN32_FIND_DATAW findData
;
696 memcpy(buf
, dir
, dirLen
* sizeof(WCHAR
));
697 if (buf
[dirLen
- 1] != '\\')
698 buf
[dirLen
++ - 1] = '\\';
699 lstrcpyW(buf
+ dirLen
, starDotStarW
);
700 hFind
= FindFirstFileW(buf
, &findData
);
701 if (hFind
!= INVALID_HANDLE_VALUE
)
703 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
704 rc
= ACTION_RecurseSearchDirectory(package
, appValue
, sig
,
705 findData
.cFileName
, depth
- 1);
706 while (rc
== ERROR_SUCCESS
&& !*appValue
&&
707 FindNextFileW(hFind
, &findData
) != 0)
709 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
710 rc
= ACTION_RecurseSearchDirectory(package
, appValue
,
711 sig
, findData
.cFileName
, depth
- 1);
720 rc
= ERROR_OUTOFMEMORY
;
725 static UINT
ACTION_CheckDirectory(MSIPACKAGE
*package
, LPCWSTR dir
,
728 DWORD attr
= GetFileAttributesW(dir
);
730 if (attr
!= INVALID_FILE_ATTRIBUTES
&& (attr
& FILE_ATTRIBUTE_DIRECTORY
))
732 TRACE("directory exists, returning %s\n", debugstr_w(dir
));
733 *appValue
= strdupW(dir
);
736 return ERROR_SUCCESS
;
739 static BOOL
ACTION_IsFullPath(LPCWSTR path
)
741 WCHAR first
= toupperW(path
[0]);
744 if (first
>= 'A' && first
<= 'Z' && path
[1] == ':')
746 else if (path
[0] == '\\' && path
[1] == '\\')
753 static UINT
ACTION_SearchDirectory(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
754 LPCWSTR path
, int depth
, LPWSTR
*appValue
)
758 TRACE("%p, %p, %s, %d, %p\n", package
, sig
, debugstr_w(path
), depth
,
760 if (ACTION_IsFullPath(path
))
763 rc
= ACTION_RecurseSearchDirectory(package
, appValue
, sig
,
767 /* Recursively searching a directory makes no sense when the
768 * directory to search is the thing you're trying to find.
770 rc
= ACTION_CheckDirectory(package
, path
, appValue
);
775 WCHAR pathWithDrive
[MAX_PATH
] = { 'C',':','\\',0 };
776 DWORD drives
= GetLogicalDrives();
781 for (i
= 0; rc
== ERROR_SUCCESS
&& !*appValue
&& i
< 26; i
++)
782 if (drives
& (1 << i
))
784 pathWithDrive
[0] = 'A' + i
;
785 if (GetDriveTypeW(pathWithDrive
) == DRIVE_FIXED
)
787 lstrcpynW(pathWithDrive
+ 3, path
,
788 sizeof(pathWithDrive
) / sizeof(pathWithDrive
[0]) - 3);
790 rc
= ACTION_RecurseSearchDirectory(package
, appValue
,
791 sig
, pathWithDrive
, depth
);
793 rc
= ACTION_CheckDirectory(package
, pathWithDrive
,
798 TRACE("returning %d\n", rc
);
802 static UINT
ACTION_AppSearchSigName(MSIPACKAGE
*package
, LPCWSTR sigName
,
803 MSISIGNATURE
*sig
, LPWSTR
*appValue
);
805 static UINT
ACTION_AppSearchDr(MSIPACKAGE
*package
, LPWSTR
*appValue
, MSISIGNATURE
*sig
)
807 static const WCHAR query
[] = {
808 's','e','l','e','c','t',' ','*',' ',
810 'D','r','L','o','c','a','t','o','r',' ',
811 'w','h','e','r','e',' ',
812 'S','i','g','n','a','t','u','r','e','_',' ','=',' ', '\'','%','s','\'',0};
813 LPWSTR parentName
= NULL
, path
= NULL
, parent
= NULL
;
814 WCHAR expanded
[MAX_PATH
];
819 TRACE("%s\n", debugstr_w(sig
->Name
));
826 row
= MSI_QueryGetRecord( package
->db
, query
, sig
->Name
);
829 TRACE("failed to query DrLocator for %s\n", debugstr_w(sig
->Name
));
830 return ERROR_SUCCESS
;
833 /* check whether parent is set */
834 parentName
= msi_dup_record_field(row
,2);
837 MSISIGNATURE parentSig
;
839 rc
= ACTION_AppSearchSigName(package
, parentName
, &parentSig
, &parent
);
840 ACTION_FreeSignature(&parentSig
);
841 msi_free(parentName
);
843 /* now look for path */
844 path
= msi_dup_record_field(row
,3);
845 if (MSI_RecordIsNull(row
,4))
848 depth
= MSI_RecordGetInteger(row
,4);
849 ACTION_ExpandAnyPath(package
, path
, expanded
, MAX_PATH
);
853 path
= msi_alloc((strlenW(parent
) + strlenW(expanded
) + 1) * sizeof(WCHAR
));
856 rc
= ERROR_OUTOFMEMORY
;
859 strcpyW(path
, parent
);
860 strcatW(path
, expanded
);
865 rc
= ACTION_SearchDirectory(package
, sig
, path
, depth
, appValue
);
868 if (path
!= expanded
)
871 msiobj_release(&row
->hdr
);
873 TRACE("returning %d\n", rc
);
877 static UINT
ACTION_AppSearchSigName(MSIPACKAGE
*package
, LPCWSTR sigName
,
878 MSISIGNATURE
*sig
, LPWSTR
*appValue
)
883 rc
= ACTION_AppSearchGetSignature(package
, sig
, sigName
);
884 if (rc
== ERROR_SUCCESS
)
886 rc
= ACTION_AppSearchComponents(package
, appValue
, sig
);
887 if (rc
== ERROR_SUCCESS
&& !*appValue
)
889 rc
= ACTION_AppSearchReg(package
, appValue
, sig
);
890 if (rc
== ERROR_SUCCESS
&& !*appValue
)
892 rc
= ACTION_AppSearchIni(package
, appValue
, sig
);
893 if (rc
== ERROR_SUCCESS
&& !*appValue
)
894 rc
= ACTION_AppSearchDr(package
, appValue
, sig
);
901 static UINT
iterate_appsearch(MSIRECORD
*row
, LPVOID param
)
903 MSIPACKAGE
*package
= param
;
904 LPWSTR propName
, sigName
, value
= NULL
;
908 /* get property and signature */
909 propName
= msi_dup_record_field(row
,1);
910 sigName
= msi_dup_record_field(row
,2);
912 TRACE("%s %s\n", debugstr_w(propName
), debugstr_w(sigName
));
914 r
= ACTION_AppSearchSigName(package
, sigName
, &sig
, &value
);
917 MSI_SetPropertyW(package
, propName
, value
);
920 ACTION_FreeSignature(&sig
);
927 /* http://msdn.microsoft.com/library/en-us/msi/setup/appsearch_table.asp
928 * is the best reference for the AppSearch table and how it's used.
930 UINT
ACTION_AppSearch(MSIPACKAGE
*package
)
932 static const WCHAR query
[] = {
933 's','e','l','e','c','t',' ','*',' ',
935 'A','p','p','S','e','a','r','c','h',0};
936 MSIQUERY
*view
= NULL
;
939 r
= MSI_OpenQuery( package
->db
, &view
, query
);
940 if (r
!= ERROR_SUCCESS
)
941 return ERROR_SUCCESS
;
943 r
= MSI_IterateRecords( view
, NULL
, iterate_appsearch
, package
);
944 msiobj_release( &view
->hdr
);
949 static UINT
ITERATE_CCPSearch(MSIRECORD
*row
, LPVOID param
)
951 MSIPACKAGE
*package
= param
;
955 UINT r
= ERROR_SUCCESS
;
957 static const WCHAR success
[] = {'C','C','P','_','S','u','c','c','e','s','s',0};
958 static const WCHAR one
[] = {'1',0};
960 signature
= MSI_RecordGetString(row
, 1);
962 TRACE("%s\n", debugstr_w(signature
));
964 ACTION_AppSearchSigName(package
, signature
, &sig
, &value
);
967 TRACE("Found signature %s\n", debugstr_w(signature
));
968 MSI_SetPropertyW(package
, success
, one
);
970 r
= ERROR_NO_MORE_ITEMS
;
973 ACTION_FreeSignature(&sig
);
978 UINT
ACTION_CCPSearch(MSIPACKAGE
*package
)
980 static const WCHAR query
[] = {
981 's','e','l','e','c','t',' ','*',' ',
983 'C','C','P','S','e','a','r','c','h',0};
984 MSIQUERY
*view
= NULL
;
987 r
= MSI_OpenQuery(package
->db
, &view
, query
);
988 if (r
!= ERROR_SUCCESS
)
989 return ERROR_SUCCESS
;
991 r
= MSI_IterateRecords(view
, NULL
, ITERATE_CCPSearch
, package
);
992 msiobj_release(&view
->hdr
);