LEFT | RIGHT |
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" |
11 #include "../shared/CriticalSection.h" | 11 #include "../shared/CriticalSection.h" |
12 #include "Debug.h" | 12 #include "Debug.h" |
13 #include "Updater.h" | 13 #include "Updater.h" |
14 | 14 |
15 namespace | 15 namespace |
16 { | 16 { |
17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; | 17 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine; |
| 18 std::auto_ptr<Updater> updater; |
18 int activeConnections = 0; | 19 int activeConnections = 0; |
19 CriticalSection activeConnectionsLock; | 20 CriticalSection activeConnectionsLock; |
20 | 21 |
21 void WriteStrings(Communication::OutputBuffer& response, | 22 void WriteStrings(Communication::OutputBuffer& response, |
22 const std::vector<std::string>& strings) | 23 const std::vector<std::string>& strings) |
23 { | 24 { |
24 int32_t count = strings.size(); | 25 int32_t count = strings.size(); |
25 response << count; | 26 response << count; |
26 for (int32_t i = 0; i < count; i++) | 27 for (int32_t i = 0; i < count; i++) |
27 response << strings[i]; | 28 response << strings[i]; |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 { | 314 { |
314 Debug("No connections left, shutting down the engine"); | 315 Debug("No connections left, shutting down the engine"); |
315 activeConnections = 0; | 316 activeConnections = 0; |
316 exit(0); | 317 exit(0); |
317 } | 318 } |
318 } | 319 } |
319 | 320 |
320 return 0; | 321 return 0; |
321 } | 322 } |
322 | 323 |
323 void OnUpdateAvailable(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValue
List& params) | 324 void OnUpdateAvailable(AdblockPlus::JsValueList& params) |
324 { | 325 { |
325 updateAvailable = true; | 326 updateAvailable = true; |
326 if (params.size() < 1) | 327 if (params.size() < 1) |
327 { | 328 { |
328 Debug("updateAvailable event missing URL"); | 329 Debug("updateAvailable event missing URL"); |
329 return; | 330 return; |
330 } | 331 } |
331 | 332 |
332 Updater updater(jsEngine, params[0]->AsString()); | 333 updater->SetUrl(params[0]->AsString()); |
333 updater.Update(); | 334 updater->Update(); |
334 } | 335 } |
335 } | 336 } |
336 | 337 |
337 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring&
locale) | 338 std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring&
locale) |
338 { | 339 { |
339 AdblockPlus::AppInfo appInfo; | 340 AdblockPlus::AppInfo appInfo; |
340 appInfo.version = ToUtf8String(IEPLUGIN_VERSION); | 341 appInfo.version = ToUtf8String(IEPLUGIN_VERSION); |
341 appInfo.name = "adblockplusie"; | 342 appInfo.name = "adblockplusie"; |
342 #ifdef _WIN64 | 343 #ifdef _WIN64 |
343 appInfo.platform = "msie64"; | 344 appInfo.platform = "msie64"; |
344 #else | 345 #else |
345 appInfo.platform = "msie32"; | 346 appInfo.platform = "msie32"; |
346 #endif | 347 #endif |
347 appInfo.locale = ToUtf8String(locale); | 348 appInfo.locale = ToUtf8String(locale); |
348 #ifdef ADBLOCK_PLUS_TEST_MODE | 349 #ifdef ADBLOCK_PLUS_TEST_MODE |
349 appInfo.developmentBuild = true; | 350 appInfo.developmentBuild = true; |
350 #else | 351 #else |
351 appInfo.developmentBuild = false; | 352 appInfo.developmentBuild = false; |
352 #endif | 353 #endif |
353 | 354 |
354 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); | 355 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); |
355 jsEngine->SetEventCallback("updateAvailable", | 356 jsEngine->SetEventCallback("updateAvailable", &OnUpdateAvailable); |
356 std::bind(&OnUpdateAvailable, jsEngine, std::placeholders::_1)); | |
357 | 357 |
358 std::string dataPath = ToUtf8String(GetAppDataPath()); | 358 std::string dataPath = ToUtf8String(GetAppDataPath()); |
359 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())
->SetBasePath(dataPath); | 359 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())
->SetBasePath(dataPath); |
360 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE
ngine(jsEngine)); | 360 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE
ngine(jsEngine)); |
361 return filterEngine; | 361 return filterEngine; |
362 } | 362 } |
363 | 363 |
364 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) | 364 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) |
365 { | 365 { |
366 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); | 366 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine")); |
367 if (!mutex) | 367 if (!mutex) |
368 { | 368 { |
369 DebugLastError("CreateMutex failed"); | 369 DebugLastError("CreateMutex failed"); |
370 return 1; | 370 return 1; |
371 } | 371 } |
372 | 372 |
373 if (GetLastError() == ERROR_ALREADY_EXISTS) | 373 if (GetLastError() == ERROR_ALREADY_EXISTS) |
374 { | 374 { |
375 DebugLastError("Named pipe exists, another engine instance appears to be run
ning"); | 375 DebugLastError("Named pipe exists, another engine instance appears to be run
ning"); |
376 return 1; | 376 return 1; |
377 } | 377 } |
378 | 378 |
379 int argc; | 379 int argc; |
380 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); | 380 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); |
381 std::wstring locale(argc >= 2 ? argv[1] : L""); | 381 std::wstring locale(argc >= 2 ? argv[1] : L""); |
382 LocalFree(argv); | 382 LocalFree(argv); |
383 Dictionary::Create(locale); | 383 Dictionary::Create(locale); |
384 filterEngine = CreateFilterEngine(locale); | 384 filterEngine = CreateFilterEngine(locale); |
| 385 updater.reset(new Updater(filterEngine->GetJsEngine())); |
385 | 386 |
386 for (;;) | 387 for (;;) |
387 { | 388 { |
388 try | 389 try |
389 { | 390 { |
390 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam
e, | 391 Communication::Pipe* pipe = new Communication::Pipe(Communication::pipeNam
e, |
391 Communication::Pipe::MODE_CREATE); | 392 Communication::Pipe::MODE_CREATE); |
392 | 393 |
393 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip
e), 0, 0)); | 394 AutoHandle thread(CreateThread(0, 0, ClientThread, static_cast<LPVOID>(pip
e), 0, 0)); |
394 if (!thread) | 395 if (!thread) |
395 { | 396 { |
396 delete pipe; | 397 delete pipe; |
397 DebugLastError("CreateThread failed"); | 398 DebugLastError("CreateThread failed"); |
398 return 1; | 399 return 1; |
399 } | 400 } |
400 } | 401 } |
401 catch (std::runtime_error e) | 402 catch (std::runtime_error e) |
402 { | 403 { |
403 DebugException(e); | 404 DebugException(e); |
404 return 1; | 405 return 1; |
405 } | 406 } |
406 } | 407 } |
407 | 408 |
408 return 0; | 409 return 0; |
409 } | 410 } |
LEFT | RIGHT |