Simplify AppSearch error checking.
[wine/multimedia.git] / dlls / msi / appsearch.c
blob0a786908eac268c7d9c24de0bba4278e817e32b0
1 /*
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
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "msi.h"
27 #include "msiquery.h"
28 #include "winver.h"
29 #include "wine/unicode.h"
30 #include "wine/debug.h"
31 #include "msipriv.h"
32 #include "action.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msi);
36 typedef struct tagMSISIGNATURE
38 LPWSTR Name; /* NOT owned by this structure */
39 LPWSTR Property; /* NOT owned by this structure */
40 LPWSTR File;
41 DWORD MinVersionMS;
42 DWORD MinVersionLS;
43 DWORD MaxVersionMS;
44 DWORD MaxVersionLS;
45 DWORD MinSize;
46 DWORD MaxSize;
47 FILETIME MinTime;
48 FILETIME MaxTime;
49 LPWSTR Languages;
50 }MSISIGNATURE;
52 static void ACTION_VerStrToInteger(LPCWSTR verStr, PDWORD ms, PDWORD ls)
54 const WCHAR *ptr;
55 int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
57 x1 = atoiW(verStr);
58 ptr = strchrW(verStr, '.');
59 if (ptr)
61 x2 = atoiW(ptr + 1);
62 ptr = strchrW(ptr + 1, '.');
64 if (ptr)
66 x3 = atoiW(ptr + 1);
67 ptr = strchrW(ptr + 1, '.');
69 if (ptr)
70 x4 = atoiW(ptr + 1);
71 /* FIXME: byte-order dependent? */
72 *ms = x1 << 16 | x2;
73 *ls = x3 << 16 | x4;
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,
84 LPCWSTR name)
86 MSIQUERY *view;
87 UINT rc;
88 static const WCHAR ExecSeqQuery[] = {
89 's','e','l','e','c','t',' ','*',' ',
90 'f','r','o','m',' ',
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',' ','=',' ',
93 '\'','%','s','\'',0};
95 TRACE("(package %p, sig %p)\n", package, sig);
96 memset(sig, 0, sizeof(*sig));
97 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, name);
98 if (rc == ERROR_SUCCESS)
100 MSIRECORD *row = 0;
101 DWORD time;
102 WCHAR *minVersion, *maxVersion;
104 rc = MSI_ViewExecute(view, 0);
105 if (rc != ERROR_SUCCESS)
107 TRACE("MSI_ViewExecute returned %d\n", rc);
108 goto end;
110 rc = MSI_ViewFetch(view,&row);
111 if (rc != ERROR_SUCCESS)
113 TRACE("MSI_ViewFetch returned %d\n", rc);
114 rc = ERROR_SUCCESS;
115 goto end;
118 /* get properties */
119 sig->File = load_dynamic_stringW(row,2);
120 minVersion = load_dynamic_stringW(row,3);
121 if (minVersion)
123 ACTION_VerStrToInteger(minVersion, &sig->MinVersionMS,
124 &sig->MinVersionLS);
125 HeapFree(GetProcessHeap(), 0, minVersion);
127 maxVersion = load_dynamic_stringW(row,4);
128 if (maxVersion)
130 ACTION_VerStrToInteger(maxVersion, &sig->MaxVersionMS,
131 &sig->MaxVersionLS);
132 HeapFree(GetProcessHeap(), 0, maxVersion);
134 sig->MinSize = MSI_RecordGetInteger(row,5);
135 if (sig->MinSize == MSI_NULL_INTEGER)
136 sig->MinSize = 0;
137 sig->MaxSize = MSI_RecordGetInteger(row,6);
138 if (sig->MaxSize == MSI_NULL_INTEGER)
139 sig->MaxSize = 0;
140 sig->Languages = load_dynamic_stringW(row,9);
141 time = MSI_RecordGetInteger(row,7);
142 if (time != MSI_NULL_INTEGER)
143 DosDateTimeToFileTime(HIWORD(time), LOWORD(time), &sig->MinTime);
144 time = MSI_RecordGetInteger(row,8);
145 if (time != MSI_NULL_INTEGER)
146 DosDateTimeToFileTime(HIWORD(time), LOWORD(time), &sig->MaxTime);
147 TRACE("Found file name %s for Signature_ %s;\n",
148 debugstr_w(sig->File), debugstr_w(name));
149 TRACE("MinVersion is %d.%d.%d.%d\n", HIWORD(sig->MinVersionMS),
150 LOWORD(sig->MinVersionMS), HIWORD(sig->MinVersionLS),
151 LOWORD(sig->MinVersionLS));
152 TRACE("MaxVersion is %d.%d.%d.%d\n", HIWORD(sig->MaxVersionMS),
153 LOWORD(sig->MaxVersionMS), HIWORD(sig->MaxVersionLS),
154 LOWORD(sig->MaxVersionLS));
155 TRACE("MinSize is %ld, MaxSize is %ld;\n", sig->MinSize, sig->MaxSize);
156 TRACE("Languages is %s\n", debugstr_w(sig->Languages));
158 end:
159 msiobj_release(&row->hdr);
160 MSI_ViewClose(view);
161 msiobj_release(&view->hdr);
163 else
165 TRACE("MSI_OpenQuery returned %d\n", rc);
166 rc = ERROR_SUCCESS;
169 TRACE("returning %d\n", rc);
170 return rc;
173 static UINT ACTION_AppSearchComponents(MSIPACKAGE *package, BOOL *appFound,
174 MSISIGNATURE *sig)
176 MSIQUERY *view;
177 UINT rc;
178 static const WCHAR ExecSeqQuery[] = {
179 's','e','l','e','c','t',' ','*',' ',
180 'f','r','o','m',' ',
181 'C','o','m','p','L','o','c','a','t','o','r',' ',
182 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
183 '\'','%','s','\'',0};
185 TRACE("(package %p, appFound %p, sig %p)\n", package, appFound, sig);
186 *appFound = FALSE;
187 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
188 if (rc == ERROR_SUCCESS)
190 MSIRECORD *row = 0;
191 WCHAR guid[50];
192 DWORD sz;
194 rc = MSI_ViewExecute(view, 0);
195 if (rc != ERROR_SUCCESS)
197 TRACE("MSI_ViewExecute returned %d\n", rc);
198 goto end;
200 rc = MSI_ViewFetch(view,&row);
201 if (rc != ERROR_SUCCESS)
203 TRACE("MSI_ViewFetch returned %d\n", rc);
204 rc = ERROR_SUCCESS;
205 goto end;
208 /* get GUID */
209 guid[0] = 0;
210 sz=sizeof(guid)/sizeof(guid[0]);
211 rc = MSI_RecordGetStringW(row,2,guid,&sz);
212 if (rc != ERROR_SUCCESS)
214 ERR("Error is %x\n",rc);
215 goto end;
217 FIXME("AppSearch unimplemented for CompLocator table (GUID %s)\n",
218 debugstr_w(guid));
220 end:
221 msiobj_release(&row->hdr);
222 MSI_ViewClose(view);
223 msiobj_release(&view->hdr);
225 else
227 TRACE("MSI_OpenQuery returned %d\n", rc);
228 rc = ERROR_SUCCESS;
231 TRACE("returning %d\n", rc);
232 return rc;
235 static UINT ACTION_AppSearchReg(MSIPACKAGE *package, BOOL *appFound,
236 MSISIGNATURE *sig)
238 MSIQUERY *view;
239 UINT rc;
240 static const WCHAR ExecSeqQuery[] = {
241 's','e','l','e','c','t',' ','*',' ',
242 'f','r','o','m',' ',
243 'R','e','g','L','o','c','a','t','o','r',' ',
244 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
245 '\'','%','s','\'',0};
247 TRACE("(package %p, appFound %p, sig %p)\n", package, appFound, sig);
248 *appFound = FALSE;
249 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
250 if (rc == ERROR_SUCCESS)
252 MSIRECORD *row = 0;
253 LPWSTR keyPath;
255 rc = MSI_ViewExecute(view, 0);
256 if (rc != ERROR_SUCCESS)
258 TRACE("MSI_ViewExecute returned %d\n", rc);
259 goto end;
261 rc = MSI_ViewFetch(view,&row);
262 if (rc != ERROR_SUCCESS)
264 TRACE("MSI_ViewFetch returned %d\n", rc);
265 rc = ERROR_SUCCESS;
266 goto end;
269 /* get key path */
270 keyPath = load_dynamic_stringW(row,3);
271 FIXME("AppSearch unimplemented for RegLocator (key path %s)\n",
272 debugstr_w(keyPath));
273 HeapFree(GetProcessHeap(), 0, keyPath);
275 end:
276 msiobj_release(&row->hdr);
277 MSI_ViewClose(view);
278 msiobj_release(&view->hdr);
280 else
282 TRACE("MSI_OpenQuery returned %d\n", rc);
283 rc = ERROR_SUCCESS;
286 TRACE("returning %d\n", rc);
287 return rc;
290 static UINT ACTION_AppSearchIni(MSIPACKAGE *package, BOOL *appFound,
291 MSISIGNATURE *sig)
293 MSIQUERY *view;
294 UINT rc;
295 static const WCHAR ExecSeqQuery[] = {
296 's','e','l','e','c','t',' ','*',' ',
297 'f','r','o','m',' ',
298 'I','n','i','L','o','c','a','t','o','r',' ',
299 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
300 '\'','%','s','\'',0};
302 TRACE("(package %p, appFound %p, sig %p)\n", package, appFound, sig);
303 *appFound = FALSE;
304 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
305 if (rc == ERROR_SUCCESS)
307 MSIRECORD *row = 0;
308 LPWSTR fileName;
310 rc = MSI_ViewExecute(view, 0);
311 if (rc != ERROR_SUCCESS)
313 TRACE("MSI_ViewExecute returned %d\n", rc);
314 goto end;
316 rc = MSI_ViewFetch(view,&row);
317 if (rc != ERROR_SUCCESS)
319 TRACE("MSI_ViewFetch returned %d\n", rc);
320 rc = ERROR_SUCCESS;
321 goto end;
324 /* get file name */
325 fileName = load_dynamic_stringW(row,2);
326 FIXME("AppSearch unimplemented for IniLocator (ini file name %s)\n",
327 debugstr_w(fileName));
328 HeapFree(GetProcessHeap(), 0, fileName);
330 end:
331 msiobj_release(&row->hdr);
332 MSI_ViewClose(view);
333 msiobj_release(&view->hdr);
335 else
337 TRACE("MSI_OpenQuery returned %d\n", rc);
338 rc = ERROR_SUCCESS;
342 TRACE("returning %d\n", rc);
343 return rc;
346 /* Expands the value in src into a path without property names and only
347 * containing long path names into dst. Replaces at most len characters of dst,
348 * and always NULL-terminates dst if dst is not NULL and len >= 1.
349 * May modify src.
350 * Assumes src and dst are non-overlapping.
351 * FIXME: return code probably needed:
352 * - what does AppSearch return if the table values are invalid?
353 * - what if dst is too small?
355 static void ACTION_ExpandAnyPath(MSIPACKAGE *package, WCHAR *src, WCHAR *dst,
356 size_t len)
358 WCHAR *ptr;
359 size_t copied = 0;
361 if (!src || !dst || !len)
362 return;
364 /* Ignore the short portion of the path, don't think we can use it anyway */
365 if ((ptr = strchrW(src, '|')))
366 ptr++;
367 else
368 ptr = src;
369 while (*ptr && copied < len - 1)
371 WCHAR *prop = strchrW(ptr, '[');
373 if (prop)
375 WCHAR *propEnd = strchrW(prop + 1, ']');
377 if (!propEnd)
379 WARN("Unterminated property name in AnyPath: %s\n",
380 debugstr_w(prop));
381 break;
383 else
385 DWORD propLen;
387 *propEnd = 0;
388 propLen = len - copied - 1;
389 MSI_GetPropertyW(package, prop + 1, dst + copied, &propLen);
390 ptr = propEnd + 1;
391 copied += propLen;
394 else
396 size_t toCopy = min(strlenW(ptr) + 1, len - copied - 1);
398 memcpy(dst + copied, ptr, toCopy * sizeof(WCHAR));
399 ptr += toCopy;
400 copied += toCopy;
403 *(dst + copied) = '\0';
406 /* Sets *matches to whether the file (whose path is filePath) matches the
407 * versions set in sig.
408 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
409 * something else if a install-halting error occurs.
411 static UINT ACTION_FileVersionMatches(MSISIGNATURE *sig, LPCWSTR filePath,
412 BOOL *matches)
414 UINT rc = ERROR_SUCCESS;
416 *matches = FALSE;
417 if (sig->Languages)
419 FIXME(": need to check version for languages %s\n",
420 debugstr_w(sig->Languages));
422 else
424 DWORD zero, size = GetFileVersionInfoSizeW(filePath, &zero);
426 if (size)
428 LPVOID buf = HeapAlloc(GetProcessHeap(), 0, size);
430 if (buf)
432 static const WCHAR rootW[] = { '\\',0 };
433 UINT versionLen;
434 LPVOID subBlock = NULL;
436 if (GetFileVersionInfoW(filePath, 0, size, buf))
437 VerQueryValueW(buf, rootW, &subBlock, &versionLen);
438 if (subBlock)
440 VS_FIXEDFILEINFO *info =
441 (VS_FIXEDFILEINFO *)subBlock;
443 TRACE("Comparing file version %d.%d.%d.%d:\n",
444 HIWORD(info->dwFileVersionMS),
445 LOWORD(info->dwFileVersionMS),
446 HIWORD(info->dwFileVersionLS),
447 LOWORD(info->dwFileVersionLS));
448 if (info->dwFileVersionMS < sig->MinVersionMS
449 || (info->dwFileVersionMS == sig->MinVersionMS &&
450 info->dwFileVersionLS < sig->MinVersionLS))
452 TRACE("Less than minimum version %d.%d.%d.%d\n",
453 HIWORD(sig->MinVersionMS),
454 LOWORD(sig->MinVersionMS),
455 HIWORD(sig->MinVersionLS),
456 LOWORD(sig->MinVersionLS));
458 else if (info->dwFileVersionMS < sig->MinVersionMS
459 || (info->dwFileVersionMS == sig->MinVersionMS &&
460 info->dwFileVersionLS < sig->MinVersionLS))
462 TRACE("Greater than minimum version %d.%d.%d.%d\n",
463 HIWORD(sig->MaxVersionMS),
464 LOWORD(sig->MaxVersionMS),
465 HIWORD(sig->MaxVersionLS),
466 LOWORD(sig->MaxVersionLS));
468 else
469 *matches = TRUE;
471 HeapFree(GetProcessHeap(), 0, buf);
473 else
474 rc = ERROR_OUTOFMEMORY;
477 return rc;
480 /* Sets *matches to whether the file in findData matches that in sig.
481 * fullFilePath is assumed to be the full path of the file specified in
482 * findData, which may be necessary to compare the version.
483 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
484 * something else if a install-halting error occurs.
486 static UINT ACTION_FileMatchesSig(MSISIGNATURE *sig,
487 LPWIN32_FIND_DATAW findData, LPCWSTR fullFilePath, BOOL *matches)
489 UINT rc = ERROR_SUCCESS;
491 *matches = TRUE;
492 /* assumes the caller has already ensured the filenames match, so check
493 * the other fields..
495 if (sig->MinTime.dwLowDateTime || sig->MinTime.dwHighDateTime)
497 if (findData->ftCreationTime.dwHighDateTime <
498 sig->MinTime.dwHighDateTime ||
499 (findData->ftCreationTime.dwHighDateTime == sig->MinTime.dwHighDateTime
500 && findData->ftCreationTime.dwLowDateTime <
501 sig->MinTime.dwLowDateTime))
502 *matches = FALSE;
504 if (*matches && (sig->MaxTime.dwLowDateTime || sig->MaxTime.dwHighDateTime))
506 if (findData->ftCreationTime.dwHighDateTime >
507 sig->MaxTime.dwHighDateTime ||
508 (findData->ftCreationTime.dwHighDateTime == sig->MaxTime.dwHighDateTime
509 && findData->ftCreationTime.dwLowDateTime >
510 sig->MaxTime.dwLowDateTime))
511 *matches = FALSE;
513 if (*matches && sig->MinSize && findData->nFileSizeLow < sig->MinSize)
514 *matches = FALSE;
515 if (*matches && sig->MaxSize && findData->nFileSizeLow > sig->MaxSize)
516 *matches = FALSE;
517 if (*matches && (sig->MinVersionMS || sig->MinVersionLS ||
518 sig->MaxVersionMS || sig->MaxVersionLS))
519 rc = ACTION_FileVersionMatches(sig, fullFilePath, matches);
520 return rc;
523 /* Recursively searches the directory dir for files that match the signature
524 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
525 * (and only dir). If depth is 1, searches dir and its immediate
526 * subdirectories.
527 * Assumes sig->File is not NULL.
528 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
529 * something else on failures which should halt the install.
530 * FIXME: according to MSDN, FindFirstFile doesn't work on root directories.
531 * Is that also true in Wine?
532 * FIXME: if dir is not a full path, have to check all fixed drives.
534 static UINT ACTION_RecurseSearchDirectory(MSIPACKAGE *package, BOOL *appFound,
535 MSISIGNATURE *sig, LPCWSTR dir, int depth)
537 static const WCHAR starDotStarW[] = { '*','.','*',0 };
538 UINT rc = ERROR_SUCCESS;
539 size_t dirLen = lstrlenW(dir), fileLen = lstrlenW(sig->File);
540 WCHAR *buf;
542 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir),
543 debugstr_w(sig->File), depth);
545 if (depth < 0)
546 return ERROR_INVALID_PARAMETER;
548 *appFound = FALSE;
549 /* We need the buffer in both paths below, so go ahead and allocate it
550 * here. Add two because we might need to add a backslash if the dir name
551 * isn't backslash-terminated.
553 buf = HeapAlloc(GetProcessHeap(), 0,
554 (dirLen + max(fileLen, lstrlenW(starDotStarW)) + 2) * sizeof(WCHAR));
555 if (buf)
557 /* a depth of 0 implies we should search dir, so go ahead and search */
558 HANDLE hFind;
559 WIN32_FIND_DATAW findData;
561 memcpy(buf, dir, dirLen * sizeof(WCHAR));
562 if (buf[dirLen - 1] != '\\')
563 buf[dirLen++ - 1] = '\\';
564 memcpy(buf + dirLen, sig->File, (fileLen + 1) * sizeof(WCHAR));
565 hFind = FindFirstFileW(buf, &findData);
566 if (hFind != INVALID_HANDLE_VALUE)
568 BOOL matches;
570 /* assuming Signature can't contain wildcards for the file name,
571 * so don't bother with FindNextFileW here.
573 if (!(rc = ACTION_FileMatchesSig(sig, &findData, buf, &matches))
574 && matches)
576 TRACE("found file, setting %s to %s\n",
577 debugstr_w(sig->Property), debugstr_w(buf));
578 rc = MSI_SetPropertyW(package, sig->Property, buf);
579 *appFound = TRUE;
581 FindClose(hFind);
583 if (rc == ERROR_SUCCESS && !*appFound && depth > 0)
585 HANDLE hFind;
586 WIN32_FIND_DATAW findData;
588 memcpy(buf, dir, dirLen * sizeof(WCHAR));
589 if (buf[dirLen - 1] != '\\')
590 buf[dirLen++ - 1] = '\\';
591 lstrcpyW(buf + dirLen, starDotStarW);
592 hFind = FindFirstFileW(buf, &findData);
593 if (hFind != INVALID_HANDLE_VALUE)
595 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
596 rc = ACTION_RecurseSearchDirectory(package, appFound,
597 sig, findData.cFileName, depth - 1);
598 while (rc == ERROR_SUCCESS && !*appFound &&
599 FindNextFileW(hFind, &findData) != 0)
601 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
602 rc = ACTION_RecurseSearchDirectory(package, appFound,
603 sig, findData.cFileName, depth - 1);
605 FindClose(hFind);
608 HeapFree(GetProcessHeap(), 0, buf);
610 else
611 rc = ERROR_OUTOFMEMORY;
613 return rc;
616 /* FIXME: if dir is not a full path, have to check all fixed drives. */
617 static UINT ACTION_CheckDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
618 LPCWSTR dir)
620 UINT rc = ERROR_SUCCESS;
622 if (GetFileAttributesW(dir) & FILE_ATTRIBUTE_DIRECTORY)
624 TRACE("directory exists, setting %s to %s\n",
625 debugstr_w(sig->Property), debugstr_w(dir));
626 rc = MSI_SetPropertyW(package, sig->Property, dir);
628 return rc;
631 static UINT ACTION_AppSearchDr(MSIPACKAGE *package, MSISIGNATURE *sig)
633 MSIQUERY *view;
634 UINT rc;
635 static const WCHAR ExecSeqQuery[] = {
636 's','e','l','e','c','t',' ','*',' ',
637 'f','r','o','m',' ',
638 'D','r','L','o','c','a','t','o','r',' ',
639 'w','h','e','r','e',' ','S','i','g','n','a','t','u','r','e','_',' ','=',' ',
640 '\'','%','s','\'',0};
642 TRACE("(package %p, sig %p)\n", package, sig);
643 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery, sig->Name);
644 if (rc == ERROR_SUCCESS)
646 MSIRECORD *row = 0;
647 WCHAR buffer[MAX_PATH], expanded[MAX_PATH];
648 DWORD sz;
649 int depth;
650 BOOL found;
652 rc = MSI_ViewExecute(view, 0);
653 if (rc != ERROR_SUCCESS)
655 TRACE("MSI_ViewExecute returned %d\n", rc);
656 goto end;
658 rc = MSI_ViewFetch(view,&row);
659 if (rc != ERROR_SUCCESS)
661 TRACE("MSI_ViewFetch returned %d\n", rc);
662 rc = ERROR_SUCCESS;
663 goto end;
666 /* check whether parent is set */
667 buffer[0] = 0;
668 sz=sizeof(buffer)/sizeof(buffer[0]);
669 rc = MSI_RecordGetStringW(row,2,buffer,&sz);
670 if (rc != ERROR_SUCCESS)
672 ERR("Error is %x\n",rc);
673 goto end;
675 else if (buffer[0])
677 FIXME(": searching parent (%s) unimplemented\n",
678 debugstr_w(buffer));
679 goto end;
681 /* no parent, now look for path */
682 buffer[0] = 0;
683 sz=sizeof(buffer)/sizeof(buffer[0]);
684 rc = MSI_RecordGetStringW(row,3,buffer,&sz);
685 if (rc != ERROR_SUCCESS)
687 ERR("Error is %x\n",rc);
688 goto end;
690 if (MSI_RecordIsNull(row,4))
691 depth = 0;
692 else
693 depth = MSI_RecordGetInteger(row,4);
694 ACTION_ExpandAnyPath(package, buffer, expanded,
695 sizeof(expanded) / sizeof(expanded[0]));
696 if (sig->File)
697 rc = ACTION_RecurseSearchDirectory(package, &found, sig,
698 expanded, depth);
699 else
701 /* Recursively searching a directory makes no sense when the
702 * directory to search is the thing you're trying to find.
704 rc = ACTION_CheckDirectory(package, sig, expanded);
707 end:
708 msiobj_release(&row->hdr);
709 MSI_ViewClose(view);
710 msiobj_release(&view->hdr);
712 else
714 TRACE("MSI_OpenQuery returned %d\n", rc);
715 rc = ERROR_SUCCESS;
719 TRACE("returning %d\n", rc);
720 return rc;
723 /* http://msdn.microsoft.com/library/en-us/msi/setup/appsearch_table.asp
724 * is the best reference for the AppSearch table and how it's used.
726 UINT ACTION_AppSearch(MSIPACKAGE *package)
728 MSIQUERY *view;
729 UINT rc;
730 static const WCHAR ExecSeqQuery[] = {
731 's','e','l','e','c','t',' ','*',' ',
732 'f','r','o','m',' ',
733 'A','p','p','S','e','a','r','c','h',0};
735 rc = MSI_OpenQuery(package->db, &view, ExecSeqQuery);
736 if (rc == ERROR_SUCCESS)
738 MSIRECORD *row = 0;
739 WCHAR propBuf[0x100], sigBuf[0x100];
740 DWORD sz;
741 MSISIGNATURE sig;
742 BOOL appFound = FALSE;
744 rc = MSI_ViewExecute(view, 0);
745 if (rc != ERROR_SUCCESS)
746 goto end;
748 while (!rc)
750 rc = MSI_ViewFetch(view,&row);
751 if (rc != ERROR_SUCCESS)
753 rc = ERROR_SUCCESS;
754 break;
757 /* get property and signature */
758 propBuf[0] = 0;
759 sz=sizeof(propBuf)/sizeof(propBuf[0]);
760 rc = MSI_RecordGetStringW(row,1,propBuf,&sz);
761 if (rc != ERROR_SUCCESS)
763 ERR("Error is %x\n",rc);
764 msiobj_release(&row->hdr);
765 break;
767 sigBuf[0] = 0;
768 sz=sizeof(sigBuf)/sizeof(sigBuf[0]);
769 rc = MSI_RecordGetStringW(row,2,sigBuf,&sz);
770 if (rc != ERROR_SUCCESS)
772 ERR("Error is %x\n",rc);
773 msiobj_release(&row->hdr);
774 break;
776 TRACE("Searching for Property %s, Signature_ %s\n",
777 debugstr_w(propBuf), debugstr_w(sigBuf));
778 /* This clears all the fields, so set Name and Property afterward */
779 rc = ACTION_AppSearchGetSignature(package, &sig, sigBuf);
780 sig.Name = sigBuf;
781 sig.Property = propBuf;
782 if (rc == ERROR_SUCCESS)
784 rc = ACTION_AppSearchComponents(package, &appFound, &sig);
785 if (rc == ERROR_SUCCESS && !appFound)
787 rc = ACTION_AppSearchReg(package, &appFound, &sig);
788 if (rc == ERROR_SUCCESS && !appFound)
790 rc = ACTION_AppSearchIni(package, &appFound, &sig);
791 if (rc == ERROR_SUCCESS && !appFound)
792 rc = ACTION_AppSearchDr(package, &sig);
796 HeapFree(GetProcessHeap(), 0, sig.File);
797 HeapFree(GetProcessHeap(), 0, sig.Languages);
798 msiobj_release(&row->hdr);
801 end:
802 MSI_ViewClose(view);
803 msiobj_release(&view->hdr);
805 else
806 rc = ERROR_SUCCESS;
808 return rc;