.nf

.nf


    ========== licence begin  GPL
    Copyright (c) 1999-2004 SAP AG

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end

.fo


.fo
*****************************************************
Copyright (c) 1999-2004 SAP AG
SAP Database Technology
 
Release :      Date : 2000-01-26
*****************************************************
modname : VOX35X
changed : 2000-01-26
module  : xtcpupd
 
Author  : GertG
Created : 1996-10-15
Pretty  : 2000-01-11
*****************************************************
 
Define  :

.CM *-END-* define --------------------------------------
***********************************************************

Use     :

.CM *-END-* use -----------------------------------------
***********************************************************

Synonym :

.CM *-END-* synonym -------------------------------------
***********************************************************
.CM -lll-
Code    :

// xtcpupdDlg.cpp : implementation file
//

// Modulname vox35x


//#include "vox30x.h"
//#include "vox32x.h"
//#include "vox34x.h"
#include <winver.h>
#include <winreg.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static char TCPIPRegistryKey[ _MAX_PATH ];

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXtcpupdDlg dialog

CXtcpupdDlg::CXtcpupdDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CXtcpupdDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CXtcpupdDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CXtcpupdDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXtcpupdDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CXtcpupdDlg, CDialog)
	//{{AFX_MSG_MAP(CXtcpupdDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_NO_TCPIP, OnNoTcpip)
	ON_BN_CLICKED(IDC_TCPIP, OnTcpip)
	ON_BN_CLICKED(IDC_NETWORK, OnNetwork)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXtcpupdDlg message handlers

BOOL CXtcpupdDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	CString strAboutMenu;
	strAboutMenu.LoadString(IDS_ABOUTBOX);
	if (!strAboutMenu.IsEmpty())
	{
		pSysMenu->AppendMenu(MF_SEPARATOR);
		pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

    (void) _tcscpy ( TCPIPRegistryKey, "HKEY_LOCAL_MACHINE" );
    (void) _tcscat ( TCPIPRegistryKey, "\\" );
    (void) _tcscat ( TCPIPRegistryKey, REG_SK_BASE );
    (void) _tcscat ( TCPIPRegistryKey, "\\" );
    (void) _tcscat ( TCPIPRegistryKey, REG_SK_APPLIC );
    (void) _tcscat ( TCPIPRegistryKey, "\\" );
    (void) _tcscat ( TCPIPRegistryKey, REG_SK_DLLS );
    (void) _tcscat ( TCPIPRegistryKey, "\\" );
    (void) _tcscat ( TCPIPRegistryKey, REG_VN_TCPIP_DLL );

	// TODO: Add extra initialization here
	if ( GetRegEntry() != 0)
		OnCancel();
	else
		SetInfoOutput();	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CXtcpupdDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CXtcpupdDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}

}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CXtcpupdDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CXtcpupdDlg::OnNoTcpip() 
{
	// TODO: Add your control notification handler code here
    CWnd *hWnd;

	if(GetCheckedRadioButton(IDC_NO_TCPIP, IDC_TCPIP)==IDC_NO_TCPIP)
	{
		CString NoTcpDll;
		NoTcpDll.LoadString(IDS_NO_TCPIP_DLL);
		Set_actualRegEntry(LPCTSTR(NoTcpDll));	
		SetInfoOutput();
	} 
    hWnd = GetDlgItem(IDC_NETWORK);
    hWnd->EnableWindow(FALSE);
}

void CXtcpupdDlg::OnTcpip() 
{
	// TODO: Add your control notification handler code here
    CWnd *hWnd;

	if(GetCheckedRadioButton(IDC_NO_TCPIP, IDC_TCPIP)==IDC_TCPIP)
	{
		CString TcpDll;
		TcpDll.LoadString(IDS_TCPIP_DLL);
		Set_actualRegEntry(LPCTSTR(TcpDll));	
		SetInfoOutput();
	}
    hWnd = GetDlgItem(IDC_NETWORK);
    hWnd->EnableWindow(TRUE);
}

void CXtcpupdDlg::OnNetwork() 
{
	// TODO: Add your control notification handler code here
    if ( IsDlgButtonChecked(IDC_NETWORK))
    {
	    CString TcpDll2;
	    TcpDll2.LoadString(IDS_TCPIP2_DLL);
	    Set_actualRegEntry(LPCTSTR(TcpDll2));	
	    SetInfoOutput();
    }
    else
        OnTcpip();
}


void CXtcpupdDlg::OnOK() 
{
	// TODO: Add extra validation here
	SetRegEntry();
	CDialog::OnOK();
}

