xref: /trunk/main/setup_native/source/win32/customactions/quickstarter/shutdown_quickstart.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "quickstarter.hxx"
29 #include <setup_native/qswin32.h>
30 
31 static BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
32 {
33     MSIHANDLE   hMSI = static_cast< MSIHANDLE >( lParam );
34     CHAR    szClassName[sizeof(QUICKSTART_CLASSNAMEA) + 1];
35 
36     int nCharsCopied = GetClassName( hWnd, szClassName, sizeof( szClassName ) );
37 
38     if ( nCharsCopied && !stricmp( QUICKSTART_CLASSNAMEA, szClassName ) )
39     {
40         DWORD   dwProcessId;
41 
42         if ( GetWindowThreadProcessId( hWnd, &dwProcessId ) )
43         {
44             std::string sImagePath = GetProcessImagePath( dwProcessId );
45             std::string sOfficeImageDir = GetOfficeInstallationPath( hMSI ) + "program\\";
46 
47             if ( !strnicmp( sImagePath.c_str(), sOfficeImageDir.c_str(), sOfficeImageDir.length() ) )
48             {
49                 UINT    uMsgShutdownQuickstart = RegisterWindowMessageA( SHUTDOWN_QUICKSTART_MESSAGEA );
50 
51                 if ( uMsgShutdownQuickstart )
52                     SendMessageA( hWnd, uMsgShutdownQuickstart, 0, 0 );
53 
54 
55                 HANDLE  hProcess = OpenProcess( SYNCHRONIZE, FALSE, dwProcessId );
56 
57                 if ( hProcess )
58                 {
59                     WaitForSingleObject( hProcess, 30000 ); // Wait at most 30 seconds for process to terminate
60                     CloseHandle( hProcess );
61                 }
62 
63                 return FALSE;
64             }
65 
66         }
67     }
68 
69     return TRUE;
70 }
71 
72 
73 extern "C" UINT __stdcall ShutDownQuickstarter( MSIHANDLE hMSI )
74 {
75     EnumWindows( EnumWindowsProc, hMSI );
76 
77     return ERROR_SUCCESS;
78 }
79 
80