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 *);
55 VOID ControlEvent_HandleControlEvent(MSIPACKAGE *, LPCWSTR, LPCWSTR, msi_dialog*);
58 * Create a dialog box and run it if it's modal
60 static UINT event_do_dialog( MSIPACKAGE *package, LPCWSTR name )
65 /* kill the current modeless dialog */
67 msi_dialog_destroy( package->dialog );
68 package->dialog = NULL;
70 /* create a new dialog */
71 dialog = msi_dialog_create( package, name,
72 ControlEvent_HandleControlEvent );
75 /* modeless dialogs return an error message */
76 r = msi_dialog_run_message_loop( dialog );
77 if( r == ERROR_SUCCESS )
78 msi_dialog_destroy( dialog );
80 package->dialog = dialog;
83 r = ERROR_FUNCTION_FAILED;
90 * End a modal dialog box
92 static VOID ControlEvent_EndDialog(MSIPACKAGE* package, LPCWSTR argument,
95 static const WCHAR szExit[] = {
97 static const WCHAR szRetry[] = {
98 'R','e','t','r','y',0};
99 static const WCHAR szIgnore[] = {
100 'I','g','n','o','r','e',0};
101 static const WCHAR szReturn[] = {
102 'R','e','t','u','r','n',0};
104 if (lstrcmpW(argument,szExit)==0)
105 package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
106 else if (lstrcmpW(argument, szRetry) == 0)
107 package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
108 else if (lstrcmpW(argument, szIgnore) == 0)
109 package->CurrentInstallState = -1;
110 else if (lstrcmpW(argument, szReturn) == 0)
111 package->CurrentInstallState = ERROR_SUCCESS;
114 ERR("Unknown argument string %s\n",debugstr_w(argument));
115 package->CurrentInstallState = ERROR_FUNCTION_FAILED;
118 ControlEvent_CleanupSubscriptions(package);
119 msi_dialog_end_dialog( dialog );
123 * transition from one modal dialog to another modal dialog
125 static VOID ControlEvent_NewDialog(MSIPACKAGE* package, LPCWSTR argument,
128 /* store the name of the next dialog, and signal this one to end */
129 package->next_dialog = strdupW(argument);
130 ControlEvent_CleanupSubscriptions(package);
131 msi_dialog_end_dialog( dialog );
135 * Create a new child dialog of an existing modal dialog
137 static VOID ControlEvent_SpawnDialog(MSIPACKAGE* package, LPCWSTR argument,
140 event_do_dialog( package, argument );
141 if( package->CurrentInstallState != ERROR_SUCCESS )
142 msi_dialog_end_dialog( dialog );
146 * Creates a dialog that remains up for a period of time
147 * based on a condition
149 static VOID ControlEvent_SpawnWaitDialog(MSIPACKAGE* package, LPCWSTR argument,
152 FIXME("Doing Nothing\n");
155 static VOID ControlEvent_DoAction(MSIPACKAGE* package, LPCWSTR argument,
158 ACTION_PerformAction(package,argument,TRUE);
161 static VOID ControlEvent_AddLocal(MSIPACKAGE* package, LPCWSTR argument,
164 static const WCHAR szAll[] = {'A','L','L',0};
167 if (lstrcmpW(szAll,argument))
169 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_LOCAL);
173 for (i = 0; i < package->loaded_features; i++)
175 package->features[i].ActionRequest = INSTALLSTATE_LOCAL;
176 package->features[i].Action = INSTALLSTATE_LOCAL;
178 ACTION_UpdateComponentStates(package,argument);
183 static VOID ControlEvent_Remove(MSIPACKAGE* package, LPCWSTR argument,
186 static const WCHAR szAll[] = {'A','L','L',0};
189 if (lstrcmpW(szAll,argument))
191 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_ABSENT);
195 for (i = 0; i < package->loaded_features; i++)
197 package->features[i].ActionRequest = INSTALLSTATE_ABSENT;
198 package->features[i].Action= INSTALLSTATE_ABSENT;
200 ACTION_UpdateComponentStates(package,argument);
204 static VOID ControlEvent_AddSource(MSIPACKAGE* package, LPCWSTR argument,
207 static const WCHAR szAll[] = {'A','L','L',0};
210 if (lstrcmpW(szAll,argument))
212 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_SOURCE);
216 for (i = 0; i < package->loaded_features; i++)
218 package->features[i].ActionRequest = INSTALLSTATE_SOURCE;
219 package->features[i].Action = INSTALLSTATE_SOURCE;
221 ACTION_UpdateComponentStates(package,argument);
229 static void free_subscriber( struct subscriber *sub )
231 HeapFree(GetProcessHeap(),0,sub->event);
232 HeapFree(GetProcessHeap(),0,sub->control);
233 HeapFree(GetProcessHeap(),0,sub->attribute);
234 HeapFree(GetProcessHeap(),0,sub);
237 VOID ControlEvent_SubscribeToEvent( MSIPACKAGE *package, LPCWSTR event,
238 LPCWSTR control, LPCWSTR attribute )
240 struct subscriber *sub;
242 sub = HeapAlloc(GetProcessHeap(),0,sizeof (*sub));
245 sub->event = strdupW(event);
246 sub->control = strdupW(control);
247 sub->attribute = strdupW(attribute);
248 list_add_tail( &package->subscriptions, &sub->entry );
251 VOID ControlEvent_UnSubscribeToEvent( MSIPACKAGE *package, LPCWSTR event,
252 LPCWSTR control, LPCWSTR attribute )
255 struct subscriber *sub;
257 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
259 sub = LIST_ENTRY( i, struct subscriber, entry );
261 if( lstrcmpiW(sub->control,control) )
263 if( lstrcmpiW(sub->attribute,attribute) )
265 if( lstrcmpiW(sub->event,event) )
267 list_remove( &sub->entry );
268 free_subscriber( sub );
272 VOID ControlEvent_FireSubscribedEvent( MSIPACKAGE *package, LPCWSTR event,
275 struct subscriber *sub;
277 TRACE("Firing Event %s\n",debugstr_w(event));
279 if (!package->dialog)
282 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
284 if (lstrcmpiW(sub->event, event))
286 msi_dialog_handle_event( package->dialog, sub->control,
287 sub->attribute, rec );
291 VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package)
294 struct subscriber *sub;
296 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
298 sub = LIST_ENTRY( i, struct subscriber, entry );
300 list_remove( &sub->entry );
301 free_subscriber( sub );
308 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
309 * if the given parameter is not a dialog box
311 UINT ACTION_DialogBox( MSIPACKAGE* package, LPCWSTR szDialogName )
313 UINT r = ERROR_SUCCESS;
315 if( package->next_dialog )
316 ERR("Already a next dialog... ignoring it\n");
317 package->next_dialog = NULL;
320 * Dialogs are chained by filling in the next_dialog member
321 * of the package structure, then terminating the current dialog.
322 * The code below sees the next_dialog member set, and runs the
324 * We fall out of the loop below if we come across a modeless
325 * dialog, as it returns ERROR_IO_PENDING when we try to run
328 r = event_do_dialog( package, szDialogName );
329 while( r == ERROR_SUCCESS && package->next_dialog )
331 LPWSTR name = package->next_dialog;
333 package->next_dialog = NULL;
334 r = event_do_dialog( package, name );
335 HeapFree( GetProcessHeap(), 0, name );
338 if( r == ERROR_IO_PENDING )
344 struct _events Events[] = {
345 { "EndDialog",ControlEvent_EndDialog },
346 { "NewDialog",ControlEvent_NewDialog },
347 { "SpawnDialog",ControlEvent_SpawnDialog },
348 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog },
349 { "DoAction",ControlEvent_DoAction },
350 { "AddLocal",ControlEvent_AddLocal },
351 { "Remove",ControlEvent_Remove },
352 { "AddSource",ControlEvent_AddSource },
356 VOID ControlEvent_HandleControlEvent(MSIPACKAGE *package, LPCWSTR event,
357 LPCWSTR argument, msi_dialog* dialog)
361 TRACE("Handling Control Event %s\n",debugstr_w(event));
365 while( Events[i].event != NULL)
367 LPWSTR wevent = strdupAtoW(Events[i].event);
368 if (lstrcmpW(wevent,event)==0)
370 HeapFree(GetProcessHeap(),0,wevent);
371 Events[i].handler(package,argument,dialog);
374 HeapFree(GetProcessHeap(),0,wevent);
377 FIXME("unhandled control event %s arg(%s)\n",
378 debugstr_w(event), debugstr_w(argument));