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;
375 LPWSTR ptr = NULL, end;
377 HKEY rootKey, key = NULL;
378 DWORD sz = 0, regType;
383 TRACE("%s\n", debugstr_w(sig->Name));
387 row = MSI_QueryGetRecord( package->db, query, sig->Name );
390 TRACE("failed to query RegLocator for %s\n", debugstr_w(sig->Name));
391 return ERROR_SUCCESS;
394 root = MSI_RecordGetInteger(row,2);
395 keyPath = msi_dup_record_field(row,3);
396 valueName = msi_dup_record_field(row,4);
397 type = MSI_RecordGetInteger(row,5);
399 deformat_string(package, keyPath, &deformatted);
403 case msidbRegistryRootClassesRoot:
404 rootKey = HKEY_CLASSES_ROOT;
406 case msidbRegistryRootCurrentUser:
407 rootKey = HKEY_CURRENT_USER;
409 case msidbRegistryRootLocalMachine:
410 rootKey = HKEY_LOCAL_MACHINE;
412 case msidbRegistryRootUsers:
413 rootKey = HKEY_USERS;
416 WARN("Unknown root key %d\n", root);
420 rc = RegOpenKeyW(rootKey, deformatted, &key);
423 TRACE("RegOpenKeyW returned %d\n", rc);
427 rc = RegQueryValueExW(key, valueName, NULL, NULL, NULL, &sz);
430 TRACE("RegQueryValueExW returned %d\n", rc);
433 /* FIXME: sanity-check sz before allocating (is there an upper-limit
434 * on the value of a property?)
436 value = msi_alloc( sz );
437 rc = RegQueryValueExW(key, valueName, NULL, ®Type, value, &sz);
440 TRACE("RegQueryValueExW returned %d\n", rc);
444 /* bail out if the registry key is empty */
448 if ((ptr = strchrW((LPWSTR)value, '"')) && (end = strchrW(++ptr, '"')))
455 case msidbLocatorTypeDirectory:
456 rc = ACTION_SearchDirectory(package, sig, ptr, 0, appValue);
458 case msidbLocatorTypeFileName:
459 *appValue = app_search_file(ptr, sig);
461 case msidbLocatorTypeRawValue:
462 ACTION_ConvertRegValue(regType, value, sz, appValue);
465 FIXME("AppSearch unimplemented for type %d (key path %s, value %s)\n",
466 type, debugstr_w(keyPath), debugstr_w(valueName));
473 msi_free( valueName );
474 msi_free( deformatted );
476 msiobj_release(&row->hdr);
478 return ERROR_SUCCESS;
481 static LPWSTR get_ini_field(LPWSTR buf, int field)
490 while ((end = strchrW(beg, ',')) && i < field)
493 while (*beg && *beg == ' ')
499 end = strchrW(beg, ',');
501 end = beg + lstrlenW(beg);
507 static UINT ACTION_AppSearchIni(MSIPACKAGE *package, LPWSTR *appValue,
510 static const WCHAR query[] = {
511 's','e','l','e','c','t',' ','*',' ',
513 'I','n','i','L','o','c','a','t','o','r',' ',
514 'w','h','e','r','e',' ',
515 'S','i','g','n','a','t','u','r','e','_',' ','=',' ','\'','%','s','\'',0};
517 LPWSTR fileName, section, key;
521 TRACE("%s\n", debugstr_w(sig->Name));
525 row = MSI_QueryGetRecord( package->db, query, sig->Name );
528 TRACE("failed to query IniLocator for %s\n", debugstr_w(sig->Name));
529 return ERROR_SUCCESS;
532 fileName = msi_dup_record_field(row, 2);
533 section = msi_dup_record_field(row, 3);
534 key = msi_dup_record_field(row, 4);
535 field = MSI_RecordGetInteger(row, 5);
536 type = MSI_RecordGetInteger(row, 6);
537 if (field == MSI_NULL_INTEGER)
539 if (type == MSI_NULL_INTEGER)
542 GetPrivateProfileStringW(section, key, NULL, buf, MAX_PATH, fileName);
547 case msidbLocatorTypeDirectory:
548 ACTION_SearchDirectory(package, sig, buf, 0, appValue);
550 case msidbLocatorTypeFileName:
551 *appValue = app_search_file(buf, sig);
553 case msidbLocatorTypeRawValue:
554 *appValue = get_ini_field(buf, field);
563 msiobj_release(&row->hdr);
565 return ERROR_SUCCESS;
568 /* Expands the value in src into a path without property names and only
569 * containing long path names into dst. Replaces at most len characters of dst,
570 * and always NULL-terminates dst if dst is not NULL and len >= 1.
572 * Assumes src and dst are non-overlapping.
573 * FIXME: return code probably needed:
574 * - what does AppSearch return if the table values are invalid?
575 * - what if dst is too small?
577 static void ACTION_ExpandAnyPath(MSIPACKAGE *package, WCHAR *src, WCHAR *dst,
580 WCHAR *ptr, *deformatted;
582 if (!src || !dst || !len)
584 if (dst) *dst = '\0';
590 /* Ignore the short portion of the path */
591 if ((ptr = strchrW(src, '|')))
596 deformat_string(package, ptr, &deformatted);
597 if (!deformatted || strlenW(deformatted) > len - 1)
599 msi_free(deformatted);
603 lstrcpyW(dst, deformatted);
604 dst[lstrlenW(deformatted)] = '\0';
605 msi_free(deformatted);
608 /* Sets *matches to whether the file (whose path is filePath) matches the
609 * versions set in sig.
610 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
611 * something else if an install-halting error occurs.
613 static UINT ACTION_FileVersionMatches(const MSISIGNATURE *sig, LPCWSTR filePath,
616 UINT rc = ERROR_SUCCESS;
621 FIXME(": need to check version for languages %s\n",
622 debugstr_w(sig->Languages));
626 DWORD zero, size = GetFileVersionInfoSizeW(filePath, &zero);
630 LPVOID buf = msi_alloc( size);
634 static const WCHAR rootW[] = { '\\',0 };
636 LPVOID subBlock = NULL;
638 if (GetFileVersionInfoW(filePath, 0, size, buf))
639 VerQueryValueW(buf, rootW, &subBlock, &versionLen);
642 VS_FIXEDFILEINFO *info = subBlock;
644 TRACE("Comparing file version %d.%d.%d.%d:\n",
645 HIWORD(info->dwFileVersionMS),
646 LOWORD(info->dwFileVersionMS),
647 HIWORD(info->dwFileVersionLS),
648 LOWORD(info->dwFileVersionLS));
649 if (info->dwFileVersionMS < sig->MinVersionMS
650 || (info->dwFileVersionMS == sig->MinVersionMS &&
651 info->dwFileVersionLS < sig->MinVersionLS))
653 TRACE("Less than minimum version %d.%d.%d.%d\n",
654 HIWORD(sig->MinVersionMS),
655 LOWORD(sig->MinVersionMS),
656 HIWORD(sig->MinVersionLS),
657 LOWORD(sig->MinVersionLS));
659 else if ((sig->MaxVersionMS || sig->MaxVersionLS) &&
660 (info->dwFileVersionMS > sig->MaxVersionMS ||
661 (info->dwFileVersionMS == sig->MaxVersionMS &&
662 info->dwFileVersionLS > sig->MaxVersionLS)))
664 TRACE("Greater than maximum version %d.%d.%d.%d\n",
665 HIWORD(sig->MaxVersionMS),
666 LOWORD(sig->MaxVersionMS),
667 HIWORD(sig->MaxVersionLS),
668 LOWORD(sig->MaxVersionLS));
676 rc = ERROR_OUTOFMEMORY;
682 /* Sets *matches to whether the file in findData matches that in sig.
683 * fullFilePath is assumed to be the full path of the file specified in
684 * findData, which may be necessary to compare the version.
685 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
686 * something else if an install-halting error occurs.
688 static UINT ACTION_FileMatchesSig(const MSISIGNATURE *sig,
689 const WIN32_FIND_DATAW *findData, LPCWSTR fullFilePath, BOOL *matches)
691 UINT rc = ERROR_SUCCESS;
694 /* assumes the caller has already ensured the filenames match, so check
697 if (sig->MinTime.dwLowDateTime || sig->MinTime.dwHighDateTime)
699 if (findData->ftCreationTime.dwHighDateTime <
700 sig->MinTime.dwHighDateTime ||
701 (findData->ftCreationTime.dwHighDateTime == sig->MinTime.dwHighDateTime
702 && findData->ftCreationTime.dwLowDateTime <
703 sig->MinTime.dwLowDateTime))
706 if (*matches && (sig->MaxTime.dwLowDateTime || sig->MaxTime.dwHighDateTime))
708 if (findData->ftCreationTime.dwHighDateTime >
709 sig->MaxTime.dwHighDateTime ||
710 (findData->ftCreationTime.dwHighDateTime == sig->MaxTime.dwHighDateTime
711 && findData->ftCreationTime.dwLowDateTime >
712 sig->MaxTime.dwLowDateTime))
715 if (*matches && sig->MinSize && findData->nFileSizeLow < sig->MinSize)
717 if (*matches && sig->MaxSize && findData->nFileSizeLow > sig->MaxSize)
719 if (*matches && (sig->MinVersionMS || sig->MinVersionLS ||
720 sig->MaxVersionMS || sig->MaxVersionLS))
721 rc = ACTION_FileVersionMatches(sig, fullFilePath, matches);
725 /* Recursively searches the directory dir for files that match the signature
726 * sig, up to (depth + 1) levels deep. That is, if depth is 0, it searches dir
727 * (and only dir). If depth is 1, searches dir and its immediate
729 * Assumes sig->File is not NULL.
730 * Returns ERROR_SUCCESS on success (which may include non-critical errors),
731 * something else on failures which should halt the install.
733 static UINT ACTION_RecurseSearchDirectory(MSIPACKAGE *package, LPWSTR *appValue,
734 MSISIGNATURE *sig, LPCWSTR dir, int depth)
737 WIN32_FIND_DATAW findData;
738 UINT rc = ERROR_SUCCESS;
739 size_t dirLen = lstrlenW(dir), fileLen = lstrlenW(sig->File);
740 WCHAR subpath[MAX_PATH];
743 static const WCHAR dot[] = {'.',0};
744 static const WCHAR dotdot[] = {'.','.',0};
745 static const WCHAR starDotStarW[] = { '*','.','*',0 };
747 TRACE("Searching directory %s for file %s, depth %d\n", debugstr_w(dir),
748 debugstr_w(sig->File), depth);
751 return ERROR_SUCCESS;
754 /* We need the buffer in both paths below, so go ahead and allocate it
755 * here. Add two because we might need to add a backslash if the dir name
756 * isn't backslash-terminated.
758 buf = msi_alloc( (dirLen + max(fileLen, strlenW(starDotStarW)) + 2) * sizeof(WCHAR));
760 return ERROR_OUTOFMEMORY;
763 PathAddBackslashW(buf);
764 lstrcatW(buf, sig->File);
766 hFind = FindFirstFileW(buf, &findData);
767 if (hFind != INVALID_HANDLE_VALUE)
769 if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
773 rc = ACTION_FileMatchesSig(sig, &findData, buf, &matches);
774 if (rc == ERROR_SUCCESS && matches)
776 TRACE("found file, returning %s\n", debugstr_w(buf));
783 if (rc == ERROR_SUCCESS && !*appValue)
786 PathAddBackslashW(buf);
787 lstrcatW(buf, starDotStarW);
789 hFind = FindFirstFileW(buf, &findData);
790 if (hFind != INVALID_HANDLE_VALUE)
792 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY &&
793 lstrcmpW(findData.cFileName, dot) &&
794 lstrcmpW(findData.cFileName, dotdot))
796 lstrcpyW(subpath, dir);
797 PathAppendW(subpath, findData.cFileName);
798 rc = ACTION_RecurseSearchDirectory(package, appValue, sig,
802 while (rc == ERROR_SUCCESS && !*appValue &&
803 FindNextFileW(hFind, &findData) != 0)
805 if (!lstrcmpW(findData.cFileName, dot) ||
806 !lstrcmpW(findData.cFileName, dotdot))
809 lstrcpyW(subpath, dir);
810 PathAppendW(subpath, findData.cFileName);
811 if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
812 rc = ACTION_RecurseSearchDirectory(package, appValue,
813 sig, subpath, depth - 1);
826 static UINT ACTION_CheckDirectory(MSIPACKAGE *package, LPCWSTR dir,
829 DWORD attr = GetFileAttributesW(dir);
831 if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY))
833 TRACE("directory exists, returning %s\n", debugstr_w(dir));
834 *appValue = strdupW(dir);
837 return ERROR_SUCCESS;
840 static BOOL ACTION_IsFullPath(LPCWSTR path)
842 WCHAR first = toupperW(path[0]);
845 if (first >= 'A' && first <= 'Z' && path[1] == ':')
847 else if (path[0] == '\\' && path[1] == '\\')
854 static UINT ACTION_SearchDirectory(MSIPACKAGE *package, MSISIGNATURE *sig,
855 LPCWSTR path, int depth, LPWSTR *appValue)
861 TRACE("%p, %p, %s, %d, %p\n", package, sig, debugstr_w(path), depth,
864 if (ACTION_IsFullPath(path))
867 rc = ACTION_RecurseSearchDirectory(package, &val, sig, path, depth);
870 /* Recursively searching a directory makes no sense when the
871 * directory to search is the thing you're trying to find.
873 rc = ACTION_CheckDirectory(package, path, &val);
878 WCHAR pathWithDrive[MAX_PATH] = { 'C',':','\\',0 };
879 DWORD drives = GetLogicalDrives();
883 for (i = 0; rc == ERROR_SUCCESS && !val && i < 26; i++)
885 if (!(drives & (1 << i)))
888 pathWithDrive[0] = 'A' + i;
889 if (GetDriveTypeW(pathWithDrive) != DRIVE_FIXED)
892 lstrcpynW(pathWithDrive + 3, path,
893 sizeof(pathWithDrive) / sizeof(pathWithDrive[0]) - 3);
896 rc = ACTION_RecurseSearchDirectory(package, &val, sig,
897 pathWithDrive, depth);
899 rc = ACTION_CheckDirectory(package, pathWithDrive, &val);
903 attr = GetFileAttributesW(val);
904 if ((attr & FILE_ATTRIBUTE_DIRECTORY) &&
905 val && val[lstrlenW(val) - 1] != '\\')
907 val = msi_realloc(val, (lstrlenW(val) + 2) * sizeof(WCHAR));
909 rc = ERROR_OUTOFMEMORY;
911 PathAddBackslashW(val);
916 TRACE("returning %d\n", rc);
920 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
921 MSISIGNATURE *sig, LPWSTR *appValue);
923 static UINT ACTION_AppSearchDr(MSIPACKAGE *package, LPWSTR *appValue, MSISIGNATURE *sig)
925 static const WCHAR query[] = {
926 's','e','l','e','c','t',' ','*',' ',
928 'D','r','L','o','c','a','t','o','r',' ',
929 'w','h','e','r','e',' ',
930 'S','i','g','n','a','t','u','r','e','_',' ','=',' ', '\'','%','s','\'',0};
931 LPWSTR parentName = NULL, parent = NULL;
932 WCHAR path[MAX_PATH];
933 WCHAR expanded[MAX_PATH];
939 TRACE("%s\n", debugstr_w(sig->Name));
943 row = MSI_QueryGetRecord( package->db, query, sig->Name );
946 TRACE("failed to query DrLocator for %s\n", debugstr_w(sig->Name));
947 return ERROR_SUCCESS;
950 /* check whether parent is set */
951 parentName = msi_dup_record_field(row,2);
954 MSISIGNATURE parentSig;
956 rc = ACTION_AppSearchSigName(package, parentName, &parentSig, &parent);
957 ACTION_FreeSignature(&parentSig);
958 msi_free(parentName);
962 MSI_RecordGetStringW(row, 3, path, &sz);
964 if (MSI_RecordIsNull(row,4))
967 depth = MSI_RecordGetInteger(row,4);
969 ACTION_ExpandAnyPath(package, path, expanded, MAX_PATH);
973 if (!(GetFileAttributesW(parent) & FILE_ATTRIBUTE_DIRECTORY))
975 PathRemoveFileSpecW(parent);
976 PathAddBackslashW(parent);
979 strcpyW(path, parent);
980 strcatW(path, expanded);
983 strcpyW(path, expanded);
985 PathAddBackslashW(path);
987 rc = ACTION_SearchDirectory(package, sig, path, depth, appValue);
990 msiobj_release(&row->hdr);
992 TRACE("returning %d\n", rc);
996 static UINT ACTION_AppSearchSigName(MSIPACKAGE *package, LPCWSTR sigName,
997 MSISIGNATURE *sig, LPWSTR *appValue)
1002 rc = ACTION_AppSearchGetSignature(package, sig, sigName);
1003 if (rc == ERROR_SUCCESS)
1005 rc = ACTION_AppSearchComponents(package, appValue, sig);
1006 if (rc == ERROR_SUCCESS && !*appValue)
1008 rc = ACTION_AppSearchReg(package, appValue, sig);
1009 if (rc == ERROR_SUCCESS && !*appValue)
1011 rc = ACTION_AppSearchIni(package, appValue, sig);
1012 if (rc == ERROR_SUCCESS && !*appValue)
1013 rc = ACTION_AppSearchDr(package, appValue, sig);
1020 static UINT iterate_appsearch(MSIRECORD *row, LPVOID param)
1022 MSIPACKAGE *package = param;
1023 LPWSTR propName, sigName, value = NULL;
1027 /* get property and signature */
1028 propName = msi_dup_record_field(row,1);
1029 sigName = msi_dup_record_field(row,2);
1031 TRACE("%s %s\n", debugstr_w(propName), debugstr_w(sigName));
1033 r = ACTION_AppSearchSigName(package, sigName, &sig, &value);
1036 MSI_SetPropertyW(package, propName, value);
1039 ACTION_FreeSignature(&sig);
1046 UINT ACTION_AppSearch(MSIPACKAGE *package)
1048 static const WCHAR query[] = {
1049 's','e','l','e','c','t',' ','*',' ',
1050 'f','r','o','m',' ',
1051 'A','p','p','S','e','a','r','c','h',0};
1052 MSIQUERY *view = NULL;
1055 r = MSI_OpenQuery( package->db, &view, query );
1056 if (r != ERROR_SUCCESS)
1057 return ERROR_SUCCESS;
1059 r = MSI_IterateRecords( view, NULL, iterate_appsearch, package );
1060 msiobj_release( &view->hdr );
1065 static UINT ITERATE_CCPSearch(MSIRECORD *row, LPVOID param)
1067 MSIPACKAGE *package = param;
1069 LPWSTR value = NULL;
1071 UINT r = ERROR_SUCCESS;
1073 static const WCHAR success[] = {'C','C','P','_','S','u','c','c','e','s','s',0};
1074 static const WCHAR one[] = {'1',0};
1076 signature = MSI_RecordGetString(row, 1);
1078 TRACE("%s\n", debugstr_w(signature));
1080 ACTION_AppSearchSigName(package, signature, &sig, &value);
1083 TRACE("Found signature %s\n", debugstr_w(signature));
1084 MSI_SetPropertyW(package, success, one);
1086 r = ERROR_NO_MORE_ITEMS;
1089 ACTION_FreeSignature(&sig);
1094 UINT ACTION_CCPSearch(MSIPACKAGE *package)
1096 static const WCHAR query[] = {
1097 's','e','l','e','c','t',' ','*',' ',
1098 'f','r','o','m',' ',
1099 'C','C','P','S','e','a','r','c','h',0};
1100 MSIQUERY *view = NULL;
1103 r = MSI_OpenQuery(package->db, &view, query);
1104 if (r != ERROR_SUCCESS)
1105 return ERROR_SUCCESS;
1107 r = MSI_IterateRecords(view, NULL, ITERATE_CCPSearch, package);
1108 msiobj_release(&view->hdr);