int CXtcpupdDlg::SetRegEntry()
{
    if ( sql40c_set_tcpip_dll_path( m_actualRegEntry ) )
    {
        CString errortext;

        AfxFormatString1( errortext, IDS_FAILURE_HANDLE_REG, TCPIPRegistryKey );
		AfxMessageBox( errortext );
		return 1;
    }
    return( 0 );
}

int CXtcpupdDlg::GetRegEntry()
{
	long rc;
    char    * p;

    if ( sql40c_get_tcpip_dll_path( & p ) )
    {
        _tcscpy( m_actualRegEntry, "sqltcp1.dll" );
        rc =  sql40c_set_tcpip_dll_path( m_actualRegEntry );
        if ( sql40c_get_tcpip_dll_path( & p ) != ERROR_SUCCESS )
        {
            CString errortext;

            AfxFormatString1( errortext, IDS_FAILURE_HANDLE_REG, TCPIPRegistryKey );
		    AfxMessageBox( errortext );
		    return 1;
        }
    }
    else
        _tcsncpy( m_actualRegEntry, p, _MAX_PATH );
    return( 0  );
}

void CXtcpupdDlg::Set_actualRegEntry(LPCTSTR szNewActualEntry)
{
	char szPath[_MAX_PATH];
	char szDrive[_MAX_DRIVE];
	char szDir[_MAX_DIR];
	char szFname[_MAX_FNAME];
	char szExt[_MAX_EXT];
	char szFname1[_MAX_FNAME];
	char szExt1[_MAX_EXT];

	_tsplitpath(szNewActualEntry, szDrive, szDir,szFname1, szExt1);
	_tsplitpath(m_actualRegEntry, szDrive, szDir,szFname, szExt);
	_tmakepath(szPath, szDrive, szDir, szFname1, szExt1);
	_tcscpy(m_actualRegEntry, szPath);

}

