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);
734 WCHAR subpath[MAX_PATH];
737 static const WCHAR dot[] = {'.',0};
738 static const WCHAR dotdot[] = {'.','.',0};
739 static const WCHAR starDotStarW[] = { '*','.','*',0 };
741 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir),
742 debugstr_w(sig->File), depth);
745 return ERROR_SUCCESS;
748 /* We need the buffer in both paths below, so go ahead and allocate it
749 * here. Add two because we might need to add a backslash if the dir name
750 * isn't backslash-terminated.
752 buf = msi_alloc( (dirLen + max(fileLen, lstrlenW(starDotStarW)) + 2) * sizeof(WCHAR));
754 return ERROR_OUTOFMEMORY;
757 PathAddBackslashW(buf);
758 lstrcatW(buf, sig->File);
760 hFind = FindFirstFileW(buf, &findData);
761 if (hFind != INVALID_HANDLE_VALUE)
763 if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
767 rc = ACTION_FileMatchesSig(sig, &findData, buf, &matches);
768 if (rc == ERROR_SUCCESS && matches)
770 TRACE("found file, returning %s\n", debugstr_w(buf));
777 if (rc == ERROR_SUCCESS && !*appValue)
780 PathAddBackslashW(buf);
781 lstrcatW(buf, starDotStarW);
783 hFind = FindFirstFileW(buf, &findData);
784 if (hFind != INVALID_HANDLE_VALUE)
786 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
787 lstrcmpW(findData.cFileName, dot) &&
788 lstrcmpW(findData.cFileName, dotdot))
790 lstrcpyW(subpath, dir);
791 PathAppendW(subpath, findData.cFileName);
792 rc = ACTION_RecurseSearchDirectory(package, appValue, sig,
796 while (rc == ERROR_SUCCESS && !*appValue &&
797 FindNextFileW(hFind, &findData) != 0)
799 if (!lstrcmpW(findData.cFileName, dot) ||
800 !lstrcmpW(findData.cFileName, dotdot))
803 lstrcpyW(subpath, dir);
804 PathAppendW(subpath, findData.cFileName);
805 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
806 rc = ACTION_RecurseSearchDirectory(package, appValue,
807 sig, subpath, depth - 1);
820 static UINT ACTION_CheckDirectory(MSIPACKAGE *package, LPCWSTR dir,
823 DWORD attr = GetFileAttributesW(dir);
825 if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY))
827 TRACE("directory exists, returning %s\n", debugstr_w(dir));
828 *appValue = strdupW(dir);
831 return ERROR_SUCCESS;
834 static BOOL ACTION_IsFullPath(LPCWSTR path)
836 WCHAR first = toupperW(path[0]);
839 if (first >= 'A' && first <= 'Z' && path[1] == ':')
841 else if (path[0] == '\\' && path[1] == '\\')
848 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
849 LPCWSTR path, int depth, LPWSTR *appValue)
855 TRACE("%p, %p, %s, %d, %p\n", package, sig, debugstr_w(path), depth,
858 if (ACTION_IsFullPath(path))
861 rc = ACTION_RecurseSearchDirectory(package, &val, sig, path, depth);
864 /* Recursively searching a directory makes no sense when the
865 * directory to search is the thing you're trying to find.
867 rc = ACTION_CheckDirectory(package, path, &val);
872 WCHAR pathWithDrive[MAX_PATH] = { 'C',':','\\',0 };
873 DWORD drives = GetLogicalDrives();
877 for (i = 0; rc == ERROR_SUCCESS && !val && i < 26; i++)
879 if (!(drives & (1 << i)))
882 pathWithDrive[0] = 'A' + i;
883 if (GetDriveTypeW(pathWithDrive) != DRIVE_FIXED)
886 lstrcpynW(pathWithDrive + 3, path,
887 sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
890 rc = ACTION_RecurseSearchDirectory(package, &val, sig,
891 pathWithDrive, depth);
893 rc = ACTION_CheckDirectory(package, pathWithDrive, &val);
897 attr = GetFileAttributesW(val);
898 if ((attr & FILE_ATTRIBUTE_DIRECTORY) &&
899 val && val[lstrlenW(val) - 1] != '\\')
901 val = msi_realloc(val, (lstrlenW(val) + 2) * sizeof(WCHAR));
903 rc = ERROR_OUTOFMEMORY;
905 PathAddBackslashW(val);
910 TRACE("returning %d\n", rc);
914 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
915 MSISIGNATURE *sig, LPWSTR *appValue);
917 static UINT ACTION_AppSearchDr(MSIPACKAGE *package, LPWSTR *appValue, MSISIGNATURE *sig)
919 static const WCHAR query[] = {
920 's','e','l','e','c','t',' ','*',' ',
922 'D','r','L','o','c','a','t','o','r',' ',
923 'w','h','e','r','e',' ',
924 'S','i','g','n','a','t','u','r','e','_',' ','=',' ', '\'','%','s','\'',0};
925 LPWSTR parentName = NULL, parent = NULL;
926 WCHAR path[MAX_PATH];
927 WCHAR expanded[MAX_PATH];
933 TRACE("%s\n", debugstr_w(sig->Name));
937 row = MSI_QueryGetRecord( package->db, query, sig->Name );
940 TRACE("failed to query DrLocator for %s\n", debugstr_w(sig->Name));
941 return ERROR_SUCCESS;
944 /* check whether parent is set */
945 parentName = msi_dup_record_field(row,2);
948 MSISIGNATURE parentSig;
950 rc = ACTION_AppSearchSigName(package, parentName, &parentSig, &parent);
951 ACTION_FreeSignature(&parentSig);
952 msi_free(parentName);
956 MSI_RecordGetStringW(row, 3, path, &sz);
958 if (MSI_RecordIsNull(row,4))
961 depth = MSI_RecordGetInteger(row,4);
963 ACTION_ExpandAnyPath(package, path, expanded, MAX_PATH);
967 strcpyW(path, parent);
968 strcatW(path, expanded);
971 strcpyW(path, expanded);
973 PathAddBackslashW(path);
975 rc = ACTION_SearchDirectory(package, sig, path, depth, appValue);
978 msiobj_release(&row->hdr);
980 TRACE("returning %d\n", rc);
984 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
985 MSISIGNATURE *sig, LPWSTR *appValue)
990 rc = ACTION_AppSearchGetSignature(package, sig, sigName);
991 if (rc == ERROR_SUCCESS)
993 rc = ACTION_AppSearchComponents(package, appValue, sig);
994 if (rc == ERROR_SUCCESS && !*appValue)
996 rc = ACTION_AppSearchReg(package, appValue, sig);
997 if (rc == ERROR_SUCCESS && !*appValue)
999 rc = ACTION_AppSearchIni(package, appValue, sig);
1000 if (rc == ERROR_SUCCESS && !*appValue)
1001 rc = ACTION_AppSearchDr(package, appValue, sig);
1008 static UINT iterate_appsearch(MSIRECORD *row, LPVOID param)
1010 MSIPACKAGE *package = param;
1011 LPWSTR propName, sigName, value = NULL;
1015 /* get property and signature */
1016 propName = msi_dup_record_field(row,1);
1017 sigName = msi_dup_record_field(row,2);
1019 TRACE("%s %s\n", debugstr_w(propName), debugstr_w(sigName));
1021 r = ACTION_AppSearchSigName(package, sigName, &sig, &value);
1024 MSI_SetPropertyW(package, propName, value);
1027 ACTION_FreeSignature(&sig);
1034 UINT ACTION_AppSearch(MSIPACKAGE *package)
1036 static const WCHAR query[] = {
1037 's','e','l','e','c','t',' ','*',' ',
1038 'f','r','o','m',' ',
1039 'A','p','p','S','e','a','r','c','h',0};
1040 MSIQUERY *view = NULL;
1043 r = MSI_OpenQuery( package->db, &view, query );
1044 if (r != ERROR_SUCCESS)
1045 return ERROR_SUCCESS;
1047 r = MSI_IterateRecords( view, NULL, iterate_appsearch, package );
1048 msiobj_release( &view->hdr );
1053 static UINT ITERATE_CCPSearch(MSIRECORD *row, LPVOID param)
1055 MSIPACKAGE *package = param;
1057 LPWSTR value = NULL;
1059 UINT r = ERROR_SUCCESS;
1061 static const WCHAR success[] = {'C','C','P','_','S','u','c','c','e','s','s',0};
1062 static const WCHAR one[] = {'1',0};
1064 signature = MSI_RecordGetString(row, 1);
1066 TRACE("%s\n", debugstr_w(signature));
1068 ACTION_AppSearchSigName(package, signature, &sig, &value);
1071 TRACE("Found signature %s\n", debugstr_w(signature));
1072 MSI_SetPropertyW(package, success, one);
1074 r = ERROR_NO_MORE_ITEMS;
1077 ACTION_FreeSignature(&sig);
1082 UINT ACTION_CCPSearch(MSIPACKAGE *package)
1084 static const WCHAR query[] = {
1085 's','e','l','e','c','t',' ','*',' ',
1086 'f','r','o','m',' ',
1087 'C','C','P','S','e','a','r','c','h',0};
1088 MSIQUERY *view = NULL;
1091 r = MSI_OpenQuery(package->db, &view, query);
1092 if (r != ERROR_SUCCESS)
1093 return ERROR_SUCCESS;
1095 r = MSI_IterateRecords(view, NULL, ITERATE_CCPSearch, package);
1096 msiobj_release(&view->hdr);