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"
35 WINE_DEFAULT_DEBUG_CHANNEL(msi);
37 typedef struct tagMSISIGNATURE
39 LPCWSTR Name; /* NOT owned by this structure */
52 static void ACTION_VerStrToInteger(LPCWSTR verStr, PDWORD ms, PDWORD ls)
55 int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
58 ptr = strchrW(verStr, '.');
62 ptr = strchrW(ptr + 1, '.');
67 ptr = strchrW(ptr + 1, '.');
71 /* FIXME: byte-order dependent? */
76 /* Fills in sig with the the values from the Signature table, where name is the
77 * signature to find. Upon return, sig->File will be NULL if the record is not
78 * found, and not NULL if it is found.
79 * Warning: clears all fields in sig!
80 * Returns ERROR_SUCCESS upon success (where not finding the record counts as
81 * success), something else on error.
83 static UINT ACTION_AppSearchGetSignature(MSIPACKAGE *package, MSISIGNATURE *sig,
88 static const WCHAR ExecSeqQuery[] = {
89 's','e','l','e','c','t',' ','*',' ',
91 'S','i','g','n','a','t','u','r','e',' ',
92 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e',' ','=',' ',
95 TRACE("(package %p, sig %p)\n", package, sig);
96 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 %d, MaxSize is %d;\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 /* Frees any memory allocated in sig */
176 static void ACTION_FreeSignature(MSISIGNATURE *sig)
179 msi_free(sig->Languages);
182 static UINT ACTION_AppSearchComponents(MSIPACKAGE *package, LPWSTR *appValue,
187 static const WCHAR ExecSeqQuery[] = {
188 's','e','l','e','c','t',' ','*',' ',
190 'C','o','m','p','L','o','c','a','t','o','r',' ',
191 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
192 '\'','%','s','\'',0};
194 TRACE("(package %p, appValue %p, sig %p)\n", package, appValue, sig);
196 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
197 if (rc == ERROR_SUCCESS)
203 rc = MSI_ViewExecute(view, 0);
204 if (rc != ERROR_SUCCESS)
206 TRACE("MSI_ViewExecute returned %d\n", rc);
209 rc = MSI_ViewFetch(view,&row);
210 if (rc != ERROR_SUCCESS)
212 TRACE("MSI_ViewFetch returned %d\n", rc);
219 sz=sizeof(guid)/sizeof(guid[0]);
220 rc = MSI_RecordGetStringW(row,2,guid,&sz);
221 if (rc != ERROR_SUCCESS)
223 ERR("Error is %x\n",rc);
226 FIXME("AppSearch unimplemented for CompLocator table (GUID %s)\n",
231 msiobj_release(&row->hdr);
233 msiobj_release(&view->hdr);
237 TRACE("MSI_OpenQuery returned %d\n", rc);
241 TRACE("returning %d\n", rc);
245 static void ACTION_ConvertRegValue(DWORD regType, const BYTE *value, DWORD sz,
248 static const WCHAR dwordFmt[] = { '#','%','d','\0' };
249 static const WCHAR expandSzFmt[] = { '#','%','%','%','s','\0' };
250 static const WCHAR binFmt[] = { '#','x','%','x','\0' };
256 if (*(LPCWSTR)value == '#')
258 /* escape leading pound with another */
259 *appValue = msi_alloc(sz + sizeof(WCHAR));
260 (*appValue)[0] = '#';
261 strcpyW(*appValue + 1, (LPCWSTR)value);
265 *appValue = msi_alloc(sz);
266 strcpyW(*appValue, (LPCWSTR)value);
270 /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign
273 *appValue = msi_alloc(10 * sizeof(WCHAR));
274 sprintfW(*appValue, dwordFmt, *(const DWORD *)value);
277 /* space for extra #% characters in front */
278 *appValue = msi_alloc(sz + 2 * sizeof(WCHAR));
279 sprintfW(*appValue, expandSzFmt, (LPCWSTR)value);
282 /* 3 == length of "#x<nibble>" */
283 *appValue = msi_alloc((sz * 3 + 1) * sizeof(WCHAR));
284 for (i = 0; i < sz; i++)
285 sprintfW(*appValue + i * 3, binFmt, value[i]);
288 WARN("unimplemented for values of type %d\n", regType);
293 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
294 LPCWSTR path, int depth, LPWSTR *appValue);
296 static UINT ACTION_AppSearchReg(MSIPACKAGE *package, LPWSTR *appValue,
301 static const WCHAR ExecSeqQuery[] = {
302 's','e','l','e','c','t',' ','*',' ',
304 'R','e','g','L','o','c','a','t','o','r',' ',
305 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
306 '\'','%','s','\'',0};
308 TRACE("(package %p, appValue %p, sig %p)\n", package, appValue, sig);
310 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
311 if (rc == ERROR_SUCCESS)
314 LPWSTR keyPath = NULL, valueName = NULL;
316 HKEY rootKey, key = NULL;
317 DWORD sz = 0, regType;
320 rc = MSI_ViewExecute(view, 0);
321 if (rc != ERROR_SUCCESS)
323 TRACE("MSI_ViewExecute returned %d\n", rc);
326 rc = MSI_ViewFetch(view,&row);
327 if (rc != ERROR_SUCCESS)
329 TRACE("MSI_ViewFetch returned %d\n", rc);
334 root = MSI_RecordGetInteger(row,2);
335 keyPath = msi_dup_record_field(row,3);
336 /* FIXME: keyPath needs to be expanded for properties */
337 valueName = msi_dup_record_field(row,4);
338 /* FIXME: valueName probably does too */
339 type = MSI_RecordGetInteger(row,5);
343 case msidbRegistryRootClassesRoot:
344 rootKey = HKEY_CLASSES_ROOT;
346 case msidbRegistryRootCurrentUser:
347 rootKey = HKEY_CURRENT_USER;
349 case msidbRegistryRootLocalMachine:
350 rootKey = HKEY_LOCAL_MACHINE;
352 case msidbRegistryRootUsers:
353 rootKey = HKEY_USERS;
356 WARN("Unknown root key %d\n", root);
360 rc = RegOpenKeyW(rootKey, keyPath, &key);
363 TRACE("RegOpenKeyW returned %d\n", rc);
367 rc = RegQueryValueExW(key, valueName, NULL, NULL, NULL, &sz);
370 TRACE("RegQueryValueExW returned %d\n", rc);
374 /* FIXME: sanity-check sz before allocating (is there an upper-limit
375 * on the value of a property?)
377 value = msi_alloc( sz);
378 rc = RegQueryValueExW(key, valueName, NULL, ®Type, value, &sz);
381 TRACE("RegQueryValueExW returned %d\n", rc);
386 /* bail out if the registry key is empty */
395 case msidbLocatorTypeDirectory:
396 rc = ACTION_SearchDirectory(package, sig, (LPCWSTR)value, 0,
399 case msidbLocatorTypeFileName:
400 *appValue = strdupW((LPCWSTR)value);
402 case msidbLocatorTypeRawValue:
403 ACTION_ConvertRegValue(regType, value, sz, appValue);
406 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
407 type, debugstr_w(keyPath), debugstr_w(valueName));
414 msi_free( valueName);
417 msiobj_release(&row->hdr);
419 msiobj_release(&view->hdr);
423 TRACE("MSI_OpenQuery returned %d\n", rc);
427 TRACE("returning %d\n", rc);
431 static UINT ACTION_AppSearchIni(MSIPACKAGE *package, LPWSTR *appValue,
436 static const WCHAR ExecSeqQuery[] = {
437 's','e','l','e','c','t',' ','*',' ',
439 'I','n','i','L','o','c','a','t','o','r',' ',
440 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
441 '\'','%','s','\'',0};
443 TRACE("(package %p, appValue %p, sig %p)\n", package, appValue, sig);
445 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
446 if (rc == ERROR_SUCCESS)
449 LPWSTR fileName, section, key;
453 rc = MSI_ViewExecute(view, 0);
454 if (rc != ERROR_SUCCESS)
456 TRACE("MSI_ViewExecute returned %d\n", rc);
459 rc = MSI_ViewFetch(view,&row);
460 if (rc != ERROR_SUCCESS)
462 TRACE("MSI_ViewFetch returned %d\n", rc);
467 fileName = msi_dup_record_field(row, 2);
468 section = msi_dup_record_field(row, 3);
469 key = msi_dup_record_field(row, 4);
470 if ((field = MSI_RecordGetInteger(row, 5)) == MSI_NULL_INTEGER)
472 if ((type = MSI_RecordGetInteger(row, 6)) == MSI_NULL_INTEGER)
475 GetPrivateProfileStringW(section, key, NULL, buf,
476 sizeof(buf) / sizeof(WCHAR), fileName);
481 case msidbLocatorTypeDirectory:
482 FIXME("unimplemented for type Directory (dir: %s)\n",
485 case msidbLocatorTypeFileName:
486 FIXME("unimplemented for type File (file: %s)\n",
489 case msidbLocatorTypeRawValue:
490 *appValue = strdupW(buf);
501 msiobj_release(&row->hdr);
503 msiobj_release(&view->hdr);
507 TRACE("MSI_OpenQuery returned %d\n", rc);
512 TRACE("returning %d\n", rc);
516 /* Expands the value in src into a path without property names and only
517 * containing long path names into dst. Replaces at most len characters of dst,
518 * and always NULL-terminates dst if dst is not NULL and len >= 1.
520 * Assumes src and dst are non-overlapping.
521 * FIXME: return code probably needed:
522 * - what does AppSearch return if the table values are invalid?
523 * - what if dst is too small?
525 static void ACTION_ExpandAnyPath(MSIPACKAGE *package, WCHAR *src, WCHAR *dst,
531 if (!src || !dst || !len)
533 if (dst) *dst = '\0';
537 /* Ignore the short portion of the path, don't think we can use it anyway */
538 if ((ptr = strchrW(src, '|')))
542 while (*ptr && copied < len - 1)
544 WCHAR *prop = strchrW(ptr, '[');
548 WCHAR *propEnd = strchrW(prop + 1, ']');
552 WARN("Unterminated property name in AnyPath: %s\n",
561 propLen = len - copied - 1;
562 MSI_GetPropertyW(package, prop + 1, dst + copied, &propLen);
569 size_t toCopy = min(strlenW(ptr) + 1, len - copied - 1);
571 memcpy(dst + copied, ptr, toCopy * sizeof(WCHAR));
576 *(dst + copied) = '\0';
579 /* Sets *matches to whether the file (whose path is filePath) matches the
580 * versions set in sig.
581 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
582 * something else if an install-halting error occurs.
584 static UINT ACTION_FileVersionMatches(MSISIGNATURE *sig, LPCWSTR filePath,
587 UINT rc = ERROR_SUCCESS;
592 FIXME(": need to check version for languages %s\n",
593 debugstr_w(sig->Languages));
597 DWORD zero, size = GetFileVersionInfoSizeW(filePath, &zero);
601 LPVOID buf = msi_alloc( size);
605 static WCHAR rootW[] = { '\\',0 };
607 LPVOID subBlock = NULL;
609 if (GetFileVersionInfoW(filePath, 0, size, buf))
610 VerQueryValueW(buf, rootW, &subBlock, &versionLen);
613 VS_FIXEDFILEINFO *info =
614 (VS_FIXEDFILEINFO *)subBlock;
616 TRACE("Comparing file version %d.%d.%d.%d:\n",
617 HIWORD(info->dwFileVersionMS),
618 LOWORD(info->dwFileVersionMS),
619 HIWORD(info->dwFileVersionLS),
620 LOWORD(info->dwFileVersionLS));
621 if (info->dwFileVersionMS < sig->MinVersionMS
622 || (info->dwFileVersionMS == sig->MinVersionMS &&
623 info->dwFileVersionLS < sig->MinVersionLS))
625 TRACE("Less than minimum version %d.%d.%d.%d\n",
626 HIWORD(sig->MinVersionMS),
627 LOWORD(sig->MinVersionMS),
628 HIWORD(sig->MinVersionLS),
629 LOWORD(sig->MinVersionLS));
631 else if (info->dwFileVersionMS < sig->MinVersionMS
632 || (info->dwFileVersionMS == sig->MinVersionMS &&
633 info->dwFileVersionLS < sig->MinVersionLS))
635 TRACE("Greater than minimum version %d.%d.%d.%d\n",
636 HIWORD(sig->MaxVersionMS),
637 LOWORD(sig->MaxVersionMS),
638 HIWORD(sig->MaxVersionLS),
639 LOWORD(sig->MaxVersionLS));
647 rc = ERROR_OUTOFMEMORY;
653 /* Sets *matches to whether the file in findData matches that in sig.
654 * fullFilePath is assumed to be the full path of the file specified in
655 * findData, which may be necessary to compare the version.
656 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
657 * something else if an install-halting error occurs.
659 static UINT ACTION_FileMatchesSig(MSISIGNATURE *sig,
660 LPWIN32_FIND_DATAW findData, LPCWSTR fullFilePath, BOOL *matches)
662 UINT rc = ERROR_SUCCESS;
665 /* assumes the caller has already ensured the filenames match, so check
668 if (sig->MinTime.dwLowDateTime || sig->MinTime.dwHighDateTime)
670 if (findData->ftCreationTime.dwHighDateTime <
671 sig->MinTime.dwHighDateTime ||
672 (findData->ftCreationTime.dwHighDateTime == sig->MinTime.dwHighDateTime
673 && findData->ftCreationTime.dwLowDateTime <
674 sig->MinTime.dwLowDateTime))
677 if (*matches && (sig->MaxTime.dwLowDateTime || sig->MaxTime.dwHighDateTime))
679 if (findData->ftCreationTime.dwHighDateTime >
680 sig->MaxTime.dwHighDateTime ||
681 (findData->ftCreationTime.dwHighDateTime == sig->MaxTime.dwHighDateTime
682 && findData->ftCreationTime.dwLowDateTime >
683 sig->MaxTime.dwLowDateTime))
686 if (*matches && sig->MinSize && findData->nFileSizeLow < sig->MinSize)
688 if (*matches && sig->MaxSize && findData->nFileSizeLow > sig->MaxSize)
690 if (*matches && (sig->MinVersionMS || sig->MinVersionLS ||
691 sig->MaxVersionMS || sig->MaxVersionLS))
692 rc = ACTION_FileVersionMatches(sig, fullFilePath, matches);
696 /* Recursively searches the directory dir for files that match the signature
697 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
698 * (and only dir). If depth is 1, searches dir and its immediate
700 * Assumes sig->File is not NULL.
701 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
702 * something else on failures which should halt the install.
704 static UINT ACTION_RecurseSearchDirectory(MSIPACKAGE *package, LPWSTR *appValue,
705 MSISIGNATURE *sig, LPCWSTR dir, int depth)
707 static const WCHAR starDotStarW[] = { '*','.','*',0 };
708 UINT rc = ERROR_SUCCESS;
709 size_t dirLen = lstrlenW(dir), fileLen = lstrlenW(sig->File);
712 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir),
713 debugstr_w(sig->File), depth);
716 return ERROR_INVALID_PARAMETER;
719 /* We need the buffer in both paths below, so go ahead and allocate it
720 * here. Add two because we might need to add a backslash if the dir name
721 * isn't backslash-terminated.
723 buf = msi_alloc( (dirLen + max(fileLen, lstrlenW(starDotStarW)) + 2) * sizeof(WCHAR));
726 /* a depth of 0 implies we should search dir, so go ahead and search */
728 WIN32_FIND_DATAW findData;
730 memcpy(buf, dir, dirLen * sizeof(WCHAR));
731 if (buf[dirLen - 1] != '\\')
732 buf[dirLen++ - 1] = '\\';
733 memcpy(buf + dirLen, sig->File, (fileLen + 1) * sizeof(WCHAR));
734 hFind = FindFirstFileW(buf, &findData);
735 if (hFind != INVALID_HANDLE_VALUE)
739 /* assuming Signature can't contain wildcards for the file name,
740 * so don't bother with FindNextFileW here.
742 if (!(rc = ACTION_FileMatchesSig(sig, &findData, buf, &matches))
745 TRACE("found file, returning %s\n", debugstr_w(buf));
750 if (rc == ERROR_SUCCESS && !*appValue && depth > 0)
753 WIN32_FIND_DATAW findData;
755 memcpy(buf, dir, dirLen * sizeof(WCHAR));
756 if (buf[dirLen - 1] != '\\')
757 buf[dirLen++ - 1] = '\\';
758 lstrcpyW(buf + dirLen, starDotStarW);
759 hFind = FindFirstFileW(buf, &findData);
760 if (hFind != INVALID_HANDLE_VALUE)
762 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
763 rc = ACTION_RecurseSearchDirectory(package, appValue, sig,
764 findData.cFileName, depth - 1);
765 while (rc == ERROR_SUCCESS && !*appValue &&
766 FindNextFileW(hFind, &findData) != 0)
768 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
769 rc = ACTION_RecurseSearchDirectory(package, appValue,
770 sig, findData.cFileName, depth - 1);
779 rc = ERROR_OUTOFMEMORY;
784 static UINT ACTION_CheckDirectory(MSIPACKAGE *package, LPCWSTR dir,
787 UINT rc = ERROR_SUCCESS;
789 if (GetFileAttributesW(dir) & FILE_ATTRIBUTE_DIRECTORY)
791 TRACE("directory exists, returning %s\n", debugstr_w(dir));
792 *appValue = strdupW(dir);
797 static BOOL ACTION_IsFullPath(LPCWSTR path)
799 WCHAR first = toupperW(path[0]);
802 if (first >= 'A' && first <= 'Z' && path[1] == ':')
804 else if (path[0] == '\\' && path[1] == '\\')
811 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
812 LPCWSTR path, int depth, LPWSTR *appValue)
816 TRACE("%p, %p, %s, %d, %p\n", package, sig, debugstr_w(path), depth,
818 if (ACTION_IsFullPath(path))
821 rc = ACTION_RecurseSearchDirectory(package, appValue, sig,
825 /* Recursively searching a directory makes no sense when the
826 * directory to search is the thing you're trying to find.
828 rc = ACTION_CheckDirectory(package, path, appValue);
833 WCHAR pathWithDrive[MAX_PATH] = { 'C',':','\\',0 };
834 DWORD drives = GetLogicalDrives();
839 for (i = 0; rc == ERROR_SUCCESS && !*appValue && i < 26; i++)
840 if (drives & (1 << drives))
842 pathWithDrive[0] = 'A' + i;
843 if (GetDriveTypeW(pathWithDrive) == DRIVE_FIXED)
845 lstrcpynW(pathWithDrive + 3, path,
846 sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
848 rc = ACTION_RecurseSearchDirectory(package, appValue,
849 sig, pathWithDrive, depth);
851 rc = ACTION_CheckDirectory(package, pathWithDrive,
856 TRACE("returning %d\n", rc);
860 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
861 MSISIGNATURE *sig, LPWSTR *appValue);
863 static UINT ACTION_AppSearchDr(MSIPACKAGE *package, LPWSTR *appValue,
868 static const WCHAR ExecSeqQuery[] = {
869 's','e','l','e','c','t',' ','*',' ',
871 'D','r','L','o','c','a','t','o','r',' ',
872 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
873 '\'','%','s','\'',0};
875 TRACE("(package %p, sig %p)\n", package, sig);
876 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
877 if (rc == ERROR_SUCCESS)
880 WCHAR expanded[MAX_PATH];
881 LPWSTR parentName = NULL, path = NULL, parent = NULL;
884 rc = MSI_ViewExecute(view, 0);
885 if (rc != ERROR_SUCCESS)
887 TRACE("MSI_ViewExecute returned %d\n", rc);
890 rc = MSI_ViewFetch(view,&row);
891 if (rc != ERROR_SUCCESS)
893 TRACE("MSI_ViewFetch returned %d\n", rc);
898 /* check whether parent is set */
899 parentName = msi_dup_record_field(row,2);
902 MSISIGNATURE parentSig;
904 rc = ACTION_AppSearchSigName(package, parentName, &parentSig,
906 ACTION_FreeSignature(&parentSig);
907 msi_free(parentName);
909 /* now look for path */
910 path = msi_dup_record_field(row,3);
911 if (MSI_RecordIsNull(row,4))
914 depth = MSI_RecordGetInteger(row,4);
915 ACTION_ExpandAnyPath(package, path, expanded,
916 sizeof(expanded) / sizeof(expanded[0]));
920 path = msi_alloc((strlenW(parent) + strlenW(expanded) + 1) * sizeof(WCHAR));
923 strcpyW(path, parent);
924 strcatW(path, expanded);
928 rc = ACTION_SearchDirectory(package, sig, path, depth, appValue);
931 if (path != expanded)
935 msiobj_release(&row->hdr);
937 msiobj_release(&view->hdr);
941 TRACE("MSI_OpenQuery returned %d\n", rc);
945 TRACE("returning %d\n", rc);
949 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
950 MSISIGNATURE *sig, LPWSTR *appValue)
955 rc = ACTION_AppSearchGetSignature(package, sig, sigName);
956 if (rc == ERROR_SUCCESS)
958 rc = ACTION_AppSearchComponents(package, appValue, sig);
959 if (rc == ERROR_SUCCESS && !*appValue)
961 rc = ACTION_AppSearchReg(package, appValue, sig);
962 if (rc == ERROR_SUCCESS && !*appValue)
964 rc = ACTION_AppSearchIni(package, appValue, sig);
965 if (rc == ERROR_SUCCESS && !*appValue)
966 rc = ACTION_AppSearchDr(package, appValue, sig);
973 /* http://msdn.microsoft.com/library/en-us/msi/setup/appsearch_table.asp
974 * is the best reference for the AppSearch table and how it's used.
976 UINT ACTION_AppSearch(MSIPACKAGE *package)
980 static const WCHAR ExecSeqQuery[] = {
981 's','e','l','e','c','t',' ','*',' ',
983 'A','p','p','S','e','a','r','c','h',0};
985 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery);
986 if (rc == ERROR_SUCCESS)
989 LPWSTR propName, sigName;
991 rc = MSI_ViewExecute(view, 0);
992 if (rc != ERROR_SUCCESS)
1000 rc = MSI_ViewFetch(view,&row);
1001 if (rc != ERROR_SUCCESS)
1007 /* get property and signature */
1008 propName = msi_dup_record_field(row,1);
1009 sigName = msi_dup_record_field(row,2);
1011 TRACE("Searching for Property %s, Signature_ %s\n",
1012 debugstr_w(propName), debugstr_w(sigName));
1014 rc = ACTION_AppSearchSigName(package, sigName, &sig, &value);
1017 MSI_SetPropertyW(package, propName, value);
1020 ACTION_FreeSignature(&sig);
1023 msiobj_release(&row->hdr);
1027 MSI_ViewClose(view);
1028 msiobj_release(&view->hdr);