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)
35 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
43 static BOOL
check_language(DWORD lang1
, LPCWSTR lang2
, DWORD attributes
)
47 if (!lang2
|| lang2
[0]==0)
50 langdword
= atoiW(lang2
);
52 if (attributes
& msidbUpgradeAttributesLanguagesExclusive
)
53 return (lang1
!= langdword
);
55 return (lang1
== langdword
);
58 static void append_productcode(MSIPACKAGE
* package
, LPCWSTR action_property
,
66 prop
= msi_dup_property(package
->db
, action_property
);
75 len
+= strlenW(productid
);
80 newprop
= msi_alloc( len
*sizeof(WCHAR
) );
84 strcpyW(newprop
,prop
);
85 strcatW(newprop
,szSemiColon
);
89 strcatW(newprop
,productid
);
91 r
= msi_set_property( package
->db
, action_property
, newprop
, -1 );
92 if (r
== ERROR_SUCCESS
&& !strcmpW( action_property
, szSourceDir
))
93 msi_reset_folders( package
, TRUE
);
95 TRACE("Found Related Product... %s now %s\n",
96 debugstr_w(action_property
), debugstr_w(newprop
));
102 static UINT
ITERATE_FindRelatedProducts(MSIRECORD
*rec
, LPVOID param
)
104 MSIPACKAGE
*package
= param
;
105 WCHAR product
[SQUASHED_GUID_SIZE
];
106 DWORD index
= 0, attributes
= 0, sz
= sizeof(product
)/sizeof(product
[0]);
107 LPCWSTR upgrade_code
;
109 UINT rc
= ERROR_SUCCESS
;
112 upgrade_code
= MSI_RecordGetString(rec
,1);
114 rc
= MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey
, FALSE
);
115 if (rc
!= ERROR_SUCCESS
)
116 return ERROR_SUCCESS
;
118 uirow
= MSI_CreateRecord(1);
119 attributes
= MSI_RecordGetInteger(rec
,5);
121 while (rc
== ERROR_SUCCESS
)
123 rc
= RegEnumValueW(hkey
, index
, product
, &sz
, NULL
, NULL
, NULL
, NULL
);
124 if (rc
== ERROR_SUCCESS
)
126 WCHAR productid
[GUID_SIZE
];
127 LPCWSTR ver
, language
, action_property
;
128 DWORD check
= 0, comp_ver
, sz
= 0x100;
132 TRACE("Looking at index %u product %s\n", index
, debugstr_w(product
));
134 unsquash_guid(product
, productid
);
135 if (MSIREG_OpenProductKey(productid
, NULL
, MSIINSTALLCONTEXT_USERMANAGED
, &hukey
, FALSE
) &&
136 MSIREG_OpenProductKey(productid
, NULL
, MSIINSTALLCONTEXT_USERUNMANAGED
, &hukey
, FALSE
) &&
137 MSIREG_OpenProductKey(productid
, NULL
, MSIINSTALLCONTEXT_MACHINE
, &hukey
, FALSE
))
139 TRACE("product key not found\n");
146 RegQueryValueExW(hukey
, INSTALLPROPERTY_VERSIONW
, NULL
, NULL
, (LPBYTE
)&check
, &sz
);
148 /* check version minimum */
149 ver
= MSI_RecordGetString(rec
,2);
152 comp_ver
= msi_version_str_to_dword(ver
);
153 r
= check
- comp_ver
;
154 if (r
< 0 || (r
== 0 && !(attributes
& msidbUpgradeAttributesVersionMinInclusive
)))
156 TRACE("version below minimum\n");
163 /* check version maximum */
164 ver
= MSI_RecordGetString(rec
,3);
167 comp_ver
= msi_version_str_to_dword(ver
);
168 r
= check
- comp_ver
;
169 if (r
> 0 || (r
== 0 && !(attributes
& msidbUpgradeAttributesVersionMaxInclusive
)))
175 TRACE("version above maximum\n");
180 RegQueryValueExW(hukey
, INSTALLPROPERTY_LANGUAGEW
, NULL
, NULL
, (LPBYTE
)&check
, &sz
);
182 language
= MSI_RecordGetString(rec
,4);
183 if (!check_language(check
, language
, attributes
))
186 TRACE("language doesn't match\n");
189 TRACE("found related product\n");
191 action_property
= MSI_RecordGetString(rec
, 7);
192 append_productcode(package
, action_property
, productid
);
193 MSI_RecordSetStringW(uirow
, 1, productid
);
194 msi_ui_actiondata(package
, szFindRelatedProducts
, uirow
);
199 msiobj_release( &uirow
->hdr
);
201 return ERROR_SUCCESS
;
204 UINT
ACTION_FindRelatedProducts(MSIPACKAGE
*package
)
206 static const WCHAR query
[] = {
207 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
208 '`','U','p','g','r','a','d','e','`',0};
212 if (msi_get_property_int(package
->db
, szInstalled
, 0))
214 TRACE("Skipping FindRelatedProducts action: product already installed\n");
215 return ERROR_SUCCESS
;
217 if (msi_action_is_unique(package
, szFindRelatedProducts
))
219 TRACE("Skipping FindRelatedProducts action: already done in UI sequence\n");
220 return ERROR_SUCCESS
;
223 msi_register_unique_action(package
, szFindRelatedProducts
);
225 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
226 if (rc
!= ERROR_SUCCESS
)
227 return ERROR_SUCCESS
;
229 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_FindRelatedProducts
, package
);
230 msiobj_release(&view
->hdr
);