📄 setup.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/Setup.cpp,v $
* $Date: 2003/05/13 18:41:59 $
*
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:
Definitions and global values
\*____________________________________________________________________________*/
static HWND __hPropSheet = 0;
extern PTConfig __pConfig;
const char **__ppArgv = 0;
static HWND __hStatusWindow = 0;
extern HINSTANCE __hInstance;
#define PI3_WNDCLASS "Pi3SetupWindowBackground"
#if defined(NDEBUG)
# define AD_MUSTBETRUE(x) x
#else
# define AD_MUSTBETRUE(x) assert(x)
#endif
#define TITLE "Pi3 Setup"
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
BOOL AD_cancelSetup( HWND hDlg )
{
if ( MessageBox( GetParent( hDlg ),
"This will cancel installation. Are you sure \
you want to abort installation?",
"Cancel",
MB_YESNO | MB_ICONQUESTION )==IDYES )
{
/* --- rollback installation */
AD_uninstall( __hInstance, 1 );
SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
}
else
{
SetWindowLong( hDlg, DWL_MSGRESULT, TRUE );
}
return (TRUE);
};
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static int Internal_SetInstallDir( PTConfig pConfig )
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
if ( !::GetModuleFileName( NULL, szBuf, BUF_SIZE ) )
{
assert( 0 );
return 0;
};
#if 0
LATER -
this is not going to work because it only gets the MS format
of the file name (not the full path).
/*
** Convert to old 8,3 MSDOS format
*/
WIN32_FIND_DATA tF;
HANDLE hFind = ::FindFirstFile( szBuf &tF );
assert( hFind!=INVALID_HANDLE_VALUE );
::FindClose( hFind );
strncpy( szBuf, tF.cAlternateFileName );
#endif
/* --- set application dir --- */
AD_replaceValue( pConfig, "General", "ExePath", szBuf );
/* --- scan to last '\' and remove it --- */
int iLen = strlen( szBuf );
int i;
for( i=iLen-1; i>=0 && szBuf[i]!='\\' && szBuf[i]!='/'; i-- );
for( ; i>=0 && ( szBuf[i]=='\\' || szBuf[i]=='/'); i-- );
for( ; i>=0 && szBuf[i]!='\\' && szBuf[i]!='/'; i-- );
for( ; i>=0 && ( szBuf[i]=='\\' || szBuf[i]=='/'); i-- );
szBuf[++i] = '\0';
AD_replaceValue( pConfig, "General", "InstallDir", szBuf );
strcat( szBuf, "\\bin" );
AD_replaceValue( pConfig, "General", "BinDir", szBuf );
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static int Internal_SetOS( PTConfig pConfig )
{
OSVERSIONINFO tOS;
tOS.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
if ( GetVersionEx( &tOS )==0 )
{
assert( 0 );
return 0;
};
/*
** Platform IDs
**
VER_PLATFORM_WIN32s Win32s on Windows 3.1.
VER_PLATFORM_WIN32_WINDOWS Win32 on Windows 95.
VER_PLATFORM_WIN32_NT Win32 on Windows NT.
*/
if ( tOS.dwMajorVersion<4 ||
( tOS.dwPlatformId!=VER_PLATFORM_WIN32_WINDOWS &&
tOS.dwPlatformId!=VER_PLATFORM_WIN32_NT )
)
{
MessageBox( NULL, "This software requires Windows 95, Windows NT4.0 \
or greater", "Version Not Supported", MB_OK );
return 0;
};
switch( tOS.dwPlatformId )
{
case VER_PLATFORM_WIN32_WINDOWS:
AD_replaceValue( pConfig, "General", "OS", "W95" );
break;
case VER_PLATFORM_WIN32_NT:
AD_replaceValue( pConfig, "General", "OS", "NT" );
break;
default:
assert( 0 );
};
return 1;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static LRESULT CALLBACK fnWndProc( HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam )
{
switch( uMsg )
{
case WM_CREATE:
::ShowWindow( hWnd, SW_NORMAL );
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = ::BeginPaint( hWnd, &ps );
RECT r;
HFONT hFont = ::CreateFont(
72, // int nHeight,
0, // int nWidth,
0, // int nEscapement,
0, // int nOrientation,
FW_EXTRABOLD, // int fnWeight,
TRUE, // DWORD fdwItalic,
FALSE, // DWORD fdwUnderline,
FALSE, // DWORD fdwStrikeOut,
DEFAULT_CHARSET, // DWORD fdwCharSet,
OUT_DEFAULT_PRECIS, // DWORD fdwOutputPrecision,
CLIP_DEFAULT_PRECIS, // DWORD fdwClipPrecision,
PROOF_QUALITY, // DWORD fdwQuality,
VARIABLE_PITCH | FF_DONTCARE, // DWORD fdwPitchAndFamily,
"Times New Roman" // LPCTSTR lpszFace
);
assert( hFont );
HFONT hOldFont = (HFONT)::SelectObject( hdc, hFont );
::GetClientRect(hWnd, &r);
::SetBkMode(hdc, TRANSPARENT);
#define THE_TEXT "Pi3Web 2.0"
#define THE_TEXT_LEN (sizeof(THE_TEXT)-1)
::SetTextColor( hdc, RGB( 0, 0, 0 ) );
::TextOut(hdc, r.left+12, r.top+8, THE_TEXT, THE_TEXT_LEN );
::SetTextColor( hdc, RGB( 0x7F, 0x7F, 0 ) );
::TextOut(hdc, r.left+11, r.top+9, THE_TEXT, THE_TEXT_LEN );
::SetTextColor( hdc, RGB( 0xFF, 0xFF, 0 ) );
::TextOut(hdc, r.left+10, r.top+10, THE_TEXT, THE_TEXT_LEN );
::SelectObject( hdc, hOldFont );
::DeleteObject( hFont );
::EndPaint( hWnd, &ps );
};
break;
default:
return ::DefWindowProc( hWnd, uMsg, wParam, lParam );
};
return (LRESULT)0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static ATOM Internal_registerClass( HINSTANCE hInstance )
{
WNDCLASS tWC;
memset( &tWC, 0, sizeof( WNDCLASS ) );
tWC.style = CS_GLOBALCLASS;
tWC.lpfnWndProc = fnWndProc;
tWC.hInstance = hInstance;
tWC.hCursor = ::LoadCursor( hInstance, IDC_ARROW );
tWC.hbrBackground = (HBRUSH)(COLOR_BACKGROUND+1);
tWC.lpszClassName = PI3_WNDCLASS;
return ::RegisterClass( &tWC );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_DoPropertySheet( HINSTANCE hInstance )
{
/*
** Create background window
*/
RECT tRect;
::GetWindowRect( ::GetDesktopWindow(), &tRect );
#define MARGIN_SPACE (40)
HWND hBackground = ::CreateWindow(
PI3_WNDCLASS,
"Pi3Web HTTP Server Installation",
WS_POPUP | WS_CLIPCHILDREN | WS_THICKFRAME, // dwStyle,
MARGIN_SPACE,
MARGIN_SPACE,
(tRect.right - tRect.left) - ( 2 * MARGIN_SPACE ),
(tRect.bottom - tRect.top) - ( 2 * MARGIN_SPACE ),
NULL, // hWndParent,
NULL, // hMenu,
hInstance,
0
);
assert( hBackground );
/*
** Setup property sheet data structures
*/
PROPSHEETPAGE psp;
PROPSHEETHEADER psh;
HPROPSHEETPAGE hpsp[NUM_SETUPPAGES];
memset( &psp, 0, sizeof( PROPSHEETPAGE ) );
psp.dwSize = sizeof( PROPSHEETPAGE );
psp.dwFlags = PSP_DEFAULT;
psp.hInstance = hInstance;
int iSheet = 0;
psp.pszTemplate = MAKEINTRESOURCE( IDD_STARTWIZARD );
psp.pfnDlgProc = fnStartWizard;
hpsp[iSheet++] = CreatePropertySheetPage( &psp );
psp.pszTemplate = MAKEINTRESOURCE( IDD_WIZARD2 );
psp.pfnDlgProc = fnWizard2;
hpsp[iSheet++] = CreatePropertySheetPage( &psp );
psp.pszTemplate = MAKEINTRESOURCE( IDD_WIZARD3 );
psp.pfnDlgProc = fnWizard3;
hpsp[iSheet++] = CreatePropertySheetPage( &psp );
if ( !strncmp( AD_lookupValue( __pConfig, "General", "OS" ),
"NT", 2 ) )
{
psp.pszTemplate = MAKEINTRESOURCE( IDD_WIZARD4 );
psp.pfnDlgProc = fnWizard4;
hpsp[iSheet++] = CreatePropertySheetPage( &psp );
};
psp.pszTemplate = MAKEINTRESOURCE( IDD_FINISHWIZARD );
psp.pfnDlgProc = fnEndWizard;
hpsp[iSheet++] = CreatePropertySheetPage( &psp );
/* setup property structure */
memset( &psh, 0, sizeof( PROPSHEETHEADER ) );
psh.dwSize = sizeof( PROPSHEETHEADER );
psh.dwFlags = PSH_MODELESS | PSH_WIZARD | PSH_USEICONID;
psh.hInstance = hInstance;
psh.hwndParent = hBackground;
psh.pszIcon = MAKEINTRESOURCE(IDI_PI3WEB);
psh.nPages = iSheet;
psh.phpage = hpsp;
psh.pszCaption = TITLE;
/* Create modeless property sheet */
assert( iSheet<=NUM_SETUPPAGES );
__hPropSheet = (HWND)PropertySheet( &psh );
/* ---
Wait for end of window
--- */
MSG tMsg;
while( GetMessage( &tMsg, NULL, 0, 0 ) )
{
if ( !(PropSheet_IsDialogMessage( __hPropSheet, &tMsg )) )
{
TranslateMessage( &tMsg );
DispatchMessage( &tMsg );
}
else
{
if (!PropSheet_GetCurrentPageHwnd(__hPropSheet))
{
::DestroyWindow( __hPropSheet );
::ExitProcess( 0 );
}
}
};
::DestroyWindow( hBackground );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Windowing loop with modeless dialog and tray icon.
\*____________________________________________________________________________*/
static int Internal_Setup( HINSTANCE hInstance, const char *pSemaphoreName,
const char *pConfigName )
{
/*
** Attempt to load configuration file
*/
assert( __ppArgv );
__pConfig = AD_createDefaultConfig();
/*
** Set the install directory
*/
Internal_SetInstallDir( __pConfig );
/*
** Set the OS
*/
if ( !Internal_SetOS( __pConfig ) )
{ goto forget_it; };
/*
** Set configuration values
*/
AD_replaceValue( __pConfig, "Startup", "SemaphoreName", pSemaphoreName );
AD_replaceValue( __pConfig, "Startup", "ConfigName", pConfigName );
/*
** register background window class
*/
if ( !Internal_registerClass( hInstance ) )
{ goto forget_it; };
/*
** Do property sheet
*/
Internal_DoPropertySheet( hInstance );
forget_it:
AD_destroyConfig( __pConfig );
return 0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Windows entry point for configuration
\*____________________________________________________________________________*/
int AD_setupMain( 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 );
const char *pSemaphoreName = sSemaphoreName;
AD_hourglassInit();
WSAData tWSAData;
enum { DESIRED_WINSOCK_VERSION=0x0101 };
WSAStartup( DESIRED_WINSOCK_VERSION, &tWSAData );
iRet = Internal_Setup( hInstance, pSemaphoreName, __ppArgv[1] );
WSACleanup();
AD_hourglassDestroy();
return iRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -