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 *);
52 static UINT ControlEvent_HandleControlEvent(MSIPACKAGE *, LPCWSTR, LPCWSTR, msi_dialog*);
55 * Create a dialog box and run it if it's modal
57 static UINT event_do_dialog( MSIPACKAGE *package, LPCWSTR name, msi_dialog *parent, BOOL destroy_modeless )
62 /* create a new dialog */
63 dialog = msi_dialog_create( package, name, parent,
64 ControlEvent_HandleControlEvent );
67 /* kill the current modeless dialog */
68 if( destroy_modeless && package->dialog )
70 msi_dialog_destroy( package->dialog );
71 package->dialog = NULL;
74 /* modeless dialogs return an error message */
75 r = msi_dialog_run_message_loop( dialog );
76 if( r == ERROR_SUCCESS )
77 msi_dialog_destroy( dialog );
79 package->dialog = dialog;
82 r = ERROR_FUNCTION_FAILED;
89 * End a modal dialog box
91 static UINT ControlEvent_EndDialog(MSIPACKAGE* package, LPCWSTR argument,
94 static const WCHAR szExit[] = {'E','x','i','t',0};
95 static const WCHAR szRetry[] = {'R','e','t','r','y',0};
96 static const WCHAR szIgnore[] = {'I','g','n','o','r','e',0};
97 static const WCHAR szReturn[] = {'R','e','t','u','r','n',0};
99 if (!strcmpW( argument, szExit ))
100 package->CurrentInstallState = ERROR_INSTALL_USEREXIT;
101 else if (!strcmpW( argument, szRetry ))
102 package->CurrentInstallState = ERROR_INSTALL_SUSPEND;
103 else if (!strcmpW( argument, szIgnore ))
104 package->CurrentInstallState = ERROR_SUCCESS;
105 else if (!strcmpW( argument, szReturn ))
107 msi_dialog *parent = msi_dialog_get_parent(dialog);
108 msi_free(package->next_dialog);
109 package->next_dialog = (parent) ? strdupW(msi_dialog_get_name(parent)) : NULL;
110 package->CurrentInstallState = ERROR_SUCCESS;
114 ERR("Unknown argument string %s\n",debugstr_w(argument));
115 package->CurrentInstallState = ERROR_FUNCTION_FAILED;
118 ControlEvent_CleanupDialogSubscriptions(package, msi_dialog_get_name( dialog ));
119 msi_dialog_end_dialog( dialog );
120 return ERROR_SUCCESS;
124 * transition from one modal dialog to another modal dialog
126 static UINT ControlEvent_NewDialog(MSIPACKAGE* package, LPCWSTR argument,
129 /* store the name of the next dialog, and signal this one to end */
130 package->next_dialog = strdupW(argument);
131 ControlEvent_CleanupSubscriptions(package);
132 msi_dialog_end_dialog( dialog );
133 return ERROR_SUCCESS;
137 * Create a new child dialog of an existing modal dialog
139 static UINT ControlEvent_SpawnDialog(MSIPACKAGE* package, LPCWSTR argument,
142 /* don't destroy a modeless dialogs that might be our parent */
143 event_do_dialog( package, argument, dialog, FALSE );
144 if( package->CurrentInstallState != ERROR_SUCCESS )
145 msi_dialog_end_dialog( dialog );
146 return ERROR_SUCCESS;
150 * Creates a dialog that remains up for a period of time
151 * based on a condition
153 static UINT ControlEvent_SpawnWaitDialog(MSIPACKAGE* package, LPCWSTR argument,
156 FIXME("Doing Nothing\n");
157 return ERROR_SUCCESS;
160 static UINT ControlEvent_DoAction(MSIPACKAGE* package, LPCWSTR argument,
163 ACTION_PerformAction(package, argument, -1);
164 return ERROR_SUCCESS;
167 static UINT ControlEvent_AddLocal( MSIPACKAGE *package, LPCWSTR argument, msi_dialog *dialog )
171 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
173 if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
175 if (feature->ActionRequest != INSTALLSTATE_LOCAL)
176 msi_set_property( package->db, szPreselected, szOne );
177 MSI_SetFeatureStateW( package, feature->Feature, INSTALLSTATE_LOCAL );
180 return ERROR_SUCCESS;
183 static UINT ControlEvent_Remove( MSIPACKAGE *package, LPCWSTR argument, msi_dialog *dialog )
187 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
189 if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
191 if (feature->ActionRequest != INSTALLSTATE_ABSENT)
192 msi_set_property( package->db, szPreselected, szOne );
193 MSI_SetFeatureStateW( package, feature->Feature, INSTALLSTATE_ABSENT );
196 return ERROR_SUCCESS;
199 static UINT ControlEvent_AddSource( MSIPACKAGE *package, LPCWSTR argument, msi_dialog *dialog )
203 LIST_FOR_EACH_ENTRY( feature, &package->features, MSIFEATURE, entry )
205 if (!strcmpW( argument, feature->Feature ) || !strcmpW( argument, szAll ))
207 if (feature->ActionRequest != INSTALLSTATE_SOURCE)
208 msi_set_property( package->db, szPreselected, szOne );
209 MSI_SetFeatureStateW( package, feature->Feature, INSTALLSTATE_SOURCE );
212 return ERROR_SUCCESS;
215 static UINT ControlEvent_SetTargetPath(MSIPACKAGE* package, LPCWSTR argument,
218 LPWSTR path = msi_dup_property( package->db, argument );
219 MSIRECORD *rec = MSI_CreateRecord( 1 );
222 static const WCHAR szSelectionPath[] = {'S','e','l','e','c','t','i','o','n','P','a','t','h',0};
224 MSI_RecordSetStringW( rec, 1, path );
225 ControlEvent_FireSubscribedEvent( package, szSelectionPath, rec );
227 /* failure to set the path halts the executing of control events */
228 r = MSI_SetTargetPathW(package, argument, path);
234 static UINT ControlEvent_Reset(MSIPACKAGE* package, LPCWSTR argument,
237 msi_dialog_reset(dialog);
238 return ERROR_SUCCESS;
244 static void free_subscriber( struct subscriber *sub )
246 msi_free(sub->event);
247 msi_free(sub->control);
248 msi_free(sub->attribute);
252 VOID ControlEvent_SubscribeToEvent( MSIPACKAGE *package, msi_dialog *dialog,
253 LPCWSTR event, LPCWSTR control, LPCWSTR attribute )
255 struct subscriber *sub;
257 TRACE("event %s control %s attribute %s\n", debugstr_w(event), debugstr_w(control), debugstr_w(attribute));
259 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
261 if (!strcmpiW( sub->event, event ) &&
262 !strcmpiW( sub->control, control ) &&
263 !strcmpiW( sub->attribute, attribute ))
265 TRACE("already subscribed\n");
269 if (!(sub = msi_alloc( sizeof(*sub) ))) return;
270 sub->dialog = dialog;
271 sub->event = strdupW(event);
272 sub->control = strdupW(control);
273 sub->attribute = strdupW(attribute);
274 list_add_tail( &package->subscriptions, &sub->entry );
277 VOID ControlEvent_FireSubscribedEvent( MSIPACKAGE *package, LPCWSTR event, MSIRECORD *rec )
279 struct subscriber *sub;
281 TRACE("Firing event %s\n", debugstr_w(event));
283 LIST_FOR_EACH_ENTRY( sub, &package->subscriptions, struct subscriber, entry )
285 if (strcmpiW( sub->event, event )) continue;
286 msi_dialog_handle_event( sub->dialog, sub->control, sub->attribute, rec );
290 VOID ControlEvent_CleanupDialogSubscriptions(MSIPACKAGE *package, LPWSTR dialog)
293 struct subscriber *sub;
295 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
297 sub = LIST_ENTRY( i, struct subscriber, entry );
299 if (strcmpW( msi_dialog_get_name( sub->dialog ), dialog ))
302 list_remove( &sub->entry );
303 free_subscriber( sub );
307 VOID ControlEvent_CleanupSubscriptions(MSIPACKAGE *package)
310 struct subscriber *sub;
312 LIST_FOR_EACH_SAFE( i, t, &package->subscriptions )
314 sub = LIST_ENTRY( i, struct subscriber, entry );
316 list_remove( &sub->entry );
317 free_subscriber( sub );
324 * Return ERROR_SUCCESS if dialog is process and ERROR_FUNCTION_FAILED
325 * if the given parameter is not a dialog box
327 UINT ACTION_DialogBox( MSIPACKAGE* package, LPCWSTR szDialogName )
329 UINT r = ERROR_SUCCESS;
331 if( package->next_dialog )
332 ERR("Already a next dialog... ignoring it\n");
333 package->next_dialog = NULL;
336 * Dialogs are chained by filling in the next_dialog member
337 * of the package structure, then terminating the current dialog.
338 * The code below sees the next_dialog member set, and runs the
340 * We fall out of the loop below if we come across a modeless
341 * dialog, as it returns ERROR_IO_PENDING when we try to run
344 r = event_do_dialog( package, szDialogName, NULL, TRUE );
345 while( r == ERROR_SUCCESS && package->next_dialog )
347 LPWSTR name = package->next_dialog;
349 package->next_dialog = NULL;
350 r = event_do_dialog( package, name, NULL, TRUE );
354 if( r == ERROR_IO_PENDING )
360 static UINT ControlEvent_SetInstallLevel(MSIPACKAGE* package, LPCWSTR argument,
363 int iInstallLevel = atolW(argument);
365 TRACE("Setting install level: %i\n", iInstallLevel);
367 return MSI_SetInstallLevel( package, iInstallLevel );
370 static UINT ControlEvent_DirectoryListUp(MSIPACKAGE *package, LPCWSTR argument,
373 return msi_dialog_directorylist_up( dialog );
376 static UINT ControlEvent_ReinstallMode(MSIPACKAGE *package, LPCWSTR argument,
379 return msi_set_property( package->db, szReinstallMode, argument );
382 static UINT ControlEvent_Reinstall( MSIPACKAGE *package, LPCWSTR argument,
385 return msi_set_property( package->db, szReinstall, argument );
388 static UINT ControlEvent_ValidateProductID(MSIPACKAGE *package, LPCWSTR argument,
391 LPWSTR key, template;
392 UINT ret = ERROR_SUCCESS;
394 template = msi_dup_property( package->db, szPIDTemplate );
395 key = msi_dup_property( package->db, szPIDKEY );
399 FIXME( "partial stub: template %s key %s\n", debugstr_w(template), debugstr_w(key) );
400 ret = msi_set_property( package->db, szProductID, key );
402 msi_free( template );
407 static const WCHAR end_dialogW[] = {'E','n','d','D','i','a','l','o','g',0};
408 static const WCHAR new_dialogW[] = {'N','e','w','D','i','a','l','o','g',0};
409 static const WCHAR spawn_dialogW[] = {'S','p','a','w','n','D','i','a','l','o','g',0};
410 static const WCHAR spawn_wait_dialogW[] = {'S','p','a','w','n','W','a','i','t','D','i','a','l','o','g',0};
411 static const WCHAR do_actionW[] = {'D','o','A','c','t','i','o','n',0};
412 static const WCHAR add_localW[] = {'A','d','d','L','o','c','a','l',0};
413 static const WCHAR removeW[] = {'R','e','m','o','v','e',0};
414 static const WCHAR add_sourceW[] = {'A','d','d','S','o','u','r','c','e',0};
415 static const WCHAR set_target_pathW[] = {'S','e','t','T','a','r','g','e','t','P','a','t','h',0};
416 static const WCHAR resetW[] = {'R','e','s','e','t',0};
417 static const WCHAR set_install_levelW[] = {'S','e','t','I','n','s','t','a','l','l','L','e','v','e','l',0};
418 static const WCHAR directory_list_upW[] = {'D','i','r','e','c','t','o','r','y','L','i','s','t','U','p',0};
419 static const WCHAR selection_browseW[] = {'S','e','l','e','c','t','i','o','n','B','r','o','w','s','e',0};
420 static const WCHAR reinstall_modeW[] = {'R','e','i','n','s','t','a','l','l','M','o','d','e',0};
421 static const WCHAR reinstallW[] = {'R','e','i','n','s','t','a','l','l',0};
422 static const WCHAR validate_product_idW[] = {'V','a','l','i','d','a','t','e','P','r','o','d','u','c','t','I','D',0};
424 static const struct control_events control_events[] =
426 { end_dialogW, ControlEvent_EndDialog },
427 { new_dialogW, ControlEvent_NewDialog },
428 { spawn_dialogW, ControlEvent_SpawnDialog },
429 { spawn_wait_dialogW, ControlEvent_SpawnWaitDialog },
430 { do_actionW, ControlEvent_DoAction },
431 { add_localW, ControlEvent_AddLocal },
432 { removeW, ControlEvent_Remove },
433 { add_sourceW, ControlEvent_AddSource },
434 { set_target_pathW, ControlEvent_SetTargetPath },
435 { resetW, ControlEvent_Reset },
436 { set_install_levelW, ControlEvent_SetInstallLevel },
437 { directory_list_upW, ControlEvent_DirectoryListUp },
438 { selection_browseW, ControlEvent_SpawnDialog },
439 { reinstall_modeW, ControlEvent_ReinstallMode },
440 { reinstallW, ControlEvent_Reinstall },
441 { validate_product_idW, ControlEvent_ValidateProductID },
445 UINT ControlEvent_HandleControlEvent( MSIPACKAGE *package, LPCWSTR event,
446 LPCWSTR argument, msi_dialog *dialog )
450 TRACE("handling control event %s\n", debugstr_w(event));
452 if (!event) return ERROR_SUCCESS;
454 for (i = 0; control_events[i].event; i++)
456 if (!strcmpW( control_events[i].event, event ))
457 return control_events[i].handler( package, argument, dialog );
459 FIXME("unhandled control event %s arg(%s)\n", debugstr_w(event), debugstr_w(argument));
460 return ERROR_SUCCESS;