Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/engine/Main.cpp

Issue 5673404602515456: Close and reopen IE and engine during intallation (Closed)
Patch Set: Created Feb. 10, 2014, 12:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « installer/msibuild.cmd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <functional> 2 #include <functional>
3 #include <vector> 3 #include <vector>
4 #include <Windows.h> 4 #include <Windows.h>
5 5
6 #include "../shared/AutoHandle.h" 6 #include "../shared/AutoHandle.h"
7 #include "../shared/Communication.h" 7 #include "../shared/Communication.h"
8 #include "../shared/Dictionary.h" 8 #include "../shared/Dictionary.h"
9 #include "../shared/Utils.h" 9 #include "../shared/Utils.h"
10 #include "../shared/Version.h" 10 #include "../shared/Version.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 371
372 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); 372 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
373 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable); 373 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable);
374 374
375 std::string dataPath = ToUtf8String(GetAppDataPath()); 375 std::string dataPath = ToUtf8String(GetAppDataPath());
376 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); 376 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath);
377 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); 377 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine));
378 return filterEngine; 378 return filterEngine;
379 } 379 }
380 380
381 LRESULT CALLBACK NotificationWindowThread(HWND window, UINT message,
382 WPARAM wParam, LPARAM lParam)
383 {
384 switch (message)
385 {
386 case WM_CLOSE:
387 // Make sure that all our C streams will be flushed and closed correctly (no corrupt files)
388 exit(0);
389 break;
390 }
391 return DefWindowProc(window, message, wParam, lParam);
392 }
393
394
395 DWORD WINAPI NotificationWindowStart(void*)
396 {
397 const std::wstring windowClassName = L"ABP_NOTIFICATION_WINDOW";
398 WNDCLASSEXW windowClass = {};
399 windowClass.cbSize = sizeof(windowClass);
400 windowClass.lpfnWndProc = NotificationWindowThread;
401 windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_MENU + 1);
402 windowClass.lpszClassName = windowClassName.c_str();
403 windowClass.hInstance = GetModuleHandle(NULL);
404 RegisterClassEx(&windowClass);
405
406 CreateWindowExW(WS_EX_TOPMOST, windowClassName.c_str(), 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0);
407
408 // Main message loop:
409 MSG msg;
410 while (GetMessage(&msg, NULL, 0, 0))
411 {
412 TranslateMessage(&msg);
413 DispatchMessage(&msg);
414 }
415 return (int)msg.wParam;
416 }
381 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) 417 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
382 { 418 {
383 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); 419 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine"));
384 if (!mutex) 420 if (!mutex)
385 { 421 {
386 DebugLastError("CreateMutex failed"); 422 DebugLastError("CreateMutex failed");
387 return 1; 423 return 1;
388 } 424 }
389 425
390 if (GetLastError() == ERROR_ALREADY_EXISTS) 426 if (GetLastError() == ERROR_ALREADY_EXISTS)
391 { 427 {
392 DebugLastError("Named pipe exists, another engine instance appears to be run ning"); 428 DebugLastError("Named pipe exists, another engine instance appears to be run ning");
393 return 1; 429 return 1;
394 } 430 }
395 431
396 int argc; 432 int argc;
397 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); 433 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
398 std::wstring locale(argc >= 2 ? argv[1] : L""); 434 std::wstring locale(argc >= 2 ? argv[1] : L"");
399 LocalFree(argv); 435 LocalFree(argv);
400 Dictionary::Create(locale); 436 Dictionary::Create(locale);
401 filterEngine = CreateFilterEngine(locale); 437 filterEngine = CreateFilterEngine(locale);
402 updater.reset(new Updater(filterEngine->GetJsEngine())); 438 updater.reset(new Updater(filterEngine->GetJsEngine()));
403 439
440 CreateThread(NULL, NULL, &NotificationWindowStart, NULL, NULL, NULL);
404 for (;;) 441 for (;;)
405 { 442 {
406 try 443 try
407 { 444 {
408 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e, 445 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam e,
409 Communication::Pipe::MODE_CREATE); 446 Communication::Pipe::MODE_CREATE);
410 447
411 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0)); 448 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip e), 0, 0));
412 if (!thread) 449 if (!thread)
413 { 450 {
414 delete pipe; 451 delete pipe;
415 DebugLastError("CreateThread failed"); 452 DebugLastError("CreateThread failed");
416 return 1; 453 return 1;
417 } 454 }
418 } 455 }
419 catch (std::runtime_error e) 456 catch (std::runtime_error e)
420 { 457 {
421 DebugException(e); 458 DebugException(e);
422 return 1; 459 return 1;
423 } 460 }
424 } 461 }
425 462
426 return 0; 463 return 0;
427 } 464 }
OLDNEW
« no previous file with comments | « installer/msibuild.cmd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld