//this file is part of NeoMule
//Copyright (C)2006 David Xanatos ( Xanatos@Lycos.at / http://neomule.sourceforge.net )
//
//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., 675 Mass Ave, Cambridge, MA 02139, USA.


#include "stdafx.h"
#include "emule.h"
#include "PPgNetwork.h"
#include "Preferences.h"
#include "OtherFunctions.h"
#include "Sion\Defaults.h"
#include "Sion\GUI\CP\TreeFunctions.h"
#include "KnownFileList.h"
#include "Opcodes.h"
#include "Sion/Functions.h"
#include "Sion/SionOpcodes.h"

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



#ifdef ISPBYPASS // MOD: SCC - [SecureClinetConnection]
class CNeedISPBypass : public CTreeOptionsCombo
{
public:
	CNeedISPBypass();
	virtual ~CNeedISPBypass();

protected:
	//{{AFX_VIRTUAL(CNeedISPBypass)
	//}}AFX_VIRTUAL

	//{{AFX_MSG(CNeedISPBypass)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()

  DECLARE_DYNCREATE(CNeedISPBypass)
};


IMPLEMENT_DYNCREATE(CNeedISPBypass, CTreeOptionsCombo)

CNeedISPBypass::CNeedISPBypass()
{
}

CNeedISPBypass::~CNeedISPBypass()
{
}

BEGIN_MESSAGE_MAP(CNeedISPBypass, CTreeOptionsCombo)
	//{{AFX_MSG_MAP(CNeedISPBypass)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


int CNeedISPBypass::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CTreeOptionsCombo::OnCreate(lpCreateStruct) == -1)
		return -1;
	
  //Add strings to the combo
	AddString(GetResString(IDS_X_CD_ISPTRAVERSAL_UNNEDED));
	AddString(GetResString(IDS_X_CD_ISPTRAVERSAL_PARTIAL));
	AddString(GetResString(IDS_X_CD_ISPTRAVERSAL_IMPLICIT));
#ifdef _DEBUG // for the moment don't allow users tu use explicit mode 
	AddString(GetResString(IDS_X_CD_ISPTRAVERSAL_EXPLICIT));
#endif

	return 0;
}
#endif // ISPBYPASS // MOD: SCC END

///////////////////////////////////////////////////////////////////////////////
// CPPgNetwork dialog

IMPLEMENT_DYNAMIC(CPPgNetwork, CPropertyPage)

BEGIN_MESSAGE_MAP(CPPgNetwork, CPropertyPage)
	ON_WM_DESTROY()
	ON_MESSAGE(WM_TREEOPTSCTRL_NOTIFY, OnTreeOptsCtrlNotify)
	ON_MESSAGE(WM_TREEITEM_HELP, DrawTreeItemHelp)
	ON_WM_HELPINFO()
END_MESSAGE_MAP()

CPPgNetwork::CPPgNetwork()
	: CPropertyPage(CPPgNetwork::IDD)
	, m_ctrlTreeOptions(theApp.m_iDfltImageListColorFlags)
{
	ClearAllMembers();
	m_ctrlTreeOptions.SetNeoStyle();
}

CPPgNetwork::~CPPgNetwork()
{
}

void CPPgNetwork::ClearAllMembers()
{
	m_bInitializedTreeOpts = false;
	
		// MOD: QS - [QuickStart]
		m_htiQuickStart = NULL;
			m_htiQuickStartEnable = NULL;
			m_htiQuickStartTime = NULL;
			m_htiQuickStartTimePerFile = NULL;
			m_htiQuickMaxConperFive = NULL;
			m_htiQuickMaxHalfOpen = NULL;
			m_htiQuickMaxConnections = NULL;
		// MOD: QS END
		// MOD: IFWS - [ICSFirewall]
		m_htiICSFirewall = NULL;
			m_htiICFSupport = NULL;
			m_htiICFClearOnClose = NULL;
		// MOD: IFWS END
#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
		m_htiUPnPNatSupport = NULL;
			m_htiUPnPNat = NULL;
			m_htiUPnPClearOnClose = NULL;

			m_htiUPnPVerboseLog = NULL;
			m_htiUPnPPort = NULL;
			m_htiUPnPLimitToFirstConnection = NULL;
#endif // UPNPNAT // MOD: UPNP END
		// MOD: RIC - [ReaskOnIDChange]
		m_htiOnIDChange = NULL;
			m_htiCheckIPChange = NULL;
			m_htiInformOnIPChange = NULL;
			m_htiReAskOnIPChange = NULL;
			m_htiQuickStartOnIPChange = NULL; // MOD: QS - [QuickStart]
			m_htiCheckL2HIDChange = NULL;
			m_htiReconnectKadOnIPChange = NULL;
			m_htiRebindSocketsOnIPChange = NULL;
		// MOD: RIC END
#ifdef ISPBYPASS // MOD: SCC - [SecureClinetConnection]
		m_htiSupportISPBypass = NULL;
			m_htiNeedISPBypass = NULL;
			m_htiEncryptedPorts = NULL;
#endif // ISPBYPASS // MOD: SCC END
}

