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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/controlevent_overview.asp
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msi);
41 typedef void (*EVENTHANDLER)(MSIPACKAGE*,LPCWSTR,msi_dialog *);
51 struct _subscriber *next;
54 struct _subscription_chain {
56 struct _subscriber *chain;
59 struct _subscriptions {
61 struct _subscription_chain* chain;
65 VOID ControlEvent_HandleControlEvent(MSIPACKAGE *, LPCWSTR, LPCWSTR, msi_dialog*);
68 * Create a dialog box and run it if it's modal
70 static UINT event_do_dialog( MSIPACKAGE *package, LPCWSTR name )
75 /* kill the current modeless dialog */
77 msi_dialog_destroy( package->dialog );
78 package->dialog = NULL;
80 /* create a new dialog */
81 dialog = msi_dialog_create( package, name,
82 ControlEvent_HandleControlEvent );
85 /* modeless dialogs return an error message */
86 r = msi_dialog_run_message_loop( dialog );
87 if( r == ERROR_SUCCESS )
88 msi_dialog_destroy( dialog );
90 package->dialog = dialog;
93 r = ERROR_FUNCTION_FAILED;
100 * End a modal dialog box
102 static VOID ControlEvent_EndDialog(MSIPACKAGE* package, LPCWSTR argument,
105 static const WCHAR szExit[] = {
107 static const WCHAR szRetry[] = {
108 'R','e','t','r','y',0};
109 static const WCHAR szIgnore[] = {
110 'I','g','n','o','r','e',0};
111 static const WCHAR szReturn[] = {
112 'R','e','t','u','r','n',0};
114 if (lstrcmpW(argument,szExit)==0)
115 package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
116 else if (lstrcmpW(argument, szRetry) == 0)
117 package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
118 else if (lstrcmpW(argument, szIgnore) == 0)
119 package->CurrentInstallState = -1;
120 else if (lstrcmpW(argument, szReturn) == 0)
121 package->CurrentInstallState = ERROR_SUCCESS;
124 ERR("Unknown argument string %s\n",debugstr_w(argument));
125 package->CurrentInstallState = ERROR_FUNCTION_FAILED;
128 msi_dialog_end_dialog( dialog );
132 * transition from one modal dialog to another modal dialog
134 static VOID ControlEvent_NewDialog(MSIPACKAGE* package, LPCWSTR argument,
137 /* store the name of the next dialog, and signal this one to end */
138 package->next_dialog = strdupW(argument);
139 msi_dialog_end_dialog( dialog );
143 * Create a new child dialog of an existing modal dialog
145 static VOID ControlEvent_SpawnDialog(MSIPACKAGE* package, LPCWSTR argument,
148 event_do_dialog( package, argument );
149 if( package->CurrentInstallState != ERROR_SUCCESS )
150 msi_dialog_end_dialog( dialog );
154 * Creates a dialog that remains up for a period of time
155 * based on a condition
157 static VOID ControlEvent_SpawnWaitDialog(MSIPACKAGE* package, LPCWSTR argument,
160 FIXME("Doing Nothing\n");
163 static VOID ControlEvent_DoAction(MSIPACKAGE* package, LPCWSTR argument,
166 ACTION_PerformAction(package,argument,TRUE);
169 static VOID ControlEvent_AddLocal(MSIPACKAGE* package, LPCWSTR argument,
172 static const WCHAR szAll[] = {'A','L','L',0};
175 if (lstrcmpW(szAll,argument))
177 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_LOCAL);
181 for (i = 0; i < package->loaded_features; i++)
183 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
184 package->features[i].Action = INSTALLSTATE_LOCAL;
186 ACTION_UpdateComponentStates(package,argument);
191 static VOID ControlEvent_Remove(MSIPACKAGE* package, LPCWSTR argument,
194 static const WCHAR szAll[] = {'A','L','L',0};
197 if (lstrcmpW(szAll,argument))
199 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_ABSENT);
203 for (i = 0; i < package->loaded_features; i++)
205 package->features[i].ActionRequest = INSTALLSTATE_ABSENT;
206 package->features[i].Action= INSTALLSTATE_ABSENT;
208 ACTION_UpdateComponentStates(package,argument);
212 static VOID ControlEvent_AddSource(MSIPACKAGE* package, LPCWSTR argument,
215 static const WCHAR szAll[] = {'A','L','L',0};
218 if (lstrcmpW(szAll,argument))
220 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_SOURCE);
224 for (i = 0; i < package->loaded_features; i++)
226 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
227 package->features[i].Action = INSTALLSTATE_SOURCE;
229 ACTION_UpdateComponentStates(package,argument);
237 static void free_subscriber(struct _subscriber *who)
239 HeapFree(GetProcessHeap(),0,who->control);
240 HeapFree(GetProcessHeap(),0,who->attribute);
241 HeapFree(GetProcessHeap(),0,who);
244 VOID ControlEvent_SubscribeToEvent(MSIPACKAGE *package, LPCWSTR event,
245 LPCWSTR control, LPCWSTR attribute)
248 struct _subscription_chain *chain;
249 struct _subscriber *subscriber, *ptr;
251 if (!package->EventSubscriptions)
253 package->EventSubscriptions = HeapAlloc(GetProcessHeap(), 0,
254 sizeof(struct _subscriptions));
255 package->EventSubscriptions->chain_count = 0;
260 for (i = 0; i < package->EventSubscriptions->chain_count; i++)
262 if (lstrcmpiW(package->EventSubscriptions->chain[i].event,event)==0)
264 chain = &package->EventSubscriptions->chain[i];
271 if (package->EventSubscriptions->chain_count)
272 chain = HeapReAlloc(GetProcessHeap(), 0,
273 package->EventSubscriptions->chain,
274 (package->EventSubscriptions->chain_count + 1) *
275 sizeof (struct _subscription_chain));
277 chain= HeapAlloc(GetProcessHeap(),0, sizeof (struct
278 _subscription_chain));
280 package->EventSubscriptions->chain = chain;
281 chain = &package->EventSubscriptions->chain[
282 package->EventSubscriptions->chain_count];
283 package->EventSubscriptions->chain_count++;
284 memset(chain,0,sizeof(struct _subscription_chain));
285 chain->event = strdupW(event);
288 subscriber = ptr = chain->chain;
295 ptr = HeapAlloc(GetProcessHeap(),0,sizeof(struct _subscriber));
296 ptr->control = strdupW(control);
297 ptr->attribute = strdupW(attribute);
301 subscriber->next = ptr;
306 VOID ControlEvent_UnSubscribeToEvent(MSIPACKAGE *package, LPCWSTR event,
307 LPCWSTR control, LPCWSTR attribute)
311 if (!package->EventSubscriptions)
314 for (i = 0; i < package->EventSubscriptions->chain_count; i++)
316 if (lstrcmpiW(package->EventSubscriptions->chain[i].event,event)==0)
318 struct _subscriber *who;
319 struct _subscriber *prev=NULL;
320 who = package->EventSubscriptions->chain[i].chain;
323 if (lstrcmpiW(who->control,control)==0
324 && lstrcmpiW(who->attribute,attribute)==0)
327 prev->next = who->next;
329 package->EventSubscriptions->chain[i].chain = who->next;
331 free_subscriber(who);
344 VOID ControlEvent_FireSubscribedEvent(MSIPACKAGE *package, LPCWSTR event,
349 TRACE("Firing Event %s\n",debugstr_w(event));
351 if (!package->dialog)
354 if (!package->EventSubscriptions)
357 for (i = 0; i < package->EventSubscriptions->chain_count; i++)
359 if (lstrcmpiW(package->EventSubscriptions->chain[i].event,event)==0)
361 struct _subscriber *who;
362 who = package->EventSubscriptions->chain[i].chain;
365 ERR("Should Fire event for %s %s\n",
366 debugstr_w(who->control), debugstr_w(who->attribute));
368 msi_dialog_fire_subscribed_event(package->dialog, who->control,
369 who->attribute, data);
378 VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package)
382 if (!package->EventSubscriptions)
385 for (i = 0; i < package->EventSubscriptions->chain_count; i++)
387 struct _subscriber *who;
388 struct _subscriber *ptr;
389 who = package->EventSubscriptions->chain[i].chain;
394 free_subscriber(ptr);
396 HeapFree(GetProcessHeap(), 0,
397 package->EventSubscriptions->chain[i].event);
399 HeapFree(GetProcessHeap(),0,package->EventSubscriptions->chain);
400 HeapFree(GetProcessHeap(),0,package->EventSubscriptions);
401 package->EventSubscriptions = NULL;
407 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
408 * if the given parameter is not a dialog box
410 UINT ACTION_DialogBox( MSIPACKAGE* package, LPCWSTR szDialogName )
412 UINT r = ERROR_SUCCESS;
414 if( package->next_dialog )
415 ERR("Already a next dialog... ignoring it\n");
416 package->next_dialog = NULL;
419 * Dialogs are chained by filling in the next_dialog member
420 * of the package structure, then terminating the current dialog.
421 * The code below sees the next_dialog member set, and runs the
423 * We fall out of the loop below if we come across a modeless
424 * dialog, as it returns ERROR_IO_PENDING when we try to run
427 r = event_do_dialog( package, szDialogName );
428 while( r == ERROR_SUCCESS && package->next_dialog )
430 LPWSTR name = package->next_dialog;
432 package->next_dialog = NULL;
433 r = event_do_dialog( package, name );
434 HeapFree( GetProcessHeap(), 0, name );
437 if( r == ERROR_IO_PENDING )
443 struct _events Events[] = {
444 { "EndDialog",ControlEvent_EndDialog },
445 { "NewDialog",ControlEvent_NewDialog },
446 { "SpawnDialog",ControlEvent_SpawnDialog },
447 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog },
448 { "DoAction",ControlEvent_DoAction },
449 { "AddLocal",ControlEvent_AddLocal },
450 { "Remove",ControlEvent_Remove },
451 { "AddSource",ControlEvent_AddSource },
455 VOID ControlEvent_HandleControlEvent(MSIPACKAGE *package, LPCWSTR event,
456 LPCWSTR argument, msi_dialog* dialog)
460 TRACE("Handling Control Event %s\n",debugstr_w(event));
464 while( Events[i].event != NULL)
466 LPWSTR wevent = strdupAtoW(Events[i].event);
467 if (lstrcmpW(wevent,event)==0)
469 HeapFree(GetProcessHeap(),0,wevent);
470 Events[i].handler(package,argument,dialog);
473 HeapFree(GetProcessHeap(),0,wevent);
476 FIXME("unhandled control event %s arg(%s)\n",
477 debugstr_w(event), debugstr_w(argument));