예제 #1
0
int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int /*nCmdShow*/ = SW_SHOWDEFAULT)
{
  LPCWSTR szCommandLine = GetCommandLineW();
  
  int argc = 0;
  LPWSTR* argv = CommandLineToArgvW(szCommandLine, &argc);
 
  // Read the crash info passed by CrashRpt.dll to CrashSender.exe 
  if(argc!=2)
    return 1; // No arguments passed

  // Read crash info
  CString sFileName = CString(argv[1]);
  g_CrashInfo.Init(sFileName);

  // Remove the file containing crash info.
  Utility::RecycleFile(sFileName, TRUE);

  if(!g_CrashInfo.m_bSendRecentReports)
  {
    // Do the crash info collection work assynchronously
    g_ErrorReportSender.DoWork(COLLECT_CRASH_INFO);
  }
  
  // Check window mirroring settings 
  CString sRTL = Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("Settings"), _T("RTLReading"));
  if(sRTL.CompareNoCase(_T("1"))==0)
  {
  	SetProcessDefaultLayout(LAYOUT_RTL);  
  }  

  CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);
    
  if(!g_CrashInfo.m_bSendRecentReports)
  {
    if(dlgErrorReport.Create(NULL) == NULL)
	  {
		  ATLTRACE(_T("Main dialog creation failed!\n"));
		  return 0;
	  }
  }
  else
  {
    // check if another instance of CrashSender.exe is running
	  ::CreateMutex( NULL, FALSE,_T("Local\\43773530-129a-4298-88f2-20eea3e4a59b"));
    if (::GetLastError() == ERROR_ALREADY_EXISTS)
	  {		
      // Another CrashSender.exe already tries to resend recent reports; exit.
		  return 0;
	  }

    if(g_CrashInfo.GetReportCount()==0)
      return 0; // There are no reports for us to send

    // Check if it is ok to remind user now
    if(!g_CrashInfo.IsRemindNowOK())
      return 0;

    if(dlgResend.Create(NULL) == NULL)
	  {
		  ATLTRACE(_T("Resend dialog creation failed!\n"));
		  return 0;
	  }
  }
  
	int nRet = theLoop.Run();

  // Wait until the worker thread is exited  
  g_ErrorReportSender.WaitForCompletion();

	_Module.RemoveMessageLoop();

	return nRet;
}
예제 #2
0
파일: CrashSender.cpp 프로젝트: cpzhang/zen
int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int /*nCmdShow*/ = SW_SHOWDEFAULT)
{ 
	int nRet = 0; // Return code
	CErrorReportDlg dlgErrorReport; // Error Report dialog
	CResendDlg dlgResend; // Resend dialog

	// Get command line parameters.
	LPCWSTR szCommandLine = GetCommandLineW();

    // Split command line.
    int argc = 0;
    LPWSTR* argv = CommandLineToArgvW(szCommandLine, &argc);

    // Check parameter count.
    if(argc!=2)
        return 1; // No arguments passed, exit.

	if(_tcscmp(argv[1], _T("/terminate"))==0)
	{
		// User wants us to find and terminate all instances of CrashSender.exe
		return CErrorReportSender::TerminateAllCrashSenderProcesses();
	}

	// Extract file mapping name from command line arg.    
    CString sFileMappingName = CString(argv[1]);
		
	// Create the sender model that will collect crash report data 
	// and send error report(s).
	CErrorReportSender* pSender = CErrorReportSender::GetInstance();

	// Init the sender object
	BOOL bInit = pSender->Init(sFileMappingName.GetBuffer(0));
	if(!bInit)
    {
		// Failed to init        
        return 0;
    }      

	// Determine what to do next 
	// (either run in GUI more or run in silent mode).
	if(!pSender->GetCrashInfo()->m_bSilentMode)
	{
		// GUI mode.
		// Create message loop.
		CMessageLoop theLoop;
		_Module.AddMessageLoop(&theLoop);

		if(!pSender->GetCrashInfo()->m_bSendRecentReports)
		{
			// Create "Error Report" dialog			
			if(dlgErrorReport.Create(NULL) == NULL)
			{
				ATLTRACE(_T("Error report dialog creation failed!\n"));
				return 1;
			}			
		}
		else
		{        
			// Create "Send Error Reports" dialog.					
			if(dlgResend.Create(NULL) == NULL)
			{
				ATLTRACE(_T("Resend dialog creation failed!\n"));
				return 1;
			}			
		}

		// Process window messages.
		nRet = theLoop.Run();	    
		_Module.RemoveMessageLoop();
	}
	else
	{
		// Silent (non-GUI mode).
		// Run the sender and wait until it exits.
		pSender->Run();
		pSender->WaitForCompletion();
		// Get return status
		nRet = pSender->GetStatus();
	}
    
	// Delete sender object.
	delete pSender;

	// Exit.
    return nRet;
}