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
23 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/controlevent_overview.asp
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(msi);
41 typedef UINT (*EVENTHANDLER)(MSIPACKAGE*,LPCWSTR,msi_dialog *);
56 UINT ControlEvent_HandleControlEvent(MSIPACKAGE *, LPCWSTR, LPCWSTR, msi_dialog*);
57 static VOID ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE *package, LPWSTR dialog);
60 * Create a dialog box and run it if it's modal
62 static UINT event_do_dialog( MSIPACKAGE *package, LPCWSTR name, msi_dialog *parent, BOOL destroy_modeless )
67 /* create a new dialog */
68 dialog = msi_dialog_create( package, name, parent,
69 ControlEvent_HandleControlEvent );
72 /* kill the current modeless dialog */
73 if( destroy_modeless && package->dialog )
75 msi_dialog_destroy( package->dialog );
76 package->dialog = NULL;
79 /* modeless dialogs return an error message */
80 r = msi_dialog_run_message_loop( dialog );
81 if( r == ERROR_SUCCESS )
82 msi_dialog_destroy( dialog );
84 package->dialog = dialog;
87 r = ERROR_FUNCTION_FAILED;
94 * End a modal dialog box
96 static UINT ControlEvent_EndDialog(MSIPACKAGE* package, LPCWSTR argument,
99 static const WCHAR szExit[] = {
101 static const WCHAR szRetry[] = {
102 'R','e','t','r','y',0};
103 static const WCHAR szIgnore[] = {
104 'I','g','n','o','r','e',0};
105 static const WCHAR szReturn[] = {
106 'R','e','t','u','r','n',0};
108 if (lstrcmpW(argument,szExit)==0)
109 package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
110 else if (lstrcmpW(argument, szRetry) == 0)
111 package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
112 else if (lstrcmpW(argument, szIgnore) == 0)
113 package->CurrentInstallState = -1;
114 else if (lstrcmpW(argument, szReturn) == 0)
116 msi_dialog *parent = msi_dialog_get_parent(dialog);
117 msi_free(package->next_dialog);
118 package->next_dialog = (parent) ? strdupW(msi_dialog_get_name(parent)) : NULL;
119 package->CurrentInstallState = ERROR_SUCCESS;
123 ERR("Unknown argument string %s\n",debugstr_w(argument));
124 package->CurrentInstallState = ERROR_FUNCTION_FAILED;
127 ControlEvent_CleanupDialogSubscriptions(package, msi_dialog_get_name( dialog ));
128 msi_dialog_end_dialog( dialog );
129 return ERROR_SUCCESS;
133 * transition from one modal dialog to another modal dialog
135 static UINT ControlEvent_NewDialog(MSIPACKAGE* package, LPCWSTR argument,
138 /* store the name of the next dialog, and signal this one to end */
139 package->next_dialog = strdupW(argument);
140 ControlEvent_CleanupSubscriptions(package);
141 msi_dialog_end_dialog( dialog );
142 return ERROR_SUCCESS;
146 * Create a new child dialog of an existing modal dialog
148 static UINT ControlEvent_SpawnDialog(MSIPACKAGE* package, LPCWSTR argument,
151 /* don't destroy a modeless dialogs that might be our parent */
152 event_do_dialog( package, argument, dialog, FALSE );
153 if( package->CurrentInstallState != ERROR_SUCCESS )
154 msi_dialog_end_dialog( dialog );
155 return ERROR_SUCCESS;
159 * Creates a dialog that remains up for a period of time
160 * based on a condition
162 static UINT ControlEvent_SpawnWaitDialog(MSIPACKAGE* package, LPCWSTR argument,
165 FIXME("Doing Nothing\n");
166 return ERROR_SUCCESS;
169 static UINT ControlEvent_DoAction(MSIPACKAGE* package, LPCWSTR argument,
172 ACTION_PerformAction(package,argument,TRUE);
173 return ERROR_SUCCESS;
176 static UINT ControlEvent_AddLocal(MSIPACKAGE* package, LPCWSTR argument,
179 static const WCHAR szAll[] = {'A','L','L',0};
180 MSIFEATURE *feature = NULL;
182 if (lstrcmpW(szAll,argument))
184 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_LOCAL);
188 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
189 msi_feature_set_state( feature, INSTALLSTATE_LOCAL );
191 ACTION_UpdateComponentStates(package,argument);
193 return ERROR_SUCCESS;
196 static UINT ControlEvent_Remove(MSIPACKAGE* package, LPCWSTR argument,
199 static const WCHAR szAll[] = {'A','L','L',0};
200 MSIFEATURE *feature = NULL;
202 if (lstrcmpW(szAll,argument))
204 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_ABSENT);
208 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
209 msi_feature_set_state( feature, INSTALLSTATE_ABSENT );
211 ACTION_UpdateComponentStates(package,argument);
213 return ERROR_SUCCESS;
216 static UINT ControlEvent_AddSource(MSIPACKAGE* package, LPCWSTR argument,
219 static const WCHAR szAll[] = {'A','L','L',0};
220 MSIFEATURE *feature = NULL;
222 if (lstrcmpW(szAll,argument))
224 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_SOURCE);
228 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
229 msi_feature_set_state( feature, INSTALLSTATE_SOURCE );
230 ACTION_UpdateComponentStates(package,argument);
232 return ERROR_SUCCESS;
235 static UINT ControlEvent_SetTargetPath(MSIPACKAGE* package, LPCWSTR argument,
238 LPWSTR path = msi_dup_property( package, argument );
239 MSIRECORD *rec = MSI_CreateRecord( 1 );
242 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
244 MSI_RecordSetStringW( rec, 1, path );
245 ControlEvent_FireSubscribedEvent( package, szSelectionPath, rec );
247 /* failure to set the path halts the executing of control events */
248 r = MSI_SetTargetPathW(package, argument, path);
254 static UINT ControlEvent_Reset(MSIPACKAGE* package, LPCWSTR argument,
257 msi_dialog_reset(dialog);
258 return ERROR_SUCCESS;
264 static void free_subscriber( struct subscriber *sub )
266 msi_free(sub->event);
267 msi_free(sub->control);
268 msi_free(sub->attribute);
272 VOID ControlEvent_SubscribeToEvent( MSIPACKAGE *package, msi_dialog *dialog,
273 LPCWSTR event, LPCWSTR control, LPCWSTR attribute )
275 struct subscriber *sub;
277 sub = msi_alloc(sizeof (*sub));
280 sub->dialog = dialog;
281 sub->event = strdupW(event);
282 sub->control = strdupW(control);
283 sub->attribute = strdupW(attribute);
284 list_add_tail( &package->subscriptions, &sub->entry );
287 VOID ControlEvent_UnSubscribeToEvent( MSIPACKAGE *package, LPCWSTR event,
288 LPCWSTR control, LPCWSTR attribute )
291 struct subscriber *sub;
293 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
295 sub = LIST_ENTRY( i, struct subscriber, entry );
297 if( lstrcmpiW(sub->control,control) )
299 if( lstrcmpiW(sub->attribute,attribute) )
301 if( lstrcmpiW(sub->event,event) )
303 list_remove( &sub->entry );
304 free_subscriber( sub );
308 VOID ControlEvent_FireSubscribedEvent( MSIPACKAGE *package, LPCWSTR event,
311 struct subscriber *sub;
313 TRACE("Firing Event %s\n",debugstr_w(event));
315 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
317 if (lstrcmpiW(sub->event, event))
319 msi_dialog_handle_event( sub->dialog, sub->control,
320 sub->attribute, rec );
324 static VOID ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE *package, LPWSTR dialog)
327 struct subscriber *sub;
329 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
331 sub = LIST_ENTRY( i, struct subscriber, entry );
333 if ( lstrcmpW( msi_dialog_get_name( sub->dialog ), dialog ))
336 list_remove( &sub->entry );
337 free_subscriber( sub );
341 VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package)
344 struct subscriber *sub;
346 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
348 sub = LIST_ENTRY( i, struct subscriber, entry );
350 list_remove( &sub->entry );
351 free_subscriber( sub );
358 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
359 * if the given parameter is not a dialog box
361 UINT ACTION_DialogBox( MSIPACKAGE* package, LPCWSTR szDialogName )
363 UINT r = ERROR_SUCCESS;
365 if( package->next_dialog )
366 ERR("Already a next dialog... ignoring it\n");
367 package->next_dialog = NULL;
370 * Dialogs are chained by filling in the next_dialog member
371 * of the package structure, then terminating the current dialog.
372 * The code below sees the next_dialog member set, and runs the
374 * We fall out of the loop below if we come across a modeless
375 * dialog, as it returns ERROR_IO_PENDING when we try to run
378 r = event_do_dialog( package, szDialogName, NULL, TRUE );
379 while( r == ERROR_SUCCESS && package->next_dialog )
381 LPWSTR name = package->next_dialog;
383 package->next_dialog = NULL;
384 r = event_do_dialog( package, name, NULL, TRUE );
388 if( r == ERROR_IO_PENDING )
394 static UINT ControlEvent_SetInstallLevel(MSIPACKAGE* package, LPCWSTR argument,
397 int iInstallLevel = atolW(argument);
399 TRACE("Setting install level: %i\n", iInstallLevel);
401 return MSI_SetInstallLevel( package, iInstallLevel );
404 static UINT ControlEvent_DirectoryListUp(MSIPACKAGE *package, LPCWSTR argument,
407 return msi_dialog_directorylist_up( dialog );
410 static const struct _events Events[] = {
411 { "EndDialog",ControlEvent_EndDialog },
412 { "NewDialog",ControlEvent_NewDialog },
413 { "SpawnDialog",ControlEvent_SpawnDialog },
414 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog },
415 { "DoAction",ControlEvent_DoAction },
416 { "AddLocal",ControlEvent_AddLocal },
417 { "Remove",ControlEvent_Remove },
418 { "AddSource",ControlEvent_AddSource },
419 { "SetTargetPath",ControlEvent_SetTargetPath },
420 { "Reset",ControlEvent_Reset },
421 { "SetInstallLevel",ControlEvent_SetInstallLevel },
422 { "DirectoryListUp",ControlEvent_DirectoryListUp },
423 { "SelectionBrowse",ControlEvent_SpawnDialog },
427 UINT ControlEvent_HandleControlEvent(MSIPACKAGE *package, LPCWSTR event,
428 LPCWSTR argument, msi_dialog* dialog)
431 UINT rc = ERROR_SUCCESS;
433 TRACE("Handling Control Event %s\n",debugstr_w(event));
437 while( Events[i].event != NULL)
439 LPWSTR wevent = strdupAtoW(Events[i].event);
440 if (lstrcmpW(wevent,event)==0)
443 rc = Events[i].handler(package,argument,dialog);
449 FIXME("unhandled control event %s arg(%s)\n",
450 debugstr_w(event), debugstr_w(argument));