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 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 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));
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 %d, MaxSize is %d;\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 /* Frees any memory allocated in sig */
177 static void ACTION_FreeSignature(MSISIGNATURE *sig)
180 msi_free(sig->Languages);
183 static UINT ACTION_AppSearchComponents(MSIPACKAGE *package, LPWSTR *appValue,
188 static const WCHAR ExecSeqQuery[] = {
189 's','e','l','e','c','t',' ','*',' ',
191 'C','o','m','p','L','o','c','a','t','o','r',' ',
192 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
193 '\'','%','s','\'',0};
195 TRACE("(package %p, appValue %p, sig %p)\n", package, appValue, sig);
197 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
198 if (rc == ERROR_SUCCESS)
204 rc = MSI_ViewExecute(view, 0);
205 if (rc != ERROR_SUCCESS)
207 TRACE("MSI_ViewExecute returned %d\n", rc);
210 rc = MSI_ViewFetch(view,&row);
211 if (rc != ERROR_SUCCESS)
213 TRACE("MSI_ViewFetch returned %d\n", rc);
220 sz=sizeof(guid)/sizeof(guid[0]);
221 rc = MSI_RecordGetStringW(row,2,guid,&sz);
222 if (rc != ERROR_SUCCESS)
224 ERR("Error is %x\n",rc);
227 FIXME("AppSearch unimplemented for CompLocator table (GUID %s)\n",
232 msiobj_release(&row->hdr);
234 msiobj_release(&view->hdr);
238 TRACE("MSI_OpenQuery returned %d\n", rc);
242 TRACE("returning %d\n", rc);
246 static void ACTION_ConvertRegValue(DWORD regType, const BYTE *value, DWORD sz,
249 static const WCHAR dwordFmt[] = { '#','%','d','\0' };
250 static const WCHAR expandSzFmt[] = { '#','%','%','%','s','\0' };
251 static const WCHAR binFmt[] = { '#','x','%','x','\0' };
257 if (*(LPCWSTR)value == '#')
259 /* escape leading pound with another */
260 *appValue = msi_alloc(sz + sizeof(WCHAR));
261 (*appValue)[0] = '#';
262 strcpyW(*appValue + 1, (LPCWSTR)value);
266 *appValue = msi_alloc(sz);
267 strcpyW(*appValue, (LPCWSTR)value);
271 /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign
274 *appValue = msi_alloc(10 * sizeof(WCHAR));
275 sprintfW(*appValue, dwordFmt, *(const DWORD *)value);
278 /* space for extra #% characters in front */
279 *appValue = msi_alloc(sz + 2 * sizeof(WCHAR));
280 sprintfW(*appValue, expandSzFmt, (LPCWSTR)value);
283 /* 3 == length of "#x<nibble>" */
284 *appValue = msi_alloc((sz * 3 + 1) * sizeof(WCHAR));
285 for (i = 0; i < sz; i++)
286 sprintfW(*appValue + i * 3, binFmt, value[i]);
289 WARN("unimplemented for values of type %d\n", regType);
294 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
295 LPCWSTR path, int depth, LPWSTR *appValue);
297 static UINT ACTION_AppSearchReg(MSIPACKAGE *package, LPWSTR *appValue,
302 static const WCHAR ExecSeqQuery[] = {
303 's','e','l','e','c','t',' ','*',' ',
305 'R','e','g','L','o','c','a','t','o','r',' ',
306 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
307 '\'','%','s','\'',0};
309 TRACE("(package %p, appValue %p, sig %p)\n", package, appValue, sig);
311 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
312 if (rc == ERROR_SUCCESS)
315 LPWSTR keyPath = NULL, valueName = NULL;
317 HKEY rootKey, key = NULL;
318 DWORD sz = 0, regType;
321 rc = MSI_ViewExecute(view, 0);
322 if (rc != ERROR_SUCCESS)
324 TRACE("MSI_ViewExecute returned %d\n", rc);
327 rc = MSI_ViewFetch(view,&row);
328 if (rc != ERROR_SUCCESS)
330 TRACE("MSI_ViewFetch returned %d\n", rc);
335 root = MSI_RecordGetInteger(row,2);
336 keyPath = msi_dup_record_field(row,3);
337 /* FIXME: keyPath needs to be expanded for properties */
338 valueName = msi_dup_record_field(row,4);
339 /* FIXME: valueName probably does too */
340 type = MSI_RecordGetInteger(row,5);
344 case msidbRegistryRootClassesRoot:
345 rootKey = HKEY_CLASSES_ROOT;
347 case msidbRegistryRootCurrentUser:
348 rootKey = HKEY_CURRENT_USER;
350 case msidbRegistryRootLocalMachine:
351 rootKey = HKEY_LOCAL_MACHINE;
353 case msidbRegistryRootUsers:
354 rootKey = HKEY_USERS;
357 WARN("Unknown root key %d\n", root);
361 rc = RegOpenKeyW(rootKey, keyPath, &key);
364 TRACE("RegOpenKeyW returned %d\n", rc);
368 rc = RegQueryValueExW(key, valueName, NULL, NULL, NULL, &sz);
371 TRACE("RegQueryValueExW returned %d\n", rc);
375 /* FIXME: sanity-check sz before allocating (is there an upper-limit
376 * on the value of a property?)
378 value = msi_alloc( sz);
379 rc = RegQueryValueExW(key, valueName, NULL, ®Type, value, &sz);
382 TRACE("RegQueryValueExW returned %d\n", rc);
387 /* bail out if the registry key is empty */
396 case msidbLocatorTypeDirectory:
397 rc = ACTION_SearchDirectory(package, sig, (LPCWSTR)value, 0,
400 case msidbLocatorTypeFileName:
401 *appValue = (LPWSTR)value;
403 case msidbLocatorTypeRawValue:
404 ACTION_ConvertRegValue(regType, value, sz, appValue);
407 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
408 type, debugstr_w(keyPath), debugstr_w(valueName));
415 msi_free( valueName);
418 msiobj_release(&row->hdr);
420 msiobj_release(&view->hdr);
424 TRACE("MSI_OpenQuery returned %d\n", rc);
428 TRACE("returning %d\n", rc);
432 static UINT ACTION_AppSearchIni(MSIPACKAGE *package, LPWSTR *appValue,
437 static const WCHAR ExecSeqQuery[] = {
438 's','e','l','e','c','t',' ','*',' ',
440 'I','n','i','L','o','c','a','t','o','r',' ',
441 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
442 '\'','%','s','\'',0};
444 TRACE("(package %p, appValue %p, sig %p)\n", package, appValue, sig);
446 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
447 if (rc == ERROR_SUCCESS)
450 LPWSTR fileName, section, key;
454 rc = MSI_ViewExecute(view, 0);
455 if (rc != ERROR_SUCCESS)
457 TRACE("MSI_ViewExecute returned %d\n", rc);
460 rc = MSI_ViewFetch(view,&row);
461 if (rc != ERROR_SUCCESS)
463 TRACE("MSI_ViewFetch returned %d\n", rc);
468 fileName = msi_dup_record_field(row, 2);
469 section = msi_dup_record_field(row, 3);
470 key = msi_dup_record_field(row, 4);
471 if ((field = MSI_RecordGetInteger(row, 5)) == MSI_NULL_INTEGER)
473 if ((type = MSI_RecordGetInteger(row, 6)) == MSI_NULL_INTEGER)
476 GetPrivateProfileStringW(section, key, NULL, buf,
477 sizeof(buf) / sizeof(WCHAR), fileName);
482 case msidbLocatorTypeDirectory:
483 FIXME("unimplemented for type Directory (dir: %s)\n",
486 case msidbLocatorTypeFileName:
487 FIXME("unimplemented for type File (file: %s)\n",
490 case msidbLocatorTypeRawValue:
491 *appValue = strdupW(buf);
502 msiobj_release(&row->hdr);
504 msiobj_release(&view->hdr);
508 TRACE("MSI_OpenQuery returned %d\n", rc);
513 TRACE("returning %d\n", rc);
517 /* Expands the value in src into a path without property names and only
518 * containing long path names into dst. Replaces at most len characters of dst,
519 * and always NULL-terminates dst if dst is not NULL and len >= 1.
521 * Assumes src and dst are non-overlapping.
522 * FIXME: return code probably needed:
523 * - what does AppSearch return if the table values are invalid?
524 * - what if dst is too small?
526 static void ACTION_ExpandAnyPath(MSIPACKAGE *package, WCHAR *src, WCHAR *dst,
532 if (!src || !dst || !len)
534 if (dst) *dst = '\0';
538 /* Ignore the short portion of the path, don't think we can use it anyway */
539 if ((ptr = strchrW(src, '|')))
543 while (*ptr && copied < len - 1)
545 WCHAR *prop = strchrW(ptr, '[');
549 WCHAR *propEnd = strchrW(prop + 1, ']');
553 WARN("Unterminated property name in AnyPath: %s\n",
562 propLen = len - copied - 1;
563 MSI_GetPropertyW(package, prop + 1, dst + copied, &propLen);
570 size_t toCopy = min(strlenW(ptr) + 1, len - copied - 1);
572 memcpy(dst + copied, ptr, toCopy * sizeof(WCHAR));
577 *(dst + copied) = '\0';
580 /* Sets *matches to whether the file (whose path is filePath) matches the
581 * versions set in sig.
582 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
583 * something else if an install-halting error occurs.
585 static UINT ACTION_FileVersionMatches(MSISIGNATURE *sig, LPCWSTR filePath,
588 UINT rc = ERROR_SUCCESS;
593 FIXME(": need to check version for languages %s\n",
594 debugstr_w(sig->Languages));
598 DWORD zero, size = GetFileVersionInfoSizeW(filePath, &zero);
602 LPVOID buf = msi_alloc( size);
606 static WCHAR rootW[] = { '\\',0 };
608 LPVOID subBlock = NULL;
610 if (GetFileVersionInfoW(filePath, 0, size, buf))
611 VerQueryValueW(buf, rootW, &subBlock, &versionLen);
614 VS_FIXEDFILEINFO *info =
615 (VS_FIXEDFILEINFO *)subBlock;
617 TRACE("Comparing file version %d.%d.%d.%d:\n",
618 HIWORD(info->dwFileVersionMS),
619 LOWORD(info->dwFileVersionMS),
620 HIWORD(info->dwFileVersionLS),
621 LOWORD(info->dwFileVersionLS));
622 if (info->dwFileVersionMS < sig->MinVersionMS
623 || (info->dwFileVersionMS == sig->MinVersionMS &&
624 info->dwFileVersionLS < sig->MinVersionLS))
626 TRACE("Less than minimum version %d.%d.%d.%d\n",
627 HIWORD(sig->MinVersionMS),
628 LOWORD(sig->MinVersionMS),
629 HIWORD(sig->MinVersionLS),
630 LOWORD(sig->MinVersionLS));
632 else if (info->dwFileVersionMS < sig->MinVersionMS
633 || (info->dwFileVersionMS == sig->MinVersionMS &&
634 info->dwFileVersionLS < sig->MinVersionLS))
636 TRACE("Greater than minimum version %d.%d.%d.%d\n",
637 HIWORD(sig->MaxVersionMS),
638 LOWORD(sig->MaxVersionMS),
639 HIWORD(sig->MaxVersionLS),
640 LOWORD(sig->MaxVersionLS));
648 rc = ERROR_OUTOFMEMORY;
654 /* Sets *matches to whether the file in findData matches that in sig.
655 * fullFilePath is assumed to be the full path of the file specified in
656 * findData, which may be necessary to compare the version.
657 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
658 * something else if an install-halting error occurs.
660 static UINT ACTION_FileMatchesSig(MSISIGNATURE *sig,
661 LPWIN32_FIND_DATAW findData, LPCWSTR fullFilePath, BOOL *matches)
663 UINT rc = ERROR_SUCCESS;
666 /* assumes the caller has already ensured the filenames match, so check
669 if (sig->MinTime.dwLowDateTime || sig->MinTime.dwHighDateTime)
671 if (findData->ftCreationTime.dwHighDateTime <
672 sig->MinTime.dwHighDateTime ||
673 (findData->ftCreationTime.dwHighDateTime == sig->MinTime.dwHighDateTime
674 && findData->ftCreationTime.dwLowDateTime <
675 sig->MinTime.dwLowDateTime))
678 if (*matches && (sig->MaxTime.dwLowDateTime || sig->MaxTime.dwHighDateTime))
680 if (findData->ftCreationTime.dwHighDateTime >
681 sig->MaxTime.dwHighDateTime ||
682 (findData->ftCreationTime.dwHighDateTime == sig->MaxTime.dwHighDateTime
683 && findData->ftCreationTime.dwLowDateTime >
684 sig->MaxTime.dwLowDateTime))
687 if (*matches && sig->MinSize && findData->nFileSizeLow < sig->MinSize)
689 if (*matches && sig->MaxSize && findData->nFileSizeLow > sig->MaxSize)
691 if (*matches && (sig->MinVersionMS || sig->MinVersionLS ||
692 sig->MaxVersionMS || sig->MaxVersionLS))
693 rc = ACTION_FileVersionMatches(sig, fullFilePath, matches);
697 /* Recursively searches the directory dir for files that match the signature
698 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
699 * (and only dir). If depth is 1, searches dir and its immediate
701 * Assumes sig->File is not NULL.
702 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
703 * something else on failures which should halt the install.
705 static UINT ACTION_RecurseSearchDirectory(MSIPACKAGE *package, LPWSTR *appValue,
706 MSISIGNATURE *sig, LPCWSTR dir, int depth)
708 static const WCHAR starDotStarW[] = { '*','.','*',0 };
709 UINT rc = ERROR_SUCCESS;
710 size_t dirLen = lstrlenW(dir), fileLen = lstrlenW(sig->File);
713 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir),
714 debugstr_w(sig->File), depth);
717 return ERROR_INVALID_PARAMETER;
720 /* We need the buffer in both paths below, so go ahead and allocate it
721 * here. Add two because we might need to add a backslash if the dir name
722 * isn't backslash-terminated.
724 buf = msi_alloc( (dirLen + max(fileLen, lstrlenW(starDotStarW)) + 2) * sizeof(WCHAR));
727 /* a depth of 0 implies we should search dir, so go ahead and search */
729 WIN32_FIND_DATAW findData;
731 memcpy(buf, dir, dirLen * sizeof(WCHAR));
732 if (buf[dirLen - 1] != '\\')
733 buf[dirLen++ - 1] = '\\';
734 memcpy(buf + dirLen, sig->File, (fileLen + 1) * sizeof(WCHAR));
735 hFind = FindFirstFileW(buf, &findData);
736 if (hFind != INVALID_HANDLE_VALUE)
740 /* assuming Signature can't contain wildcards for the file name,
741 * so don't bother with FindNextFileW here.
743 if (!(rc = ACTION_FileMatchesSig(sig, &findData, buf, &matches))
746 TRACE("found file, returning %s\n", debugstr_w(buf));
751 if (rc == ERROR_SUCCESS && !*appValue && depth > 0)
754 WIN32_FIND_DATAW findData;
756 memcpy(buf, dir, dirLen * sizeof(WCHAR));
757 if (buf[dirLen - 1] != '\\')
758 buf[dirLen++ - 1] = '\\';
759 lstrcpyW(buf + dirLen, starDotStarW);
760 hFind = FindFirstFileW(buf, &findData);
761 if (hFind != INVALID_HANDLE_VALUE)
763 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
764 rc = ACTION_RecurseSearchDirectory(package, appValue, sig,
765 findData.cFileName, depth - 1);
766 while (rc == ERROR_SUCCESS && !*appValue &&
767 FindNextFileW(hFind, &findData) != 0)
769 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
770 rc = ACTION_RecurseSearchDirectory(package, appValue,
771 sig, findData.cFileName, depth - 1);
780 rc = ERROR_OUTOFMEMORY;
785 static UINT ACTION_CheckDirectory(MSIPACKAGE *package, LPCWSTR dir,
788 UINT rc = ERROR_SUCCESS;
790 if (GetFileAttributesW(dir) & FILE_ATTRIBUTE_DIRECTORY)
792 TRACE("directory exists, returning %s\n", debugstr_w(dir));
793 *appValue = strdupW(dir);
798 static BOOL ACTION_IsFullPath(LPCWSTR path)
800 WCHAR first = toupperW(path[0]);
803 if (first >= 'A' && first <= 'Z' && path[1] == ':')
805 else if (path[0] == '\\' && path[1] == '\\')
812 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
813 LPCWSTR path, int depth, LPWSTR *appValue)
817 TRACE("%p, %p, %s, %d, %p\n", package, sig, debugstr_w(path), depth,
819 if (ACTION_IsFullPath(path))
822 rc = ACTION_RecurseSearchDirectory(package, appValue, sig,
826 /* Recursively searching a directory makes no sense when the
827 * directory to search is the thing you're trying to find.
829 rc = ACTION_CheckDirectory(package, path, appValue);
834 WCHAR pathWithDrive[MAX_PATH] = { 'C',':','\\',0 };
835 DWORD drives = GetLogicalDrives();
840 for (i = 0; rc == ERROR_SUCCESS && !*appValue && i < 26; i++)
841 if (drives & (1 << drives))
843 pathWithDrive[0] = 'A' + i;
844 if (GetDriveTypeW(pathWithDrive) == DRIVE_FIXED)
846 lstrcpynW(pathWithDrive + 3, path,
847 sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
849 rc = ACTION_RecurseSearchDirectory(package, appValue,
850 sig, pathWithDrive, depth);
852 rc = ACTION_CheckDirectory(package, pathWithDrive,
857 TRACE("returning %d\n", rc);
861 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
862 MSISIGNATURE *sig, LPWSTR *appValue);
864 static UINT ACTION_AppSearchDr(MSIPACKAGE *package, LPWSTR *appValue,
869 static const WCHAR ExecSeqQuery[] = {
870 's','e','l','e','c','t',' ','*',' ',
872 'D','r','L','o','c','a','t','o','r',' ',
873 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
874 '\'','%','s','\'',0};
876 TRACE("(package %p, sig %p)\n", package, sig);
877 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
878 if (rc == ERROR_SUCCESS)
881 WCHAR expanded[MAX_PATH];
882 LPWSTR parentName = NULL, path = NULL, parent = NULL;
885 rc = MSI_ViewExecute(view, 0);
886 if (rc != ERROR_SUCCESS)
888 TRACE("MSI_ViewExecute returned %d\n", rc);
891 rc = MSI_ViewFetch(view,&row);
892 if (rc != ERROR_SUCCESS)
894 TRACE("MSI_ViewFetch returned %d\n", rc);
899 /* check whether parent is set */
900 parentName = msi_dup_record_field(row,2);
903 MSISIGNATURE parentSig;
905 rc = ACTION_AppSearchSigName(package, parentName, &parentSig,
907 ACTION_FreeSignature(&parentSig);
908 msi_free(parentName);
910 /* now look for path */
911 path = msi_dup_record_field(row,3);
912 if (MSI_RecordIsNull(row,4))
915 depth = MSI_RecordGetInteger(row,4);
916 ACTION_ExpandAnyPath(package, path, expanded,
917 sizeof(expanded) / sizeof(expanded[0]));
921 path = msi_alloc((strlenW(parent) + strlenW(expanded) + 1) * sizeof(WCHAR));
924 strcpyW(path, parent);
925 strcatW(path, expanded);
929 rc = ACTION_SearchDirectory(package, sig, path, depth, appValue);
932 if (path != expanded)
936 msiobj_release(&row->hdr);
938 msiobj_release(&view->hdr);
942 TRACE("MSI_OpenQuery returned %d\n", rc);
946 TRACE("returning %d\n", rc);
950 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
951 MSISIGNATURE *sig, LPWSTR *appValue)
956 rc = ACTION_AppSearchGetSignature(package, sig, sigName);
957 if (rc == ERROR_SUCCESS)
959 rc = ACTION_AppSearchComponents(package, appValue, sig);
960 if (rc == ERROR_SUCCESS && !*appValue)
962 rc = ACTION_AppSearchReg(package, appValue, sig);
963 if (rc == ERROR_SUCCESS && !*appValue)
965 rc = ACTION_AppSearchIni(package, appValue, sig);
966 if (rc == ERROR_SUCCESS && !*appValue)
967 rc = ACTION_AppSearchDr(package, appValue, sig);
974 /* http://msdn.microsoft.com/library/en-us/msi/setup/appsearch_table.asp
975 * is the best reference for the AppSearch table and how it's used.
977 UINT ACTION_AppSearch(MSIPACKAGE *package)
981 static const WCHAR ExecSeqQuery[] = {
982 's','e','l','e','c','t',' ','*',' ',
984 'A','p','p','S','e','a','r','c','h',0};
986 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery);
987 if (rc == ERROR_SUCCESS)
990 LPWSTR propName, sigName;
992 rc = MSI_ViewExecute(view, 0);
993 if (rc != ERROR_SUCCESS)
1001 rc = MSI_ViewFetch(view,&row);
1002 if (rc != ERROR_SUCCESS)
1008 /* get property and signature */
1009 propName = msi_dup_record_field(row,1);
1010 sigName = msi_dup_record_field(row,2);
1012 TRACE("Searching for Property %s, Signature_ %s\n",
1013 debugstr_w(propName), debugstr_w(sigName));
1015 rc = ACTION_AppSearchSigName(package, sigName, &sig, &value);
1018 MSI_SetPropertyW(package, propName, value);
1021 ACTION_FreeSignature(&sig);
1024 msiobj_release(&row->hdr);
1028 MSI_ViewClose(view);
1029 msiobj_release(&view->hdr);