📄 wizard2.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/Wizard2.cpp,v $
* $Date: 2003/05/29 16:43:31 $
*
Description:
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include <winsock.h>
#include "PIString.h"
#include "PICompat.h"
#include "resrc1.h"
#include "Dialogs.h"
#include "Config.h"
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
static HWND hWndHost = 0;
static HWND hWndIP = 0;
static HWND hWndLocal = 0;
static HWND hWndEdit = 0;
static HWND hWndPort = 0;
static HWND hWndURL = 0;
static HWND hWndSsl = 0;
static HWND hWndRemote = 0;
static PIString *pHost;
static PIString *pIP;
static PIString *pLocal;
static int __iCurrentRadioButton = 0;
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static PIString *Internal_stringFromRadioButton( int iId )
{
switch( iId )
{
case IDC_REMOTEHOST: return pHost;
case IDC_REMOTEIP: return pIP;
case IDC_LOCAL: return pLocal;
default:
assert( 0 );
};
return 0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_radioButtonChange( int iNewId )
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
/* --- Get current value --- */
*szBuf = '\0';
SendMessage( hWndEdit, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
*(Internal_stringFromRadioButton( __iCurrentRadioButton )) = szBuf;
__iCurrentRadioButton = iNewId;
SendMessage( hWndEdit, WM_SETTEXT, 0, (LPARAM)(const char *)
*(Internal_stringFromRadioButton( __iCurrentRadioButton )) );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_updateURL()
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
/* --- Get current value --- */
assert( AD_lookupValue( __pConfig, "Internal", "URLProtocol" ) );
strcpy( szBuf, AD_lookupValue( __pConfig, "Internal", "URLProtocol" ) );
int iLen = strlen( szBuf );
SendMessage( hWndEdit, WM_GETTEXT, BUF_SIZE-7, (LPARAM)&(szBuf[iLen]) );
iLen = strlen( szBuf );
szBuf[iLen++] = ':';
SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE-iLen, (LPARAM)&(szBuf[iLen]) );
assert( AD_lookupValue( __pConfig, "Internal", "DefaultPort" ) );
if ( atoi( &(szBuf[iLen]) )==atoi(AD_lookupValue( __pConfig, "Internal",
"DefaultPort" )) )
{ szBuf[--iLen] = '\0'; };
/* --- now update the URL --- */
SendMessage( hWndURL, WM_SETTEXT, 0, (LPARAM)szBuf );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
switch (uMsg)
{
case WM_INITDIALOG:
{
hWndHost = GetDlgItem( hDlg, IDC_REMOTEHOST );
hWndIP = GetDlgItem( hDlg, IDC_REMOTEIP );
hWndLocal = GetDlgItem( hDlg, IDC_LOCAL );
hWndEdit = GetDlgItem( hDlg, IDC_HOST );
hWndPort = GetDlgItem( hDlg, IDC_PORT );
hWndURL = GetDlgItem( hDlg, IDC_URL );
hWndSsl = GetDlgItem( hDlg, IDC_SSL );
hWndRemote = GetDlgItem( hDlg, IDC_REMOTE );
pHost = PI_NEW( PIString );
pIP = PI_NEW( PIString );
pLocal = PI_NEW( PIString );
assert( hWndHost && hWndIP && hWndLocal );
assert( hWndEdit && hWndPort && hWndURL );
/* --- just for sanity --- */
SendMessage( hWndEdit, EM_SETLIMITTEXT, 256, 0 );
SendMessage( hWndPort, EM_SETLIMITTEXT, 256, 0 );
SendMessage( hWndLocal, BM_SETCHECK, BST_UNCHECKED, 0 );
SendMessage( hWndHost, BM_SETCHECK, BST_UNCHECKED, 0 );
SendMessage( hWndIP, BM_SETCHECK, BST_UNCHECKED, 0 );
SendMessage( hWndSsl, BM_SETCHECK, BST_UNCHECKED, 0 );
SendMessage( hWndRemote, BM_SETCHECK, BST_UNCHECKED, 0 );
/*
** Get local network information
*/
*szBuf = '\0';
if ( ::gethostname( szBuf, BUF_SIZE ) )
{
/*
** Error
*/
*pHost = "localhost";
*pIP = "127.0.0.1";
}
else
{
struct hostent *pEnt = ::gethostbyname( szBuf );
*pHost = szBuf;
if ( !pEnt )
{
/*
** Error
*/
*pIP = "127.0.0.1";
}
else
{
*pIP = inet_ntoa( *((in_addr *)(pEnt->h_addr_list)[0]) );
};
};
*pLocal = "localhost";
const char *pUse = AD_lookupValue( __pConfig, "Identity", "Use" );
if ( !stricmp( pUse, "local" ) )
{
SendMessage( hWndLocal, BM_SETCHECK, BST_CHECKED, 0 );
__iCurrentRadioButton = IDC_LOCAL;
SendMessage( hWndEdit, WM_SETTEXT, 0, (LPARAM)(const char *)*pLocal );
SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)TRUE, 0 );
}
else if ( !stricmp( pUse, "remote" ) )
{
SendMessage( hWndHost, BM_SETCHECK, BST_CHECKED, 0 );
__iCurrentRadioButton = IDC_REMOTEHOST;
SendMessage( hWndEdit, WM_SETTEXT, 0, (LPARAM)(const char *)*pHost );
SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
}
else if ( !stricmp( pUse, "ip" ) )
{
SendMessage( hWndIP, BM_SETCHECK, BST_CHECKED, 0 );
__iCurrentRadioButton = IDC_REMOTEIP;
SendMessage( hWndEdit, WM_SETTEXT, 0, (LPARAM)(const char *)*pIP );
SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
};
SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)
AD_lookupValue( __pConfig, "General", "Port" ) );
const char *pTest = AD_lookupValue( __pConfig, "Internal", \
"ServerIOObjectLine" );
if ( strstr( pTest, "SSLIO" ) )
{
SendMessage( hWndSsl, BM_SETCHECK, BST_CHECKED, 0 );
}
pTest = AD_lookupValue( __pConfig, "Internal", "HandlerLine" );
if ( strstr( pTest, "TopSiteRoot" ) )
{
SendMessage( hWndRemote, BM_SETCHECK, BST_CHECKED, 0 );
}
Internal_updateURL();
}
break;
case WM_COMMAND:
if ( GET_WM_COMMAND_CMD(wParam, lParam)==BN_CLICKED )
{
switch( GET_WM_COMMAND_ID( wParam, lParam) )
{
case IDC_REMOTEHOST:
Internal_radioButtonChange( IDC_REMOTEHOST );
SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
break;
case IDC_REMOTEIP:
Internal_radioButtonChange( IDC_REMOTEIP );
SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)FALSE, 0 );
break;
case IDC_LOCAL:
Internal_radioButtonChange( IDC_LOCAL );
SendMessage( hWndEdit, EM_SETREADONLY, (BOOL)TRUE, 0 );
break;
case IDC_SSL:
*szBuf = '\0';
SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
if ( ::SendMessage( hWndSsl, BM_GETCHECK, 0, 0 )==BST_CHECKED )
{
AD_replaceValue( __pConfig, "Internal", "URLProtocol", "https://" );
AD_replaceValue( __pConfig, "Internal", "DefaultPort", "443" );
if (!stricmp(szBuf, "80")) {
SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)"443");
};
}
else
{
AD_replaceValue( __pConfig, "Internal", "URLProtocol", "http://" );
AD_replaceValue( __pConfig, "Internal", "DefaultPort", "80" );
if (!stricmp(szBuf, "443")) {
SendMessage( hWndPort, WM_SETTEXT, 0, (LPARAM)"80");
};
};
Internal_updateURL();
break;
default:;
};
}
else if ( GET_WM_COMMAND_CMD(wParam, lParam)==EN_CHANGE )
{ Internal_updateURL(); };
break;
case WM_DESTROY:
PI_DELETE( pHost );
PI_DELETE( pIP );
PI_DELETE( pLocal );
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_NEXT );
break;
case PSN_KILLACTIVE:
{
*szBuf = '\0';
SendMessage( hWndPort, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
int iPort = atoi( szBuf );
if ( iPort<0 || iPort>65535 )
{
/*
** Give message and abort change
*/
MessageBox( hDlg, "Port must be in the range [0..65536]",
"Port Field Error", MB_OK );
SetFocus( hWndPort );
SendMessage( hWndPort, EM_SETSEL, 0, -1 );
SetWindowLong( hDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
return (TRUE);
};
AD_replaceValue( __pConfig, "General", "Port", szBuf );
SendMessage( hWndEdit, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
AD_replaceValue( __pConfig, "General", "Host", szBuf );
SendMessage( hWndURL, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
AD_replaceValue( __pConfig, "Identity", "URL", szBuf );
switch( __iCurrentRadioButton )
{
case IDC_LOCAL:
AD_replaceValue( __pConfig, "Identity", "Use", "local" );
break;
case IDC_REMOTEHOST:
AD_replaceValue( __pConfig, "Identity", "Use", "remote" );
break;
case IDC_REMOTEIP:
AD_replaceValue( __pConfig, "Identity", "Use", "ip" );
break;
default:;
};
};
if ( ::SendMessage( hWndSsl, BM_GETCHECK, 0, 0 )==BST_CHECKED )
{
AD_replaceValue( __pConfig, "Internal", "ServerIOObjectLine", \
"\tIOObject SSLIOObject" );
DlgData data;
const char *pTmp = szBuf;
// copy ssl servername
data.pSslServername = pTmp;
strcpy( (char *)pTmp, AD_lookupValue( __pConfig, "General", "Host" ) );
pTmp = data.pSslServername + strlen(data.pSslServername);
pTmp++;
// copy ssl private key filename
data.pSslKeyFilename = pTmp;
strcpy( (char *)pTmp, AD_lookupValue( __pConfig, "SSL", "PKeyFile" ) );
pTmp = data.pSslKeyFilename + strlen(data.pSslKeyFilename);
pTmp++;
// copy ssl certificate filename
data.pSslCertFilename = pTmp;
strcpy( (char *)pTmp, AD_lookupValue( __pConfig, "SSL", "CertFile" ) );
pTmp = data.pSslCertFilename + strlen(data.pSslCertFilename);
int iRet = DialogBoxParam(
::GetModuleHandle( NULL ),
MAKEINTRESOURCE( IDD_GENKEYS ),
hDlg,
(DLGPROC)fnGenSslKeys,
(LPARAM)&data
);
if ( iRet == 0 )
{
SetWindowLong( hDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE );
return (TRUE);
}
}
else
{
AD_replaceValue( __pConfig, "Internal", "ServerIOObjectLine", \
"\tIOObject ServerIOObject" );
}
if ( ::SendMessage( hWndRemote, BM_GETCHECK, 0, 0 )==BST_CHECKED )
{
AD_replaceValue( __pConfig, "Internal", "HandlerLine", \
"\tHandlers TopSiteRoot" );
}
else
{
AD_replaceValue( __pConfig, "Internal", "HandlerLine", \
DEFAULT_HANDLERS );
}
break;
};
break;
default:
return (FALSE);
};
return (TRUE);
}
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
DLGPROC fnWizard2 = (DLGPROC)DialogProc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -