Ejemplo n.º 1
0
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
  AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine"));
  if (!mutex)
  {
    DebugLastError("CreateMutex failed");
    return 1;
  }

  if (GetLastError() == ERROR_ALREADY_EXISTS)
  {
    DebugLastError("Named pipe exists, another engine instance appears to be running");
    return 1;
  }

  int argc;
  LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
  std::wstring locale(argc >= 2 ? argv[1] : L"");
  Communication::browserSID = argc >= 3 ? argv[2] : L"";
  LocalFree(argv);
  Dictionary::Create(locale);
  filterEngine = CreateFilterEngine(locale);
  updater.reset(new Updater(filterEngine->GetJsEngine()));

  for (;;)
  {
    try
    {
      Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeName,
            Communication::Pipe::MODE_CREATE);

      AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pipe), 0, 0));
      if (!thread)
      {
        delete pipe;
        DebugLastError("CreateThread failed");
        return 1;
      }
    }
    catch (std::runtime_error e)
    {
      DebugException(e);
      return 1;
    }
  }

  return 0;
}
Ejemplo n.º 2
0
// Control or query the service
DWORD CControlService::Control(DWORD dwControl)
{
	DWORD dwRet = ERROR_ACCESS_DENIED;
	try
	{
		if (IsOpen())
		{
			// Intialize the service status
			SERVICE_STATUS ServiceStatus;
			memset(&ServiceStatus,0,sizeof(ServiceStatus));
			if (ControlService(m_hService,dwControl,&ServiceStatus))
			{
				dwRet = ServiceStatus.dwCurrentState;
				switch (dwRet)
				{
				case SERVICE_STOPPED:
					DebugMsg("The service is not running\n");
					break;
				case SERVICE_START_PENDING:
					DebugMsg("The service is starting\n");
					break;
				case SERVICE_STOP_PENDING:
					DebugMsg("The service is stopping\n");
					break;
				case SERVICE_RUNNING:
					DebugMsg("The service is running\n");
					break;
				case SERVICE_CONTINUE_PENDING:
					DebugMsg("The service continue is pending\n");
					break;
				case SERVICE_PAUSE_PENDING:
					DebugMsg("The service pause is pending\n");
					break;
				case SERVICE_PAUSED:
					DebugMsg("The service is paused\n");
					break;
				case ERROR_SERVICE_NOT_ACTIVE:
					DebugMsg("The service is not active\n");
					break;
				default:
					DebugMsg("The service returned code %d\n",dwRet);
					break;
				}
			}
			else
			{
				dwRet = GetLastError();
				DebugLastError();
			}
		}
	}
	catch (...)
	{
	}
	return dwRet;
}
Ejemplo n.º 3
0
void Updater::OnDownloadSuccess()
{
  UpdateInstallDialog dialog;
  bool shouldInstall = dialog.Show();
  if (shouldInstall)
  {
    if (!InstallUpdate(tempFile))
    {
      DebugLastError("Failed to install update");
      Dictionary* dictionary = Dictionary::GetInstance();
      MessageBoxW(
        0, dictionary->Lookup("updater", "install-error-text").c_str(),
        dictionary->Lookup("updater", "install-error-title").c_str(),
        MB_OK | MB_ICONEXCLAMATION);
    }
  }
}