Пример #1
0
BOOL CMailMsg::DetectMailClient(WTL::CString& sMailClientName)
{
    ATL::CRegKey regKey;
    TCHAR buf[1024] = _T("");
    ULONG buf_size = 0;
    LONG lResult;

    lResult = regKey.Open(HKEY_CURRENT_USER, _T("SOFTWARE\\Clients\\Mail"), KEY_READ);
    if(lResult!=ERROR_SUCCESS)
    {
        lResult = regKey.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Clients\\Mail"), KEY_READ);
    }

    if(lResult==ERROR_SUCCESS)
    {    
        buf_size = 1023;
#pragma warning(disable:4996)
        LONG result = regKey.QueryValue(buf, _T(""), &buf_size);
#pragma warning(default:4996)
        if(result==ERROR_SUCCESS)
        {
            sMailClientName = buf;
            return TRUE;  
        }

        regKey.Close();  
    }
    else
    {
        sMailClientName = "Not Detected";
    }

    return FALSE;
}
BOOL CNTEventLogSource::GetStringArrayFromRegistry(ATL::CRegKey& key, LPCTSTR lpszEntry, CNTServiceStringArray& array, DWORD* pLastError)
{
  //Validate our parameters
  ATLASSERT(lpszEntry != NULL);

  //What will be the return value from this function, assume the worst
  BOOL bSuccess = FALSE;

  //Empty the array before we go any further
#ifdef CNTSERVICE_MFC_EXTENSIONS
  array.RemoveAll();
#else
  array.clear();
#endif

  DWORD dwType = 0;
  ULONG nBytes = 0;
  LONG lResult = key.QueryValue(lpszEntry, &dwType, NULL, &nBytes);
  if (lResult == ERROR_SUCCESS)
  {
    //Allocate some memory for the API
    ATL::CHeapPtr<TCHAR> lpBuffer;
    ULONG nChars = nBytes / sizeof(TCHAR);
    if (nChars < 2) //Ensure we can handle an empty MULTI_SZ string
      nChars = 2;
    if (!lpBuffer.Allocate(nChars))
    {
      SetLastError(ERROR_OUTOFMEMORY);
      if (pLastError)
        *pLastError = ERROR_OUTOFMEMORY;
      return FALSE;
    }

    lResult = key.QueryMultiStringValue(lpszEntry, lpBuffer, &nChars);      
    if (lResult == ERROR_SUCCESS)
    {
      LPTSTR lpszStrings = lpBuffer.m_pData;
      while (lpszStrings[0] != 0)
      {
      #ifdef CNTSERVICE_MFC_EXTENSIONS
        array.Add(lpszStrings);
      #else
        array.push_back(lpszStrings);
      #endif
        lpszStrings += (_tcslen(lpszStrings) + 1);
      }

      bSuccess = TRUE;
    }
    else
    {
      if (pLastError)
        *pLastError = lResult;
    }
  }
  else
  {
    if (pLastError)
      *pLastError = lResult;
  }

  return bSuccess;
}
Пример #3
0
void CCrashHandler::GenerateErrorReport(PEXCEPTION_POINTERS pExInfo)
{
   CExceptionReport  rpt(pExInfo);
   CMainDlg          mainDlg;
   CZLib             zlib;
   CString           sTempFileName = CUtility::getTempFileName();
   unsigned int      i;

   // let client add application specific files to report
   if (m_lpfnCallback && !m_lpfnCallback(this))
      return;

	//Определеяем, что делать с отчетом
	DumpType dumpType = Referenced;//По умолчанию сбрасываем только ту память, на которую идут ссылки в стеке
	ActionType actionType = GUI;//По умолчанию - выводим пользователю диалог
	CString action, storeFolder, dump;

	ATL::CRegKey rk;
	//Читаем из ключа с именем приложения
	int32_t lRet = rk.Open(HKEY_LOCAL_MACHINE,
	   TEXT("SOFTWARE\\Cognitive Technologies Ltd.\\CuneiForm\\PumaCrashRpt\\")
	   + CUtility::getAppName(), KEY_QUERY_VALUE);
	if(lRet != ERROR_SUCCESS)
	{
		//Читаем из дефолтного ключа
		lRet = rk.Open(HKEY_LOCAL_MACHINE,
			TEXT("SOFTWARE\\Cognitive Technologies Ltd.\\CuneiForm\\PumaCrashRpt\\Default"),
			KEY_QUERY_VALUE);
	}
	if(lRet == ERROR_SUCCESS)
	{
		//Читаем дейтсвие
		uint32_t dwBufLen = 1000;
		rk.QueryValue(action.GetBuffer(1000), "Action", &dwBufLen);
	    action.ReleaseBuffer(MAX(dwBufLen - 1, 0));

		//Читаем папку для автосохранения
		dwBufLen = 1000;
		rk.QueryValue(storeFolder.GetBuffer(1000), "StoreFolder", &dwBufLen);
	    storeFolder.ReleaseBuffer(MAX(dwBufLen - 1, 0));

		//Читаем тип дампа
		dwBufLen = 1000;
		rk.QueryValue(dump.GetBuffer(1000), "DumpType", &dwBufLen);
	    dump.ReleaseBuffer(MAX(dwBufLen - 1, 0));

		rk.Close();

		if (!action.IsEmpty())
		{
			if (action.CompareNoCase("GUI") == 0)
				actionType = GUI;
			else if (action.CompareNoCase("QuietStore") == 0)
				actionType = QuietStore;
			else if (action.CompareNoCase("NoAction") == 0)
				actionType = NoAction;

		}
		if (!dump.IsEmpty())
		{
			if (dump.CompareNoCase("Mini") == 0)
				dumpType = Mini;
			else if (dump.CompareNoCase("Referenced") == 0)
				dumpType = Referenced;
			else if (dump.CompareNoCase("Full") == 0)
				dumpType = Full;

		}
		if (storeFolder.CompareNoCase("Temp folder") == 0)
			storeFolder = getenv("TEMP");
	}

	if (actionType == NoAction)
		return;

   // add crash files to report
   m_files[rpt.getCrashFile(dumpType)] = CString((const char *)IDS_CRASH_DUMP);
   m_files[rpt.getCrashLog()] = CString((const char *)IDS_CRASH_LOG);

   // add symbol files to report
   for (i = 0; i < (uint)rpt.getNumSymbolFiles(); i++)
      m_files[(const char *)rpt.getSymbolFile(i)] =
      CString((const char *)IDS_SYMBOL_FILE);

   // zip the report
   if (!zlib.Open(sTempFileName))
      return;

   // add report files to zip
   TStrStrMap::iterator cur = m_files.begin();
   for (i = 0; i < m_files.size(); i++, cur++)
      zlib.AddFile((*cur).first);

   zlib.Close();

   if (actionType == GUI)
   {
	   // display main dialog
	   mainDlg.m_pUDFiles = &m_files;

	   //Сохраняем флаги по исключениям с плавающей точкой - кто-то их злобно сбрасывает при показе диалога
	   uint oldFpState = _controlfp(0, 0);
	   if (IDOK == mainDlg.DoModal())
	   {
	      if (m_sTo.IsEmpty() ||
		      !MailReport(rpt, sTempFileName, mainDlg.m_sEmail, mainDlg.m_sDescription))
		  {
			 SaveReport(rpt, sTempFileName);
		  }
	   }
	   //Восстанавливаем флаги
	   _controlfp(oldFpState, _MCW_DN | _MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC);
   }
   else if (actionType == QuietStore)
   {
		// Just in-case it already exist
		::DeleteFile(storeFolder + '\\' + CUtility::formatSaveFileName() + ".zip");
		::CopyFile(sTempFileName, storeFolder + '\\' + CUtility::formatSaveFileName() + ".zip", TRUE);
   }
   DeleteFile(sTempFileName);
}