void CXtcpupdDlg::SetInfoOutput()
{

	char szPath[_MAX_PATH];
	char szFoundPath[_MAX_PATH];
	char szFilename[_MAX_FNAME + _MAX_EXT];
	char szDrive[_MAX_DRIVE];
	char szDir[_MAX_DIR];
	char szFname[_MAX_FNAME];
	char szExt[_MAX_EXT];

	LPTSTR pPath = NULL;
	LPCTSTR szSearchPath;
    tsp00_Pathc szIndepPGMPath ;

	_tsplitpath(m_actualRegEntry, szDrive, szDir,szFname, szExt);
	_tmakepath(szPath, szDrive, szDir, NULL, NULL);
	_tmakepath(szFilename, NULL, NULL, szFname, szExt);

	CString strTcp1, strTcp2, strTcpn;
	strTcp1.LoadString(IDS_TCPIP_DLL);
	strTcp2.LoadString(IDS_TCPIP2_DLL);
	strTcpn.LoadString(IDS_NO_TCPIP_DLL);
	// Ist DLL eine gltige DLL
	if (strTcp1.CompareNoCase(szFilename) != 0 && 
		strTcp2.CompareNoCase(szFilename) != 0 && 
		strTcpn.CompareNoCase(szFilename) != 0 )
	{
        CString errortext;

        AfxFormatString1( errortext, IDS_INCORRECT_DLL, TCPIPRegistryKey );
		AfxMessageBox( errortext );
		OnCancel();
		return;
	}
	// Entsprechenden Radiobutton setzen
	if (strTcp1.CompareNoCase(szFilename) == 0 || 
		strTcp2.CompareNoCase(szFilename) == 0 )
	{
		CheckRadioButton(IDC_NO_TCPIP, IDC_TCPIP, IDC_TCPIP);
        // PTS 1105442 G.G.
        if ( strTcp2.CompareNoCase(szFilename) == 0 )
        {
            CheckDlgButton(IDC_NETWORK, 1);
        }
	}
	else
    {
		CheckRadioButton(IDC_NO_TCPIP, IDC_TCPIP, IDC_NO_TCPIP);
    }


	if (_tcslen(szPath)==0) 
    {
      // PTS 1104558
      tsp01_RteError          RteError ;
      if ( sqlGetIndependentPgmPath ( szIndepPGMPath, TERM_WITHOUT_DELIMITER_EO01, &RteError ) )
		szSearchPath = szIndepPGMPath;
      else
		szSearchPath = NULL;
    }
	else
		szSearchPath = szPath;

	if (SearchPath(szSearchPath, szFilename, NULL, _MAX_PATH-1, szFoundPath,  &pPath) == 0) 
    {
        CString errortext;

        AfxFormatString1( errortext, IDS_FILE_NOT_FOUND_ABS, TCPIPRegistryKey );
		AfxMessageBox( errortext );
		OnCancel();
		return;
	}
	
	//Info mit Hilfe von szFoundPath (enthlt nun den Pfad mit Filename) setzen
	SetDlgItemText(IDC_VER_PATH, szFoundPath);

	// falls vorhanden VersionsInfo ausgeben
	DWORD rawInfoSize;
	DWORD dummy;
	
	rawInfoSize = GetFileVersionInfoSize(szFoundPath, &dummy); 
	
	if (rawInfoSize != 0)
	{
		// falls es Versionskennung gibt, gib diese aus
		
		
		LPVOID rawInfo = HeapAlloc( GetProcessHeap(), HEAP_NO_SERIALIZE, rawInfoSize );
		
		if ( NULL == rawInfo )
		{
			AfxMessageBox(TEXT("not enough memory! (abort)"));
			OnCancel();
			return;
		}
		
		// get information about version
		GetFileVersionInfo(szFoundPath, 0, rawInfoSize, rawInfo);
		
		LPVOID lang_charset = NULL;
		UINT lang_charsetSize = 0; 
		// get language und character-set identifiers
		VerQueryValue(rawInfo, TEXT("\\VarFileInfo\\Translation"), &lang_charset, &lang_charsetSize);
	
		const StringLanguageID_size = 9*sizeof(_TCHAR);
		TCHAR Language[StringLanguageID_size] = "040904E4";

		if ( lang_charsetSize != 0) {
			//LanguageID erstellen
			LCID lcid = *(PLCID(lang_charset));
			//HIWORD(lcid) ergibt die Code-Page
			_stprintf(Language, TEXT("%.4X%.4X"), LANGIDFROMLCID(lcid), HIWORD(lcid));
		} 

		TCHAR InfoRoot[30];
		_tcscpy(InfoRoot, TEXT("\\StringFileInfo\\"));
		_tcscat(InfoRoot, Language);

		TCHAR InfoDescription[50];

		// Zugriff auf die einzelnen Informationen
		LPVOID Info = NULL;
		UINT InfoSize = 0;
		const MAX_STATICTEXT_LEN = 24; //Lnge der Textfelder in der Dialogbox
		// FileVersion
		_tcscpy(InfoDescription, InfoRoot);
		_tcscat(InfoDescription, TEXT("\\FileVersion"));
		VerQueryValue(LPVOID(rawInfo), InfoDescription, &Info, &InfoSize);
		if(InfoSize!=0)
		{
			TCHAR FileVersion[MAX_STATICTEXT_LEN];
			_tcsncpy(FileVersion, LPCTSTR(Info),InfoSize);
			SetDlgItemText(IDC_VER_FILEVER, FileVersion);
		}
	
		//ProductVersion
		_tcscpy(InfoDescription, InfoRoot);
		_tcscat(InfoDescription, TEXT("\\ProductVersion"));
		VerQueryValue(LPVOID(rawInfo), InfoDescription, &Info, &InfoSize);
		if(InfoSize!=0)
		{	
			TCHAR ProductVersion[MAX_STATICTEXT_LEN];
			_tcsncpy(ProductVersion, LPCTSTR(Info),InfoSize);
			SetDlgItemText(IDC_VER_PRODUCTVER, ProductVersion);
		}

		//LegalCopyright
		_tcscpy(InfoDescription, InfoRoot);
		_tcscat(InfoDescription, TEXT("\\LegalCopyright"));
		VerQueryValue(LPVOID(rawInfo), InfoDescription, &Info, &InfoSize);
		if(InfoSize!=0)
		{
			TCHAR LegalCopyright[MAX_STATICTEXT_LEN];
			_tcsncpy(LegalCopyright, LPCTSTR(Info),InfoSize);
			SetDlgItemText(IDC_VER_COPYRIGHT, LegalCopyright);
		}

		//OriginalFilename
		_tcscpy(InfoDescription, InfoRoot);
		_tcscat(InfoDescription, TEXT("\\OriginalFilename"));
		VerQueryValue(LPVOID(rawInfo), InfoDescription, &Info, &InfoSize);
		if(InfoSize!=0)
		{
			TCHAR OriginalFilename[MAX_STATICTEXT_LEN];
			_tcsncpy(OriginalFilename, LPCTSTR(Info),InfoSize);
			SetDlgItemText(IDC_VER_ORIG_FILENAME, OriginalFilename);
		}

		HeapFree ( GetProcessHeap(), HEAP_NO_SERIALIZE, rawInfo );
	}
	else
	{
		// Info loeschen
			SetDlgItemText(IDC_VER_FILEVER, "");
			SetDlgItemText(IDC_VER_PRODUCTVER, "");
			SetDlgItemText(IDC_VER_COPYRIGHT, "");
			SetDlgItemText(IDC_VER_ORIG_FILENAME, "");
	}

}


.CM *-END-* code ----------------------------------------
.SP 2
***********************************************************
.PA
