//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 "PPgSources.h"
#include "Preferences.h"
#include "PartFile.h"
#include "OtherFunctions.h"
#include "Sion/Functions.h"
#include "Sion/GUI/CP/TreeFunctions.h"
#include "Sion/Defaults.h"
#include "UserMsgs.h"
#include "downloadqueue.h"

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


///////////////////////////////////////////////////////////////////////////////
// CPPgSources dialog

IMPLEMENT_DYNAMIC(CPPgSources, CPropertyPage)

BEGIN_MESSAGE_MAP(CPPgSources, CPropertyPage)
	ON_WM_TIMER() // MOD: FCFG - [FileConfiguration]
	ON_WM_DESTROY()
	ON_MESSAGE(UM_DATA_CHANGED, OnDataChanged) // MOD: FCFG - [FileConfiguration]
	ON_MESSAGE(WM_TREEOPTSCTRL_NOTIFY, OnTreeOptsCtrlNotify)
	ON_MESSAGE(WM_TREEITEM_HELP, DrawTreeItemHelp)
	ON_WM_HELPINFO()
END_MESSAGE_MAP()

CPPgSources::CPPgSources()
	: CPropertyPage(CPPgSources::IDD)
	, m_ctrlTreeOptions(theApp.m_iDfltImageListColorFlags)
{
	// MOD: FCFG - [FileConfiguration]
	m_bFilePreferences = false;

	m_paFiles = NULL;
	m_bDataChanged = false;
	//m_strCaption = GetResString(IDS_FILEINFORMATION);
	//m_psp.pszTitle = m_strCaption;
	//m_psp.dwFlags |= PSP_USETITLE;
	m_timer = 0;
	// MOD: FCFG END
	ClearAllMembers();
	m_ctrlTreeOptions.SetNeoStyle();
}

CPPgSources::~CPPgSources()
{
}

void CPPgSources::ClearAllMembers()
{
	m_bInitializedTreeOpts = false;

	// MOD: DR - [DownloadReask]
	m_htiDownloadReask = NULL;
		m_htiSpreadReask = NULL; // MOD: SR - [SpreadReask]
		m_htiReask = NULL;
			m_htiReaskIntervals = NULL;
		m_htiNnPReask = NULL;
			m_htiReaskNnPDefault = NULL;
			m_htiReaskNnPEnable = NULL;
			m_htiReaskNnPDisable = NULL;
			m_htiReaskNnPIntervals = NULL;
		m_htiFullQReask = NULL;
			m_htiReaskFullQDefault = NULL;
			m_htiReaskFullQEnable = NULL;
			m_htiReaskFullQDisable = NULL;
			m_htiReaskFullQIntervals = NULL;
	// MOD: DR END

	// MOD: DS - [DropSources]
	m_htiDrop = NULL;
		m_htiUseDontAskThisIP = NULL;
			m_htiUseDontAskThisIPDefault = NULL;
			m_htiUseDontAskThisIPEnable = NULL;
			m_htiUseDontAskThisIPDisable = NULL;
			m_htiDontAskThisIPTime = NULL;
		m_htiDropNnP = NULL;
			m_htiDropNnPDefault = NULL;
			m_htiDropNnPEnable = NULL;
			m_htiDropNnPDisable = NULL;
			m_htiDropNnPLimit = NULL;
				m_htiDropNnPLimitDefault = NULL;
				m_htiDropNnPLimitTotal = NULL;
				m_htiDropNnPLimitRelativ = NULL;
				m_htiDropNnPLimitSpecyfic = NULL;
				m_htiDropNnPLimitDisable = NULL;
			m_htiDropNnPTimer = NULL;
		m_htiDropFullQ = NULL;
			m_htiDropFullQDefault = NULL;
			m_htiDropFullQEnable = NULL;
			m_htiDropFullQDisable = NULL;
			m_htiDropFullQLimit = NULL;
				m_htiDropFullQLimitDefault = NULL;
				m_htiDropFullQLimitTotal = NULL;
				m_htiDropFullQLimitRelativ = NULL;
				m_htiDropFullQLimitSpecyfic = NULL;
				m_htiDropFullQLimitDisable = NULL;
			m_htiDropFullQTimer = NULL;
		m_htiDropHighQ = NULL;
			m_htiDropHighQDefault = NULL;
			m_htiDropHighQEnable = NULL;
			m_htiDropHighQDisable = NULL;
			m_htiDropHighQValue = NULL;
			m_htiDropHighQLimit = NULL;
				m_htiDropHighQLimitDefault = NULL;
				m_htiDropHighQLimitTotal = NULL;
				m_htiDropHighQLimitRelativ = NULL;
				m_htiDropHighQLimitSpecyfic = NULL;
				m_htiDropHighQLimitDisable = NULL;
			m_htiDropHighQTimer = NULL;
	// MOD: DS END
}

void CPPgSources::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MOD_OPTS, m_ctrlTreeOptions);
	if (!m_bInitializedTreeOpts)
	{
		// MOD: DR - [DownloadReask]
		int iImgReask = 8;
		int iImgReaskSrc = 8;
		int iImgReaskNnP = 8;
		int iImgReaskFullQ = 8;
		// MOD: DR END
		// MOD: DS - [DropSources]
		int iImgDrop = 8;
		int iImgDropList = 8;
		int iImgDropNnP = 8;
		int iImgDropFullQ = 8;
		int iImgDropHighQ = 8;
		// MOD: DS END

        CImageList* piml = m_ctrlTreeOptions.GetImageList(TVSIL_NORMAL);
		if (piml){
			// MOD: DR - [DownloadReask]
			iImgReask = piml->Add(CTempIconLoader(_T("REASKDL")));
			iImgReaskSrc = piml->Add(CTempIconLoader(_T("REASKSRC")));
			iImgReaskNnP = piml->Add(CTempIconLoader(_T("REASKNNP")));
			iImgReaskFullQ = piml->Add(CTempIconLoader(_T("REASKFULLQ")));
			// MOD: DR END
			// MOD: DS - [DropSources]
			iImgDrop = piml->Add(CTempIconLoader(_T("DROP")));
			iImgDropList = piml->Add(CTempIconLoader(_T("DROPLIST")));
			iImgDropNnP = piml->Add(CTempIconLoader(_T("DROPNNP")));
			iImgDropFullQ = piml->Add(CTempIconLoader(_T("DROPFULLQ")));
			iImgDropHighQ = piml->Add(CTempIconLoader(_T("DROPHIGHQ")));
			// MOD: DS END
		}

		// MOD: DR - [DownloadReask]
		SetTreeGroup(m_ctrlTreeOptions,m_htiDownloadReask,GetResString(IDS_X_REASK_TWEAKS),iImgReask, TVI_ROOT,GetResString(IDS_X_REASK_TWEAKS_INFO));
			if(!ForFile())
				SetTreeCheckNumEdit(m_ctrlTreeOptions,m_htiSpreadReask,GetResString(IDS_X_SPREAD_REASK), m_htiDownloadReask,GetResString(IDS_X_SPREAD_REASK_INFO),FALSE, m_bSpreadReask); // MOD: SR - [SpreadReask]
			SetTreeGroup(m_ctrlTreeOptions,m_htiReask,GetResString(IDS_X_REASKSRC),iImgReaskSrc, m_htiDownloadReask,GetResString(IDS_X_REASKSRC_INFO));
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiReaskIntervals,GetResString(IDS_X_REASKSRC_INTERVALS), m_htiReask,GetResString(IDS_X_REASKSRC_INTERVALS_INFO));
			SetTreeGroup(m_ctrlTreeOptions,m_htiNnPReask,GetResString(IDS_X_REASKNNP),iImgReaskNnP, m_htiDownloadReask,GetResString(IDS_X_REASKNNP_INFO));
				if(ForFile()){
					SetTreeRadio(m_ctrlTreeOptions,m_htiReaskNnPDefault,GetResString(IDS_X_REASKNNP_DEFAULT),m_htiNnPReask,GetResString(IDS_X_REASKNNP_DEFAULT_INFO),TRUE,m_iNnPReask == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiReaskNnPEnable,GetResString(IDS_X_REASKNNP_ENABLE),m_htiNnPReask,GetResString(IDS_X_REASKNNP_ENABLE_INFO),TRUE,m_iNnPReask == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiReaskNnPDisable,GetResString(IDS_X_REASKNNP_DISABLE),m_htiNnPReask,GetResString(IDS_X_REASKNNP_DISABLE_INFO),TRUE,m_iNnPReask == 2);
				}else
					SetTreeCheck(m_ctrlTreeOptions,m_htiReaskNnPDisable,GetResString(IDS_X_REASKNNP_DISABLE),m_htiNnPReask,GetResString(IDS_X_REASKNNP_DISABLE_INFO),FALSE,m_bDontNnPReask);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiReaskNnPIntervals,GetResString(IDS_X_REASKNNP_INTERVALS), m_htiNnPReask,GetResString(IDS_X_REASKNNP_INTERVALS_INFO));
			SetTreeGroup(m_ctrlTreeOptions,m_htiFullQReask,GetResString(IDS_X_REASKFULLQ),iImgReaskFullQ, m_htiDownloadReask,GetResString(IDS_X_REASKFULLQ_INFO));
				if(ForFile()){
					SetTreeRadio(m_ctrlTreeOptions,m_htiReaskFullQDefault,GetResString(IDS_X_REASKFULLQ_DEFAULT),m_htiFullQReask,GetResString(IDS_X_REASKFULLQ_DEFAULT_INFO),TRUE,m_iFullQReask == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiReaskFullQEnable,GetResString(IDS_X_REASKFULLQ_ENABLE),m_htiFullQReask,GetResString(IDS_X_REASKFULLQ_ENABLE_INFO),TRUE,m_iFullQReask == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiReaskFullQDisable,GetResString(IDS_X_REASKFULLQ_DISABLE),m_htiFullQReask,GetResString(IDS_X_REASKFULLQ_DISABLE_INFO),TRUE,m_iFullQReask == 2);
				}else
					SetTreeCheck(m_ctrlTreeOptions,m_htiReaskFullQDisable,GetResString(IDS_X_REASKFULLQ_DISABLE),m_htiFullQReask,GetResString(IDS_X_REASKFULLQ_DISABLE_INFO),FALSE,m_iFullQReask);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiReaskFullQIntervals,GetResString(IDS_X_REASKFULLQ_INTERVALS), m_htiFullQReask,GetResString(IDS_X_REASKFULLQ_INTERVALS_INFO));
		// MOD: DR END

		// MOD: DS - [DropSources]
		SetTreeGroup(m_ctrlTreeOptions,m_htiDrop,GetResString(IDS_X_DROPSRC),iImgDrop, TVI_ROOT,GetResString(IDS_X_DROPSRC_INFO));
			if(ForFile()){
				SetTreeGroup(m_ctrlTreeOptions,m_htiUseDontAskThisIP,GetResString(IDS_X_DROP_LIST),iImgDropList, m_htiDrop,GetResString(IDS_X_DROPSRCNNP_INFO));
					SetTreeRadio(m_ctrlTreeOptions,m_htiUseDontAskThisIPDefault,GetResString(IDS_X_DROP_LIST_DEFAULT),m_htiUseDontAskThisIP,GetResString(IDS_X_DROP_LIST_DEFAULT_INFO),TRUE,m_iUseDontAskThisIP == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiUseDontAskThisIPEnable,GetResString(IDS_X_DROP_LIST_ENABLE),m_htiUseDontAskThisIP,GetResString(IDS_X_DROP_LIST_ENABLE_INFO),TRUE,m_iUseDontAskThisIP == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiUseDontAskThisIPDisable,GetResString(IDS_X_DROP_LIST_DISABLE),m_htiUseDontAskThisIP,GetResString(IDS_X_DROP_LIST_DISABLE_INFO),TRUE,m_iUseDontAskThisIP == 2);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDontAskThisIPTime,GetResString(IDS_X_DROP_LIST_TIME), m_htiUseDontAskThisIP,GetResString(IDS_X_DROP_LIST_TIME_INFO));
			}else
				SetTreeCheckNumEdit(m_ctrlTreeOptions,m_htiDontAskThisIPTime,GetResString(IDS_X_USE_DROP_LIST), m_htiDrop,GetResString(IDS_X_USE_DROP_LIST_INFO),FALSE, m_bUseDontAskThisIP);
			SetTreeGroup(m_ctrlTreeOptions,m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP),iImgDropNnP, m_htiDrop,GetResString(IDS_X_DROPSRCNNP_INFO));
				if(ForFile()){
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPDefault,GetResString(IDS_X_DROPSRCNNP_DEFAULT),m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP_DEFAULT_INFO),TRUE,m_iDropNnP == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPEnable,GetResString(IDS_X_DROPSRCNNP_ENABLE_TTS),m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP_ENABLE_TTS_INFO),TRUE,m_iDropNnP == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPEnable,GetResString(IDS_X_DROPSRCNNP_ENABLE),m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP_ENABLE_INFO),TRUE,m_iDropNnP == 2);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPDisable,GetResString(IDS_X_DROPSRCNNP_DISABLE),m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP_DISABLE_INFO),TRUE,m_iDropNnP == 3);
				}else
					SetTreeCheck(m_ctrlTreeOptions,m_htiDropNnPEnable,GetResString(IDS_X_DROPSRCNNP_ENABLE),m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP_ENABLE_INFO),TRUE,m_uDropNnP);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDropNnPLimit,GetResString(IDS_X_DROPSRCNNP_LIMIT), m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP_LIMIT_INFO));
					if(ForFile())
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPLimitDefault,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_DEFAULT),m_htiDropNnPLimit,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_DEFAULT_INFO),TRUE,m_iDropNnPLimitMode == 0);
					else
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPLimitDisable,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_DISABLE),m_htiDropNnPLimit,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_DISABLE_INFO),FALSE,m_iDropNnPLimitMode == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPLimitTotal,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_TOTAL),m_htiDropNnPLimit,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_TOTAL_INFO),ForFile(),m_iDropNnPLimitMode == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPLimitRelativ,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_RELATIVE),m_htiDropNnPLimit,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_RELATIVE_INFO),ForFile(),m_iDropNnPLimitMode == 2);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPLimitSpecyfic,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_SPECYFIC),m_htiDropNnPLimit,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_SPECYFIC_INFO),ForFile(),m_iDropNnPLimitMode == 3);
					if(ForFile())
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropNnPLimitDisable,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_DISABLE),m_htiDropNnPLimit,GetResString(IDS_X_DROPSRCNNP_LIMIT_MODE_DISABLE_INFO),TRUE,m_iDropNnPLimitMode == 4);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDropNnPTimer,GetResString(IDS_X_DROPSRCNNP_TIMER), m_htiDropNnP,GetResString(IDS_X_DROPSRCNNP_TIMER_INFO));
			SetTreeGroup(m_ctrlTreeOptions,m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ),iImgDropFullQ, m_htiDrop,GetResString(IDS_X_DROPSRCFULLQ_INFO));
				if(ForFile()){
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQDefault,GetResString(IDS_X_DROPSRCFULLQ_DEFAULT),m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ_DEFAULT_INFO),TRUE,m_iDropFullQ == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQEnable,GetResString(IDS_X_DROPSRCFULLQ_ENABLE_TTS),m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ_ENABLE_TTS_INFO),TRUE,m_iDropFullQ == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQEnable,GetResString(IDS_X_DROPSRCFULLQ_ENABLE),m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ_ENABLE_INFO),TRUE,m_iDropFullQ == 2);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQDisable,GetResString(IDS_X_DROPSRCFULLQ_DISABLE),m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ_DISABLE_INFO),TRUE,m_iDropFullQ == 3);
				}else
					SetTreeCheck(m_ctrlTreeOptions,m_htiDropFullQEnable,GetResString(IDS_X_DROPSRCFULLQ_ENABLE),m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ_ENABLE_INFO),TRUE,m_uDropFullQ);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDropFullQLimit,GetResString(IDS_X_DROPSRCFULLQ_LIMIT), m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_INFO));
					if(ForFile())
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQLimitDefault,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_DEFAULT),m_htiDropFullQLimit,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_DEFAULT_INFO),TRUE,m_iDropFullQLimitMode == 0);
					else
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQLimitDisable,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_DISABLE),m_htiDropFullQLimit,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_DISABLE_INFO),FALSE,m_iDropFullQLimitMode == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQLimitTotal,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_TOTAL),m_htiDropFullQLimit,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_TOTAL_INFO),ForFile(),m_iDropFullQLimitMode == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQLimitRelativ,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_RELATIVE),m_htiDropFullQLimit,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_RELATIVE_INFO),ForFile(),m_iDropFullQLimitMode == 2);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQLimitSpecyfic,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_SPECYFIC),m_htiDropFullQLimit,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_SPECYFIC_INFO),ForFile(),m_iDropFullQLimitMode == 3);
					if(ForFile())
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropFullQLimitDisable,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_DISABLE),m_htiDropFullQLimit,GetResString(IDS_X_DROPSRCFULLQ_LIMIT_MODE_DISABLE_INFO),TRUE,m_iDropFullQLimitMode == 4);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDropFullQTimer,GetResString(IDS_X_DROPSRCFULLQ_TIMER), m_htiDropFullQ,GetResString(IDS_X_DROPSRCFULLQ_TIMER_INFO));
			SetTreeGroup(m_ctrlTreeOptions,m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ),iImgDropHighQ, m_htiDrop,GetResString(IDS_X_DROPSRCHIGHQ_INFO));
				if(ForFile()){
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQDefault,GetResString(IDS_X_DROPSRCHIGHQ_DEFAULT),m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_DEFAULT_INFO),TRUE,m_iDropHighQ == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQEnable,GetResString(IDS_X_DROPSRCHIGHQ_ENABLE_TTS),m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_ENABLE_TTS_INFO),TRUE,m_iDropHighQ == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQEnable,GetResString(IDS_X_DROPSRCHIGHQ_ENABLE),m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_ENABLE_INFO),TRUE,m_iDropHighQ == 2);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQDisable,GetResString(IDS_X_DROPSRCHIGHQ_DISABLE),m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_DISABLE_INFO),TRUE,m_iDropHighQ == 3);
				}else
					SetTreeCheck(m_ctrlTreeOptions,m_htiDropHighQEnable,GetResString(IDS_X_DROPSRCHIGHQ_ENABLE),m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_ENABLE_INFO),TRUE,m_uDropHighQ);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDropHighQValue,GetResString(IDS_X_DROPSRCHIGHQ_VALUE), m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_VALUE_INFO));
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDropHighQLimit,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT), m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_INFO));
					if(ForFile())
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQLimitDefault,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_DEFAULT),m_htiDropHighQLimit,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_DEFAULT_INFO),TRUE,m_iDropHighQLimitMode == 0);
					else
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQLimitDisable,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_DISABLE),m_htiDropHighQLimit,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_DISABLE_INFO),FALSE,m_iDropHighQLimitMode == 0);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQLimitTotal,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_TOTAL),m_htiDropHighQLimit,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_TOTAL_INFO),ForFile(),m_iDropHighQLimitMode == 1);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQLimitRelativ,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_RELATIVE),m_htiDropHighQLimit,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_RELATIVE_INFO),ForFile(),m_iDropHighQLimitMode == 2);
					SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQLimitSpecyfic,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_SPECYFIC),m_htiDropHighQLimit,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_SPECYFIC_INFO),ForFile(),m_iDropHighQLimitMode == 3);
					if(ForFile())
						SetTreeRadio(m_ctrlTreeOptions,m_htiDropHighQLimitDisable,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_DISABLE),m_htiDropHighQLimit,GetResString(IDS_X_DROPSRCHIGHQ_LIMIT_MODE_DISABLE_INFO),TRUE,m_iDropHighQLimitMode == 4);
				SetTreeNumEdit(m_ctrlTreeOptions,m_htiDropHighQTimer,GetResString(IDS_X_DROPSRCHIGHQ_TIMER), m_htiDropHighQ,GetResString(IDS_X_DROPSRCHIGHQ_TIMER_INFO));
		// MOD: DS END

		//CheckSLEnable();

		if(!ForFile())

		m_ctrlTreeOptions.Expand(m_htiDownloadReask, TVE_EXPAND);
		m_ctrlTreeOptions.Expand(m_htiDrop, TVE_EXPAND);
		m_bInitializedTreeOpts = true;
	}

		// MOD: SR - [SpreadReask]
		if(!ForFile()){
			DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiSpreadReask, m_iSpreadReask);
			DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiSpreadReask, m_bSpreadReask);
		}
		// MOD: SR END

		// MOD: DR - [DownloadReask]
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiReaskIntervals, m_iReaskIntervals);

		if(ForFile()) 
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiNnPReask, m_iNnPReask);
		else
			DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiReaskNnPDisable, m_bDontNnPReask);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiReaskNnPIntervals, m_iNnPReaskIntervals);
	
		if(ForFile()) 
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiFullQReask, m_iFullQReask);
		else
			DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiReaskFullQDisable, m_bDontFullQReask);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiReaskFullQIntervals, m_iFullQReaskIntervals);
		// MOD: DR END

		// MOD: DS - [DropSources]
		if(ForFile())
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiUseDontAskThisIP, m_iUseDontAskThisIP);
		else
			DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiDontAskThisIPTime, m_bUseDontAskThisIP);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDontAskThisIPTime, m_iDontAskThisIPTime);

		if(ForFile()) 
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiDropNnP, m_iDropNnP);
		else
			DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiDropNnPEnable, m_uDropNnP);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDropNnPLimit, m_iDropNnPLimit);
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiDropNnPLimit, m_iDropNnPLimitMode);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDropNnPTimer, m_iDropNnPTimer);

		if(ForFile()) 
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiDropFullQ, m_iDropFullQ);
		else
			DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiDropFullQEnable, m_uDropFullQ);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDropFullQLimit, m_iDropFullQLimit);
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiDropFullQLimit, m_iDropFullQLimitMode);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDropFullQTimer, m_iDropFullQTimer);

		if(ForFile()) 
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiDropHighQ, m_iDropHighQ);
		else
			DDX_TreeCheck(pDX, IDC_MOD_OPTS, m_htiDropHighQEnable, m_uDropHighQ);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDropHighQValue, m_iDropHighQValue);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDropHighQLimit, m_iDropHighQLimit);
			DDX_TreeRadio(pDX, IDC_MOD_OPTS, m_htiDropHighQLimit, m_iDropHighQLimitMode);
		DDX_TreeEditE0(&m_ctrlTreeOptions, pDX, IDC_MOD_OPTS, m_htiDropHighQTimer, m_iDropHighQTimer);
		// MOD: DS END
}

BOOL CPPgSources::OnInitDialog()
{
	if(!m_bFilePreferences)
		LoadSettings();
	else
		RefreshData();

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

	// MOD: FCFG - [FileConfiguration]
	// no need to explicitly call 'RefreshData' here, 'OnSetActive' will be called right after 'OnInitDialog'

	// start time for calling 'RefreshData'
	if(m_bFilePreferences)
		VERIFY( (m_timer = SetTimer(301, 5000, 0)) != NULL );
	// MOD: FCFG END

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

BOOL CPPgSources::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;

	if(!m_bFilePreferences){
		/*
		* Globale Einstellungen Speichern
		*/

		// MOD: SR - [SpreadReask]
		thePrefs.m_bSpreadReask = m_bSpreadReask;
		if(m_iSpreadReask) thePrefs.m_iSpreadReask = m_iSpreadReask;
		// MOD: SR END

		// MOD: DR - [DownloadReask]
		if(m_iReaskIntervals) thePrefs.m_iReaskIntervals = m_iReaskIntervals;

		thePrefs.m_bDontNnPReask = m_bDontNnPReask;
		if(m_iNnPReaskIntervals) thePrefs.m_iNnPReaskIntervals = m_iNnPReaskIntervals;

		thePrefs.m_bDontFullQReask = m_bDontFullQReask;
		if(m_iFullQReaskIntervals) thePrefs.m_iFullQReaskIntervals = m_iFullQReaskIntervals;
		// MOD: DR END

		// MOD: DS - [DropSources]
		thePrefs.m_bUseDontAskThisIP = m_bUseDontAskThisIP;
		if(m_iDontAskThisIPTime) thePrefs.m_iDontAskThisIPTime = m_iDontAskThisIPTime;

		thePrefs.m_uDropNnP = m_uDropNnP;
		if(m_iDropNnPLimit) thePrefs.m_iDropNnPLimit = m_iDropNnPLimit;
		thePrefs.m_iDropNnPLimitMode = m_iDropNnPLimitMode;
		if(m_iDropNnPTimer) thePrefs.m_iDropNnPTimer = m_iDropNnPTimer;

		thePrefs.m_uDropFullQ = m_uDropFullQ;
		if(m_iDropFullQLimit) thePrefs.m_iDropFullQLimit = m_iDropFullQLimit;
		thePrefs.m_iDropFullQLimitMode = m_iDropFullQLimitMode;
		if(m_iDropFullQTimer) thePrefs.m_iDropFullQTimer = m_iDropFullQTimer;

		thePrefs.m_uDropHighQ = m_uDropHighQ;
		if(m_iDropHighQValue) thePrefs.m_iDropHighQValue = m_iDropHighQValue;
		if(m_iDropHighQLimit) thePrefs.m_iDropHighQLimit = m_iDropHighQLimit;
		thePrefs.m_iDropHighQLimitMode = m_iDropHighQLimitMode;
		if(m_iDropHighQTimer) thePrefs.m_iDropHighQTimer = m_iDropHighQTimer;
		// MOD: DS END

		thePrefs.CheckSionPreferences();
		LoadSettings();

	}else{
		/*
		* Datei Einstellungen Speichern
		*/
		// MOD: FCFG - [FileConfiguration]
		CPartFile* file;
		for (int i = 0; i < m_paFiles->GetSize(); i++)
		{
			file = STATIC_DOWNCAST(CPartFile, (*m_paFiles)[i]);


			//if (file->IsPartFile())

			// MOD: DR - [DownloadReask]
			if(m_iReaskIntervals) file->PartPrefs.m_iReaskIntervals = (m_iReaskIntervals != thePrefs.GetReaskIntervals()) ? m_iReaskIntervals : 0;

			if(m_iNnPReask != -1) file->PartPrefs.m_iNnPReask = m_iNnPReask;
			if(m_iNnPReaskIntervals) file->PartPrefs.m_iNnPReaskIntervals = (m_iNnPReaskIntervals != thePrefs.GetNnPReaskIntervals()) ? m_iNnPReaskIntervals : 0;

			if(m_iFullQReask != -1) file->PartPrefs.m_iFullQReask = m_iFullQReask;
			if(m_iFullQReaskIntervals) file->PartPrefs.m_iFullQReaskIntervals = (m_iFullQReaskIntervals != thePrefs.GetFullQReaskIntervals()) ? m_iFullQReaskIntervals : 0;
			// MOD: DR END

			// MOD: DS - [DropSources]
			if(m_iDropNnP != -1) file->PartPrefs.m_iDropNnP = m_iDropNnP;
			if(m_iDropNnPLimit) file->PartPrefs.m_iDropNnPLimit = (m_iDropNnPLimit != thePrefs.GetDropNnPLimit()) ? m_iDropNnPLimit : 0;
			if(m_iDropNnPLimitMode != -1) file->PartPrefs.m_iDropNnPLimitMode = m_iDropNnPLimitMode;
			if(m_iDropNnPTimer) file->PartPrefs.m_iDropNnPTimer = (m_iDropNnPTimer != thePrefs.GetDropNnPTimer()) ? m_iDropNnPTimer : 0;

			if(m_iDropFullQ != -1) file->PartPrefs.m_iDropFullQ = m_iDropFullQ;
			if(m_iDropFullQLimit) file->PartPrefs.m_iDropFullQLimit = (m_iDropFullQLimit != thePrefs.GetDropFullQLimit()) ? m_iDropFullQLimit : 0;
			if(m_iDropFullQLimitMode != -1) file->PartPrefs.m_iDropFullQLimitMode = m_iDropFullQLimitMode;
			if(m_iDropFullQTimer) file->PartPrefs.m_iDropFullQTimer = (m_iDropFullQTimer != thePrefs.GetDropFullQTimer()) ? m_iDropFullQTimer : 0;

			if(m_iDropHighQ != -1) file->PartPrefs.m_iDropHighQ = m_iDropHighQ;
			if(m_iDropHighQValue) file->PartPrefs.m_iDropHighQValue = (m_iDropHighQValue != thePrefs.GetDropHighQValue()) ? m_iDropHighQValue : 0;
			if(m_iDropHighQLimit) file->PartPrefs.m_iDropHighQLimit = (m_iDropHighQLimit != thePrefs.GetDropHighQLimit()) ? m_iDropHighQLimit : 0;
			if(m_iDropHighQLimitMode != -1) file->PartPrefs.m_iDropHighQLimitMode = m_iDropHighQLimitMode;
			if(m_iDropHighQTimer) file->PartPrefs.m_iDropHighQTimer = (m_iDropHighQTimer != thePrefs.GetDropHighQTimer()) ? m_iDropHighQTimer : 0;

			if(m_iUseDontAskThisIP != -1) file->PartPrefs.m_iUseDontAskThisIP = m_iUseDontAskThisIP;
			if(m_iDontAskThisIPTime) file->PartPrefs.m_iDontAskThisIPTime = (m_iDontAskThisIPTime != thePrefs.GetDontAskThisIPCleanUpTime()) ? m_iDontAskThisIPTime : 0;
			// MOD: DS END

			file->PartPrefs.CheckTweaks();
		}

		RefreshData();
		// MOD: FCFG END
	}

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

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

	// MOD: SR - [SpreadReask]
	m_bSpreadReask = thePrefs.m_bSpreadReask;
	m_iSpreadReask = thePrefs.m_iSpreadReask;
	// MOD: SR END

	// MOD: DR - [DownloadReask]
	m_iReaskIntervals = thePrefs.m_iReaskIntervals;

	m_bDontNnPReask = thePrefs.m_bDontNnPReask;
	m_iNnPReaskIntervals = thePrefs.m_iNnPReaskIntervals;

	m_bDontFullQReask = thePrefs.m_bDontFullQReask;
	m_iFullQReaskIntervals = thePrefs.m_iFullQReaskIntervals;
	// MOD: DR END

	// MOD: DS - [DropSources]
	m_bUseDontAskThisIP = thePrefs.m_bUseDontAskThisIP;
	m_iDontAskThisIPTime = thePrefs.m_iDontAskThisIPTime;

	m_uDropNnP = thePrefs.m_uDropNnP;
	m_iDropNnPLimit = thePrefs.m_iDropNnPLimit;
	m_iDropNnPLimitMode = thePrefs.m_iDropNnPLimitMode;
	m_iDropNnPTimer = thePrefs.m_iDropNnPTimer;

	m_uDropFullQ = thePrefs.m_uDropFullQ;
	m_iDropFullQLimit = thePrefs.m_iDropFullQLimit;
	m_iDropFullQLimitMode = thePrefs.m_iDropFullQLimitMode;
	m_iDropFullQTimer = thePrefs.m_iDropFullQTimer;

	m_uDropHighQ = thePrefs.m_uDropHighQ;
	m_iDropHighQValue = thePrefs.m_iDropHighQValue;
	m_iDropHighQLimit = thePrefs.m_iDropHighQLimit;
	m_iDropHighQLimitMode = thePrefs.m_iDropHighQLimitMode;
	m_iDropHighQTimer = thePrefs.m_iDropHighQTimer;
	// MOD: DS END
}

