int CDefaultDlg::ShowPreloaderOptionsDlg() {
	COptionsDlg dlg(this);	// Set the options dialog's parent
	CString szLPath;		// This is where autofind will save the path it finds
	CRegistryKey *softKey = this->p_cReg.KeyCurrentUser()->CreateKey(_T("SOFTWARE\\6XGate Incorporated\\PalemoonPreload"));

	// Initialize the dialog
	dlg.m_szPath = this->p_szPalemoonPath;			// Current Palemoon Path
	dlg.m_bAutoFindFF = this->p_bAutoFindFF;		// Do we AutoFind Palemoon?
	dlg.m_bWarnOnUnload = this->p_bWarnOnUnloads;	// Do we warn the user about unloading Palemoon?
	
	// Show the dialog
	int nResponse = dlg.DoModal();
	if (nResponse == IDOK) {
		// If the user enables AutoFind, try to find Palemoon automaticly
		if (dlg.m_bAutoFindFF && ::GetLatestPalemoonInstallDir(&szLPath)) {

			// Remove the saved path since AutoFind found Palemoon's path
			softKey->DeleteValue(_T("Path"));
			this->p_bAutoFindFF = TRUE;
			this->p_szPalemoonPath = szLPath;
			softKey->SetIntegerValue(_T("AutoFind"), TRUE);
			::OutputDebugString(_T("Using AutoFind Path\r\n"));

		// If the user manually entered the path that was validated, use it
		} else {

			// Disable AutoFind and get the manually entered path
			this->p_bAutoFindFF = FALSE;
			this->p_szPalemoonPath = dlg.m_szPath;

			// Trim the \ off the path if it is present save the settings
			if (this->p_szPalemoonPath[this->p_szPalemoonPath.GetLength() - 1] == _T('\\')) this->p_szPalemoonPath.TrimRight(_T('\\'));
			softKey->SetStringValue(_T("Path"), this->p_szPalemoonPath);
			softKey->SetIntegerValue(_T("AutoFind"), FALSE);
			::OutputDebugString(_T("Using Manually Entered Path\r\n"));
		
		}

		// Get and save the warning settings
		this->p_bWarnOnUnloads = dlg.m_bWarnOnUnload;
		softKey->SetIntegerValue(_T("WarnOnUnloads"), this->p_bWarnOnUnloads);
		
		// Free the registry key
		delete softKey;
	}

	return nResponse;
}
BOOL CDefaultDlg::OnInitDialog() {
	CDialog::OnInitDialog();
	CString				// Strings
		szMessage,		// MessageBox message resources
		szTitle,		// MessageBox title resources
		szLPath;		// This is where autofind will save the path it finds

	// Initialize Registry Access
	CRegistryKey *softKey = this->p_cReg.KeyCurrentUser()->CreateKey(_T("SOFTWARE\\6XGate Incorporated\\PalemoonPreload"));
	::OutputDebugString(_T("\r\nLoading Settings...\r\n"));
	
	// Load the timer configuration, save and use the default if not set
	softKey->GetIntegerValue(_T("PollInterval"), (ULONG*)&(this->p_nTimerInt));
	if (this->p_nTimerInt == 0) {
		::OutputDebugString(_T("Default timer Interval\r\n"));
		this->p_nTimerInt = 5000;
		softKey->SetIntegerValue(_T("PollInterval"), this->p_nTimerInt);
	}
	
	// Load the Warning configuration, save and use the default it not set
	if (softKey->GetIntegerValue(_T("WarnOnUnloads"), (ULONG*)&(this->p_bWarnOnUnloads)) != ERROR_SUCCESS)
		softKey->SetIntegerValue(_T("WarnOnUnloads"), this->p_bWarnOnUnloads);

	// Load the AutoFind configuration, then get Palemoon's path if AutoFind is enabled
	softKey->GetIntegerValue(_T("AutoFind"), (ULONG*)&(this->p_bAutoFindFF));
	if (this->p_bAutoFindFF && ::GetLatestPalemoonInstallDir(&szLPath)) {
		::OutputDebugString(_T("Using AutoFind\r\n"));

		// Remove the saved path since AutoFind found Palemoon's path
		softKey->DeleteValue(_T("Path"));
		this->p_szPalemoonPath = szLPath;		
		softKey->SetIntegerValue(_T("AutoFind"), TRUE);

	// If AutoFind is not enabled, or the path couldn't be found, use the manually entered path
	} else {
		::OutputDebugString(_T("Unable to use AutoFind, trying manually\r\n"));

		this->p_bAutoFindFF = FALSE;
		softKey->SetIntegerValue(_T("AutoFind"), FALSE);
		softKey->GetStringValue(_T("Path"), &(this->p_szPalemoonPath));
	}

	// If the path was not found by the manual setting or automatically, ask the user for it
	if (this->p_szPalemoonPath.IsEmpty()) {
		::OutputDebugString(_T("We didn't get the path, lets ask the user for on\r\n"));
		
		this->p_bTimer = FALSE;
		szMessage.LoadString(IDS_ENTERPATH); szTitle.LoadString(IDS_TRAYTIP);
		this->MessageBox (szMessage, szTitle, MB_OK);
		
		// Display the Options dialog box to ask the user for the path, or let the user enable AutoFind
		if (this->ShowPreloaderOptionsDlg() != IDOK) {
			::OutputDebugString(_T("The user cancelled\r\n"));
			szTitle.LoadString(IDS_ERROR_TITLE);
			szMessage.LoadString(IDS_NEEDPATH);

			// The user didn't enter the path, display a warning and end the program
			this->MessageBox (szMessage, szTitle, MB_OK);
			delete softKey;					// Free the key
			this->EndDialog(IDCANCEL);		// End the dialog
			return TRUE;					// And end the funcion
		}
	}

	// If the current profile directory can be found, then enable to parent.lock watcher code
	this->p_bUserLock = ::GetCurrentPalemoonProfile(&(this->p_szProfilePath));

	// Show the tray icon, free the key, and load Palemoon
	this->ShowTrayIcon();
	delete softKey;
	this->PreloadFF();

	// Set the timer
	this->SetTimer(1, this->p_nTimerInt, NULL);
	this->p_bTimer = TRUE;

	return TRUE;  // return TRUE unless you set the focus to a control
}