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;
}
Пример #2
0
int CShellCommandDeleteValue::Execute(CConsole &rConsole, CArgumentParser& rArguments)
{
  rArguments.ResetArgumentIteration();
  TCHAR *pszCommandItself = rArguments.GetNextArgument();

  TCHAR *pszParameter;
  TCHAR *pszValueFull = NULL;
  BOOL blnHelp = FALSE;

  if ((_tcsnicmp(pszCommandItself,DV_CMD _T(".."),DV_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
      (_tcsnicmp(pszCommandItself,DV_CMD _T("\\"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
  {
    pszValueFull = pszCommandItself + DV_CMD_LENGTH;
  }
  else if (_tcsnicmp(pszCommandItself,DV_CMD _T("/"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
  {
    pszParameter = pszCommandItself + DV_CMD_LENGTH;
    goto CheckValueArgument;
  }

  while((pszParameter = rArguments.GetNextArgument()) != NULL)
  {
CheckValueArgument:
    if ((_tcsicmp(pszParameter,_T("/?")) == 0)
        ||(_tcsicmp(pszParameter,_T("-?")) == 0))
    {
      blnHelp = TRUE;
      break;
    }
    else if (!pszValueFull)
    {
      pszValueFull = pszParameter;
    }
    else
    {
      rConsole.Write(_T("Bad parameter: "));
      rConsole.Write(pszParameter);
      rConsole.Write(_T("\n"));
    }
  }

  CRegistryKey Key;
  TCHAR *pszValueNamePattern;
  const TCHAR *pszEmpty = _T("");
  const TCHAR *pszPath;

  if (blnHelp)
  {
    rConsole.Write(GetHelpString());
    return 0;
  }

  if (pszValueFull)
  {
    if (_tcscmp(pszValueFull,_T("\\")) == 0)
      goto CommandNAonRoot;

    TCHAR *pchSep = _tcsrchr(pszValueFull,_T('\\'));
    pszValueNamePattern = pchSep?(pchSep+1):(pszValueFull);
    pszPath = pchSep?pszValueFull:_T(".");

    if (pchSep)
      *pchSep = 0;
  }
  else
  {
    pszValueNamePattern = (TCHAR*)pszEmpty;
    pszPath = _T(".");
  }

  {
    size_t s = _tcslen(pszValueNamePattern);
    if (s && (pszValueNamePattern[0] == _T('\"'))&&(pszValueNamePattern[s-1] == _T('\"')))
    {
      pszValueNamePattern[s-1] = 0;
      pszValueNamePattern++;
    }
  }

  if (!m_rTree.GetKey(pszPath,KEY_QUERY_VALUE|KEY_SET_VALUE,Key))
  {
    rConsole.Write(m_rTree.GetLastErrorDescription());
    return 0;
  }

  if (!Key.IsRoot())
  {	// not root key ???
    TCHAR Buffer[254];
    DWORD dwMaxValueNameLength;
    LONG nError = Key.GetMaxValueNameLength(dwMaxValueNameLength);
    if (nError != ERROR_SUCCESS)
    {
      _stprintf(Buffer,_T("Cannot query info about %s key. Error is %u\n"),Key.GetKeyName(),(unsigned int)nError);
      rConsole.Write(Buffer);
      return 0;
    }

    TCHAR *pszValueName = new (std::nothrow) TCHAR[dwMaxValueNameLength];
    if (!pszValueName)
    {
      rConsole.Write("Out of memory.");
      return 0;
    }

    Key.InitValueEnumeration(pszValueName,dwMaxValueNameLength,NULL,0,NULL);

    while ((nError = Key.GetNextValue()) == ERROR_SUCCESS)
    {
      if (PatternMatch(pszValueNamePattern,pszValueName))
      {
        nError = Key.DeleteValue(pszValueName);
        if (nError != ERROR_SUCCESS)
        {
          _stprintf(Buffer,_T("Cannot delete value. Error is %u\n"),(unsigned int)nError);
          rConsole.Write(Buffer);
        }
        else
        {
          InvalidateCompletion();
        }
        Key.InitValueEnumeration(pszValueName,dwMaxValueNameLength,NULL,0,NULL); // reset iteration
      }
    }
  } // if (pKey)
  else
  {
CommandNAonRoot:
    rConsole.Write(DV_CMD COMMAND_NA_ON_ROOT);
  }

  return 0;
}
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
}