📄 pmain.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/PMain.cpp,v $
* $Date: 2004/07/04 19:32:22 $
*
Description:
This file is a bit of a mess while I sort out what sort of main window
it should have.
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include <stdio.h>
#include "PIString.h"
#include "MiscUtil.h"
#include "resrc1.h"
#include "Common.h"
/*____________________________________________________________________________*\
*
Description:
Values for substitution
\*____________________________________________________________________________*/
#define AD_WNDCLASS "Ad class"
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
static HWND __hPropSheet = 0;
PTConfig __pConfig = 0;
static const char **__ppArgv = 0;
static const char *__pSemaphoreName = 0;
static HWND __hStatusWindow = 0;
static int __iChanged = 0;
#if defined(NDEBUG)
# define AD_MUSTBETRUE(x) x
#else
# define AD_MUSTBETRUE(x) assert(x)
#endif
#define TITLE "Pi3Web Server Admin"
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 for true, 0 for false and -1 for failure.
\*____________________________________________________________________________*/
static int Internal_isServiceInstalled()
{
const char *pServiceName = AD_lookupValue( __pConfig, "General",
"ServiceName" );
return CTRL_isServiceInstalled( pServiceName );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 for true and -1 for failure.
\*____________________________________________________________________________*/
static int Internal_installService()
{
/*
** Get command line of server
*/
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
const char *pServiceName = AD_lookupValue( __pConfig, "General",
"ServiceName" );
/*
** Get commandline
*/
sprintf( szBuf, "%s\\bin\\%s", AD_SERVICE_EXECUTABLE,
AD_lookupValue( __pConfig, "General", "InstallDir" ) );
return CTRL_installService( pServiceName, szBuf );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 for true and -1 for failure.
\*____________________________________________________________________________*/
static int Internal_unInstallService()
{
const char *pServiceName = AD_lookupValue( __pConfig, "General",
"ServiceName" );
return CTRL_unInstallService( pServiceName );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Start server with appropriate messages. Starts the server as either
a system service or an application. Assumes the server is not already
running.
Returns 1 on success, and -1 on failure.
\*____________________________________________________________________________*/
static int Internal_startServer(int iService)
{
/*
** Get command line of server
*/
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
int iRet;
if ( iService )
{
/*
** Service
*/
/*
** Firstly, make sure the service is installed
*/
int iInstalled = Internal_isServiceInstalled();
if ( iInstalled==-1 )
{ return -1; };
if ( !iInstalled )
{
if ( Internal_installService()!=1 )
{ return -1; };
};
const char *pServiceName = AD_lookupValue( __pConfig, "General",
"ServiceName" );
iRet = CTRL_startService( pServiceName );
}
else
{
/*
** Desktop
*/
/*
** Get commandline and semaphore name
*/
sprintf( szBuf, "%s /START %s", __ppArgv[0], __ppArgv[1] );
iRet = CTRL_startPi3( szBuf, __pSemaphoreName );
};
return iRet;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 on success, and -1 on failure.
\*____________________________________________________________________________*/
static int Internal_stopServer(int iService)
{
int iRet;
if ( iService )
{
/*
** Service
*/
const char *pServiceName = AD_lookupValue( __pConfig, "General",
"ServiceName" );
iRet = CTRL_stopService( pServiceName );
}
else
{
/*
** Desktop
*/
/*
** Get semaphore name
*/
iRet = CTRL_stopPi3( __pSemaphoreName );
};
return iRet;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 for true, 0 for false and -1 for failure.
\*____________________________________________________________________________*/
static int Internal_isServerRunning(int iService)
{
int iRet;
if ( iService )
{
/*
** Service
*/
const char *pServiceName = AD_lookupValue( __pConfig, "General",
"ServiceName" );
iRet = CTRL_isServiceRunning( pServiceName );
}
else
{
/*
** Desktop
*/
/*
** Get semaphore name
*/
iRet = CTRL_isPi3Running( __pSemaphoreName );
};
return iRet;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Returns 1 for true and -1 for failure.
\*____________________________________________________________________________*/
static int Internal_applyChanges()
{
/*
** Is this a service or no?
*/
const char *pType = AD_lookupValue( __pConfig, "General", "RunMode" );
int iService = ( pType && strcmp( pType, "Desktop" ) );
/*
** Is the server current running or no?
*/
int iRunning = Internal_isServerRunning(iService);
if ( iRunning==-1 )
{ return -1; };
/*
** Stop the server if it is running
*/
if ( iRunning )
{
if ( Internal_stopServer(iService)==-1 )
{ return -1; };
::Sleep(100);
};
/*
** Write out configuration values
*/
AD_writeConfig( __pConfig, __ppArgv[1] );
/*
** If the server was running then start ip up again
*/
if ( iRunning )
{
if ( Internal_startServer(iService)!=1 )
{ return -1; };
};
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
void AD_Changed( HWND __hDlg ) {
__iChanged = 1;
PropSheet_Changed( GetParent( __hDlg ), __hDlg );
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
void AD_UnChanged( HWND __hDlg ) {
__iChanged = 0;
PropSheet_UnChanged( GetParent( __hDlg ), __hDlg );
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -