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
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msi);
36 typedef UINT (*EVENTHANDLER)(MSIPACKAGE*,LPCWSTR,msi_dialog *);
51 static UINT ControlEvent_HandleControlEvent(MSIPACKAGE *, LPCWSTR, LPCWSTR, msi_dialog*);
54 * Create a dialog box and run it if it's modal
56 static UINT event_do_dialog( MSIPACKAGE *package, LPCWSTR name, msi_dialog *parent, BOOL destroy_modeless )
61 /* create a new dialog */
62 dialog = msi_dialog_create( package, name, parent,
63 ControlEvent_HandleControlEvent );
66 /* kill the current modeless dialog */
67 if( destroy_modeless && package->dialog )
69 msi_dialog_destroy( package->dialog );
70 package->dialog = NULL;
73 /* modeless dialogs return an error message */
74 r = msi_dialog_run_message_loop( dialog );
75 if( r == ERROR_SUCCESS )
76 msi_dialog_destroy( dialog );
78 package->dialog = dialog;
81 r = ERROR_FUNCTION_FAILED;
88 * End a modal dialog box
90 static UINT ControlEvent_EndDialog(MSIPACKAGE* package, LPCWSTR argument,
93 static const WCHAR szExit[] = {
95 static const WCHAR szRetry[] = {
96 'R','e','t','r','y',0};
97 static const WCHAR szIgnore[] = {
98 'I','g','n','o','r','e',0};
99 static const WCHAR szReturn[] = {
100 'R','e','t','u','r','n',0};
102 if (lstrcmpW(argument,szExit)==0)
103 package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
104 else if (lstrcmpW(argument, szRetry) == 0)
105 package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
106 else if (lstrcmpW(argument, szIgnore) == 0)
107 package->CurrentInstallState = ERROR_SUCCESS;
108 else if (lstrcmpW(argument, szReturn) == 0)
110 msi_dialog *parent = msi_dialog_get_parent(dialog);
111 msi_free(package->next_dialog);
112 package->next_dialog = (parent) ? strdupW(msi_dialog_get_name(parent)) : NULL;
113 package->CurrentInstallState = ERROR_SUCCESS;
117 ERR("Unknown argument string %s\n",debugstr_w(argument));
118 package->CurrentInstallState = ERROR_FUNCTION_FAILED;
121 ControlEvent_CleanupDialogSubscriptions(package, msi_dialog_get_name( dialog ));
122 msi_dialog_end_dialog( dialog );
123 return ERROR_SUCCESS;
127 * transition from one modal dialog to another modal dialog
129 static UINT ControlEvent_NewDialog(MSIPACKAGE* package, LPCWSTR argument,
132 /* store the name of the next dialog, and signal this one to end */
133 package->next_dialog = strdupW(argument);
134 ControlEvent_CleanupSubscriptions(package);
135 msi_dialog_end_dialog( dialog );
136 return ERROR_SUCCESS;
140 * Create a new child dialog of an existing modal dialog
142 static UINT ControlEvent_SpawnDialog(MSIPACKAGE* package, LPCWSTR argument,
145 /* don't destroy a modeless dialogs that might be our parent */
146 event_do_dialog( package, argument, dialog, FALSE );
147 if( package->CurrentInstallState != ERROR_SUCCESS )
148 msi_dialog_end_dialog( dialog );
149 return ERROR_SUCCESS;
153 * Creates a dialog that remains up for a period of time
154 * based on a condition
156 static UINT ControlEvent_SpawnWaitDialog(MSIPACKAGE* package, LPCWSTR argument,
159 FIXME("Doing Nothing\n");
160 return ERROR_SUCCESS;
163 static UINT ControlEvent_DoAction(MSIPACKAGE* package, LPCWSTR argument,
166 ACTION_PerformAction(package,argument,-1,TRUE);
167 return ERROR_SUCCESS;
170 static UINT ControlEvent_AddLocal(MSIPACKAGE* package, LPCWSTR argument,
173 static const WCHAR szAll[] = {'A','L','L',0};
174 MSIFEATURE *feature = NULL;
176 if (lstrcmpW(szAll,argument))
178 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_LOCAL);
182 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
183 msi_feature_set_state(package, feature, INSTALLSTATE_LOCAL);
185 ACTION_UpdateComponentStates(package,argument);
187 return ERROR_SUCCESS;
190 static UINT ControlEvent_Remove(MSIPACKAGE* package, LPCWSTR argument,
193 static const WCHAR szAll[] = {'A','L','L',0};
194 MSIFEATURE *feature = NULL;
196 if (lstrcmpW(szAll,argument))
198 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_ABSENT);
202 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
203 msi_feature_set_state(package, feature, INSTALLSTATE_ABSENT);
205 ACTION_UpdateComponentStates(package,argument);
207 return ERROR_SUCCESS;
210 static UINT ControlEvent_AddSource(MSIPACKAGE* package, LPCWSTR argument,
213 static const WCHAR szAll[] = {'A','L','L',0};
214 MSIFEATURE *feature = NULL;
216 if (lstrcmpW(szAll,argument))
218 MSI_SetFeatureStateW(package,argument,INSTALLSTATE_SOURCE);
222 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
223 msi_feature_set_state(package, feature, INSTALLSTATE_SOURCE);
224 ACTION_UpdateComponentStates(package,argument);
226 return ERROR_SUCCESS;
229 static UINT ControlEvent_SetTargetPath(MSIPACKAGE* package, LPCWSTR argument,
232 LPWSTR path = msi_dup_property( package, argument );
233 MSIRECORD *rec = MSI_CreateRecord( 1 );
236 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
238 MSI_RecordSetStringW( rec, 1, path );
239 ControlEvent_FireSubscribedEvent( package, szSelectionPath, rec );
241 /* failure to set the path halts the executing of control events */
242 r = MSI_SetTargetPathW(package, argument, path);
248 static UINT ControlEvent_Reset(MSIPACKAGE* package, LPCWSTR argument,
251 msi_dialog_reset(dialog);
252 return ERROR_SUCCESS;
258 static void free_subscriber( struct subscriber *sub )
260 msi_free(sub->event);
261 msi_free(sub->control);
262 msi_free(sub->attribute);
266 VOID ControlEvent_SubscribeToEvent( MSIPACKAGE *package, msi_dialog *dialog,
267 LPCWSTR event, LPCWSTR control, LPCWSTR attribute )
269 struct subscriber *sub;
271 sub = msi_alloc(sizeof (*sub));
274 sub->dialog = dialog;
275 sub->event = strdupW(event);
276 sub->control = strdupW(control);
277 sub->attribute = strdupW(attribute);
278 list_add_tail( &package->subscriptions, &sub->entry );
281 VOID ControlEvent_FireSubscribedEvent( MSIPACKAGE *package, LPCWSTR event,
284 struct subscriber *sub;
286 TRACE("Firing Event %s\n",debugstr_w(event));
288 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
290 if (lstrcmpiW(sub->event, event))
292 msi_dialog_handle_event( sub->dialog, sub->control,
293 sub->attribute, rec );
297 VOID ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE *package, LPWSTR dialog)
300 struct subscriber *sub;
302 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
304 sub = LIST_ENTRY( i, struct subscriber, entry );
306 if ( lstrcmpW( msi_dialog_get_name( sub->dialog ), dialog ))
309 list_remove( &sub->entry );
310 free_subscriber( sub );
314 VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package)
317 struct subscriber *sub;
319 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
321 sub = LIST_ENTRY( i, struct subscriber, entry );
323 list_remove( &sub->entry );
324 free_subscriber( sub );
331 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
332 * if the given parameter is not a dialog box
334 UINT ACTION_DialogBox( MSIPACKAGE* package, LPCWSTR szDialogName )
336 UINT r = ERROR_SUCCESS;
338 if( package->next_dialog )
339 ERR("Already a next dialog... ignoring it\n");
340 package->next_dialog = NULL;
343 * Dialogs are chained by filling in the next_dialog member
344 * of the package structure, then terminating the current dialog.
345 * The code below sees the next_dialog member set, and runs the
347 * We fall out of the loop below if we come across a modeless
348 * dialog, as it returns ERROR_IO_PENDING when we try to run
351 r = event_do_dialog( package, szDialogName, NULL, TRUE );
352 while( r == ERROR_SUCCESS && package->next_dialog )
354 LPWSTR name = package->next_dialog;
356 package->next_dialog = NULL;
357 r = event_do_dialog( package, name, NULL, TRUE );
361 if( r == ERROR_IO_PENDING )
367 static UINT ControlEvent_SetInstallLevel(MSIPACKAGE* package, LPCWSTR argument,
370 int iInstallLevel = atolW(argument);
372 TRACE("Setting install level: %i\n", iInstallLevel);
374 return MSI_SetInstallLevel( package, iInstallLevel );
377 static UINT ControlEvent_DirectoryListUp(MSIPACKAGE *package, LPCWSTR argument,
380 return msi_dialog_directorylist_up( dialog );
383 static UINT ControlEvent_ReinstallMode(MSIPACKAGE *package, LPCWSTR argument,
386 static const WCHAR szReinstallMode[] = {'R','E','I','N','S','T','A','L','L','M','O','D','E',0};
387 return MSI_SetPropertyW( package, szReinstallMode, argument );
390 static const struct _events Events[] = {
391 { "EndDialog",ControlEvent_EndDialog },
392 { "NewDialog",ControlEvent_NewDialog },
393 { "SpawnDialog",ControlEvent_SpawnDialog },
394 { "SpawnWaitDialog",ControlEvent_SpawnWaitDialog },
395 { "DoAction",ControlEvent_DoAction },
396 { "AddLocal",ControlEvent_AddLocal },
397 { "Remove",ControlEvent_Remove },
398 { "AddSource",ControlEvent_AddSource },
399 { "SetTargetPath",ControlEvent_SetTargetPath },
400 { "Reset",ControlEvent_Reset },
401 { "SetInstallLevel",ControlEvent_SetInstallLevel },
402 { "DirectoryListUp",ControlEvent_DirectoryListUp },
403 { "SelectionBrowse",ControlEvent_SpawnDialog },
404 { "ReinstallMode",ControlEvent_ReinstallMode },
408 UINT ControlEvent_HandleControlEvent(MSIPACKAGE *package, LPCWSTR event,
409 LPCWSTR argument, msi_dialog* dialog)
412 UINT rc = ERROR_SUCCESS;
414 TRACE("Handling Control Event %s\n",debugstr_w(event));
418 while( Events[i].event != NULL)
420 LPWSTR wevent = strdupAtoW(Events[i].event);
421 if (lstrcmpW(wevent,event)==0)
424 rc = Events[i].handler(package,argument,dialog);
430 FIXME("unhandled control event %s arg(%s)\n",
431 debugstr_w(event), debugstr_w(argument));