void CPPgNetwork::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MOD_OPTS, m_ctrlTreeOptions);
	if (!m_bInitializedTreeOpts)
	{
		int iImgReaskOnIDChange = 8;
		int iImgQuickStart = 8;
		int iImgWinXPFW = 8; 
#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
		int iImgUPnP = 8; 
#endif // UPNPNAT // MOD: UPNP END
        CImageList* piml = m_ctrlTreeOptions.GetImageList(TVSIL_NORMAL);
		if (piml){
			iImgReaskOnIDChange = piml->Add(CTempIconLoader(_T("RIC")));
			iImgWinXPFW  = piml->Add(CTempIconLoader(_T("WXPFW")));
#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
			iImgUPnP = piml->Add(CTempIconLoader(_T("UPNP")));
#endif // UPNPNAT // MOD: UPNP END
			iImgQuickStart = piml->Add(CTempIconLoader(_T("QUICKSTART")));
		}
			// MOD: RIC - [ReaskOnIDChange]
			SetTreeGroup(m_ctrlTreeOptions,m_htiOnIDChange,GetResString(IDS_X_ON_ID_CHANGE),iImgReaskOnIDChange, TVI_ROOT, GetResString(IDS_X_ON_ID_CHANGE_INFO));
				SetTreeCheck(m_ctrlTreeOptions,m_htiCheckIPChange,GetResString(IDS_X_CHECK_ID_CHANGES),m_htiOnIDChange,GetResString(IDS_X_CHECK_ID_CHANGES_INFO),TRUE,m_uCheckIPChange);
					SetTreeCheck(m_ctrlTreeOptions,m_htiCheckL2HIDChange,GetResString(IDS_X_CHECK_L2H_CHANGES),m_htiCheckIPChange,GetResString(IDS_X_CHECK_L2H_CHANGES_INFO),FALSE,m_bCheckL2HIDChange);
				SetTreeCheck(m_ctrlTreeOptions,m_htiInformOnIPChange,GetResString(IDS_X_INFORM_ON_ID_CHANGE),m_htiOnIDChange,GetResString(IDS_X_INFORM_ON_ID_CHANGE_INFO),FALSE,m_bInformOnIPChange);
				SetTreeCheck(m_ctrlTreeOptions,m_htiReAskOnIPChange,GetResString(IDS_X_REASK_ON_ID_CHANGE),m_htiOnIDChange,GetResString(IDS_X_REASK_ON_ID_CHANGE_INFO),FALSE,m_bReAskOnIPChange);
					SetTreeCheck(m_ctrlTreeOptions,m_htiQuickStartOnIPChange,GetResString(IDS_X_QUICK_START_ON_ID_CHANGE),m_htiReAskOnIPChange,GetResString(IDS_X_QUICK_START_ON_ID_CHANGE_INFO),FALSE,m_bQuickStartOnIPChange); // MOD: QS - [QuickStart]
				SetTreeCheck(m_ctrlTreeOptions,m_htiReconnectKadOnIPChange,GetResString(IDS_X_RECONNECTKAD_ON_ID_CHANGE),m_htiOnIDChange,GetResString(IDS_X_RECONNECTKAD_ON_ID_CHANGE_INFO),FALSE,m_bReconnectKadOnIPChange);
				SetTreeCheck(m_ctrlTreeOptions,m_htiRebindSocketsOnIPChange,GetResString(IDS_X_REBIND_SOCKETS_ON_IP_CHANGE),m_htiOnIDChange,GetResString(IDS_X_REBIND_SOCKETS_ON_IP_CHANGE_INFO),FALSE,m_bRebindSocketsOnIPChange);
			// MOD: RIC END
			// MOD: QS - [QuickStart]
			SetTreeGroup(m_ctrlTreeOptions,m_htiQuickStart,GetResString(IDS_X_QUICK_START),iImgQuickStart, TVI_ROOT, GetResString(IDS_X_QUICK_START_INFO));
				SetTreeCheck(m_ctrlTreeOptions,m_htiQuickStartEnable,GetResString(IDS_X_QUICK_START_ENABLE),m_htiQuickStart,GetResString(IDS_X_QUICK_START_ENABLE_INFO),FALSE,m_bQuickStart);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiQuickStartTime,GetResString(IDS_X_QUICK_START_TIME), m_htiQuickStart,GetResString(IDS_X_QUICK_START_TIME_INFO));
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiQuickStartTimePerFile,GetResString(IDS_X_QUICK_START_TIME_PER_FILE), m_htiQuickStart,GetResString(IDS_X_QUICK_START_TIME_PER_FILE_INFO));
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiQuickMaxConperFive,GetResString(IDS_X_QUICK_START_MAXPER5), m_htiQuickStart,GetResString(IDS_X_QUICK_START_MAXPER5_INFO));
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiQuickMaxHalfOpen,GetResString(IDS_X_QUICK_START_MAXHALF), m_htiQuickStart,GetResString(IDS_X_QUICK_START_MAXHALF_INFO));
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiQuickMaxConnections,GetResString(IDS_X_QUICK_START_MAXCON), m_htiQuickStart,GetResString(IDS_X_QUICK_START_MAXCON_INFO));
			// MOD: QS END
			// MOD: IFWS - [ICSFirewall]
			SetTreeGroup(m_ctrlTreeOptions,m_htiICSFirewall,GetResString(IDS_X_ICS_FIREWALL),iImgWinXPFW, TVI_ROOT, GetResString(IDS_X_ICS_FIREWALL_INFO));
				SetTreeCheck(m_ctrlTreeOptions,m_htiICFSupport,GetResString(IDS_X_ICS_SUPPORT),m_htiICSFirewall,GetResString(IDS_X_ICS_SUPPORT_INFO),FALSE,m_uICFSupport);
				SetTreeCheck(m_ctrlTreeOptions,m_htiICFClearOnClose,GetResString(IDS_X_ICF_CLEAR_ON_CLOSE),m_htiICSFirewall,GetResString(IDS_X_ICF_CLEAR_ON_CLOSE_INFO),FALSE,m_bICFClearOnClose);
			// MOD: IFWS END
#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
			SetTreeGroup(m_ctrlTreeOptions,m_htiUPnPNatSupport,GetResString(IDS_X_UPNP),iImgUPnP, TVI_ROOT, GetResString(IDS_X_UPNP_INFO));
				SetTreeCheck(m_ctrlTreeOptions,m_htiUPnPNat,GetResString(IDS_X_UPNP_SUPPORT),m_htiUPnPNatSupport,GetResString(IDS_X_UPNP_SUPPORT_INFO),TRUE,m_uUPnPNat);
				SetTreeCheck(m_ctrlTreeOptions,m_htiUPnPClearOnClose,GetResString(IDS_X_UPNP_CLEAR_ON_CLOSE),m_htiUPnPNatSupport,GetResString(IDS_X_UPNP_CLEAR_ON_CLOSE_INFO),FALSE,m_bUPnPClearOnClose);

				SetTreeCheck(m_ctrlTreeOptions,m_htiUPnPVerboseLog,GetResString(IDS_X_UPNP_VERBOSE_LOG),m_htiUPnPNatSupport,GetResString(IDS_X_UPNP_VERBOSE_LOG_INFO),FALSE,m_bUPnPVerboseLog);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiUPnPPort,GetResString(IDS_X_UPNP_PORT), m_htiUPnPNatSupport,GetResString(IDS_X_UPNP_PORT_INFO));
				SetTreeCheck(m_ctrlTreeOptions,m_htiUPnPLimitToFirstConnection,GetResString(IDS_X_UPNP_LIMIT_TO_FIRST_CONNECTION),m_htiUPnPNatSupport,GetResString(IDS_X_UPNP_LIMIT_TO_FIRST_CONNECTION_INFO),FALSE,m_bUPnPLimitToFirstConnection);
#endif // UPNPNAT // MOD: UPNP END
		// MOD: RIC - [ReaskOnIDChange]
		m_ctrlTreeOptions.SetItemEnable(m_htiCheckL2HIDChange,m_uCheckIPChange); 
		m_ctrlTreeOptions.SetItemEnable(m_htiInformOnIPChange,m_uCheckIPChange); 
		m_ctrlTreeOptions.SetItemEnable(m_htiReAskOnIPChange,m_uCheckIPChange); 
		m_ctrlTreeOptions.SetItemEnable(m_htiQuickStartOnIPChange,m_uCheckIPChange && m_bQuickStart); 
		m_ctrlTreeOptions.SetItemEnable(m_htiReconnectKadOnIPChange,m_uCheckIPChange); 
		m_ctrlTreeOptions.SetItemEnable(m_htiRebindSocketsOnIPChange,m_uCheckIPChange); 
		// MOD: RIC END
		// MOD: QS - [QuickStart]
		m_ctrlTreeOptions.SetItemEnable(m_htiQuickStartTime, m_bQuickStart); 
		m_ctrlTreeOptions.SetItemEnable(m_htiQuickStartTimePerFile, m_bQuickStart); 
		m_ctrlTreeOptions.SetItemEnable(m_htiQuickMaxConperFive, m_bQuickStart); 
		m_ctrlTreeOptions.SetItemEnable(m_htiQuickMaxHalfOpen, m_bQuickStart); 
		m_ctrlTreeOptions.SetItemEnable(m_htiQuickMaxConnections, m_bQuickStart); 
		// MOD: QS END

		m_ctrlTreeOptions.SetItemEnable(m_htiICSFirewall, thePrefs.GetWindowsVersion() == _WINVER_XP_); // MOD: IFWS - [ICSFirewall]
#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
		m_ctrlTreeOptions.SetItemEnable(m_htiUPnPClearOnClose,m_uUPnPNat); 
		m_ctrlTreeOptions.SetItemEnable(m_htiUPnPVerboseLog,m_uUPnPNat && thePrefs.GetVerbose()); 
		m_ctrlTreeOptions.SetItemEnable(m_htiUPnPPort,m_uUPnPNat); 
		m_ctrlTreeOptions.SetItemEnable(m_htiUPnPLimitToFirstConnection,m_uUPnPNat); 
#endif // UPNPNAT // MOD: UPNP END

#ifdef ISPBYPASS // MOD: SCC - [SecureClinetConnection]
			SetTreeCheck(m_ctrlTreeOptions,m_htiSupportISPBypass,GetResString(IDS_X_SUPPORT_ISPTRAVERSAL), TVI_ROOT,GetResString(IDS_X_SUPPORT_ISPTRAVERSAL_INFO),TRUE,m_uSupportISPBypass);
				m_htiNeedISPBypass = m_ctrlTreeOptions.InsertItem(GetResString(IDS_X_NEED_ISPTRAVERSAL), TREEOPTSCTRLIMG_EDIT, TREEOPTSCTRLIMG_EDIT, m_htiSupportISPBypass);
				m_ctrlTreeOptions.AddComboBox(m_htiNeedISPBypass,RUNTIME_CLASS(CNeedISPBypass));
				m_ctrlTreeOptions.SetItemInfo(m_htiNeedISPBypass,GetResString(IDS_X_NEED_ISPTRAVERSAL_INFO));
				SetTreeEdit(m_ctrlTreeOptions,m_htiEncryptedPorts,GetResString(IDS_X_AUX_PORTS), m_htiSupportISPBypass,GetResString(IDS_X_AUX_PORTS_INFO));
#endif // ISPBYPASS // MOD: SCC END

		m_ctrlTreeOptions.Expand(m_htiICSFirewall, TVE_EXPAND);
		m_ctrlTreeOptions.Expand(m_htiUPnPNatSupport, TVE_EXPAND);
		m_ctrlTreeOptions.Expand(m_htiSupportISPBypass, TVE_EXPAND);
		m_bInitializedTreeOpts = true;
	}

		// MOD: RIC - [ReaskOnIDChange]
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiCheckIPChange, m_uCheckIPChange);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiInformOnIPChange, m_bInformOnIPChange);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiReAskOnIPChange, m_bReAskOnIPChange);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiQuickStartOnIPChange, m_bQuickStartOnIPChange); // MOD: QS - [QuickStart]
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiCheckL2HIDChange, m_bCheckL2HIDChange);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiReconnectKadOnIPChange, m_bReconnectKadOnIPChange);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiRebindSocketsOnIPChange, m_bRebindSocketsOnIPChange);
		// MOD: RIC END
		// MOD: QS - [QuickStart]
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiQuickStartEnable, m_bQuickStart);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiQuickStartTime, m_iQuickStartTime);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiQuickStartTimePerFile, m_iQuickStartTimePerFile);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiQuickMaxConperFive, m_iQuickMaxConperFive);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiQuickMaxHalfOpen, m_iQuickMaxHalfOpen);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiQuickMaxConnections, m_iQuickMaxConnections);
		// MOD: QS END
		// MOD: IFWS - [ICSFirewall]
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiICFSupport, m_uICFSupport);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiICFClearOnClose, m_bICFClearOnClose);
		// MOD: IFWS END
#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiUPnPNat, m_uUPnPNat);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiUPnPClearOnClose, m_bUPnPClearOnClose);

		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiUPnPVerboseLog, m_bUPnPVerboseLog);
		DDX_TreeEdit(pDX, IDC_MOD_OPTS, m_htiUPnPPort, m_iUPnPPort);
		DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiUPnPLimitToFirstConnection, m_bUPnPLimitToFirstConnection);
#endif // UPNPNAT // MOD: UPNP END

#ifdef ISPBYPASS // MOD: SCC - [SecureClinetConnection]
	DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiSupportISPBypass, m_uSupportISPBypass);

		if (pDX->m_bSaveAndValidate)
		{
			CString sOperator;
			sOperator = m_ctrlTreeOptions.GetComboText(m_htiNeedISPBypass);
			if(sOperator.Compare(GetResString(IDS_X_CD_ISPTRAVERSAL_UNNEDED)) == 0)
				m_uNeedISPBypass = 0;
			else if(sOperator.Compare(GetResString(IDS_X_CD_ISPTRAVERSAL_PARTIAL)) == 0)
				m_uNeedISPBypass = 1;
			else if(sOperator.Compare(GetResString(IDS_X_CD_ISPTRAVERSAL_IMPLICIT)) == 0)
				m_uNeedISPBypass = 2;
			else if(sOperator.Compare(GetResString(IDS_X_CD_ISPTRAVERSAL_EXPLICIT)) == 0)
				m_uNeedISPBypass = 3;
			else 
				ASSERT(0);
		}
		else
		{
			if(m_uNeedISPBypass == 0)
				m_ctrlTreeOptions.SetComboText(m_htiNeedISPBypass,GetResString(IDS_X_CD_ISPTRAVERSAL_UNNEDED));
			else if(m_uNeedISPBypass == 1)
				m_ctrlTreeOptions.SetComboText(m_htiNeedISPBypass,GetResString(IDS_X_CD_ISPTRAVERSAL_PARTIAL));
			else if(m_uNeedISPBypass == 2)
				m_ctrlTreeOptions.SetComboText(m_htiNeedISPBypass,GetResString(IDS_X_CD_ISPTRAVERSAL_IMPLICIT));
			else if(m_uNeedISPBypass == 3)
				m_ctrlTreeOptions.SetComboText(m_htiNeedISPBypass,GetResString(IDS_X_CD_ISPTRAVERSAL_EXPLICIT));
			else
				ASSERT(0);
		}

		DDX_TreeEdit(pDX, IDC_MOD_OPTS, m_htiEncryptedPorts, m_strEncryptedPorts);
#endif // ISPBYPASS // MOD: SCC END

}

BOOL CPPgNetwork::OnInitDialog()
{
	LoadSettings();

	CPropertyPage::OnInitDialog();
	InitWindowStyles(this);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // EXCEPTION: OCX Property Pages should return FALSE
}

void CPPgNetwork::LoadSettings()
{
	/*
	* Globale Einstellungen Laden
	*/

	// MOD: QS - [QuickStart]
	m_bQuickStart = thePrefs.m_bQuickStart;
	m_iQuickStartTime = thePrefs.m_iQuickStartTime;
	m_iQuickStartTimePerFile = thePrefs.m_iQuickStartTimePerFile;
	m_iQuickMaxConperFive = thePrefs.m_iQuickMaxConperFive;
	m_iQuickMaxHalfOpen = thePrefs.m_iQuickMaxHalfOpen;
	m_iQuickMaxConnections = thePrefs.m_iQuickMaxConnections;
	// MOD: QS END

	// MOD: IFWS - [ICSFirewall]
	m_uICFSupport = thePrefs.m_uICFSupport;
	m_bICFClearOnClose = thePrefs.m_bICFClearOnClose;
	// MOD: IFWS END

#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
	m_uUPnPNat = thePrefs.m_uUPnPNat;
	m_bUPnPClearOnClose = thePrefs.m_bUPnPClearOnClose;

	m_bUPnPVerboseLog = thePrefs.m_bUPnPVerboseLog;
	m_iUPnPPort = thePrefs.m_iUPnPPort;
	m_bUPnPLimitToFirstConnection = thePrefs.m_bUPnPLimitToFirstConnection;
#endif // UPNPNAT // MOD: UPNP END

	// MOD: RIC - [ReaskOnIDChange]
	m_uCheckIPChange = thePrefs.m_uCheckIPChange;
	m_bInformOnIPChange = thePrefs.m_bInformOnIPChange;
	m_bReAskOnIPChange = thePrefs.m_bReAskOnIPChange;
	m_bQuickStartOnIPChange = thePrefs.m_bQuickStartOnIPChange; // MOD: QS - [QuickStart]
	m_bCheckL2HIDChange = thePrefs.m_bCheckL2HIDChange;
	m_bReconnectKadOnIPChange = thePrefs.m_bReconnectKadOnIPChange;
	m_bRebindSocketsOnIPChange = thePrefs.m_bRebindSocketsOnIPChange;
	// MOD: RIC END

#ifdef ISPBYPASS // MOD: SCC - [SecureClinetConnection]
	m_uSupportISPBypass = thePrefs.m_uSupportISPBypass;
	m_strEncryptedPorts = thePrefs.m_strEncryptedPorts;
	m_uNeedISPBypass = thePrefs.m_uNeedISPBypass;
#endif // ISPBYPASS // MOD: SCC END

}

BOOL CPPgNetwork::OnApply()
{
	// if prop page is closed by pressing ENTER we have to explicitly commit any possibly pending
	// data from an open edit control
	m_ctrlTreeOptions.HandleChildControlLosingFocus();

	if (!UpdateData())
		return FALSE;

	/*
	* Globale Einstellungen Speichern
	*/

	// MOD: QS - [QuickStart]
	thePrefs.m_bQuickStart = m_bQuickStart;
	thePrefs.m_iQuickStartTime = m_iQuickStartTime;
	thePrefs.m_iQuickStartTimePerFile = m_iQuickStartTimePerFile;
	thePrefs.m_iQuickMaxConperFive = m_iQuickMaxConperFive;
	thePrefs.m_iQuickMaxHalfOpen = m_iQuickMaxHalfOpen;
	thePrefs.m_iQuickMaxConnections = m_iQuickMaxConnections;
	// MOD: QS END

	// MOD: IFWS - [ICSFirewall]
	thePrefs.m_uICFSupport = m_uICFSupport;
	thePrefs.m_bICFClearOnClose = m_bICFClearOnClose;
	// MOD: IFWS END

#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
	thePrefs.m_uUPnPNat = m_uUPnPNat;
	thePrefs.m_bUPnPClearOnClose = m_bUPnPClearOnClose;

	thePrefs.m_bUPnPVerboseLog = m_bUPnPVerboseLog;
	thePrefs.m_iUPnPPort = (uint16)m_iUPnPPort;
	thePrefs.m_bUPnPLimitToFirstConnection = m_bUPnPLimitToFirstConnection;
#endif // UPNPNAT // MOD: UPNP END

	// MOD: RIC - [ReaskOnIDChange]
	thePrefs.m_uCheckIPChange = m_uCheckIPChange;
	thePrefs.m_bInformOnIPChange = m_bInformOnIPChange;
	thePrefs.m_bReAskOnIPChange = m_bReAskOnIPChange;
	thePrefs.m_bQuickStartOnIPChange = m_bQuickStartOnIPChange; // MOD: QS - [QuickStart]
	thePrefs.m_bCheckL2HIDChange = m_bCheckL2HIDChange;
	thePrefs.m_bReconnectKadOnIPChange = m_bReconnectKadOnIPChange;
	thePrefs.m_bRebindSocketsOnIPChange = m_bRebindSocketsOnIPChange;
	// MOD: RIC END

#ifdef ISPBYPASS // MOD: SCC - [SecureClinetConnection]
	thePrefs.m_uSupportISPBypass = m_uSupportISPBypass;
	thePrefs.m_strEncryptedPorts = m_strEncryptedPorts;
	thePrefs.m_uNeedISPBypass = m_uNeedISPBypass;
#endif // ISPBYPASS // MOD: SCC END

	thePrefs.CheckSionPreferences();
	LoadSettings();

	SetModified(FALSE);
	return CPropertyPage::OnApply();
}

BOOL CPPgNetwork::OnKillActive()
{
	// if prop page is closed by pressing ENTER we have to explicitly commit any possibly pending
	// data from an open edit control
	m_ctrlTreeOptions.HandleChildControlLosingFocus();
	return CPropertyPage::OnKillActive();
}

void CPPgNetwork::OnDestroy()
{
	m_ctrlTreeOptions.DeleteAllItems();
	m_ctrlTreeOptions.DestroyWindow();
	ClearAllMembers();
	CPropertyPage::OnDestroy();
}

LRESULT CPPgNetwork::OnTreeOptsCtrlNotify(WPARAM wParam, LPARAM lParam)
{
	if(!IsWindowVisible())
		return 0;

	if (wParam == IDC_MOD_OPTS){
		TREEOPTSCTRLNOTIFY* pton = (TREEOPTSCTRLNOTIFY*)lParam;
		if(pton->nmhdr.code == EN_KILLFOCUS){		
			// MOD: QS - [QuickStart]
			if(m_htiQuickStartTime && pton->hItem == m_htiQuickStartTime){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiQuickStartTime, TIM_QUICK_START_MIN, TIM_QUICK_START_DEF, TIM_QUICK_START_MAX)) SetModified();
			}else if(m_htiQuickStartTimePerFile && pton->hItem == m_htiQuickStartTimePerFile){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiQuickStartTimePerFile, VAL_QUICK_START_PF_MIN, VAL_QUICK_START_PF_DEF, VAL_QUICK_START_PF_MAX)) SetModified();
			}
			// MOD: QS END
		}else{
			UINT bCheck;

			// MOD: RIC - [ReaskOnIDChange]
			if (m_htiCheckIPChange && pton->hItem == m_htiCheckIPChange){
				m_ctrlTreeOptions.GetCheckBox(m_htiCheckIPChange, bCheck);

				m_ctrlTreeOptions.SetItemEnable(m_htiCheckL2HIDChange,bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiInformOnIPChange,bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiReAskOnIPChange,bCheck); 
				UINT bCheck2;
				m_ctrlTreeOptions.GetCheckBox(m_htiQuickStartEnable, bCheck2);
				m_ctrlTreeOptions.SetItemEnable(m_htiQuickStartOnIPChange,bCheck && bCheck2); 
				m_ctrlTreeOptions.SetItemEnable(m_htiReconnectKadOnIPChange,bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiRebindSocketsOnIPChange,bCheck); 	
			}
			// MOD: RIC END
			// MOD: QS - [QuickStart]
			if (m_htiQuickStartEnable && pton->hItem == m_htiQuickStartEnable){
				m_ctrlTreeOptions.GetCheckBox(m_htiQuickStartEnable, bCheck);
				
				m_ctrlTreeOptions.SetItemEnable(m_htiQuickStartTime, bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiQuickStartTimePerFile, bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiQuickMaxConperFive, bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiQuickMaxHalfOpen, bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiQuickMaxConnections, bCheck); 
			}
			// MOD: QS END
#ifdef UPNPNAT // MOD: UPNP - [UPnPNat]
			if (m_htiUPnPNat && pton->hItem == m_htiUPnPNat){
				m_ctrlTreeOptions.GetCheckBox(m_htiUPnPNat, bCheck);

				m_ctrlTreeOptions.SetItemEnable(m_htiUPnPClearOnClose,bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiUPnPVerboseLog,bCheck && thePrefs.GetVerbose()); 
				m_ctrlTreeOptions.SetItemEnable(m_htiUPnPPort,bCheck); 
				m_ctrlTreeOptions.SetItemEnable(m_htiUPnPLimitToFirstConnection,bCheck); 
			}
#endif // UPNPNAT // MOD: UPNP END
			// MOD: TCR END
			SetModified();
		}
	}
	return 0;
}

LRESULT CPPgNetwork::DrawTreeItemHelp(WPARAM wParam, LPARAM lParam)
{
	if(!IsWindowVisible())
		return 0;

	if (wParam == IDC_MOD_OPTS){
		CString* sInfo = (CString*)lParam;
		SetDlgItemText(IDC_MOD_OPTS_INFO, *sInfo);
	}
	return FALSE;
}

void CPPgNetwork::OnHelp()
{
	//theApp.ShowHelp(0);
}

BOOL CPPgNetwork::OnCommand(WPARAM wParam, LPARAM lParam)
{
	if (wParam == ID_HELP)
	{
		OnHelp();
		return TRUE;
	}
	return __super::OnCommand(wParam, lParam);
}

BOOL CPPgNetwork::OnHelpInfo(HELPINFO* /*pHelpInfo*/)
{
	OnHelp();
	return TRUE;
}
