📄 uninstal.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/Uninstal.cpp,v $
* $Date: 2003/05/13 18:41:59 $
*
Description:
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <assert.h>
#include <stdio.h>
#include "Common.h"
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
extern PTConfig __pConfig;
static const char **__ppArgv = 0;
static const char *__pSemaphoreName = 0;
#define TITLE "Pi3 Uninstall"
#if 0
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static HWND __hWndStatus = 0;
static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
__hWndStatus = ::GetDlgItem( hDlg, IDC_STATUS );
break;
default:
return (FALSE);
};
return (TRUE);
}
#endif
#if 0
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 on success, 0 on failure.
\*____________________________________________________________________________*/
int Internal_deltree( const char *pDirectory );
int Internal_recursiveDeltree( const char *pDirectory,
HANDLE hFind, WIN32_FIND_DATA &tData )
{
while( ::FindNextFile( hFind, &tData ) )
{
/*
** Ignore special files '.' and '..'
*/
int iLen = strlen( tData.cFileName );
if ( iLen>=1 && tData.cFileName[0]=='.' )
{
if ( iLen==1 || ( iLen==2 && tData.cFileName[1]=='.' ) )
{ continue; };
};
PIString sFullFile( pDirectory );
sFullFile.Concatenate( "\\" );
sFullFile.Concatenate( tData.cFileName );
//MessageBox( NULL, sFullFile, tData.cFileName, MB_OK );
/*
** If this is a directory tranverse into it
*/
if ( tData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
if ( !Internal_deltree( sFullFile ) )
{ return 0; };
}
else if ( !::DeleteFile( sFullFile ) )
{ return 0; };
};
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 on success, 0 on failure.
\*____________________________________________________________________________*/
int Internal_deltree( const char *pDirectory )
{
return 0;
WIN32_FIND_DATA tData;
PIString sTmp( pDirectory );
sTmp.Concatenate( "\\*.*" );
HANDLE hFind = ::FindFirstFile( sTmp, &tData );
if ( hFind==INVALID_HANDLE_VALUE )
{ return 0; };
int iRet = Internal_recursiveDeltree( pDirectory, hFind, tData );
::FindClose( hFind );
if ( iRet )
{ return ::RemoveDirectory( pDirectory ) ? 1 : 0; };
return iRet;
}
#endif
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
int AD_uninstall( HINSTANCE hInstance, int iError )
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
int iRet;
const char *pInstall;
/*
** Give message
*/
if ( !iError )
{
if ( MessageBox( NULL, "This program will uninstall Pi3Web HTTP server \
including all registry entries and installed files. \n\n\
Do you want to continue?", "Uninstall", MB_ICONEXCLAMATION | MB_YESNO)!=IDYES )
{ return 1; };
};
#if 0
/*
** Make uninstall dialog
*/
HWND hDlg = ::CreateDialog(
__hInstance,
MAKEINTRESOURCE( IDD_STATUS ),
NULL,
DialogProc,
);
#endif
/*
** Attempt to load configuration file
*/
if ( !__pConfig )
{
assert( __ppArgv );
__pConfig = AD_loadConfig( __ppArgv[1] );
if ( !__pConfig && !iError )
{
sprintf( szBuf, "The configuration file'%s' could not be opened. \n\n\
Uninstall will not be able to shutdown the server and remove installed \
system services.", __ppArgv[1] );
MessageBox( NULL, szBuf, "Uninstall - Configuration Not Found", MB_OK );
};
};
const char *pType;
int iServer;
const char *pSemaphoreName;
const char *pServiceName;
#define UNINSTALL_ERROR { goto uninstall_error; };
/*
** Delete registry entries
*/
REG_delete();
/*
** Remove program files
*/
PM_openConnection();
PM_deleteGroup( "Pi3Web" );
PM_closeConnection();
/*
** See what type of server this is
*/
pType = AD_lookupValue( __pConfig, "General", "RunMode" );
iServer = pType && strcmp( pType, "Desktop" );
/*
** Remove server from any startup groups, or remove service
*/
/* --- service --- */
pServiceName = AD_lookupValue( __pConfig, "General", "ServiceName" );
iRet = 0;
if ( iServer )
{
iRet = strncmp( "NT", AD_lookupValue( __pConfig, "General",
"OS" ), 2 ) ? 0 : CTRL_isServiceInstalled( pServiceName );
};
assert( pServiceName );
if ( !pServiceName ) { UNINSTALL_ERROR; };
if ( iRet==-1 ) { UNINSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** An old service is installed
*/
iRet = CTRL_isServiceRunning( pServiceName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** Old service is running, stop it first
*/
iRet = CTRL_stopService( pServiceName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
};
iRet = CTRL_unInstallService( pServiceName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
};
/* --- desktop --- */
pSemaphoreName = AD_lookupValue( __pConfig, "Startup", "SemaphoreName" );
assert( pSemaphoreName );
if ( !pSemaphoreName ) { UNINSTALL_ERROR; };
iRet = iServer ? 0 : CTRL_isStartupInstalled( pSemaphoreName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** Startup is installed
*/
iRet = CTRL_isPi3Running( pSemaphoreName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** Startup is running, stop it first
*/
iRet = CTRL_stopPi3( pSemaphoreName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
};
iRet = CTRL_unInstallStartup( pSemaphoreName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
};
/*
** Stop the server if it is running
*/
iRet = iServer ? 0 : CTRL_isPi3Running( pSemaphoreName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
if ( iRet /* ==1 */ )
{
/*
** Startup is running, stop it first
*/
iRet = CTRL_stopPi3( pSemaphoreName );
if ( iRet==-1 ) { UNINSTALL_ERROR; };
};
/*
** Last thing, remove the installation directory
*/
pInstall = AD_lookupValue( __pConfig, "General",
"InstallDir" );
if ( pInstall && !iError )
{
#if 0
sprintf( szBuf, "Uninstall will now delete the directory '%s' \
and its entire contents.\n\nAre you sure you want to do this?", pInstall );
if ( MessageBox( NULL, szBuf, "Uninstall", MB_ICONEXCLAMATION | MB_YESNO
)==IDYES )
{
// if ( !Internal_deltree( pInstall ) )
// { UNINSTALL_ERROR; };
};
#endif
sprintf( szBuf, "Uninstall has removed installed program items and \
registry entries.\n\nTo complete uninstallation you should delete the directory '%s'.",
pInstall );
::MessageBox( NULL, szBuf, "Uninstall", MB_OK | MB_ICONEXCLAMATION );
};
return 1;
uninstall_error:
if ( !iError )
{
MessageBox( NULL, "Uninstallation was not fully successful. \
Not all components have been removed.",
"Uninstall", MB_OK );
};
return 0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Windows entry point for uninstall
\*____________________________________________________________________________*/
int AD_uninstallMain( HINSTANCE hInstance, int iArgc,
const char *ppArgv[] )
{
int iRet;
/*
** Check that argument 1 exists and is an existing configuration
** file
*/
if ( iArgc<=1 )
{
/*
** No configuration file specified
*/
MessageBox( NULL, "No configuration file specified", "Error in \
parameters", MB_OK );
return -1;
};
__ppArgv = ppArgv;
assert( __ppArgv );
/*
** Semaphore name for application is the full
** path to the configuration file in upper case
*/
PIString sSemaphoreName;
CTRL_semaphoreNameFromConfigPath( __ppArgv[1], sSemaphoreName );
__pSemaphoreName = sSemaphoreName;
AD_hourglassInit();
iRet = AD_uninstall( hInstance, 0 );
AD_hourglassDestroy();
return iRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -