📄 endwiz.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/EnhPi3/EndWiz.cpp,v $
* $Date: 2003/05/13 18:41:57 $
*
Description:
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include <stdio.h>
#include "resrc1.h"
#include "Common.h"
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
static HWND hWndYesServer = 0;
static HWND hWndYesBrowser = 0;
static HWND hWndYesAdmin = 0;
static HWND hWndStatusGroup = 0;
static HWND hWndStatus = 0;
extern const char **__ppArgv;
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
LRESULT Internal_doInstall( HWND hDlg )
{
/*
** Enable status windows
*/
::ShowWindow( hWndStatusGroup, SW_NORMAL );
::UpdateWindow( hWndStatusGroup );
::ShowWindow( hWndStatus, SW_NORMAL );
#define SMSG(x) { ::SendMessage( hWndStatus, WM_SETTEXT, 0, (LPARAM)(x) ); }
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
char szBuf2[BUF_SIZE+1];
const char *pExe = 0;
const char *pWork = 0;
int iStartupBrowser;
int iStartupServer;
int iStartupAdmin;
int iRet; /* used as a temporary */
const char *pServiceName = 0;
const char *pSemaphoreName;
const char *pConfigName;
const char *pType;
const char *pOs = 0;
int iServer;
int iErrorCode = 0;
#define INSTALL_ERROR { iErrorCode = __LINE__; goto an_error; }
int iHourGlass = 0;
#define HOURGLASS_ON { if (!iHourGlass) { AD_hourglassOn(); iHourGlass = 1; }; }
#define HOURGLASS_OFF { if (iHourGlass) { AD_hourglassOff(); iHourGlass = 0; }; }
/* --- save configuration file --- */
SMSG( "Writing configuration file" );
if (!AD_writeConfig( __pConfig, __ppArgv[1] ))
{ INSTALL_ERROR; };
/* --- make registry entries --- */
SMSG( "Making registry entries" );
if ( !REG_add() )
{ INSTALL_ERROR; };
/* --- add program files --- */
SMSG( "Adding program files" );
if ( !PM_openConnection() )
{ INSTALL_ERROR; };
if ( !PM_addGroup( "Pi3Web" ) )
{ INSTALL_ERROR; };
pExe = AD_lookupValue( __pConfig, "General", "ExePath" );
pWork = AD_lookupValue( __pConfig, "General", "BinDir" );
sprintf( szBuf2, "\"%s\\Icons.dll\"", pWork );
sprintf( szBuf, "\"%s\" /START %s", pExe, __ppArgv[1] );
if ( !PM_addItem( "Start Server", szBuf, szBuf2, 0, 0, 0, pWork ) )
{ INSTALL_ERROR; };
sprintf( szBuf, "\"%s\" /ADMIN %s", pExe, __ppArgv[1] );
if ( !PM_addItem( "Server Admin", szBuf, szBuf2, 1, 0, 0, pWork ) )
{ INSTALL_ERROR; };
sprintf( szBuf, "\"%s\" /UNINSTALL %s", pExe, __ppArgv[1] );
if ( !PM_addItem( "Uninstall", szBuf, szBuf2, 2, 0, 0, pWork ) )
{ INSTALL_ERROR; };
sprintf( szBuf, "Write.Exe %s\\..\\RELNOTES", pWork );
if ( !PM_addItem( "Release Notes", szBuf, "", 0, 0, 0, pWork ) )
{ INSTALL_ERROR; };
PM_closeConnection();
/* --- is this a service ? --- */
pType = AD_lookupValue( __pConfig, "General", "RunMode" );
iServer = pType && strcmp( pType, "Desktop" );
/* --- remove any old service, in all cases --- */
HOURGLASS_ON;
pServiceName = AD_lookupValue( __pConfig, "General", "ServiceName" );
assert( pServiceName );
if ( !pServiceName ) { INSTALL_ERROR; };
iRet = strncmp( "NT", AD_lookupValue( __pConfig, "General",
"OS" ), 2 ) ? 0 : CTRL_isServiceInstalled( pServiceName );
if ( iRet==-1 ) { INSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** An old service is installed
*/
iRet = CTRL_isServiceRunning( pServiceName );
if ( iRet==-1 ) { INSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** Old service is running, stop it first
*/
SMSG( "Stopping old service" );
iRet = CTRL_stopService( pServiceName );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
SMSG( "Uninstalling old service" );
iRet = CTRL_unInstallService( pServiceName );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
HOURGLASS_OFF;
/* --- install service --- */
HOURGLASS_ON;
if ( iServer )
{
assert( pServiceName );
/*
** Now install the service
*/
sprintf( szBuf, "%s\\%s", pWork, AD_SERVICE_EXECUTABLE );
SMSG( "Installing service" );
iRet = CTRL_installService( pServiceName, szBuf );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
HOURGLASS_OFF;
/* --- remove any desktop mode startup in any case --- */
HOURGLASS_ON;
pOs = AD_lookupValue( __pConfig, "General", "OS" );
assert( pOs );
if ( pOs && strncmp( pOs, "NT", 2 ) )
{
pSemaphoreName = AD_lookupValue( __pConfig, "Startup",
"SemaphoreName" );
assert( pSemaphoreName );
if ( !pSemaphoreName ) { INSTALL_ERROR; };
iRet = CTRL_isStartupInstalled( pSemaphoreName );
if ( iRet==-1 ) { INSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** An old startup is installed
*/
iRet = CTRL_isPi3Running( pSemaphoreName );
if ( iRet==-1 ) { INSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** Old startup is running, stop it first
*/
SMSG( "Stopping old server" );
iRet = CTRL_stopPi3( pSemaphoreName );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
SMSG( "Uninstalling old startup" );
iRet = CTRL_unInstallStartup( pSemaphoreName );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
};
HOURGLASS_OFF;
/* --- install startup for desktop mode --- */
HOURGLASS_ON;
pOs = AD_lookupValue( __pConfig, "General", "OS" );
assert( pOs );
if ( !iServer && pOs && strncmp( pOs, "NT", 2 ) )
{
pSemaphoreName = AD_lookupValue( __pConfig, "Startup",
"SemaphoreName" );
assert( pSemaphoreName );
if ( !pSemaphoreName ) { INSTALL_ERROR; };
/*
** Now install the startup
*/
pConfigName = AD_lookupValue( __pConfig, "Startup",
"ConfigName" );
assert( pConfigName );
if ( !pConfigName ) { INSTALL_ERROR; };
sprintf( szBuf, "%s /START %s", pExe, pConfigName );
SMSG( "Installing startup" );
iRet = CTRL_installStartup( pSemaphoreName, szBuf );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
HOURGLASS_OFF;
/* --- startup server --- */
HOURGLASS_ON;
iStartupServer = ( SendMessage( hWndYesServer, BM_GETCHECK, 0, 0 )
==BST_CHECKED );
if ( iStartupServer )
{
SMSG( "Starting server" );
iRet;
if ( iServer )
{
assert( CTRL_isServiceRunning( pServiceName )==0 );
assert( CTRL_isServiceInstalled( pServiceName )==1 );
assert( pServiceName );
iRet = CTRL_startService( pServiceName );
if ( iRet==-1 ) { INSTALL_ERROR; };
}
else
{
/*
** If the application is already running, then
** stop it
*/
const char *pSemaphoreName = AD_lookupValue(
__pConfig, "Startup", "SemaphoreName" );
if ( !pSemaphoreName ) { INSTALL_ERROR; };
iRet = CTRL_isPi3Running( pSemaphoreName );
if ( iRet==-1 ) { INSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** Application is running, stop it
*/
iRet = CTRL_stopPi3( pSemaphoreName );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
const char *pExe = AD_lookupValue( __pConfig,
"General", "ExePath" );
const char *pConf = AD_lookupValue( __pConfig,
"Startup", "ConfigName" );
assert( pExe && pConf );
if ( !pExe || !pConf ) { INSTALL_ERROR; };
sprintf( szBuf, "\"%s\" /START %s", pExe, pConf );
iRet = CTRL_startPi3( szBuf, pServiceName );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
};
HOURGLASS_OFF;
/* --- startup browser --- */
HOURGLASS_ON;
iStartupBrowser = ( iStartupServer &&
SendMessage( hWndYesBrowser, BM_GETCHECK, 0, 0 )==BST_CHECKED );
assert( AD_lookupValue( __pConfig, "Identity", "URL" ) );
if ( iStartupBrowser )
{
SMSG( "Starting browser" );
assert( AD_lookupValue( __pConfig, "Identity", "URL" ) );
if ( (int)::ShellExecute( hDlg,
"open",
AD_lookupValue( __pConfig, "Identity", "URL" ),
NULL,
NULL,
SW_SHOWNORMAL)<32 )
{
/*
** This is not such a big deal
*/
::MessageBox( GetParent( hDlg ),
"Unable to start web browser to view server home page. \
\n\nPlease ensure that you have a default web browser (e.g. Microsoft Internet Explorer or \
Netscape Navigator) installed.\n\nInstallation of the Pi3Web has successfully completed.",
"Starting Default Web Browser", MB_OK | MB_ICONEXCLAMATION );
};
};
HOURGLASS_OFF;
/* --- startup admin --- */
HOURGLASS_ON;
iStartupAdmin = ( SendMessage( hWndYesAdmin, BM_GETCHECK, 0, 0 )
==BST_CHECKED );
if ( iStartupAdmin )
{
SMSG( "Starting admin" );
iRet;
const char *pExe = AD_lookupValue( __pConfig,
"General", "ExePath" );
const char *pConf = AD_lookupValue( __pConfig,
"Startup", "ConfigName" );
assert( pExe && pConf );
if ( !pExe || !pConf ) { INSTALL_ERROR; };
sprintf( szBuf, "\"%s\" /ADMIN %s", pExe, pConf );
iRet = CTRL_startPi3( szBuf, pServiceName );
if ( iRet==-1 ) { INSTALL_ERROR; };
};
HOURGLASS_OFF;
/* --- done! --- */
return (TRUE); // AD_close( hDlg );
an_error:
HOURGLASS_OFF;
PM_closeConnection();
sprintf( szBuf, "An error occurred \
configuring the server. Please run uninstall, check for free disk space \
and try again. Internal error code (%d).", iErrorCode );
::MessageBox( GetParent( hDlg ), szBuf, "Installation Error", MB_OK );
return (TRUE); //AD_close( hDlg );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
hWndYesServer = GetDlgItem( hDlg, IDC_YESSERVER );
hWndYesBrowser = GetDlgItem( hDlg, IDC_YESBROWSER );
hWndYesAdmin = GetDlgItem( hDlg, IDC_YESADMIN );
hWndStatusGroup = GetDlgItem( hDlg, IDC_STATUSGROUP );
hWndStatus = GetDlgItem( hDlg, IDC_STATUS );
assert( hWndYesServer && hWndYesBrowser && hWndYesAdmin );
assert( hWndStatusGroup && hWndStatus );
SendMessage( hWndYesServer, BM_SETCHECK, BST_CHECKED, 0 );
SendMessage( hWndYesBrowser, BM_SETCHECK, BST_CHECKED, 0 );
SendMessage( hWndYesAdmin, BM_SETCHECK, BST_CHECKED, 0 );
break;
case WM_COMMAND:
switch( GET_WM_COMMAND_ID( wParam, lParam ) )
{
case IDC_YESSERVER:
if ( GET_WM_COMMAND_CMD( wParam, lParam )==BN_CLICKED )
{
if ( SendMessage( hWndYesServer, BM_GETCHECK, 0, 0 )
==BST_CHECKED )
{
::EnableWindow( hWndYesBrowser, TRUE );
::SendMessage( hWndYesBrowser, BM_SETCHECK,
BST_CHECKED, 0 );
}
else
{
::EnableWindow( hWndYesBrowser, FALSE );
::SendMessage( hWndYesBrowser, BM_SETCHECK,
BST_UNCHECKED, 0 );
}
};
break;
default:;
};
break;
case WM_NOTIFY:
switch( ((NMHDR *)lParam)->code )
{
case PSN_QUERYCANCEL:
return AD_cancelSetup( hDlg );
case PSN_SETACTIVE:
PropSheet_SetWizButtons( GetParent( hDlg ),
PSWIZB_BACK | PSWIZB_FINISH );
break;
case PSN_KILLACTIVE:
break;
case PSN_WIZFINISH:
return Internal_doInstall( hDlg );
};
break;
default:
return (FALSE);
};
return (TRUE);
}
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
DLGPROC fnEndWizard = (DLGPROC)DialogProc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -