2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
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
22 * Actions focused on in this module
25 * MigrateFeatureStates (TODO)
26 * RemoveExistingProducts (TODO)
31 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
33 static BOOL
check_language(DWORD lang1
, LPCWSTR lang2
, DWORD attributes
)
37 if (!lang2
|| lang2
[0]==0)
40 langdword
= atoiW(lang2
);
42 if (attributes
& msidbUpgradeAttributesLanguagesExclusive
)
43 return (lang1
!= langdword
);
45 return (lang1
== langdword
);
48 static void append_productcode(MSIPACKAGE
* package
, LPCWSTR action_property
,
56 prop
= msi_dup_property(package
->db
, action_property
);
65 len
+= strlenW(productid
);
70 newprop
= msi_alloc( len
*sizeof(WCHAR
) );
74 strcpyW(newprop
,prop
);
75 strcatW(newprop
,szSemiColon
);
79 strcatW(newprop
,productid
);
81 r
= msi_set_property( package
->db
, action_property
, newprop
, -1 );
82 if (r
== ERROR_SUCCESS
&& !strcmpW( action_property
, szSourceDir
))
83 msi_reset_folders( package
, TRUE
);
85 TRACE("Found Related Product... %s now %s\n",
86 debugstr_w(action_property
), debugstr_w(newprop
));
92 static UINT
ITERATE_FindRelatedProducts(MSIRECORD
*rec
, LPVOID param
)
94 MSIPACKAGE
*package
= param
;
95 WCHAR product
[SQUASHED_GUID_SIZE
];
96 DWORD index
= 0, attributes
= 0, sz
= sizeof(product
)/sizeof(product
[0]);
99 UINT rc
= ERROR_SUCCESS
;
102 upgrade_code
= MSI_RecordGetString(rec
,1);
104 rc
= MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey
, FALSE
);
105 if (rc
!= ERROR_SUCCESS
)
106 return ERROR_SUCCESS
;
108 uirow
= MSI_CreateRecord(1);
109 attributes
= MSI_RecordGetInteger(rec
,5);
111 while (rc
== ERROR_SUCCESS
)
113 rc
= RegEnumValueW(hkey
, index
, product
, &sz
, NULL
, NULL
, NULL
, NULL
);
114 if (rc
== ERROR_SUCCESS
)
116 WCHAR productid
[GUID_SIZE
];
117 LPCWSTR ver
, language
, action_property
;
118 DWORD check
= 0, comp_ver
, sz
= 0x100;
122 TRACE("Looking at index %u product %s\n", index
, debugstr_w(product
));
124 unsquash_guid(product
, productid
);
125 if (MSIREG_OpenProductKey(productid
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, &hukey
, FALSE
) &&
126 MSIREG_OpenProductKey(productid
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, &hukey
, FALSE
) &&
127 MSIREG_OpenProductKey(productid
, NULL
, MSIINSTALLCONTEXT_MACHINE
, &hukey
, FALSE
))
129 TRACE("product key not found\n");
136 RegQueryValueExW(hukey
, INSTALLPROPERTY_VERSIONW
, NULL
, NULL
, (LPBYTE
)&check
, &sz
);
138 /* check version minimum */
139 ver
= MSI_RecordGetString(rec
,2);
142 comp_ver
= msi_version_str_to_dword(ver
);
143 r
= check
- comp_ver
;
144 if (r
< 0 || (r
== 0 && !(attributes
& msidbUpgradeAttributesVersionMinInclusive
)))
146 TRACE("version below minimum\n");
153 /* check version maximum */
154 ver
= MSI_RecordGetString(rec
,3);
157 comp_ver
= msi_version_str_to_dword(ver
);
158 r
= check
- comp_ver
;
159 if (r
> 0 || (r
== 0 && !(attributes
& msidbUpgradeAttributesVersionMaxInclusive
)))
165 TRACE("version above maximum\n");
170 RegQueryValueExW(hukey
, INSTALLPROPERTY_LANGUAGEW
, NULL
, NULL
, (LPBYTE
)&check
, &sz
);
172 language
= MSI_RecordGetString(rec
,4);
173 if (!check_language(check
, language
, attributes
))
176 TRACE("language doesn't match\n");
179 TRACE("found related product\n");
181 action_property
= MSI_RecordGetString(rec
, 7);
182 append_productcode(package
, action_property
, productid
);
183 MSI_RecordSetStringW(uirow
, 1, productid
);
184 MSI_ProcessMessage(package
, INSTALLMESSAGE_ACTIONDATA
, uirow
);
189 msiobj_release( &uirow
->hdr
);
191 return ERROR_SUCCESS
;
194 UINT
ACTION_FindRelatedProducts(MSIPACKAGE
*package
)
196 static const WCHAR query
[] = {
197 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
198 '`','U','p','g','r','a','d','e','`',0};
202 if (msi_get_property_int(package
->db
, szInstalled
, 0))
204 TRACE("Skipping FindRelatedProducts action: product already installed\n");
205 return ERROR_SUCCESS
;
207 if (msi_action_is_unique(package
, szFindRelatedProducts
))
209 TRACE("Skipping FindRelatedProducts action: already done in UI sequence\n");
210 return ERROR_SUCCESS
;
213 msi_register_unique_action(package
, szFindRelatedProducts
);
215 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
216 if (rc
!= ERROR_SUCCESS
)
217 return ERROR_SUCCESS
;
219 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_FindRelatedProducts
, package
);
220 msiobj_release(&view
->hdr
);