// MOD: FCFG - [FileConfiguration]
void CPPgSources::RefreshData()
{
	/*
	* Datei Einstellungen Laden
	*/

	const CPartFile* file = STATIC_DOWNCAST(CPartFile, (*m_paFiles)[0]);

	//if (file->IsPartFile())

	// MOD: DR - [DownloadReask]
	m_iReaskIntervals = file->PartPrefs.m_iReaskIntervals;

	m_iNnPReask = file->PartPrefs.m_iNnPReask;
	m_iNnPReaskIntervals = file->PartPrefs.m_iNnPReaskIntervals;

	m_iFullQReask = file->PartPrefs.m_iFullQReask;
	m_iFullQReaskIntervals = file->PartPrefs.m_iFullQReaskIntervals;
	// MOD: DR END

	// MOD: DS - [DropSources]
	m_iDropNnP = file->PartPrefs.m_iDropNnP;
	m_iDropNnPLimit = file->PartPrefs.m_iDropNnPLimit;
	m_iDropNnPLimitMode = file->PartPrefs.m_iDropNnPLimitMode;
	m_iDropNnPTimer = file->PartPrefs.m_iDropNnPTimer;

	m_iDropFullQ = file->PartPrefs.m_iDropFullQ;
	m_iDropFullQLimit = file->PartPrefs.m_iDropFullQLimit;
	m_iDropFullQLimitMode = file->PartPrefs.m_iDropFullQLimitMode;
	m_iDropFullQTimer = file->PartPrefs.m_iDropFullQTimer;

	m_iDropHighQ = file->PartPrefs.m_iDropHighQ;
	m_iDropHighQValue = file->PartPrefs.m_iDropHighQValue;
	m_iDropHighQLimit = file->PartPrefs.m_iDropHighQLimit;
	m_iDropHighQLimitMode = file->PartPrefs.m_iDropHighQLimitMode;
	m_iDropHighQTimer = file->PartPrefs.m_iDropHighQTimer;

	m_iUseDontAskThisIP = file->PartPrefs.m_iUseDontAskThisIP;
	m_iDontAskThisIPTime = file->PartPrefs.m_iDontAskThisIPTime;
	// MOD: DS END

	for (int i = 1; i < m_paFiles->GetSize(); i++)
	{
		file = STATIC_DOWNCAST(CPartFile, (*m_paFiles)[i]);

		//if (file->IsPartFile())

		// MOD: DR - [DownloadReask]
		if(m_iReaskIntervals != file->PartPrefs.m_iReaskIntervals) m_iReaskIntervals = UN_INT;

		if(m_iNnPReask != file->PartPrefs.m_iNnPReask) m_iNnPReask = -1;
		if(m_iNnPReaskIntervals != file->PartPrefs.m_iNnPReaskIntervals) m_iNnPReaskIntervals = UN_INT;

		if(m_iFullQReask != file->PartPrefs.m_iFullQReask) m_iFullQReask = -1;
		if(m_iFullQReaskIntervals != file->PartPrefs.m_iFullQReaskIntervals) m_iFullQReaskIntervals = UN_INT;
		// MOD: DR END

		// MOD: DS - [DropSources]
		if(m_iDropNnP != file->PartPrefs.m_iDropNnP) m_iDropNnP = -1;
		if(m_iDropNnPLimit != file->PartPrefs.m_iDropNnPLimit) m_iDropNnPLimit = UN_INT;
		if(m_iDropNnPLimitMode != file->PartPrefs.m_iDropNnPLimitMode) m_iDropNnPLimitMode = -1;
		if(m_iDropNnPTimer != file->PartPrefs.m_iDropNnPTimer) m_iDropNnPTimer = UN_INT;

		if(m_iDropFullQ != file->PartPrefs.m_iDropFullQ) m_iDropFullQ = -1;
		if(m_iDropFullQLimit != file->PartPrefs.m_iDropFullQLimit) m_iDropFullQLimit = UN_INT;
		if(m_iDropFullQLimitMode != file->PartPrefs.m_iDropFullQLimitMode) m_iDropFullQLimitMode = -1;
		if(m_iDropFullQTimer != file->PartPrefs.m_iDropFullQTimer) m_iDropFullQTimer = UN_INT;

		if(m_iDropHighQ != file->PartPrefs.m_iDropHighQ) m_iDropHighQ = -1;
		if(m_iDropHighQValue != file->PartPrefs.m_iDropHighQValue) m_iDropHighQValue = UN_INT;
		if(m_iDropHighQLimit != file->PartPrefs.m_iDropHighQLimit) m_iDropHighQLimit = UN_INT;
		if(m_iDropHighQLimitMode != file->PartPrefs.m_iDropHighQLimitMode) m_iDropHighQLimitMode = -1;
		if(m_iDropHighQTimer != file->PartPrefs.m_iDropHighQTimer) m_iDropHighQTimer = UN_INT;

		if(m_iUseDontAskThisIP != file->PartPrefs.m_iUseDontAskThisIP) m_iUseDontAskThisIP = -1;
		if(m_iDontAskThisIPTime != file->PartPrefs.m_iDontAskThisIPTime) m_iDontAskThisIPTime = UN_INT;
		// MOD: DS END
	}

	// MOD: DR - [DownloadReask]
	if(!m_iReaskIntervals)
		m_iReaskIntervals = thePrefs.GetReaskIntervals();
	else if(m_iReaskIntervals == UN_INT)
		m_iReaskIntervals = 0;

	if(!m_iNnPReaskIntervals)
		m_iNnPReaskIntervals = thePrefs.GetNnPReaskIntervals();
	else if(m_iNnPReaskIntervals == UN_INT)
		m_iNnPReaskIntervals = 0;

	if(!m_iFullQReaskIntervals)
		m_iFullQReaskIntervals = thePrefs.GetFullQReaskIntervals();
	else if(m_iFullQReaskIntervals == UN_INT)
		m_iFullQReaskIntervals = 0;
	// MOD: DR END

	// MOD: DS - [DropSources]
	if(!m_iDropNnPLimit)
		m_iDropNnPLimit = thePrefs.GetDropNnPLimit();
	else if(m_iDropNnPLimit == UN_INT)
		m_iDropNnPLimit = 0;
	if(!m_iDropNnPTimer)
		m_iDropNnPTimer = thePrefs.GetDropNnPTimer();
	else if(m_iDropNnPTimer == UN_INT)
		m_iDropNnPTimer = 0;

	if(!m_iDropFullQLimit)
		m_iDropFullQLimit = thePrefs.GetDropFullQLimit();
	else if(m_iDropFullQLimit == UN_INT)
		m_iDropFullQLimit = 0;
	if(!m_iDropFullQTimer)
		m_iDropFullQTimer = thePrefs.GetDropFullQTimer();
	else if(m_iDropFullQTimer == UN_INT)
		m_iDropFullQTimer = 0;

	if(!m_iDropFullQLimit)
		m_iDropFullQLimit = thePrefs.GetDropFullQLimit();
	else if(m_iDropFullQLimit == UN_INT)
		m_iDropFullQLimit = 0;

	if(!m_iDropHighQValue)
		m_iDropHighQValue = thePrefs.GetDropHighQValue();
	else if(m_iDropHighQValue == UN_INT)
		m_iDropHighQValue = 0;
	if(!m_iDropHighQLimit)
		m_iDropHighQLimit = thePrefs.GetDropHighQLimit();
	else if(m_iDropHighQLimit == UN_INT)
		m_iDropHighQLimit = 0;
	if(!m_iDropHighQTimer)
		m_iDropHighQTimer = thePrefs.GetDropHighQTimer();
	else if(m_iDropHighQTimer == UN_INT)
		m_iDropHighQTimer = 0;

	if(!m_iDontAskThisIPTime)
		m_iDontAskThisIPTime = thePrefs.GetDontAskThisIPCleanUpTime();
	else if(m_iDontAskThisIPTime == UN_INT)
		m_iDontAskThisIPTime = 0;
	// MOD: DS END
}

void CPPgSources::OnTimer(UINT /*nIDEvent*/)
{
	if (m_bDataChanged)
	{
		RefreshData();
		m_bDataChanged = false;
	}
}

BOOL CPPgSources::OnSetActive()
{
	if (!CPropertyPage::OnSetActive())
		return FALSE;
	if (m_bDataChanged)
	{
		RefreshData();
		m_bDataChanged = false;
	}
	return TRUE;
}

LRESULT CPPgSources::OnDataChanged(WPARAM, LPARAM)
{
	m_bDataChanged = true;
	return 1;
}
// MOD: FCFG END

void CPPgSources::OnDestroy()
{
	// MOD: FCFG - [FileConfiguration]
	if (m_timer){
		KillTimer(m_timer);
		m_timer = 0;
	}
	// MOD: FCFG END

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

/*void CPPgSources::Localize()
{
}*/

BOOL CPPgSources::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();
}

LRESULT CPPgSources::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: FCFG - [FileConfiguration]

			// MOD: DR - [DownloadReask]
			// MOD: SR - [SpreadReask]
			if(!ForFile() && m_htiSpreadReask && pton->hItem == m_htiSpreadReask){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiSpreadReask, VAL_SPREAD_REASK_MIN, VAL_SPREAD_REASK_DEF, VAL_SPREAD_REASK_MAX)) SetModified();
			}
			// MOD: SR END
			else if(m_htiReaskIntervals && pton->hItem == m_htiReaskIntervals){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiReaskIntervals, TIM_REASK_MIN, ForFile() ? thePrefs.GetReaskIntervals() : TIM_REASK_DEF, TIM_REASK_MAX)) SetModified();
			}
			else if(m_htiReaskNnPIntervals && pton->hItem == m_htiReaskNnPIntervals){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiReaskNnPIntervals, TIM_REASK_NNP_MIN, ForFile() ? thePrefs.GetNnPReaskIntervals() : TIM_REASK_NNP_DEF, TIM_REASK_NNP_MAX)) SetModified();
			}
			else if(m_htiReaskFullQIntervals && pton->hItem == m_htiReaskFullQIntervals){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiReaskFullQIntervals, TIM_REASK_FULLQ_MIN, ForFile() ? thePrefs.GetFullQReaskIntervals() : TIM_REASK_FULLQ_DEF, TIM_REASK_FULLQ_MAX)) SetModified();
			}
			// MOD: DR END
			// MOD: DS - [DropSources]
			else if(m_htiDontAskThisIPTime && pton->hItem == m_htiDontAskThisIPTime){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDontAskThisIPTime, VAL_DONT_ASK_THIS_IP_TIME_MIN, ForFile() ? thePrefs.GetDontAskThisIPCleanUpTime() : VAL_DONT_ASK_THIS_IP_TIME_DEF, VAL_DONT_ASK_THIS_IP_TIME_MAX)) SetModified();
			}
			else if(m_htiDropNnPLimit && pton->hItem == m_htiDropNnPLimit){
				int m_iLimitMode; HTREEITEM hDummy;
				m_ctrlTreeOptions.GetRadioButton(m_htiDropNnPLimit,m_iLimitMode,hDummy);
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDropNnPLimit, VAL_DROP_LIMIT_MIN(m_iLimitMode), (ForFile() && m_iLimitMode == thePrefs.m_iDropNnPLimitMode)? thePrefs.GetDropNnPLimit() : VAL_DROP_LIMIT_DEF(m_iLimitMode), VAL_DROP_LIMIT_MAX(m_iLimitMode))) SetModified();
			}
			else if(m_htiDropNnPTimer && pton->hItem == m_htiDropNnPTimer){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDropNnPTimer, TIM_DROP_MIN, ForFile() ? thePrefs.GetDropNnPTimer() : TIM_DROP_DEF, TIM_DROP_MAX)) SetModified();
			}

			else if(m_htiDropFullQLimit && pton->hItem == m_htiDropFullQLimit){
				int m_iLimitMode; HTREEITEM hDummy;
				m_ctrlTreeOptions.GetRadioButton(m_htiDropFullQLimit,m_iLimitMode,hDummy);
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDropFullQLimit, VAL_DROP_LIMIT_MIN(m_iLimitMode), (ForFile() && m_iLimitMode == thePrefs.m_iDropFullQLimitMode) ? thePrefs.GetDropFullQLimit() : VAL_DROP_LIMIT_DEF(m_iLimitMode), VAL_DROP_LIMIT_MAX(m_iLimitMode))) SetModified();
			}
			else if(m_htiDropFullQTimer && pton->hItem == m_htiDropFullQTimer){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDropFullQTimer, TIM_DROP_MIN, ForFile() ? thePrefs.GetDropFullQTimer() : TIM_DROP_DEF, TIM_DROP_MAX)) SetModified();
			}

			else if(m_htiDropHighQLimit && pton->hItem == m_htiDropHighQLimit){
				int m_iLimitMode; HTREEITEM hDummy;
				m_ctrlTreeOptions.GetRadioButton(m_htiDropHighQLimit,m_iLimitMode,hDummy);
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDropHighQLimit, VAL_DROP_LIMIT_MIN(m_iLimitMode), (ForFile() && m_iLimitMode == thePrefs.m_iDropHighQLimitMode) ? thePrefs.GetDropHighQLimit() : VAL_DROP_LIMIT_DEF(m_iLimitMode), VAL_DROP_LIMIT_MAX(m_iLimitMode))) SetModified();
			}
			else if(m_htiDropHighQTimer && pton->hItem == m_htiDropHighQTimer){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDropHighQTimer, TIM_DROP_MIN, ForFile() ? thePrefs.GetDropHighQTimer() : TIM_DROP_DEF, TIM_DROP_MAX)) SetModified();
			}
			else if(m_htiDropHighQValue && pton->hItem == m_htiDropHighQValue){
				if(CheckTreeEditLimit(m_ctrlTreeOptions, m_htiDropHighQValue, VAL_DROP_HQ_VALUE_MIN, ForFile() ? thePrefs.GetDropHighQValue() : VAL_DROP_HQ_VALUE_DEF, VAL_DROP_HQ_VALUE_MAX)) SetModified();
			}
			// MOD: DS END
			// MOD: FCFG END
			
		}else{
			UINT bCheck;

			// MOD: SR - [SpreadReask]
			if (!ForFile() && m_htiSpreadReask && pton->hItem == m_htiSpreadReask){
				m_ctrlTreeOptions.GetCheckBox(m_htiSpreadReask, bCheck);
				m_ctrlTreeOptions.SetItemEnable(m_htiSpreadReask, bCheck, TRUE, TRUE);
			}
			// MOD: SR END
			if (!ForFile() && m_htiDontAskThisIPTime && pton->hItem == m_htiDontAskThisIPTime){
				m_ctrlTreeOptions.GetCheckBox(m_htiDontAskThisIPTime, bCheck);
				m_ctrlTreeOptions.SetItemEnable(m_htiDontAskThisIPTime, bCheck, TRUE, TRUE);
			}
			SetModified();
		}
	}
	return 0;
}

// MOD: NST - [NeoSourceTweaks]
/*void CPPgSources::CheckSLEnable()
{
	UINT bCheck;
	if(!ForFile())
		m_ctrlTreeOptions.GetCheckBox(m_htiCalcStandardLimits, bCheck)
	else{
		int Index;
		m_ctrlTreeOptions.GetRadioButton(m_htiCalcStandardLimits, Index);
		if(Index == 1 || (Index == 0 && thePrefs.IsCalcStandardLimits()))
			bCheck = 1
		else
			bCheck = 0;
	}
	m_ctrlTreeOptions.SetItemEnable(m_htiXSLimit, bCheck);
	m_ctrlTreeOptions.SetItemEnable(m_htiSVRLimit, bCheck);
	m_ctrlTreeOptions.SetItemEnable(m_htiKADLimit, bCheck);
	m_ctrlTreeOptions.SetItemEnable(m_htiUDPLimit, bCheck);
}*/
// MOD: NST END


LRESULT CPPgSources::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 CPPgSources::OnHelp()
{
	//theApp.ShowHelp(0);
}

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

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