Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: installer/src/custom-action/close_application.cpp

Issue 5219280069066752: Issue #1186 - Change names that appear in the custom action (Closed)
Left Patch Set: Created Oct. 2, 2014, 6:51 p.m.
Right Patch Set: Created Jan. 4, 2015, 7 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /** 1 /**
2 * \file close_application.cpp 2 * \file close_application.cpp
3 */ 3 */
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "session.h" 7 #include "session.h"
8 #include "property.h" 8 #include "property.h"
9 #include "database.h" 9 #include "database.h"
10 #include "process.h" 10 #include "process.h"
(...skipping 11 matching lines...) Expand all
22 22
23 ProcessCloser browserCloser ; 23 ProcessCloser browserCloser ;
24 24
25 ProcessCloser engineCloser ; 25 ProcessCloser engineCloser ;
26 26
27 public: 27 public:
28 InternetExplorerCloser() 28 InternetExplorerCloser()
29 : snapshot(), browserCloser( snapshot, browserNames ), engineCloser( snapsho t, engineNames ) 29 : snapshot(), browserCloser( snapshot, browserNames ), engineCloser( snapsho t, engineNames )
30 {} 30 {}
31 31
32 void refresh() 32 void Refresh()
33 { 33 {
34 snapshot.refresh() ; 34 snapshot.Refresh() ;
35 browserCloser.refresh() ; 35 browserCloser.Refresh() ;
36 engineCloser.refresh() ; 36 engineCloser.Refresh() ;
37 } 37 }
38 38
39 bool isRunning() 39 bool IsRunning()
Felix Dahlke 2014/10/15 02:46:57 Functions should start with an upper case letter.
Eric 2014/10/15 15:30:44 Missed that one, apparently.
40 { 40 {
41 return browserCloser.isRunning() || engineCloser.isRunning() ; 41 return browserCloser.IsRunning() || engineCloser.IsRunning() ;
42 } 42 }
43 43
44 bool shutDown() 44 bool ShutDown()
45 { 45 {
46 if ( browserCloser.isRunning() && ! browserCloser.shutDown() ) 46 if ( browserCloser.IsRunning() && ! browserCloser.ShutDown() )
47 { 47 {
48 // Assert IE is still running 48 // Assert IE is still running
49 // This is after we've tried to shut it down, so we fail 49 // This is after we've tried to shut it down, so we fail
50 return false ; 50 return false ;
51 } 51 }
52 if ( engineCloser.isRunning() && ! engineCloser.shutDown() ) 52 if ( engineCloser.IsRunning() && ! engineCloser.ShutDown() )
53 { 53 {
54 // Assert the engine is still running 54 // Assert the engine is still running
55 // This is after IE has shut down itself and after we've tried to shut dow n the engine. Whatever. 55 // This is after IE has shut down itself and after we've tried to shut dow n the engine. Whatever.
56 return false ; 56 return false ;
57 } 57 }
58 return true ; 58 return true ;
59 } 59 }
60 } ; 60 } ;
61 61
62 62
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // MSI property BROWSERRUNNING is one of the return values of this function. 124 // MSI property BROWSERRUNNING is one of the return values of this function.
125 Property browserRunning( session, L"BROWSERRUNNING" ) ; 125 Property browserRunning( session, L"BROWSERRUNNING" ) ;
126 Property browserClosed( session, L"BROWSERCLOSED" ) ; 126 Property browserClosed( session, L"BROWSERCLOSED" ) ;
127 127
128 // Instantiation of ProcessCloser takes a snapshot. 128 // Instantiation of ProcessCloser takes a snapshot.
129 InternetExplorerCloser iec ; 129 InternetExplorerCloser iec ;
130 130
131 /* 131 /*
132 * We take the short path through this function if neither IE nor engine is not running at the outset. 132 * We take the short path through this function if neither IE nor engine is not running at the outset.
133 */ 133 */
134 if ( ! iec.isRunning() ) 134 if ( ! iec.IsRunning() )
135 { 135 {
136 browserRunning = L"0" ; // The browser is not running. 136 browserRunning = L"0" ; // The browser is not running.
137 browserClosed = L"0" ; // We didn't close the browser (and we could n't have). 137 browserClosed = L"0" ; // We didn't close the browser (and we could n't have).
138 session.log( "IE not running. No issue with reboot policy." ) ; 138 session.Log( "IE not running. No issue with reboot policy." ) ;
139 return ERROR_SUCCESS ; 139 return ERROR_SUCCESS ;
140 } 140 }
141 141
142 /* 142 /*
143 * As a (potentially) user-driven function, a state machine manages control flow. 143 * As a (potentially) user-driven function, a state machine manages control flow.
144 * The states are organized around the policy stances. 144 * The states are organized around the policy stances.
145 */ 145 */
146 enum PolicyState { 146 enum PolicyState {
147 // Non-terminal states 147 // Non-terminal states
148 notKnown, // We don't know the user's stance at all 148 notKnown, // We don't know the user's stance at all
(...skipping 15 matching lines...) Expand all
164 */ 164 */
165 std::wstring avoidReboot = Property( session, L"AVOIDREBOOT" ) ; 165 std::wstring avoidReboot = Property( session, L"AVOIDREBOOT" ) ;
166 std::transform( avoidReboot.begin(), avoidReboot.end(), avoidReboot.begin(), ::towupper ) ; 166 std::transform( avoidReboot.begin(), avoidReboot.end(), avoidReboot.begin(), ::towupper ) ;
167 if ( avoidReboot == L"" ) 167 if ( avoidReboot == L"" )
168 { 168 {
169 state = notKnown ; 169 state = notKnown ;
170 } 170 }
171 else if ( avoidReboot == L"NO" ) 171 else if ( avoidReboot == L"NO" )
172 { 172 {
173 state = allow ; 173 state = allow ;
174 session.log( "Reboot allowed on command line." ) ; 174 session.Log( "Reboot allowed on command line." ) ;
175 } 175 }
176 else if ( avoidReboot == L"PASSIVE" ) 176 else if ( avoidReboot == L"PASSIVE" )
177 { 177 {
178 state = passive ; 178 state = passive ;
179 session.log( "Reboot avoided on command line." ) ; 179 session.Log( "Reboot avoided on command line." ) ;
180 } 180 }
181 else if ( avoidReboot == L"ACTIVE" ) 181 else if ( avoidReboot == L"ACTIVE" )
182 { 182 {
183 state = active ; 183 state = active ;
184 } 184 }
185 else if ( avoidReboot == L"AUTOMATIC" ) 185 else if ( avoidReboot == L"AUTOMATIC" )
186 { 186 {
187 state = automatic ; 187 state = automatic ;
188 } 188 }
189 else 189 else
(...skipping 26 matching lines...) Expand all
216 // Assert installer is running without user interaction. 216 // Assert installer is running without user interaction.
217 interactive = false ; 217 interactive = false ;
218 if ( state == notKnown ) 218 if ( state == notKnown )
219 { 219 {
220 // Assert AVOIDREBOOT was not specified 220 // Assert AVOIDREBOOT was not specified
221 /* 221 /*
222 * This is where we specify default behavior for non-interactive operati on. 222 * This is where we specify default behavior for non-interactive operati on.
223 * The choice of "allow" makes it act like other installers, which is to make no effort to avoid a reboot after installation. 223 * The choice of "allow" makes it act like other installers, which is to make no effort to avoid a reboot after installation.
224 */ 224 */
225 state = allow ; 225 state = allow ;
226 » session.log( "Reboot allowed by default in non-interactive session." ) ; 226 » session.Log( "Reboot allowed by default in non-interactive session." ) ;
227 } 227 }
228 else if ( state == active ) 228 else if ( state == active )
229 { 229 {
230 throw std::runtime_error( "AVOIDREBOOT=ACTIVE in non-interative session is not consistent" ) ; 230 throw std::runtime_error( "AVOIDREBOOT=ACTIVE in non-interative session is not consistent" ) ;
231 } 231 }
232 // Assert state is one of { allow, passive, automatic } 232 // Assert state is one of { allow, passive, automatic }
233 } 233 }
234 else 234 else
235 { 235 {
236 throw std::runtime_error( "unrecognized value for UILevel" ) ; 236 throw std::runtime_error( "unrecognized value for UILevel" ) ;
237 } 237 }
238 238
239 /* 239 /*
240 * Now that preliminaries are over, we set up the accessors for UI text. 240 * Now that preliminaries are over, we set up the accessors for UI text.
241 * We only use the object 'messageText' for interactive sessions, but it's c heap to set up and a hassle to conditionalize. 241 * We only use the object 'messageText' for interactive sessions, but it's c heap to set up and a hassle to conditionalize.
242 * 242 *
243 * The key "close_ie" is the component name within the file "close_ie.wxi" t hat defines rows in the localization table. 243 * The key "close_ie" is the component name within the file "close_ie.wxi" t hat defines rows in the localization table.
244 * The identifiers for the messageText.text() function are defined within th at file. 244 * The identifiers for the messageText.text() function are defined within th at file.
245 */ 245 */
246 InstallationDatabase db( session ) ; 246 InstallationDatabase db( session ) ;
247 CustomMessageText messageText( db, L"close_ie" ) ; 247 CustomMessageText messageText( db, L"close_ie" ) ;
248 248
249 /* 249 /*
250 * State machine: Loop through non-terminal states. 250 * State machine: Loop through non-terminal states.
251 * 251 *
252 * Loop invariant: IE was running at last check, that is, iec.isRunning() wo uld return true. 252 * Loop invariant: IE was running at last check, that is, iec.IsRunning() wo uld return true.
253 */ 253 */
254 while ( state <= automatic ) // "automatic" is the non-terminal sta te with the highest value 254 while ( state <= automatic ) // "automatic" is the non-terminal sta te with the highest value
255 { 255 {
256 switch ( state ) 256 switch ( state )
257 { 257 {
258 case notKnown: 258 case notKnown:
259 /* 259 /*
260 * Precondition: interactive session 260 * Precondition: interactive session
261 * 261 *
262 * Ask the user "Would you like to close IE and avoid reboot?" 262 * Ask the user "Would you like to close IE and avoid reboot?"
263 * Yes -> Close IE somehow. Goto partKnown. 263 * Yes -> Close IE somehow. Goto partKnown.
264 * No -> Install with reboot. Goto allow. 264 * No -> Install with reboot. Goto allow.
265 * Cancel -> terminate installation. Goto abort. 265 * Cancel -> terminate installation. Goto abort.
266 */ 266 */
267 » { 267 {
268 » int x = session.WriteMessage( IMB( messageText.text( L"dialog_unknown" ), IMB::warningBox, IMB::yesNoCancel, IMB::defaultButtonThree ) ) ; 268 int x = session.WriteMessage(IMB(
269 messageText.Text(L"dialog_unknown"),
270 IMB::Box::warning, IMB::ButtonSet::yesNoCancel, IMB::DefaultButton:: three
271 )) ;
269 switch ( x ) 272 switch ( x )
270 { 273 {
271 case IDYES: 274 case IDYES:
272 state = partKnown ; 275 state = partKnown ;
273 break ; 276 break ;
274 case IDNO: 277 case IDNO:
275 state = allow ; 278 state = allow ;
276 » session.log( "User chose to allow reboot" ) ; 279 » session.Log( "User chose to allow reboot" ) ;
277 break ; 280 break ;
278 case IDCANCEL: 281 case IDCANCEL:
279 state = abort ; 282 state = abort ;
280 » session.log( "User cancelled installation" ) ; 283 » session.Log( "User cancelled installation" ) ;
281 break ; 284 break ;
282 default: 285 default:
283 throw UnexpectedReturnValueFromMessageBox() ; 286 throw UnexpectedReturnValueFromMessageBox() ;
284 } 287 }
285 } 288 }
286 break ; 289 break ;
287 290
288 case partKnown: 291 case partKnown:
289 /* 292 /*
290 * Precondition: interactive session 293 * Precondition: interactive session
291 * 294 *
292 * Ask the user "Would you like the installer to close IE for you?" 295 * Ask the user "Would you like the installer to close IE for you?"
293 * Yes -> Goto automatic 296 * Yes -> Goto automatic
294 * No -> Goto active 297 * No -> Goto active
295 * Cancel -> Goto notKnown 298 * Cancel -> Goto notKnown
296 */ 299 */
297 { 300 {
298 » int x = session.WriteMessage( IMB( messageText.text( L"dialog_part_kno wn" ), IMB::warningBox, IMB::yesNoCancel, IMB::defaultButtonThree ) ) ; 301 » int x = session.WriteMessage(IMB(
302 messageText.Text(L"dialog_part_known"),
303 IMB::Box::warning, IMB::ButtonSet::yesNoCancel, IMB::DefaultButton:: three
304 )) ;
299 switch ( x ) 305 switch ( x )
300 { 306 {
301 case IDYES: 307 case IDYES:
302 state = automatic ; 308 state = automatic ;
303 break ; 309 break ;
304 case IDNO: 310 case IDNO:
305 state = active ; 311 state = active ;
306 break ; 312 break ;
307 case IDCANCEL: 313 case IDCANCEL:
308 state = notKnown ; 314 state = notKnown ;
309 break ; 315 break ;
310 default: 316 default:
311 throw UnexpectedReturnValueFromMessageBox() ; 317 throw UnexpectedReturnValueFromMessageBox() ;
312 } 318 }
313 } 319 }
314 break ; 320 break ;
315 321
316 case active: 322 case active:
317 /* 323 /*
318 * Precondition: interactive session 324 * Precondition: interactive session
319 * 325 *
320 * IE is no longer running -> Goto success 326 * IE is no longer running -> Goto success
321 * IE is still running -> 327 * IE is still running ->
322 * Ask the user to close IE manually 328 * Ask the user to close IE manually
323 * OK -> re-enter this state 329 * OK -> re-enter this state
324 * Cancel -> Goto notKnown 330 * Cancel -> Goto notKnown
325 */ 331 */
326 { 332 {
327 » int x = session.WriteMessage( IMB( messageText.text( L"dialog_active_r etry" ), IMB::warningBox, IMB::okCancel, IMB::defaultButtonOne ) ) ; 333 » int x = session.WriteMessage(IMB(
334 messageText.Text(L"dialog_active_retry"),
335 IMB::Box::warning, IMB::ButtonSet::okCancel, IMB::DefaultButton::one
336 )) ;
328 switch ( x ) 337 switch ( x )
329 { 338 {
330 case IDOK: 339 case IDOK:
331 /* 340 /*
332 * Refresh our knowledge of whether IE is running. 341 * Refresh our knowledge of whether IE is running.
333 * If it is, we display the dialog again. The state doesn't change, so we just iterate again. 342 * If it is, we display the dialog again. The state doesn't change, so we just iterate again.
334 * If it's not, then the user has closed IE and we're done. 343 * If it's not, then the user has closed IE and we're done.
335 */ 344 */
336 » iec.refresh() ; 345 » iec.Refresh() ;
337 » if ( ! iec.isRunning() ) 346 » if ( ! iec.IsRunning() )
338 { 347 {
339 state = success ; 348 state = success ;
340 » session.log( "User shut down IE manually." ) ; 349 » session.Log( "User shut down IE manually." ) ;
341 } 350 }
342 break ; 351 break ;
343 case IDCANCEL: 352 case IDCANCEL:
344 state = notKnown ; 353 state = notKnown ;
345 break ; 354 break ;
346 default: 355 default:
347 throw UnexpectedReturnValueFromMessageBox() ; 356 throw UnexpectedReturnValueFromMessageBox() ;
348 } 357 }
349 } 358 }
350 break ; 359 break ;
351 360
352 case automatic: 361 case automatic:
353 /* 362 /*
354 * Close all known IE instances. 363 * Close all known IE instances.
355 * Unlike other cases, this state starts with an action and not a user q uery. 364 * Unlike other cases, this state starts with an action and not a user q uery.
356 * We first shut down IE, or at least attempt to. 365 * We first shut down IE, or at least attempt to.
357 * 366 *
358 * Succeeded -> Goto success 367 * Succeeded -> Goto success
359 * Failed && interactive -> 368 * Failed && interactive ->
360 * Ask user if they would like to try again 369 * Ask user if they would like to try again
361 * Retry -> re-enter this state 370 * Retry -> re-enter this state
362 * Cancel -> Goto notKnown 371 * Cancel -> Goto notKnown
363 * Failed && not interactive -> Goto abort 372 * Failed && not interactive -> Goto abort
364 */ 373 */
365 { 374 {
366 » bool ieWasClosed = iec.shutDown() ; 375 » bool ieWasClosed = iec.ShutDown() ;
367 » if ( iec.isRunning() ) 376 » if ( iec.IsRunning() )
368 { 377 {
369 » session.log( "Attempt to shut down IE automatically failed." ) ; 378 » session.Log( "Attempt to shut down IE automatically failed." ) ;
370 if ( interactive ) 379 if ( interactive )
371 { 380 {
372 // Assert Interactive session and IE did not shut down. 381 // Assert Interactive session and IE did not shut down.
373 » int x = session.WriteMessage( IMB( messageText.text( L"dialog_auto matic_retry" ), IMB::warningBox, IMB::retryCancel, IMB::defaultButtonOne ) ) ; 382 » int x = session.WriteMessage(IMB(
383 messageText.Text(L"dialog_automatic_retry"),
384 IMB::Box::warning, IMB::ButtonSet::retryCancel, IMB::DefaultButt on::one
385 )) ;
374 switch ( x ) 386 switch ( x )
375 { 387 {
376 case IDRETRY: 388 case IDRETRY:
377 // Don't change the state. Iterate again. 389 // Don't change the state. Iterate again.
378 break ; 390 break ;
379 case IDCANCEL: 391 case IDCANCEL:
380 state = notKnown ; 392 state = notKnown ;
381 break ; 393 break ;
382 default: 394 default:
383 throw UnexpectedReturnValueFromMessageBox() ; 395 throw UnexpectedReturnValueFromMessageBox() ;
384 } 396 }
385 } 397 }
386 else 398 else
387 { 399 {
388 // Assert Non-interactive session and IE did not shut down. 400 // Assert Non-interactive session and IE did not shut down.
389 state = abort ; 401 state = abort ;
390 » session.log( "Failed to shut down IE automatically." ) ; 402 » session.Log( "Failed to shut down IE automatically." ) ;
391 } 403 }
392 } 404 }
393 else 405 else
394 { 406 {
395 » // Assert IE is not running, so shutDown() succeeded. 407 » // Assert IE is not running, so ShutDown() succeeded.
396 state = success ; 408 state = success ;
397 » session.log( "Automatically shut down IE." ) ; 409 » session.Log( "Automatically shut down IE." ) ;
398 } 410 }
399 } 411 }
400 break; 412 break;
401 } 413 }
402 } 414 }
403 /* 415 /*
404 * State machine: Actions for terminal states. 416 * State machine: Actions for terminal states.
405 */ 417 */
406 switch ( state ) 418 switch ( state )
407 { 419 {
408 case success: 420 case success:
409 » if ( iec.isRunning() ) 421 » if ( iec.IsRunning() )
410 { 422 {
411 browserRunning = L"1" ; 423 browserRunning = L"1" ;
412 browserClosed = L"0" ; 424 browserClosed = L"0" ;
413 } 425 }
414 else 426 else
415 { 427 {
416 browserRunning = L"0" ; 428 browserRunning = L"0" ;
417 browserClosed = L"1" ; 429 browserClosed = L"1" ;
418 } 430 }
419 return ERROR_SUCCESS ; 431 return ERROR_SUCCESS ;
420 break; 432 break;
421 case abort: 433 case abort:
422 return ERROR_INSTALL_USEREXIT ; 434 return ERROR_INSTALL_USEREXIT ;
423 break; 435 break;
424 } 436 }
425 } 437 }
426 catch( std::exception & e ) 438 catch( std::exception & e )
427 { 439 {
428 session.LogNoexcept( "terminated by exception: " + std::string( e.what() ) ) ; 440 session.LogNoexcept( "terminated by exception: " + std::string( e.what() ) ) ;
429 return ERROR_INSTALL_FAILURE ; 441 return ERROR_INSTALL_FAILURE ;
430 } 442 }
431 catch( ... ) 443 catch( ... )
432 { 444 {
433 session.LogNoexcept( "terminated by unknown exception" ) ; 445 session.LogNoexcept( "terminated by unknown exception" ) ;
434 return ERROR_INSTALL_FAILURE ; 446 return ERROR_INSTALL_FAILURE ;
435 } 447 }
436 // Should be unreachable. 448 // Should be unreachable.
437 return ERROR_INSTALL_FAILURE ; 449 return ERROR_INSTALL_FAILURE ;
438 } 450 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld