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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 = load_dynamic_stringW(row,2);
122 minVersion = load_dynamic_stringW(row,3);
125 ACTION_VerStrToInteger(minVersion, &sig->MinVersionMS,
127 HeapFree(GetProcessHeap(), 0, minVersion);
129 maxVersion = load_dynamic_stringW(row,4);
132 ACTION_VerStrToInteger(maxVersion, &sig->MaxVersionMS,
134 HeapFree(GetProcessHeap(), 0, 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 = load_dynamic_stringW(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));
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 static UINT ACTION_AppSearchComponents(MSIPACKAGE *package, BOOL *appFound,
180 static const WCHAR ExecSeqQuery[] = {
181 's','e','l','e','c','t',' ','*',' ',
183 'C','o','m','p','L','o','c','a','t','o','r',' ',
184 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
185 '\'','%','s','\'',0};
187 TRACE("(package %p, appFound %p, sig %p)\n", package, appFound, sig);
189 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
190 if (rc == ERROR_SUCCESS)
196 rc = MSI_ViewExecute(view, 0);
197 if (rc != ERROR_SUCCESS)
199 TRACE("MSI_ViewExecute returned %d\n", rc);
202 rc = MSI_ViewFetch(view,&row);
203 if (rc != ERROR_SUCCESS)
205 TRACE("MSI_ViewFetch returned %d\n", rc);
212 sz=sizeof(guid)/sizeof(guid[0]);
213 rc = MSI_RecordGetStringW(row,2,guid,&sz);
214 if (rc != ERROR_SUCCESS)
216 ERR("Error is %x\n",rc);
219 FIXME("AppSearch unimplemented for CompLocator table (GUID %s)\n",
223 msiobj_release(&row->hdr);
225 msiobj_release(&view->hdr);
229 TRACE("MSI_OpenQuery returned %d\n", rc);
233 TRACE("returning %d\n", rc);
237 static UINT ACTION_AppSearchReg(MSIPACKAGE *package, BOOL *appFound,
242 static const WCHAR ExecSeqQuery[] = {
243 's','e','l','e','c','t',' ','*',' ',
245 'R','e','g','L','o','c','a','t','o','r',' ',
246 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
247 '\'','%','s','\'',0};
248 static const WCHAR dwordFmt[] = { '#','%','d','\0' };
249 static const WCHAR expandSzFmt[] = { '#','%','%','%','s','\0' };
250 static const WCHAR binFmt[] = { '#','x','%','x','\0' };
252 TRACE("(package %p, appFound %p, sig %p)\n", package, appFound, sig);
254 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
255 if (rc == ERROR_SUCCESS)
258 LPWSTR keyPath = NULL, valueName = NULL, propertyValue = NULL;
260 HKEY rootKey, key = NULL;
261 DWORD sz = 0, regType, i;
264 rc = MSI_ViewExecute(view, 0);
265 if (rc != ERROR_SUCCESS)
267 TRACE("MSI_ViewExecute returned %d\n", rc);
270 rc = MSI_ViewFetch(view,&row);
271 if (rc != ERROR_SUCCESS)
273 TRACE("MSI_ViewFetch returned %d\n", rc);
278 root = MSI_RecordGetInteger(row,2);
279 keyPath = load_dynamic_stringW(row,3);
280 /* FIXME: keyPath needs to be expanded for properties */
281 valueName = load_dynamic_stringW(row,4);
282 /* FIXME: valueName probably does too */
283 type = MSI_RecordGetInteger(row,5);
285 if ((type & 0x0f) != msidbLocatorTypeRawValue)
287 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
288 type, debugstr_w(keyPath), debugstr_w(valueName));
294 case msidbRegistryRootClassesRoot:
295 rootKey = HKEY_CLASSES_ROOT;
297 case msidbRegistryRootCurrentUser:
298 rootKey = HKEY_CURRENT_USER;
300 case msidbRegistryRootLocalMachine:
301 rootKey = HKEY_LOCAL_MACHINE;
303 case msidbRegistryRootUsers:
304 rootKey = HKEY_USERS;
307 WARN("Unknown root key %d\n", root);
311 rc = RegCreateKeyW(rootKey, keyPath, &key);
314 TRACE("RegCreateKeyW returned %d\n", rc);
318 rc = RegQueryValueExW(key, valueName, NULL, NULL, NULL, &sz);
321 TRACE("RegQueryValueExW returned %d\n", rc);
325 /* FIXME: sanity-check sz before allocating (is there an upper-limit
326 * on the value of a property?)
328 value = HeapAlloc(GetProcessHeap(), 0, sz);
329 rc = RegQueryValueExW(key, valueName, NULL, ®Type, value, &sz);
332 TRACE("RegQueryValueExW returned %d\n", rc);
337 /* bail out if the registry key is empty */
347 if (*(LPWSTR)value == '#')
349 /* escape leading pound with another */
350 propertyValue = HeapAlloc(GetProcessHeap(), 0,
352 propertyValue[0] = '#';
353 strcpyW(propertyValue + 1, (LPWSTR)value);
357 propertyValue = HeapAlloc(GetProcessHeap(), 0, sz);
358 strcpyW(propertyValue, (LPWSTR)value);
362 /* 7 chars for digits, 1 for NULL, 1 for #, and 1 for sign
365 propertyValue = HeapAlloc(GetProcessHeap(), 0,
367 sprintfW(propertyValue, dwordFmt, *(DWORD *)value);
370 /* space for extra #% characters in front */
371 propertyValue = HeapAlloc(GetProcessHeap(), 0,
372 sz + 2 * sizeof(WCHAR));
373 sprintfW(propertyValue, expandSzFmt, (LPWSTR)value);
376 /* 3 == length of "#x<nibble>" */
377 propertyValue = HeapAlloc(GetProcessHeap(), 0,
378 (sz * 3 + 1) * sizeof(WCHAR));
379 for (i = 0; i < sz; i++)
380 sprintfW(propertyValue + i * 3, binFmt, value[i]);
383 WARN("unimplemented for values of type %ld\n", regType);
387 TRACE("found registry value, setting %s to %s\n",
388 debugstr_w(sig->Property), debugstr_w(propertyValue));
389 rc = MSI_SetPropertyW(package, sig->Property, propertyValue);
393 HeapFree(GetProcessHeap(), 0, propertyValue);
394 HeapFree(GetProcessHeap(), 0, value);
397 HeapFree(GetProcessHeap(), 0, keyPath);
398 HeapFree(GetProcessHeap(), 0, valueName);
400 msiobj_release(&row->hdr);
402 msiobj_release(&view->hdr);
406 TRACE("MSI_OpenQuery returned %d\n", rc);
410 TRACE("returning %d\n", rc);
414 static UINT ACTION_AppSearchIni(MSIPACKAGE *package, BOOL *appFound,
419 static const WCHAR ExecSeqQuery[] = {
420 's','e','l','e','c','t',' ','*',' ',
422 'I','n','i','L','o','c','a','t','o','r',' ',
423 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
424 '\'','%','s','\'',0};
426 TRACE("(package %p, appFound %p, sig %p)\n", package, appFound, sig);
428 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
429 if (rc == ERROR_SUCCESS)
434 rc = MSI_ViewExecute(view, 0);
435 if (rc != ERROR_SUCCESS)
437 TRACE("MSI_ViewExecute returned %d\n", rc);
440 rc = MSI_ViewFetch(view,&row);
441 if (rc != ERROR_SUCCESS)
443 TRACE("MSI_ViewFetch returned %d\n", rc);
449 fileName = load_dynamic_stringW(row,2);
450 FIXME("AppSearch unimplemented for IniLocator (ini file name %s)\n",
451 debugstr_w(fileName));
452 HeapFree(GetProcessHeap(), 0, 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 = HeapAlloc(GetProcessHeap(), 0, size);
556 static const 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));
595 HeapFree(GetProcessHeap(), 0, buf);
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 = HeapAlloc(GetProcessHeap(), 0,
675 (dirLen + max(fileLen, lstrlenW(starDotStarW)) + 2) * sizeof(WCHAR));
678 /* a depth of 0 implies we should search dir, so go ahead and search */
680 WIN32_FIND_DATAW findData;
682 memcpy(buf, dir, dirLen * sizeof(WCHAR));
683 if (buf[dirLen - 1] != '\\')
684 buf[dirLen++ - 1] = '\\';
685 memcpy(buf + dirLen, sig->File, (fileLen + 1) * sizeof(WCHAR));
686 hFind = FindFirstFileW(buf, &findData);
687 if (hFind != INVALID_HANDLE_VALUE)
691 /* assuming Signature can't contain wildcards for the file name,
692 * so don't bother with FindNextFileW here.
694 if (!(rc = ACTION_FileMatchesSig(sig, &findData, buf, &matches))
697 TRACE("found file, setting %s to %s\n",
698 debugstr_w(sig->Property), debugstr_w(buf));
699 rc = MSI_SetPropertyW(package, sig->Property, buf);
704 if (rc == ERROR_SUCCESS && !*appFound && depth > 0)
707 WIN32_FIND_DATAW findData;
709 memcpy(buf, dir, dirLen * sizeof(WCHAR));
710 if (buf[dirLen - 1] != '\\')
711 buf[dirLen++ - 1] = '\\';
712 lstrcpyW(buf + dirLen, starDotStarW);
713 hFind = FindFirstFileW(buf, &findData);
714 if (hFind != INVALID_HANDLE_VALUE)
716 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
717 rc = ACTION_RecurseSearchDirectory(package, appFound,
718 sig, findData.cFileName, depth - 1);
719 while (rc == ERROR_SUCCESS && !*appFound &&
720 FindNextFileW(hFind, &findData) != 0)
722 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
723 rc = ACTION_RecurseSearchDirectory(package, appFound,
724 sig, findData.cFileName, depth - 1);
729 HeapFree(GetProcessHeap(), 0, buf);
732 rc = ERROR_OUTOFMEMORY;
737 static UINT ACTION_CheckDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
740 UINT rc = ERROR_SUCCESS;
742 if (GetFileAttributesW(dir) & FILE_ATTRIBUTE_DIRECTORY)
744 TRACE("directory exists, setting %s to %s\n",
745 debugstr_w(sig->Property), debugstr_w(dir));
746 rc = MSI_SetPropertyW(package, sig->Property, dir);
751 static BOOL ACTION_IsFullPath(LPCWSTR path)
753 WCHAR first = toupperW(path[0]);
756 if (first >= 'A' && first <= 'Z' && path[1] == ':')
758 else if (path[0] == '\\' && path[1] == '\\')
765 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
766 LPCWSTR expanded, int depth)
771 TRACE("%p, %p, %s, %d\n", package, sig, debugstr_w(expanded), depth);
772 if (ACTION_IsFullPath(expanded))
775 rc = ACTION_RecurseSearchDirectory(package, &found, sig,
779 /* Recursively searching a directory makes no sense when the
780 * directory to search is the thing you're trying to find.
782 rc = ACTION_CheckDirectory(package, sig, expanded);
787 WCHAR pathWithDrive[MAX_PATH] = { 'C',':','\\',0 };
788 DWORD drives = GetLogicalDrives();
793 for (i = 0; rc == ERROR_SUCCESS && !found && i < 26; i++)
794 if (drives & (1 << drives))
796 pathWithDrive[0] = 'A' + i;
797 if (GetDriveTypeW(pathWithDrive) == DRIVE_FIXED)
799 lstrcpynW(pathWithDrive + 3, expanded,
800 sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
802 rc = ACTION_RecurseSearchDirectory(package, &found, sig,
803 pathWithDrive, depth);
805 rc = ACTION_CheckDirectory(package, sig, pathWithDrive);
809 TRACE("returning %d\n", rc);
813 static UINT ACTION_AppSearchDr(MSIPACKAGE *package, MSISIGNATURE *sig)
817 static const WCHAR ExecSeqQuery[] = {
818 's','e','l','e','c','t',' ','*',' ',
820 'D','r','L','o','c','a','t','o','r',' ',
821 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
822 '\'','%','s','\'',0};
824 TRACE("(package %p, sig %p)\n", package, sig);
825 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
826 if (rc == ERROR_SUCCESS)
829 WCHAR buffer[MAX_PATH], expanded[MAX_PATH];
833 rc = MSI_ViewExecute(view, 0);
834 if (rc != ERROR_SUCCESS)
836 TRACE("MSI_ViewExecute returned %d\n", rc);
839 rc = MSI_ViewFetch(view,&row);
840 if (rc != ERROR_SUCCESS)
842 TRACE("MSI_ViewFetch returned %d\n", rc);
847 /* check whether parent is set */
849 sz=sizeof(buffer)/sizeof(buffer[0]);
850 rc = MSI_RecordGetStringW(row,2,buffer,&sz);
851 if (rc != ERROR_SUCCESS)
853 ERR("Error is %x\n",rc);
858 FIXME(": searching parent (%s) unimplemented\n",
862 /* no parent, now look for path */
864 sz=sizeof(buffer)/sizeof(buffer[0]);
865 rc = MSI_RecordGetStringW(row,3,buffer,&sz);
866 if (rc != ERROR_SUCCESS)
868 ERR("Error is %x\n",rc);
871 if (MSI_RecordIsNull(row,4))
874 depth = MSI_RecordGetInteger(row,4);
875 ACTION_ExpandAnyPath(package, buffer, expanded,
876 sizeof(expanded) / sizeof(expanded[0]));
877 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);
968 HeapFree(GetProcessHeap(), 0, sig.File);
969 HeapFree(GetProcessHeap(), 0, sig.Languages);
970 msiobj_release(&row->hdr);
975 msiobj_release(&view->hdr);