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
,
65 prop
= msi_dup_property(package
, action_property
);
74 len
+= strlenW(productid
);
79 newprop
= msi_alloc( len
*sizeof(WCHAR
) );
83 strcpyW(newprop
,prop
);
84 strcatW(newprop
,szSemiColon
);
88 strcatW(newprop
,productid
);
90 MSI_SetPropertyW(package
, action_property
, newprop
);
91 TRACE("Found Related Product... %s now %s\n",debugstr_w(action_property
),
97 static UINT
ITERATE_FindRelatedProducts(MSIRECORD
*rec
, LPVOID param
)
99 MSIPACKAGE
*package
= param
;
100 WCHAR product
[GUID_SIZE
];
102 DWORD attributes
= 0;
103 DWORD sz
= GUID_SIZE
;
104 LPCWSTR upgrade_code
;
106 UINT rc
= ERROR_SUCCESS
;
109 upgrade_code
= MSI_RecordGetString(rec
,1);
111 rc
= MSIREG_OpenUpgradeCodesKey(upgrade_code
, &hkey
, FALSE
);
112 if (rc
!= ERROR_SUCCESS
)
113 return ERROR_SUCCESS
;
115 uirow
= MSI_CreateRecord(1);
116 attributes
= MSI_RecordGetInteger(rec
,5);
118 while (rc
== ERROR_SUCCESS
)
120 rc
= RegEnumValueW(hkey
, index
, product
, &sz
, NULL
, NULL
, NULL
, NULL
);
121 TRACE("Looking at (%i) %s\n",index
,debugstr_w(product
));
122 if (rc
== ERROR_SUCCESS
)
124 WCHAR productid
[GUID_SIZE
];
127 LPCWSTR action_property
;
128 DWORD check
= 0x00000000;
129 DWORD comp_ver
= 0x00000000;
134 unsquash_guid(product
, productid
);
135 rc
= MSIREG_OpenProductKey(productid
, NULL
, package
->Context
,
137 if (rc
!= ERROR_SUCCESS
)
145 RegQueryValueExW(hukey
, INSTALLPROPERTY_VERSIONW
, NULL
, NULL
,
146 (LPBYTE
)&check
, &sz
);
148 ver
= MSI_RecordGetString(rec
,2);
149 comp_ver
= msi_version_str_to_dword(ver
);
150 r
= check
- comp_ver
;
151 if (r
< 0 || (r
== 0 && !(attributes
&
152 msidbUpgradeAttributesVersionMinInclusive
)))
160 ver
= MSI_RecordGetString(rec
,3);
161 comp_ver
= msi_version_str_to_dword(ver
);
162 r
= check
- comp_ver
;
163 if (r
> 0 || (r
== 0 && !(attributes
&
164 msidbUpgradeAttributesVersionMaxInclusive
)))
173 RegQueryValueExW(hukey
, INSTALLPROPERTY_LANGUAGEW
, NULL
, NULL
,
174 (LPBYTE
)&check
, &sz
);
176 language
= MSI_RecordGetString(rec
,4);
177 TRACE("Checking languages %x and %s\n", check
,
178 debugstr_w(language
));
179 if (!check_language(check
, language
, attributes
))
185 action_property
= MSI_RecordGetString(rec
,7);
186 append_productcode(package
,action_property
,productid
);
187 ui_actiondata(package
,szFindRelatedProducts
,uirow
);
192 msiobj_release( &uirow
->hdr
);
194 return ERROR_SUCCESS
;
197 UINT
ACTION_FindRelatedProducts(MSIPACKAGE
*package
)
199 static const WCHAR Query
[] =
200 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',
201 ' ','`','U','p','g','r','a','d','e','`',0};
202 UINT rc
= ERROR_SUCCESS
;
205 if (check_unique_action(package
,szFindRelatedProducts
))
207 TRACE("Skipping FindRelatedProducts action: already done on client side\n");
208 return ERROR_SUCCESS
;
211 register_unique_action(package
,szFindRelatedProducts
);
213 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
214 if (rc
!= ERROR_SUCCESS
)
215 return ERROR_SUCCESS
;
217 rc
= MSI_IterateRecords(view
, NULL
, ITERATE_FindRelatedProducts
, package
);
218 msiobj_release(&view
->hdr
);