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 LPWSTR
app_search_file(LPWSTR path
, MSISIGNATURE
*sig
)
160 VS_FIXEDFILEINFO
*info
;
161 DWORD attr
, handle
, size
;
165 static const WCHAR root
[] = {'\\',0};
169 PathRemoveFileSpecW(path
);
170 PathAddBackslashW(path
);
172 attr
= GetFileAttributesW(path
);
173 if (attr
!= INVALID_FILE_ATTRIBUTES
&&
174 (attr
& FILE_ATTRIBUTE_DIRECTORY
))
175 return strdupW(path
);
180 attr
= GetFileAttributesW(path
);
181 if (attr
== INVALID_FILE_ATTRIBUTES
|| attr
== FILE_ATTRIBUTE_DIRECTORY
)
184 size
= GetFileVersionInfoSizeW(path
, &handle
);
186 return strdupW(path
);
188 buffer
= msi_alloc(size
);
192 if (!GetFileVersionInfoW(path
, 0, size
, buffer
))
195 if (!VerQueryValueW(buffer
, root
, (LPVOID
)&info
, &size
) || !info
)
198 if (sig
->MinVersionLS
|| sig
->MinVersionMS
)
200 if (info
->dwFileVersionMS
< sig
->MinVersionMS
)
203 if (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
204 info
->dwFileVersionLS
< sig
->MinVersionLS
)
208 if (sig
->MaxVersionLS
|| sig
->MaxVersionMS
)
210 if (info
->dwFileVersionMS
> sig
->MaxVersionMS
)
213 if (info
->dwFileVersionMS
== sig
->MaxVersionMS
&&
214 info
->dwFileVersionLS
> sig
->MaxVersionLS
)
225 static UINT
ACTION_AppSearchComponents(MSIPACKAGE
*package
, LPWSTR
*appValue
, MSISIGNATURE
*sig
)
227 static const WCHAR query
[] = {
228 'S','E','L','E','C','T',' ','*',' ',
230 '`','C','o','m','p','L','o','c','a','t','o','r','`',' ',
231 'W','H','E','R','E',' ','`','S','i','g','n','a','t','u','r','e','_','`',' ','=',' ',
232 '\'','%','s','\'',0};
233 static const WCHAR sigquery
[] = {
234 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
235 '`','S','i','g','n','a','t','u','r','e','`',' ',
236 'W','H','E','R','E',' ','`','S','i','g','n','a','t','u','r','e','`',' ','=',' ',
237 '\'','%','s','\'',0};
239 MSIRECORD
*row
, *rec
;
240 LPCWSTR signature
, guid
;
241 BOOL sigpresent
= TRUE
;
244 WCHAR path
[MAX_PATH
];
245 DWORD size
= MAX_PATH
;
249 TRACE("%s\n", debugstr_w(sig
->Name
));
253 row
= MSI_QueryGetRecord(package
->db
, query
, sig
->Name
);
256 TRACE("failed to query CompLocator for %s\n", debugstr_w(sig
->Name
));
257 return ERROR_SUCCESS
;
260 signature
= MSI_RecordGetString(row
, 1);
261 guid
= MSI_RecordGetString(row
, 2);
262 type
= MSI_RecordGetInteger(row
, 3);
264 rec
= MSI_QueryGetRecord(package
->db
, sigquery
, signature
);
269 MsiLocateComponentW(guid
, path
, &size
);
273 attr
= GetFileAttributesW(path
);
274 if (attr
== INVALID_FILE_ATTRIBUTES
)
277 isdir
= (attr
& FILE_ATTRIBUTE_DIRECTORY
);
279 if (type
!= msidbLocatorTypeDirectory
&& sigpresent
&& !isdir
)
281 *appValue
= app_search_file(path
, sig
);
283 else if (!sigpresent
&& (type
!= msidbLocatorTypeDirectory
|| isdir
))
285 if (type
== msidbLocatorTypeFileName
)
287 ptr
= strrchrW(path
, '\\');
291 PathAddBackslashW(path
);
293 *appValue
= strdupW(path
);
297 PathAddBackslashW(path
);
298 lstrcatW(path
, MSI_RecordGetString(rec
, 2));
300 attr
= GetFileAttributesW(path
);
301 if (attr
!= INVALID_FILE_ATTRIBUTES
&& attr
!= FILE_ATTRIBUTE_DIRECTORY
)
302 *appValue
= strdupW(path
);
306 if (rec
) msiobj_release(&rec
->hdr
);
307 msiobj_release(&row
->hdr
);
308 return ERROR_SUCCESS
;
311 static void ACTION_ConvertRegValue(DWORD regType
, const BYTE
*value
, DWORD sz
,
314 static const WCHAR dwordFmt
[] = { '#','%','d','\0' };
315 static const WCHAR binPre
[] = { '#','x','\0' };
316 static const WCHAR binFmt
[] = { '%','0','2','X','\0' };
323 if (*(LPCWSTR
)value
== '#')
325 /* escape leading pound with another */
326 *appValue
= msi_alloc(sz
+ sizeof(WCHAR
));
327 (*appValue
)[0] = '#';
328 strcpyW(*appValue
+ 1, (LPCWSTR
)value
);
332 *appValue
= msi_alloc(sz
);
333 strcpyW(*appValue
, (LPCWSTR
)value
);
337 /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign
340 *appValue
= msi_alloc(10 * sizeof(WCHAR
));
341 sprintfW(*appValue
, dwordFmt
, *(const DWORD
*)value
);
344 sz
= ExpandEnvironmentStringsW((LPCWSTR
)value
, NULL
, 0);
345 *appValue
= msi_alloc(sz
* sizeof(WCHAR
));
346 ExpandEnvironmentStringsW((LPCWSTR
)value
, *appValue
, sz
);
350 *appValue
= msi_alloc((sz
* 2 + 3) * sizeof(WCHAR
));
351 lstrcpyW(*appValue
, binPre
);
352 ptr
= *appValue
+ lstrlenW(binPre
);
353 for (i
= 0; i
< sz
; i
++, ptr
+= 2)
354 sprintfW(ptr
, binFmt
, value
[i
]);
357 WARN("unimplemented for values of type %d\n", regType
);
362 static UINT
ACTION_SearchDirectory(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
363 LPCWSTR path
, int depth
, LPWSTR
*appValue
);
365 static UINT
ACTION_AppSearchReg(MSIPACKAGE
*package
, LPWSTR
*appValue
, MSISIGNATURE
*sig
)
367 static const WCHAR query
[] = {
368 's','e','l','e','c','t',' ','*',' ',
370 'R','e','g','L','o','c','a','t','o','r',' ',
371 'w','h','e','r','e',' ',
372 'S','i','g','n','a','t','u','r','e','_',' ','=',' ', '\'','%','s','\'',0};
373 LPWSTR keyPath
= NULL
, valueName
= NULL
;
374 LPWSTR deformatted
= NULL
;
376 HKEY rootKey
, key
= NULL
;
377 DWORD sz
= 0, regType
;
382 TRACE("%s\n", debugstr_w(sig
->Name
));
386 row
= MSI_QueryGetRecord( package
->db
, query
, sig
->Name
);
389 TRACE("failed to query RegLocator for %s\n", debugstr_w(sig
->Name
));
390 return ERROR_SUCCESS
;
393 root
= MSI_RecordGetInteger(row
,2);
394 keyPath
= msi_dup_record_field(row
,3);
395 valueName
= msi_dup_record_field(row
,4);
396 type
= MSI_RecordGetInteger(row
,5);
398 deformat_string(package
, keyPath
, &deformatted
);
402 case msidbRegistryRootClassesRoot
:
403 rootKey
= HKEY_CLASSES_ROOT
;
405 case msidbRegistryRootCurrentUser
:
406 rootKey
= HKEY_CURRENT_USER
;
408 case msidbRegistryRootLocalMachine
:
409 rootKey
= HKEY_LOCAL_MACHINE
;
411 case msidbRegistryRootUsers
:
412 rootKey
= HKEY_USERS
;
415 WARN("Unknown root key %d\n", root
);
419 rc
= RegOpenKeyW(rootKey
, deformatted
, &key
);
422 TRACE("RegOpenKeyW returned %d\n", rc
);
426 rc
= RegQueryValueExW(key
, valueName
, NULL
, NULL
, NULL
, &sz
);
429 TRACE("RegQueryValueExW returned %d\n", rc
);
432 /* FIXME: sanity-check sz before allocating (is there an upper-limit
433 * on the value of a property?)
435 value
= msi_alloc( sz
);
436 rc
= RegQueryValueExW(key
, valueName
, NULL
, ®Type
, value
, &sz
);
439 TRACE("RegQueryValueExW returned %d\n", rc
);
443 /* bail out if the registry key is empty */
449 case msidbLocatorTypeDirectory
:
450 rc
= ACTION_SearchDirectory(package
, sig
, (LPWSTR
)value
, 0, appValue
);
452 case msidbLocatorTypeFileName
:
453 *appValue
= app_search_file((LPWSTR
)value
, sig
);
455 case msidbLocatorTypeRawValue
:
456 ACTION_ConvertRegValue(regType
, value
, sz
, appValue
);
459 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
460 type
, debugstr_w(keyPath
), debugstr_w(valueName
));
467 msi_free( valueName
);
468 msi_free( deformatted
);
470 msiobj_release(&row
->hdr
);
472 return ERROR_SUCCESS
;
475 static LPWSTR
get_ini_field(LPWSTR buf
, int field
)
484 while ((end
= strchrW(beg
, ',')) && i
< field
)
487 while (*beg
&& *beg
== ' ')
493 end
= strchrW(beg
, ',');
495 end
= beg
+ lstrlenW(beg
);
501 static UINT
ACTION_AppSearchIni(MSIPACKAGE
*package
, LPWSTR
*appValue
,
504 static const WCHAR query
[] = {
505 's','e','l','e','c','t',' ','*',' ',
507 'I','n','i','L','o','c','a','t','o','r',' ',
508 'w','h','e','r','e',' ',
509 'S','i','g','n','a','t','u','r','e','_',' ','=',' ','\'','%','s','\'',0};
511 LPWSTR fileName
, section
, key
;
515 TRACE("%s\n", debugstr_w(sig
->Name
));
519 row
= MSI_QueryGetRecord( package
->db
, query
, sig
->Name
);
522 TRACE("failed to query IniLocator for %s\n", debugstr_w(sig
->Name
));
523 return ERROR_SUCCESS
;
526 fileName
= msi_dup_record_field(row
, 2);
527 section
= msi_dup_record_field(row
, 3);
528 key
= msi_dup_record_field(row
, 4);
529 field
= MSI_RecordGetInteger(row
, 5);
530 type
= MSI_RecordGetInteger(row
, 6);
531 if (field
== MSI_NULL_INTEGER
)
533 if (type
== MSI_NULL_INTEGER
)
536 GetPrivateProfileStringW(section
, key
, NULL
, buf
, MAX_PATH
, fileName
);
541 case msidbLocatorTypeDirectory
:
542 ACTION_SearchDirectory(package
, sig
, buf
, 0, appValue
);
544 case msidbLocatorTypeFileName
:
545 *appValue
= app_search_file(buf
, sig
);
547 case msidbLocatorTypeRawValue
:
548 *appValue
= get_ini_field(buf
, field
);
557 msiobj_release(&row
->hdr
);
559 return ERROR_SUCCESS
;
562 /* Expands the value in src into a path without property names and only
563 * containing long path names into dst. Replaces at most len characters of dst,
564 * and always NULL-terminates dst if dst is not NULL and len >= 1.
566 * Assumes src and dst are non-overlapping.
567 * FIXME: return code probably needed:
568 * - what does AppSearch return if the table values are invalid?
569 * - what if dst is too small?
571 static void ACTION_ExpandAnyPath(MSIPACKAGE
*package
, WCHAR
*src
, WCHAR
*dst
,
574 WCHAR
*ptr
, *deformatted
;
576 if (!src
|| !dst
|| !len
)
578 if (dst
) *dst
= '\0';
584 /* Ignore the short portion of the path */
585 if ((ptr
= strchrW(src
, '|')))
590 deformat_string(package
, ptr
, &deformatted
);
591 if (!deformatted
|| lstrlenW(deformatted
) > len
- 1)
593 msi_free(deformatted
);
597 lstrcpyW(dst
, deformatted
);
598 dst
[lstrlenW(deformatted
)] = '\0';
599 msi_free(deformatted
);
602 /* Sets *matches to whether the file (whose path is filePath) matches the
603 * versions set in sig.
604 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
605 * something else if an install-halting error occurs.
607 static UINT
ACTION_FileVersionMatches(const MSISIGNATURE
*sig
, LPCWSTR filePath
,
610 UINT rc
= ERROR_SUCCESS
;
615 FIXME(": need to check version for languages %s\n",
616 debugstr_w(sig
->Languages
));
620 DWORD zero
, size
= GetFileVersionInfoSizeW(filePath
, &zero
);
624 LPVOID buf
= msi_alloc( size
);
628 static const WCHAR rootW
[] = { '\\',0 };
630 LPVOID subBlock
= NULL
;
632 if (GetFileVersionInfoW(filePath
, 0, size
, buf
))
633 VerQueryValueW(buf
, rootW
, &subBlock
, &versionLen
);
636 VS_FIXEDFILEINFO
*info
=
637 (VS_FIXEDFILEINFO
*)subBlock
;
639 TRACE("Comparing file version %d.%d.%d.%d:\n",
640 HIWORD(info
->dwFileVersionMS
),
641 LOWORD(info
->dwFileVersionMS
),
642 HIWORD(info
->dwFileVersionLS
),
643 LOWORD(info
->dwFileVersionLS
));
644 if (info
->dwFileVersionMS
< sig
->MinVersionMS
645 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
646 info
->dwFileVersionLS
< sig
->MinVersionLS
))
648 TRACE("Less than minimum version %d.%d.%d.%d\n",
649 HIWORD(sig
->MinVersionMS
),
650 LOWORD(sig
->MinVersionMS
),
651 HIWORD(sig
->MinVersionLS
),
652 LOWORD(sig
->MinVersionLS
));
654 else if (info
->dwFileVersionMS
< sig
->MinVersionMS
655 || (info
->dwFileVersionMS
== sig
->MinVersionMS
&&
656 info
->dwFileVersionLS
< sig
->MinVersionLS
))
658 TRACE("Greater than minimum version %d.%d.%d.%d\n",
659 HIWORD(sig
->MaxVersionMS
),
660 LOWORD(sig
->MaxVersionMS
),
661 HIWORD(sig
->MaxVersionLS
),
662 LOWORD(sig
->MaxVersionLS
));
670 rc
= ERROR_OUTOFMEMORY
;
676 /* Sets *matches to whether the file in findData matches that in sig.
677 * fullFilePath is assumed to be the full path of the file specified in
678 * findData, which may be necessary to compare the version.
679 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
680 * something else if an install-halting error occurs.
682 static UINT
ACTION_FileMatchesSig(const MSISIGNATURE
*sig
,
683 const WIN32_FIND_DATAW
*findData
, LPCWSTR fullFilePath
, BOOL
*matches
)
685 UINT rc
= ERROR_SUCCESS
;
688 /* assumes the caller has already ensured the filenames match, so check
691 if (sig
->MinTime
.dwLowDateTime
|| sig
->MinTime
.dwHighDateTime
)
693 if (findData
->ftCreationTime
.dwHighDateTime
<
694 sig
->MinTime
.dwHighDateTime
||
695 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MinTime
.dwHighDateTime
696 && findData
->ftCreationTime
.dwLowDateTime
<
697 sig
->MinTime
.dwLowDateTime
))
700 if (*matches
&& (sig
->MaxTime
.dwLowDateTime
|| sig
->MaxTime
.dwHighDateTime
))
702 if (findData
->ftCreationTime
.dwHighDateTime
>
703 sig
->MaxTime
.dwHighDateTime
||
704 (findData
->ftCreationTime
.dwHighDateTime
== sig
->MaxTime
.dwHighDateTime
705 && findData
->ftCreationTime
.dwLowDateTime
>
706 sig
->MaxTime
.dwLowDateTime
))
709 if (*matches
&& sig
->MinSize
&& findData
->nFileSizeLow
< sig
->MinSize
)
711 if (*matches
&& sig
->MaxSize
&& findData
->nFileSizeLow
> sig
->MaxSize
)
713 if (*matches
&& (sig
->MinVersionMS
|| sig
->MinVersionLS
||
714 sig
->MaxVersionMS
|| sig
->MaxVersionLS
))
715 rc
= ACTION_FileVersionMatches(sig
, fullFilePath
, matches
);
719 /* Recursively searches the directory dir for files that match the signature
720 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
721 * (and only dir). If depth is 1, searches dir and its immediate
723 * Assumes sig->File is not NULL.
724 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
725 * something else on failures which should halt the install.
727 static UINT
ACTION_RecurseSearchDirectory(MSIPACKAGE
*package
, LPWSTR
*appValue
,
728 MSISIGNATURE
*sig
, LPCWSTR dir
, int depth
)
731 WIN32_FIND_DATAW findData
;
732 UINT rc
= ERROR_SUCCESS
;
733 size_t dirLen
= lstrlenW(dir
), fileLen
= lstrlenW(sig
->File
);
736 static const WCHAR starDotStarW
[] = { '*','.','*',0 };
738 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir
),
739 debugstr_w(sig
->File
), depth
);
742 return ERROR_INVALID_PARAMETER
;
745 /* We need the buffer in both paths below, so go ahead and allocate it
746 * here. Add two because we might need to add a backslash if the dir name
747 * isn't backslash-terminated.
749 buf
= msi_alloc( (dirLen
+ max(fileLen
, lstrlenW(starDotStarW
)) + 2) * sizeof(WCHAR
));
751 return ERROR_OUTOFMEMORY
;
754 PathAddBackslashW(buf
);
755 lstrcatW(buf
, sig
->File
);
757 hFind
= FindFirstFileW(buf
, &findData
);
758 if (hFind
!= INVALID_HANDLE_VALUE
)
762 /* assuming Signature can't contain wildcards for the file name,
763 * so don't bother with FindNextFileW here.
765 rc
= ACTION_FileMatchesSig(sig
, &findData
, buf
, &matches
);
766 if (rc
== ERROR_SUCCESS
&& matches
)
768 TRACE("found file, returning %s\n", debugstr_w(buf
));
775 if (rc
== ERROR_SUCCESS
&& !*appValue
&& depth
> 0)
778 PathAddBackslashW(buf
);
779 lstrcatW(buf
, starDotStarW
);
781 hFind
= FindFirstFileW(buf
, &findData
);
782 if (hFind
!= INVALID_HANDLE_VALUE
)
784 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
785 rc
= ACTION_RecurseSearchDirectory(package
, appValue
, sig
,
789 while (rc
== ERROR_SUCCESS
&& !*appValue
&&
790 FindNextFileW(hFind
, &findData
) != 0)
792 if (findData
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
)
793 rc
= ACTION_RecurseSearchDirectory(package
, appValue
,
794 sig
, findData
.cFileName
,
808 static UINT
ACTION_CheckDirectory(MSIPACKAGE
*package
, LPCWSTR dir
,
811 DWORD attr
= GetFileAttributesW(dir
);
813 if (attr
!= INVALID_FILE_ATTRIBUTES
&& (attr
& FILE_ATTRIBUTE_DIRECTORY
))
815 TRACE("directory exists, returning %s\n", debugstr_w(dir
));
816 *appValue
= strdupW(dir
);
819 return ERROR_SUCCESS
;
822 static BOOL
ACTION_IsFullPath(LPCWSTR path
)
824 WCHAR first
= toupperW(path
[0]);
827 if (first
>= 'A' && first
<= 'Z' && path
[1] == ':')
829 else if (path
[0] == '\\' && path
[1] == '\\')
836 static UINT
ACTION_SearchDirectory(MSIPACKAGE
*package
, MSISIGNATURE
*sig
,
837 LPCWSTR path
, int depth
, LPWSTR
*appValue
)
843 TRACE("%p, %p, %s, %d, %p\n", package
, sig
, debugstr_w(path
), depth
,
846 if (ACTION_IsFullPath(path
))
849 rc
= ACTION_RecurseSearchDirectory(package
, &val
, sig
, path
, depth
);
852 /* Recursively searching a directory makes no sense when the
853 * directory to search is the thing you're trying to find.
855 rc
= ACTION_CheckDirectory(package
, path
, &val
);
860 WCHAR pathWithDrive
[MAX_PATH
] = { 'C',':','\\',0 };
861 DWORD drives
= GetLogicalDrives();
865 for (i
= 0; rc
== ERROR_SUCCESS
&& !val
&& i
< 26; i
++)
867 if (!(drives
& (1 << i
)))
870 pathWithDrive
[0] = 'A' + i
;
871 if (GetDriveTypeW(pathWithDrive
) != DRIVE_FIXED
)
874 lstrcpynW(pathWithDrive
+ 3, path
,
875 sizeof(pathWithDrive
) / sizeof(pathWithDrive
[0]) - 3);
878 rc
= ACTION_RecurseSearchDirectory(package
, &val
, sig
,
879 pathWithDrive
, depth
);
881 rc
= ACTION_CheckDirectory(package
, pathWithDrive
, &val
);
885 attr
= GetFileAttributesW(val
);
886 if ((attr
& FILE_ATTRIBUTE_DIRECTORY
) &&
887 val
&& val
[lstrlenW(val
) - 1] != '\\')
889 val
= msi_realloc(val
, (lstrlenW(val
) + 2) * sizeof(WCHAR
));
891 rc
= ERROR_OUTOFMEMORY
;
893 PathAddBackslashW(val
);
898 TRACE("returning %d\n", rc
);
902 static UINT
ACTION_AppSearchSigName(MSIPACKAGE
*package
, LPCWSTR sigName
,
903 MSISIGNATURE
*sig
, LPWSTR
*appValue
);
905 static UINT
ACTION_AppSearchDr(MSIPACKAGE
*package
, LPWSTR
*appValue
, MSISIGNATURE
*sig
)
907 static const WCHAR query
[] = {
908 's','e','l','e','c','t',' ','*',' ',
910 'D','r','L','o','c','a','t','o','r',' ',
911 'w','h','e','r','e',' ',
912 'S','i','g','n','a','t','u','r','e','_',' ','=',' ', '\'','%','s','\'',0};
913 LPWSTR parentName
= NULL
, parent
= NULL
;
914 WCHAR path
[MAX_PATH
];
915 WCHAR expanded
[MAX_PATH
];
921 TRACE("%s\n", debugstr_w(sig
->Name
));
925 row
= MSI_QueryGetRecord( package
->db
, query
, sig
->Name
);
928 TRACE("failed to query DrLocator for %s\n", debugstr_w(sig
->Name
));
929 return ERROR_SUCCESS
;
932 /* check whether parent is set */
933 parentName
= msi_dup_record_field(row
,2);
936 MSISIGNATURE parentSig
;
938 rc
= ACTION_AppSearchSigName(package
, parentName
, &parentSig
, &parent
);
939 ACTION_FreeSignature(&parentSig
);
940 msi_free(parentName
);
944 MSI_RecordGetStringW(row
, 3, path
, &sz
);
946 if (MSI_RecordIsNull(row
,4))
949 depth
= MSI_RecordGetInteger(row
,4);
951 ACTION_ExpandAnyPath(package
, path
, expanded
, MAX_PATH
);
955 strcpyW(path
, parent
);
956 strcatW(path
, expanded
);
959 strcpyW(path
, expanded
);
961 PathAddBackslashW(path
);
963 rc
= ACTION_SearchDirectory(package
, sig
, path
, depth
, appValue
);
966 msiobj_release(&row
->hdr
);
968 TRACE("returning %d\n", rc
);
972 static UINT
ACTION_AppSearchSigName(MSIPACKAGE
*package
, LPCWSTR sigName
,
973 MSISIGNATURE
*sig
, LPWSTR
*appValue
)
978 rc
= ACTION_AppSearchGetSignature(package
, sig
, sigName
);
979 if (rc
== ERROR_SUCCESS
)
981 rc
= ACTION_AppSearchComponents(package
, appValue
, sig
);
982 if (rc
== ERROR_SUCCESS
&& !*appValue
)
984 rc
= ACTION_AppSearchReg(package
, appValue
, sig
);
985 if (rc
== ERROR_SUCCESS
&& !*appValue
)
987 rc
= ACTION_AppSearchIni(package
, appValue
, sig
);
988 if (rc
== ERROR_SUCCESS
&& !*appValue
)
989 rc
= ACTION_AppSearchDr(package
, appValue
, sig
);
996 static UINT
iterate_appsearch(MSIRECORD
*row
, LPVOID param
)
998 MSIPACKAGE
*package
= param
;
999 LPWSTR propName
, sigName
, value
= NULL
;
1003 /* get property and signature */
1004 propName
= msi_dup_record_field(row
,1);
1005 sigName
= msi_dup_record_field(row
,2);
1007 TRACE("%s %s\n", debugstr_w(propName
), debugstr_w(sigName
));
1009 r
= ACTION_AppSearchSigName(package
, sigName
, &sig
, &value
);
1012 MSI_SetPropertyW(package
, propName
, value
);
1015 ACTION_FreeSignature(&sig
);
1022 UINT
ACTION_AppSearch(MSIPACKAGE
*package
)
1024 static const WCHAR query
[] = {
1025 's','e','l','e','c','t',' ','*',' ',
1026 'f','r','o','m',' ',
1027 'A','p','p','S','e','a','r','c','h',0};
1028 MSIQUERY
*view
= NULL
;
1031 r
= MSI_OpenQuery( package
->db
, &view
, query
);
1032 if (r
!= ERROR_SUCCESS
)
1033 return ERROR_SUCCESS
;
1035 r
= MSI_IterateRecords( view
, NULL
, iterate_appsearch
, package
);
1036 msiobj_release( &view
->hdr
);
1041 static UINT
ITERATE_CCPSearch(MSIRECORD
*row
, LPVOID param
)
1043 MSIPACKAGE
*package
= param
;
1045 LPWSTR value
= NULL
;
1047 UINT r
= ERROR_SUCCESS
;
1049 static const WCHAR success
[] = {'C','C','P','_','S','u','c','c','e','s','s',0};
1050 static const WCHAR one
[] = {'1',0};
1052 signature
= MSI_RecordGetString(row
, 1);
1054 TRACE("%s\n", debugstr_w(signature
));
1056 ACTION_AppSearchSigName(package
, signature
, &sig
, &value
);
1059 TRACE("Found signature %s\n", debugstr_w(signature
));
1060 MSI_SetPropertyW(package
, success
, one
);
1062 r
= ERROR_NO_MORE_ITEMS
;
1065 ACTION_FreeSignature(&sig
);
1070 UINT
ACTION_CCPSearch(MSIPACKAGE
*package
)
1072 static const WCHAR query
[] = {
1073 's','e','l','e','c','t',' ','*',' ',
1074 'f','r','o','m',' ',
1075 'C','C','P','S','e','a','r','c','h',0};
1076 MSIQUERY
*view
= NULL
;
1079 r
= MSI_OpenQuery(package
->db
, &view
, query
);
1080 if (r
!= ERROR_SUCCESS
)
1081 return ERROR_SUCCESS
;
1083 r
= MSI_IterateRecords(view
, NULL
, ITERATE_CCPSearch
, package
);
1084 msiobj_release(&view
->hdr
);