Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
2 | 2 |
3 #include <Wbemidl.h> | 3 #include <Wbemidl.h> |
4 #include <time.h> | 4 #include <time.h> |
5 #include "PluginIniFileW.h" | 5 #include "PluginIniFileW.h" |
6 #include "PluginIniFile.h" | 6 #include "PluginIniFile.h" |
7 #include "PluginSettings.h" | 7 #include "PluginSettings.h" |
8 #include "PluginDictionary.h" | 8 #include "PluginDictionary.h" |
9 #include "PluginClient.h" | 9 #include "PluginClient.h" |
10 #include "PluginChecksum.h" | 10 #include "PluginChecksum.h" |
11 #include "PluginSystem.h" | 11 #include "PluginSystem.h" |
12 #ifdef SUPPORT_FILTER | 12 #ifdef SUPPORT_FILTER |
13 #include "PluginFilter.h" | 13 #include "PluginFilter.h" |
14 #endif | 14 #endif |
15 #include "PluginMutex.h" | 15 #include "PluginMutex.h" |
16 #include "PluginHttpRequest.h" | 16 #include "PluginHttpRequest.h" |
17 #include <memory> | |
18 | |
17 | 19 |
18 // IE functions | 20 // IE functions |
19 #pragma comment(lib, "iepmapi.lib") | 21 #pragma comment(lib, "iepmapi.lib") |
20 | 22 |
21 #include <knownfolders.h> | 23 #include <knownfolders.h> |
22 | 24 |
23 class TSettings | 25 class TSettings |
24 { | 26 { |
25 DWORD processorId; | 27 DWORD processorId; |
26 | 28 |
27 char sPluginId[44]; | 29 char sPluginId[44]; |
28 }; | 30 }; |
31 | |
32 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription s); | |
29 | 33 |
30 | 34 |
31 class CPluginSettingsLock : public CPluginMutex | 35 class CPluginSettingsLock : public CPluginMutex |
32 { | 36 { |
33 public: | 37 public: |
34 CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN GS_FILE) {} | 38 CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN GS_FILE) {} |
35 ~CPluginSettingsLock() {} | 39 ~CPluginSettingsLock() {} |
36 | 40 |
37 }; | 41 }; |
38 | 42 |
(...skipping 16 matching lines...) Expand all Loading... | |
55 | 59 |
56 #endif | 60 #endif |
57 | 61 |
58 WCHAR* CPluginSettings::s_dataPath; | 62 WCHAR* CPluginSettings::s_dataPath; |
59 WCHAR* CPluginSettings::s_dataPathParent; | 63 WCHAR* CPluginSettings::s_dataPathParent; |
60 | 64 |
61 CPluginSettings* CPluginSettings::s_instance = NULL; | 65 CPluginSettings* CPluginSettings::s_instance = NULL; |
62 bool CPluginSettings::s_isLightOnly = false; | 66 bool CPluginSettings::s_isLightOnly = false; |
63 | 67 |
64 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; | 68 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; |
65 #ifdef SUPPORT_FILTER | |
66 CComAutoCriticalSection CPluginSettings::s_criticalSectionFilters; | |
67 #endif | |
68 #ifdef SUPPORT_WHITELIST | 69 #ifdef SUPPORT_WHITELIST |
69 CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; | 70 CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; |
70 #endif | 71 #endif |
71 | 72 |
72 | 73 |
73 CPluginSettings::CPluginSettings() : | 74 CPluginSettings::CPluginSettings() : |
74 m_settingsVersion("1"), m_isDirty(false), m_isFirstRun(false), m_isFirstRunUpd ate(false), m_dwMainProcessId(0), m_dwMainThreadId(0), m_dwWorkingThreadId(0), | 75 m_settingsVersion("1"), m_isDirty(false), m_isFirstRun(false), m_isFirstRunUpd ate(false), m_dwMainProcessId(0), m_dwMainThreadId(0), m_dwWorkingThreadId(0), |
75 m_isDirtyTab(false), m_isPluginEnabledTab(true), m_tabNumber("1") | 76 m_isDirtyTab(false), m_isPluginEnabledTab(true), m_tabNumber("1") |
76 { | 77 { |
77 | 78 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
219 | 220 |
220 CPluginSettings* CPluginSettings::GetInstance() | 221 CPluginSettings* CPluginSettings::GetInstance() |
221 { | 222 { |
222 CPluginSettings* instance = NULL; | 223 CPluginSettings* instance = NULL; |
223 | 224 |
224 s_criticalSectionLocal.Lock(); | 225 s_criticalSectionLocal.Lock(); |
225 { | 226 { |
226 if ((!s_instance) || (s_isLightOnly)) | 227 if ((!s_instance) || (s_isLightOnly)) |
227 { | 228 { |
228 s_instance = new CPluginSettings(); | 229 s_instance = new CPluginSettings(); |
230 CPluginClient::GetInstance()->GetFilterEngine()->FetchAvailableSubscriptio ns((AdblockPlus::SubscriptionsCallback)&SubsCallback); | |
229 s_isLightOnly = false; | 231 s_isLightOnly = false; |
230 } | 232 } |
231 | 233 |
232 instance = s_instance; | 234 instance = s_instance; |
233 } | 235 } |
234 s_criticalSectionLocal.Unlock(); | 236 s_criticalSectionLocal.Unlock(); |
235 | 237 |
236 return instance; | 238 return instance; |
237 } | 239 } |
238 | 240 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 | 285 |
284 CPluginSettingsLock lock; | 286 CPluginSettingsLock lock; |
285 if (lock.IsLocked()) | 287 if (lock.IsLocked()) |
286 { | 288 { |
287 isRead = m_settingsFile->Read(); | 289 isRead = m_settingsFile->Read(); |
288 if (isRead) | 290 if (isRead) |
289 { | 291 { |
290 if (m_settingsFile->IsValidChecksum()) | 292 if (m_settingsFile->IsValidChecksum()) |
291 { | 293 { |
292 m_properties = m_settingsFile->GetSectionData("Settings"); | 294 m_properties = m_settingsFile->GetSectionData("Settings"); |
293 | |
294 #ifdef SUPPORT_FILTER | |
295 // Unpack filter URLs | |
296 CPluginIniFileW::TSectionData filters = m_settingsFile->GetSectionData ("Filters"); | |
297 int filterCount = 0; | |
298 bool bContinue = true; | |
299 | |
300 s_criticalSectionFilters.Lock(); | |
301 { | |
302 m_filterUrlList.clear(); | |
303 | |
304 do | |
305 { | |
306 CString filterCountStr; | |
307 filterCountStr.Format(L"%d", ++filterCount); | |
308 | |
309 CPluginIniFileW::TSectionData::iterator filterIt = filters.find(L" filter" + filterCountStr); | |
310 CPluginIniFileW::TSectionData::iterator versionIt = filters.find(L "filter" + filterCountStr + "v"); | |
311 CPluginIniFileW::TSectionData::iterator fileNameIt = filters.find( L"filter" + filterCountStr + "fileName"); | |
312 CPluginIniFileW::TSectionData::iterator languageIt = filters.find( L"filter" + filterCountStr + "language"); | |
313 CPluginIniFileW::TSectionData::iterator languageTitleIt = filters. find(L"filter" + filterCountStr + "languageTitle"); | |
314 CPluginIniFileW::TSectionData::iterator dltIt = filters.find(L"fil ter" + filterCountStr + "refreshin"); | |
315 | |
316 if (bContinue = (filterIt != filters.end() && versionIt != filters .end())) | |
317 { | |
318 m_filterUrlList[filterIt->second] = _wtoi(versionIt->second); | |
319 } | |
320 | |
321 if (filterIt != filters.end() && fileNameIt != filters.end()) | |
322 { | |
323 m_filterFileNameList[filterIt->second] = fileNameIt->second; | |
324 } | |
325 | |
326 if (filterIt != filters.end() && languageIt != filters.end()) | |
327 { | |
328 m_filterLanguagesList[filterIt->second] = languageIt->second; | |
329 } | |
330 | |
331 if (filterIt != filters.end() && languageIt != filters.end() && languageTitleIt != filters.end()) | |
332 { | |
333 m_filterLanguageTitleList[languageIt->second] = languageTitleIt- >second; | |
334 } | |
335 | |
336 if (filterIt != filters.end() && dltIt != filters.end()) | |
337 { | |
338 m_filterDownloadTimesList[filterIt->second] = (time_t)_wtoi(dltI t->second.GetString()); | |
339 } | |
340 | |
341 } while (bContinue); | |
342 } | |
343 s_criticalSectionFilters.Unlock(); | |
344 | |
345 #endif // SUPPORT_FILTER | |
346 } | 295 } |
347 else | 296 else |
348 { | 297 { |
349 DEBUG_SETTINGS("Settings:Invalid checksum - Deleting file") | 298 DEBUG_SETTINGS("Settings:Invalid checksum - Deleting file") |
350 | 299 |
351 Clear(); | 300 Clear(); |
352 | 301 |
353 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, PLUGIN_ERROR_SETTINGS_FILE_READ_CHECKSUM, "Settings::Read - Checksum") | 302 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, PLUGIN_ERROR_SETTINGS_FILE_READ_CHECKSUM, "Settings::Read - Checksum") |
354 isRead = false; | 303 isRead = false; |
355 m_isDirty = true; | 304 m_isDirty = true; |
356 } | 305 } |
357 } | 306 } |
358 else if (m_settingsFile->GetLastError() == ERROR_FILE_NOT_FOUND) | 307 else if (m_settingsFile->GetLastError() == ERROR_FILE_NOT_FOUND) |
359 { | 308 { |
360 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, P LUGIN_ERROR_SETTINGS_FILE_READ, "Settings::Read") | 309 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, P LUGIN_ERROR_SETTINGS_FILE_READ, "Settings::Read") |
361 m_isDirty = true; | 310 m_isDirty = true; |
362 } | 311 } |
363 else | 312 else |
364 { | 313 { |
(...skipping 20 matching lines...) Expand all Loading... | |
385 { | 334 { |
386 // Default settings | 335 // Default settings |
387 s_criticalSectionLocal.Lock(); | 336 s_criticalSectionLocal.Lock(); |
388 { | 337 { |
389 m_properties.clear(); | 338 m_properties.clear(); |
390 | 339 |
391 m_properties[SETTING_PLUGIN_VERSION] = IEPLUGIN_VERSION; | 340 m_properties[SETTING_PLUGIN_VERSION] = IEPLUGIN_VERSION; |
392 m_properties[SETTING_LANGUAGE] = "en"; | 341 m_properties[SETTING_LANGUAGE] = "en"; |
393 } | 342 } |
394 s_criticalSectionLocal.Unlock(); | 343 s_criticalSectionLocal.Unlock(); |
395 | |
396 // Default filters | |
397 #ifdef SUPPORT_FILTER | |
398 | |
399 s_criticalSectionFilters.Lock(); | |
400 { | |
401 m_filterUrlList.clear(); | |
402 } | |
403 s_criticalSectionFilters.Unlock(); | |
404 | |
405 #endif // SUPPORT_FILTER | |
406 } | 344 } |
407 | 345 |
408 bool CPluginSettings::MakeRequestForUpdate() | 346 bool CPluginSettings::MakeRequestForUpdate() |
Felix Dahlke
2013/04/03 05:35:27
Shouldn't this call UpdateSubscription()?
| |
409 { | 347 { |
410 time_t updateTime = this->GetValue(SETTING_LAST_UPDATE_TIME); | 348 time_t updateTime = this->GetValue(SETTING_LAST_UPDATE_TIME); |
411 | 349 |
412 if (time(NULL) <= updateTime) | 350 if (time(NULL) <= updateTime) |
413 return false; | 351 return false; |
414 | 352 |
415 CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL); | 353 CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL); |
416 | 354 |
417 CPluginSystem* system = CPluginSystem::GetInstance(); | 355 CPluginSystem* system = CPluginSystem::GetInstance(); |
418 | 356 |
(...skipping 25 matching lines...) Expand all Loading... | |
444 it = settingsData.find("pluginupdatev"); | 382 it = settingsData.find("pluginupdatev"); |
445 if (it != settingsData.end()) | 383 if (it != settingsData.end()) |
446 { | 384 { |
447 CString ver(it->second); | 385 CString ver(it->second); |
448 SetString(SETTING_PLUGIN_UPDATE_VERSION, ver); | 386 SetString(SETTING_PLUGIN_UPDATE_VERSION, ver); |
449 m_isDirty = true; | 387 m_isDirty = true; |
450 DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->seco nd); | 388 DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->seco nd); |
451 } | 389 } |
452 } | 390 } |
453 | 391 |
454 return true; | |
455 } | |
456 bool CPluginSettings::CheckFilterAndDownload() | |
457 { | |
458 s_criticalSectionLocal.Lock(); | |
459 TFilterUrlList currentFilterUrlList = this->GetFilterUrlList(); | |
460 std::map<CString, CString> fileNamesList = this->GetFilterFileNamesList(); | |
461 | |
462 bool filterAvailable = false; | |
463 for (TFilterUrlList::iterator it = currentFilterUrlList.begin(); it != current FilterUrlList.end(); ++it) | |
464 { | |
465 CString downloadFilterName = it->first; | |
466 | |
467 std::map<CString, CString>::const_iterator fni = fileNamesList.find(download FilterName); | |
468 CString filename = ""; | |
469 if (fni != fileNamesList.end()) | |
470 { | |
471 filename = fni->second; | |
472 } | |
473 else | |
474 { | |
475 filename = downloadFilterName.Trim().Right(downloadFilterName.GetLength() - downloadFilterName.ReverseFind('/') - 1).Trim(); | |
476 } | |
477 int version = it->second; | |
478 | |
479 DEBUG_GENERAL("*** before FilterShouldLoad: " + downloadFilterName); | |
480 | |
481 if ((this->FilterShouldLoad(downloadFilterName))) | |
482 { | |
483 filterAvailable = true; | |
484 DEBUG_GENERAL("*** before FilterlistExpired: " + downloadFilterName); | |
485 if (this->FilterlistExpired(downloadFilterName)) | |
486 { | |
487 DEBUG_GENERAL("*** before DownloadFilterFile: " + downloadFilterName); | |
488 // CPluginFilter::DownloadFilterFile(downloadFilterName, filename); | |
Felix Dahlke
2013/04/03 05:35:27
Might as well remove this line, likewise below.
| |
489 this->SetFilterRefreshDate(downloadFilterName, time(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8)); | |
490 } | |
491 } | |
492 else | |
493 { | |
494 //Cleanup, since we don't need the filter definition | |
495 DeleteFile(CPluginSettings::GetDataPath(filename)); | |
496 this->SetFilterRefreshDate(downloadFilterName, 0); | |
497 } | |
498 } | |
499 | |
500 if (!filterAvailable) | |
501 { | |
502 //If no filter list found, default to "en" | |
503 | |
504 this->SetString(SETTING_LANGUAGE, (BSTR)L"en"); | |
505 | |
506 CPluginDictionary* dict = CPluginDictionary::GetInstance(); | |
507 dict->SetLanguage(L"en"); | |
508 | |
509 for (std::map<CString, CString>::iterator it = m_filterLanguagesList.begin() ; it != m_filterLanguagesList.end(); ++it) | |
510 { | |
511 if (it->second == L"en") | |
512 { | |
513 // CPluginFilter::DownloadFilterFile(it->first, m_filterFileNameList.find (it->first)->second); | |
514 this->SetFilterRefreshDate(it->first, time(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8)); | |
515 } | |
516 } | |
517 } | |
518 | |
519 this->Write(); | |
520 | |
521 this->IncrementTabVersion(SETTING_TAB_FILTER_VERSION); | |
522 | |
523 s_criticalSectionLocal.Unlock(); | |
524 return true; | 392 return true; |
525 } | 393 } |
526 | 394 |
527 CString CPluginSettings::GetDataPathParent() | 395 CString CPluginSettings::GetDataPathParent() |
528 { | 396 { |
529 if (s_dataPathParent == NULL) | 397 if (s_dataPathParent == NULL) |
530 { | 398 { |
531 WCHAR* lpData = new WCHAR[MAX_PATH]; | 399 WCHAR* lpData = new WCHAR[MAX_PATH]; |
532 | 400 |
533 OSVERSIONINFO osVersionInfo; | 401 OSVERSIONINFO osVersionInfo; |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 { | 733 { |
866 SetString(key, value ? "true":"false"); | 734 SetString(key, value ? "true":"false"); |
867 } | 735 } |
868 | 736 |
869 | 737 |
870 bool CPluginSettings::IsPluginEnabled() const | 738 bool CPluginSettings::IsPluginEnabled() const |
871 { | 739 { |
872 return m_isPluginEnabledTab; | 740 return m_isPluginEnabledTab; |
873 } | 741 } |
874 | 742 |
875 | 743 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription s) |
876 #ifdef SUPPORT_FILTER | 744 { |
877 | 745 CPluginSettings::GetInstance()->m_subscriptions = subscriptions; |
878 void CPluginSettings::SetFilterUrlList(const TFilterUrlList& filters) | 746 return; |
879 { | |
880 DEBUG_SETTINGS(L"Settings::SetFilterUrlList") | |
881 | |
882 s_criticalSectionFilters.Lock(); | |
883 { | |
884 if (m_filterUrlList != filters) | |
885 { | |
886 m_filterUrlList = filters; | |
887 m_isDirty = true; | |
888 } | |
889 } | |
890 s_criticalSectionFilters.Unlock(); | |
891 } | |
892 | |
893 void CPluginSettings::SetFilterFileNamesList(const std::map<CString, CString>& f ilters) | |
894 { | |
895 DEBUG_SETTINGS(L"Settings::SetFilterUrlList") | |
896 | |
897 s_criticalSectionFilters.Lock(); | |
898 { | |
899 if (m_filterFileNameList != filters) | |
900 { | |
901 m_filterFileNameList = filters; | |
902 m_isDirty = true; | |
903 } | |
904 } | |
905 s_criticalSectionFilters.Unlock(); | |
906 } | |
907 | |
908 TFilterUrlList CPluginSettings::GetFilterUrlList() const | |
909 { | |
910 TFilterUrlList filterUrlList; | |
911 | |
912 s_criticalSectionFilters.Lock(); | |
913 { | |
914 filterUrlList = m_filterUrlList; | |
915 } | |
916 s_criticalSectionFilters.Unlock(); | |
917 | |
918 return filterUrlList; | |
919 } | |
920 | |
921 | |
922 std::map<CString, CString> CPluginSettings::GetFilterFileNamesList() const | |
923 { | |
924 std::map<CString, CString> filterFileNamesList; | |
925 | |
926 s_criticalSectionFilters.Lock(); | |
927 { | |
928 filterFileNamesList = m_filterFileNameList; | |
929 } | |
930 s_criticalSectionFilters.Unlock(); | |
931 | |
932 return filterFileNamesList; | |
933 } | 747 } |
934 | 748 |
935 | 749 |
936 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const | 750 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const |
937 { | 751 { |
938 std::map<CString, CString> filterList; | 752 std::map<CString, CString> filterList; |
939 | 753 for (int i = 0; i < m_subscriptions.size(); i ++) |
940 s_criticalSectionFilters.Lock(); | 754 { |
941 { | 755 AdblockPlus::SubscriptionPtr it = m_subscriptions[i]; |
942 filterList = m_filterLanguageTitleList; | 756 std::string title = ""; |
943 } | 757 std::string url = ""; |
944 s_criticalSectionFilters.Unlock(); | 758 |
945 | 759 //TODO: Property for language name? |
760 title = it.get()->GetProperty("title", title); | |
761 url = it.get()->GetProperty("url", url); | |
762 | |
763 filterList.insert(std::make_pair(CString(CA2T(url.c_str(), CP_UTF8)), CStrin g(CA2T(title.c_str(), CP_UTF8)))); | |
764 } | |
946 return filterList; | 765 return filterList; |
947 } | 766 } |
948 | 767 |
949 | |
950 bool CPluginSettings::FilterlistExpired(CString filterlist) const | |
951 { | |
952 std::map<CString, time_t>::const_iterator it = m_filterDownloadTimesList.find( filterlist); | |
953 if (it == m_filterDownloadTimesList.end()) | |
954 return false; | |
955 if (time(NULL) >= it->second) | |
956 return true; | |
957 return false; | |
958 } | |
959 | |
960 bool CPluginSettings::FilterShouldLoad(CString filterlist) const | |
961 { | |
962 std::map<CString, CString>::const_iterator it = m_filterLanguagesList.find(fil terlist); | |
963 if (it == m_filterLanguagesList.end()) | |
964 return false; | |
965 CPluginSettings* pluginSettings = CPluginSettings::GetInstance(); | |
966 if (it->second == pluginSettings->GetString(SETTING_LANGUAGE)) | |
967 return true; | |
968 return false; | |
969 } | |
970 | |
971 | |
972 bool CPluginSettings::SetFilterRefreshDate(CString filterlist, time_t refreshtim e) | |
973 { | |
974 m_filterDownloadTimesList[filterlist] = refreshtime; | |
975 m_isDirty = true; | |
976 return true; | |
977 } | |
978 void CPluginSettings::AddFilterUrl(const CString& url, int version) | |
979 { | |
980 s_criticalSectionFilters.Lock(); | |
981 { | |
982 TFilterUrlList::iterator it = m_filterUrlList.find(url); | |
983 if (it == m_filterUrlList.end() || it->second != version) | |
984 { | |
985 m_filterUrlList[url] = version; | |
986 m_isDirty = true; | |
987 } | |
988 } | |
989 s_criticalSectionFilters.Unlock(); | |
990 } | |
991 | |
992 void CPluginSettings::AddFilterFileName(const CString& url, const CString& fileN ame) | |
993 { | |
994 s_criticalSectionFilters.Lock(); | |
995 { | |
996 std::map<CString, CString>::iterator it = m_filterFileNameList.find(url); | |
997 if (it == m_filterFileNameList.end() || it->second != fileName) | |
998 { | |
999 m_filterFileNameList[url] = fileName; | |
1000 m_isDirty = true; | |
1001 } | |
1002 } | |
1003 s_criticalSectionFilters.Unlock(); | |
1004 } | |
1005 #endif // SUPPORT_FILTER | |
1006 | 768 |
1007 bool CPluginSettings::Write(bool isDebug) | 769 bool CPluginSettings::Write(bool isDebug) |
1008 { | 770 { |
1009 bool isWritten = true; | 771 bool isWritten = true; |
1010 | 772 |
1011 if (!m_isDirty) | 773 if (!m_isDirty) |
1012 { | 774 { |
1013 return isWritten; | 775 return isWritten; |
1014 } | 776 } |
1015 | 777 |
(...skipping 13 matching lines...) Expand all Loading... | |
1029 s_criticalSectionLocal.Lock(); | 791 s_criticalSectionLocal.Lock(); |
1030 { | 792 { |
1031 for (TProperties::iterator it = m_properties.begin(); it != m_properties.e nd(); ++it) | 793 for (TProperties::iterator it = m_properties.begin(); it != m_properties.e nd(); ++it) |
1032 { | 794 { |
1033 settings[it->first] = it->second; | 795 settings[it->first] = it->second; |
1034 } | 796 } |
1035 } | 797 } |
1036 s_criticalSectionLocal.Unlock(); | 798 s_criticalSectionLocal.Unlock(); |
1037 | 799 |
1038 m_settingsFile->UpdateSection("Settings", settings); | 800 m_settingsFile->UpdateSection("Settings", settings); |
1039 | |
1040 // Filter URL's | |
1041 #ifdef SUPPORT_FILTER | |
1042 | |
1043 int filterCount = 0; | |
1044 CPluginIniFileW::TSectionData filters; | |
1045 | |
1046 s_criticalSectionFilters.Lock(); | |
1047 { | |
1048 for (TFilterUrlList::iterator it = m_filterUrlList.begin(); it != m_filter UrlList.end(); ++it) | |
1049 { | |
1050 CString filterCountStr; | |
1051 filterCountStr.Format(L"%d", ++filterCount); | |
1052 | |
1053 CString filterVersion; | |
1054 filterVersion.Format(L"%d", it->second); | |
1055 | |
1056 filters[L"filter" + filterCountStr] = it->first; | |
1057 filters[L"filter" + filterCountStr + L"v"] = filterVersion; | |
1058 if (m_filterFileNameList.size() > 0) | |
1059 { | |
1060 std::map<CString, CString>::iterator fni = m_filterFileNameList.find(i t->first); | |
1061 if (fni != m_filterFileNameList.end()) | |
1062 { | |
1063 CString fileName = fni->second; | |
1064 filters[L"filter" + filterCountStr + "fileName"] = fileName; | |
1065 } | |
1066 } | |
1067 if (m_filterLanguagesList.size() > 0) | |
1068 { | |
1069 std::map<CString, CString>::iterator fli = m_filterLanguagesList.find( it->first); | |
1070 if (fli != m_filterLanguagesList.end()) | |
1071 { | |
1072 CString language = fli->second; | |
1073 filters[L"filter" + filterCountStr + "language"] = language; | |
1074 | |
1075 if (m_filterLanguageTitleList.size() > 0) | |
1076 { | |
1077 std::map<CString, CString>::iterator fli = m_filterLanguageTitleLi st.find(language); | |
1078 if (fli != m_filterLanguageTitleList.end()) | |
1079 { | |
1080 CString language = fli->second; | |
1081 filters[L"filter" + filterCountStr + "languageTitle"] = language ; | |
1082 } | |
1083 } | |
1084 | |
1085 } | |
1086 } | |
1087 if (m_filterDownloadTimesList.size() > 0) | |
1088 { | |
1089 std::map<CString, time_t>::iterator fdti = m_filterDownloadTimesList.f ind(it->first); | |
1090 if (fdti != m_filterDownloadTimesList.end()) | |
1091 { | |
1092 CString timeString; | |
1093 timeString.Format(L"%d", (int)fdti->second); | |
1094 filters[L"filter" + filterCountStr + "refreshin"] = timeString; | |
1095 } | |
1096 } | |
1097 | |
1098 } | |
1099 } | |
1100 s_criticalSectionFilters.Unlock(); | |
1101 | |
1102 m_settingsFile->UpdateSection("Filters", filters); | |
1103 | |
1104 #endif // SUPPORT_FILTER | |
1105 | 801 |
1106 // Write file | 802 // Write file |
1107 isWritten = m_settingsFile->Write(); | 803 isWritten = m_settingsFile->Write(); |
1108 if (!isWritten) | 804 if (!isWritten) |
1109 { | 805 { |
1110 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, PLU GIN_ERROR_SETTINGS_FILE_WRITE, "Settings::Write") | 806 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, PLU GIN_ERROR_SETTINGS_FILE_WRITE, "Settings::Write") |
1111 } | 807 } |
1112 | 808 |
1113 m_isDirty = false; | 809 m_isDirty = false; |
1114 | 810 |
1115 IncrementTabVersion(SETTING_TAB_SETTINGS_VERSION); | 811 IncrementTabVersion(SETTING_TAB_SETTINGS_VERSION); |
1116 } | 812 } |
1117 else | 813 else |
1118 { | 814 { |
1119 isWritten = false; | 815 isWritten = false; |
1120 } | 816 } |
1121 | 817 |
1122 return isWritten; | 818 return isWritten; |
1123 } | 819 } |
1124 | |
1125 #ifdef SUPPORT_WHITELIST | |
1126 | |
1127 void CPluginSettings::AddDomainToHistory(const CString& domain) | |
1128 { | |
1129 if (!CPluginClient::IsValidDomain(domain)) | |
1130 { | |
1131 return; | |
1132 } | |
1133 | |
1134 // Delete domain | |
1135 s_criticalSectionDomainHistory.Lock(); | |
1136 { | |
1137 for (TDomainHistory::iterator it = m_domainHistory.begin(); it != m_domainHi story.end(); ++it) | |
1138 { | |
1139 if (it->first == domain) | |
1140 { | |
1141 m_domainHistory.erase(it); | |
1142 break; | |
1143 } | |
1144 } | |
1145 | |
1146 // Get whitelist reason | |
1147 int reason = 0; | |
1148 | |
1149 s_criticalSectionLocal.Lock(); | |
1150 { | |
1151 TDomainList::iterator it = m_whitelist.find(domain); | |
1152 if (it != m_whitelist.end()) | |
1153 { | |
1154 reason = it->second; | |
1155 } | |
1156 else | |
1157 { | |
1158 reason = 3; | |
1159 } | |
1160 } | |
1161 s_criticalSectionLocal.Unlock(); | |
1162 | |
1163 // Delete domain, if history is too long | |
1164 if (m_domainHistory.size() >= DOMAIN_HISTORY_MAX_COUNT) | |
1165 { | |
1166 m_domainHistory.erase(m_domainHistory.begin()); | |
1167 } | |
1168 | |
1169 m_domainHistory.push_back(std::make_pair(domain, reason)); | |
1170 } | |
1171 s_criticalSectionDomainHistory.Unlock(); | |
1172 } | |
1173 | |
1174 | |
1175 TDomainHistory CPluginSettings::GetDomainHistory() const | |
1176 { | |
1177 TDomainHistory domainHistory; | |
1178 | |
1179 s_criticalSectionDomainHistory.Lock(); | |
1180 { | |
1181 domainHistory = m_domainHistory; | |
1182 } | |
1183 s_criticalSectionDomainHistory.Unlock(); | |
1184 | |
1185 return domainHistory; | |
1186 } | |
1187 | |
1188 #endif // SUPPORT_WHITELIST | |
1189 | 820 |
1190 | 821 |
1191 bool CPluginSettings::IsPluginUpdateAvailable() const | 822 bool CPluginSettings::IsPluginUpdateAvailable() const |
1192 { | 823 { |
1193 bool isAvailable = Has(SETTING_PLUGIN_UPDATE_VERSION); | 824 bool isAvailable = Has(SETTING_PLUGIN_UPDATE_VERSION); |
1194 if (isAvailable) | 825 if (isAvailable) |
1195 { | 826 { |
1196 CString newVersion = GetString(SETTING_PLUGIN_UPDATE_VERSION); | 827 CString newVersion = GetString(SETTING_PLUGIN_UPDATE_VERSION); |
1197 CString curVersion = IEPLUGIN_VERSION; | 828 CString curVersion = IEPLUGIN_VERSION; |
1198 | 829 |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1867 // ============================================================================ | 1498 // ============================================================================ |
1868 // Whitelist settings | 1499 // Whitelist settings |
1869 // ============================================================================ | 1500 // ============================================================================ |
1870 | 1501 |
1871 #ifdef SUPPORT_WHITELIST | 1502 #ifdef SUPPORT_WHITELIST |
1872 | 1503 |
1873 void CPluginSettings::ClearWhitelist() | 1504 void CPluginSettings::ClearWhitelist() |
1874 { | 1505 { |
1875 s_criticalSectionLocal.Lock(); | 1506 s_criticalSectionLocal.Lock(); |
1876 { | 1507 { |
1877 m_whitelist.clear(); | 1508 m_whitelistedDomains.clear(); |
1878 m_whitelistToGo.clear(); | |
1879 } | 1509 } |
1880 s_criticalSectionLocal.Unlock(); | 1510 s_criticalSectionLocal.Unlock(); |
1881 } | 1511 } |
1882 | 1512 |
1883 | 1513 |
1884 bool CPluginSettings::ReadWhitelist(bool isDebug) | 1514 bool CPluginSettings::ReadWhitelist(bool isDebug) |
1885 { | 1515 { |
1886 bool isRead = true; | 1516 bool isRead = true; |
1887 | 1517 |
1888 DEBUG_SETTINGS("SettingsWhitelist::Read") | 1518 DEBUG_SETTINGS("SettingsWhitelist::Read") |
1889 | 1519 |
1890 if (isDebug) | 1520 if (isDebug) |
1891 { | 1521 { |
1892 DEBUG_GENERAL("*** Loading whitelist settings:" + m_settingsFileWhitelist- >GetFilePath()); | 1522 DEBUG_GENERAL("*** Loading whitelist settings"); |
1893 } | 1523 } |
1894 | 1524 |
1895 CPluginSettingsWhitelistLock lock; | 1525 CPluginSettingsWhitelistLock lock; |
1896 if (lock.IsLocked()) | 1526 if (lock.IsLocked()) |
1897 { | 1527 { |
1898 isRead = m_settingsFileWhitelist->Read(); | 1528 ClearWhitelist(); |
1899 if (isRead) | 1529 |
1900 { | 1530 s_criticalSectionLocal.Lock(); |
1901 if (m_settingsFileWhitelist->IsValidChecksum()) | 1531 std::vector<AdblockPlus::FilterPtr> filters = CPluginClient::GetInstance() ->GetFilterEngine()->GetListedFilters(); |
1532 for (int i = 0; i < filters.size(); i ++) | |
1533 { | |
1534 if (filters[i]->GetProperty("type", AdblockPlus::Filter::Type::TYPE_INVA LID) == AdblockPlus::Filter::Type::TYPE_EXCEPTION) | |
1902 { | 1535 { |
1903 ClearWhitelist(); | 1536 std::string text = filters[i]->GetProperty("text", ""); |
1904 | 1537 //@@||example.com^$document |
1905 s_criticalSectionLocal.Lock(); | 1538 size_t endPos = text.rfind("^$document"); |
1539 if (endPos != std::string::npos) | |
1906 { | 1540 { |
1907 // Unpack white list | 1541 size_t startPos = text.find("@@||") + 4; |
1908 CPluginIniFileW::TSectionData whitelist = m_settingsFileWhitelist->G etSectionData("Whitelist"); | 1542 if (startPos != std::string::npos) |
1909 int domainCount = 0; | |
1910 bool bContinue = true; | |
1911 | |
1912 do | |
1913 { | 1543 { |
1914 CString domainCountStr; | 1544 m_whitelistedDomains.push_back(text.substr(startPos, endPos - star tPos)); |
1915 domainCountStr.Format(L"%d", ++domainCount); | 1545 } |
1916 | |
1917 CPluginIniFileW::TSectionData::iterator domainIt = whitelist.find( L"domain" + domainCountStr); | |
1918 CPluginIniFileW::TSectionData::iterator reasonIt = whitelist.find( L"domain" + domainCountStr + L"r"); | |
1919 | |
1920 if (bContinue = (domainIt != whitelist.end() && reasonIt != whitel ist.end())) | |
1921 { | |
1922 m_whitelist[domainIt->second] = _wtoi(reasonIt->second); | |
1923 } | |
1924 | |
1925 } while (bContinue); | |
1926 | |
1927 // Unpack white list | |
1928 whitelist = m_settingsFileWhitelist->GetSectionData("Whitelist togo" ); | |
1929 domainCount = 0; | |
1930 bContinue = true; | |
1931 | |
1932 do | |
1933 { | |
1934 CString domainCountStr; | |
1935 domainCountStr.Format(L"%d", ++domainCount); | |
1936 | |
1937 CPluginIniFileW::TSectionData::iterator domainIt = whitelist.find( L"domain" + domainCountStr); | |
1938 CPluginIniFileW::TSectionData::iterator reasonIt = whitelist.find( L"domain" + domainCountStr + L"r"); | |
1939 | |
1940 if (bContinue = (domainIt != whitelist.end() && reasonIt != whitel ist.end())) | |
1941 { | |
1942 m_whitelistToGo[domainIt->second] = _wtoi(reasonIt->second); | |
1943 } | |
1944 | |
1945 } while (bContinue); | |
1946 } | 1546 } |
1947 s_criticalSectionLocal.Unlock(); | |
1948 } | 1547 } |
1949 else | 1548 } |
1950 { | 1549 s_criticalSectionLocal.Unlock(); |
1951 DEBUG_SETTINGS("SettingsWhitelist:Invalid checksum - Deleting file") | |
1952 | |
1953 DEBUG_ERROR_LOG(m_settingsFileWhitelist->GetLastError(), PLUGIN_ERRO R_SETTINGS_WHITELIST, PLUGIN_ERROR_SETTINGS_FILE_READ_CHECKSUM, "SettingsWhiteli st::Read - Checksum") | |
1954 isRead = false; | |
1955 m_isDirtyWhitelist = true; | |
1956 } | |
1957 } | |
1958 else if (m_settingsFileWhitelist->GetLastError() == ERROR_FILE_NOT_FOUND) | |
1959 { | |
1960 m_isDirtyWhitelist = true; | |
1961 } | |
1962 else | |
1963 { | |
1964 DEBUG_ERROR_LOG(m_settingsFileWhitelist->GetLastError(), PLUGIN_ERROR_SE TTINGS_WHITELIST, PLUGIN_ERROR_SETTINGS_FILE_READ, "SettingsWhitelist::Read") | |
1965 } | |
1966 } | 1550 } |
1967 else | 1551 else |
1968 { | 1552 { |
1969 isRead = false; | 1553 isRead = false; |
1970 } | 1554 } |
1971 | 1555 |
1972 // Write file in case it is dirty | |
1973 WriteWhitelist(isDebug); | |
1974 | |
1975 return isRead; | 1556 return isRead; |
1976 } | 1557 } |
1977 | 1558 |
1978 | 1559 |
1979 bool CPluginSettings::WriteWhitelist(bool isDebug) | 1560 void CPluginSettings::AddWhiteListedDomain(const CString& domain) |
1980 { | 1561 { |
1981 bool isWritten = true; | 1562 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) |
1982 | 1563 |
1983 if (!m_isDirtyWhitelist) | 1564 bool isNewVersion = false; |
1984 { | 1565 bool isForcingUpdateOnStart = false; |
1985 return isWritten; | |
1986 } | |
1987 | |
1988 if (isDebug) | |
1989 { | |
1990 DEBUG_GENERAL("*** Writing changed whitelist settings") | |
1991 } | |
1992 | 1566 |
1993 CPluginSettingsWhitelistLock lock; | 1567 CPluginSettingsWhitelistLock lock; |
1994 if (lock.IsLocked()) | 1568 if (lock.IsLocked()) |
1995 { | 1569 { |
1996 m_settingsFileWhitelist->Clear(); | 1570 ReadWhitelist(false); |
1997 | 1571 |
1572 std::string newDomain = CW2A(domain, CP_UTF8); | |
1573 | |
1574 //Domain already present? | |
1575 if (std::find(m_whitelistedDomains.begin(), m_whitelistedDomains.end(), newD omain) != m_whitelistedDomains.end()) | |
1576 { | |
1577 return; | |
1578 } | |
1998 s_criticalSectionLocal.Lock(); | 1579 s_criticalSectionLocal.Lock(); |
1999 { | 1580 { |
2000 // White list | 1581 AdblockPlus::FilterPtr whitelistFilter = CPluginClient::GetInstance()->Get FilterEngine()->GetFilter(std::string("@@||").append(CW2A(domain)).append("^$doc ument")); |
2001 int whitelistCount = 0; | 1582 whitelistFilter->AddToList(); |
2002 CPluginIniFileW::TSectionData whitelist; | |
2003 | |
2004 for (TDomainList::iterator it = m_whitelist.begin(); it != m_whitelist.end (); ++it) | |
2005 { | |
2006 CString whitelistCountStr; | |
2007 whitelistCountStr.Format(L"%d", ++whitelistCount); | |
2008 | |
2009 CString reason; | |
2010 reason.Format(L"%d", it->second); | |
2011 | |
2012 whitelist[L"domain" + whitelistCountStr] = it->first; | |
2013 whitelist[L"domain" + whitelistCountStr + L"r"] = reason; | |
2014 } | |
2015 | |
2016 m_settingsFileWhitelist->UpdateSection("Whitelist", whitelist); | |
2017 | |
2018 // White list (not yet committed) | |
2019 whitelistCount = 0; | |
2020 whitelist.clear(); | |
2021 | |
2022 for (TDomainList::iterator it = m_whitelistToGo.begin(); it != m_whitelist ToGo.end(); ++it) | |
2023 { | |
2024 CString whitelistCountStr; | |
2025 whitelistCountStr.Format(L"%d", ++whitelistCount); | |
2026 | |
2027 CString reason; | |
2028 reason.Format(L"%d", it->second); | |
2029 | |
2030 whitelist[L"domain" + whitelistCountStr] = it->first; | |
2031 whitelist[L"domain" + whitelistCountStr + L"r"] = reason; | |
2032 } | |
2033 | |
2034 m_settingsFileWhitelist->UpdateSection("Whitelist togo", whitelist); | |
2035 } | 1583 } |
2036 s_criticalSectionLocal.Unlock(); | 1584 s_criticalSectionLocal.Unlock(); |
2037 | 1585 |
2038 // Write file | |
2039 isWritten = m_settingsFileWhitelist->Write(); | |
2040 if (!isWritten) | |
2041 { | |
2042 DEBUG_ERROR_LOG(m_settingsFileWhitelist->GetLastError(), PLUGIN_ERROR_SETT INGS_WHITELIST, PLUGIN_ERROR_SETTINGS_FILE_WRITE, "SettingsWhitelist::Write") | |
2043 } | |
2044 | |
2045 m_isDirty = false; | |
2046 } | |
2047 else | |
2048 { | |
2049 isWritten = false; | |
2050 } | |
2051 | |
2052 if (isWritten) | |
2053 { | |
2054 DEBUG_WHITELIST("Whitelist::Icrement version") | |
2055 | |
2056 IncrementTabVersion(SETTING_TAB_WHITELIST_VERSION); | |
2057 } | |
2058 | |
2059 return isWritten; | |
2060 } | |
2061 | |
2062 | |
2063 void CPluginSettings::AddWhiteListedDomain(const CString& domain, int reason, bo ol isToGo) | |
2064 { | |
2065 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) | |
2066 | |
2067 bool isNewVersion = false; | |
2068 bool isForcingUpdateOnStart = false; | |
2069 | |
2070 CPluginSettingsWhitelistLock lock; | |
2071 if (lock.IsLocked()) | |
2072 { | |
2073 ReadWhitelist(false); | |
2074 | |
2075 s_criticalSectionLocal.Lock(); | |
2076 { | |
2077 bool isToGoMatcingReason = false; | |
2078 bool isToGoMatcingDomain = false; | |
2079 | |
2080 TDomainList::iterator itToGo = m_whitelistToGo.find(domain); | |
2081 TDomainList::iterator it = m_whitelist.find(domain); | |
2082 if (isToGo) | |
2083 { | |
2084 if (itToGo != m_whitelistToGo.end()) | |
2085 { | |
2086 isToGoMatcingDomain = true; | |
2087 isToGoMatcingReason = itToGo->second == reason; | |
2088 | |
2089 if (reason == 3) | |
2090 { | |
2091 m_whitelistToGo.erase(itToGo); | |
2092 m_isDirtyWhitelist = true; | |
2093 } | |
2094 else if (!isToGoMatcingReason) | |
2095 { | |
2096 itToGo->second = reason; | |
2097 m_isDirtyWhitelist = true; | |
2098 } | |
2099 } | |
2100 else | |
2101 { | |
2102 m_whitelistToGo[domain] = reason; | |
2103 m_isDirtyWhitelist = true; | |
2104 | |
2105 // Delete new togo item from saved white list | |
2106 if (it != m_whitelist.end()) | |
2107 { | |
2108 m_whitelist.erase(it); | |
2109 } | |
2110 } | |
2111 } | |
2112 else | |
2113 { | |
2114 if (isToGoMatcingDomain) | |
2115 { | |
2116 m_whitelistToGo.erase(itToGo); | |
2117 m_isDirtyWhitelist = true; | |
2118 } | |
2119 | |
2120 if (it != m_whitelist.end()) | |
2121 { | |
2122 if (it->second != reason) | |
2123 { | |
2124 it->second = reason; | |
2125 m_isDirtyWhitelist = true; | |
2126 } | |
2127 } | |
2128 else | |
2129 { | |
2130 m_whitelist[domain] = reason; | |
2131 m_isDirtyWhitelist = true; | |
2132 } | |
2133 } | |
2134 | |
2135 isForcingUpdateOnStart = m_whitelistToGo.size() > 0; | |
2136 } | |
2137 s_criticalSectionLocal.Unlock(); | |
2138 | |
2139 WriteWhitelist(false); | |
2140 } | 1586 } |
2141 | 1587 |
2142 if (isForcingUpdateOnStart) | 1588 if (isForcingUpdateOnStart) |
2143 { | 1589 { |
2144 ForceConfigurationUpdateOnStart(); | 1590 ForceConfigurationUpdateOnStart(); |
2145 } | 1591 } |
2146 } | 1592 } |
2147 | 1593 |
2148 | 1594 |
2149 bool CPluginSettings::IsWhiteListedDomain(const CString& domain) const | 1595 bool CPluginSettings::IsWhiteListedDomain(const CString& domain) const |
2150 { | 1596 { |
2151 bool bIsWhiteListed; | 1597 bool bIsWhiteListed; |
2152 | 1598 |
2153 s_criticalSectionLocal.Lock(); | 1599 s_criticalSectionLocal.Lock(); |
2154 { | 1600 { |
2155 bIsWhiteListed = m_whitelist.find(domain) != m_whitelist.end(); | 1601 bIsWhiteListed = std::find(m_whitelistedDomains.begin(), m_whitelistedDomain s.end(), std::string(CW2A(domain, CP_UTF8))) != m_whitelistedDomains.end(); |
2156 if (!bIsWhiteListed) | |
2157 { | |
2158 TDomainList::const_iterator it = m_whitelistToGo.find(domain); | |
2159 bIsWhiteListed = it != m_whitelistToGo.end() && it->second != 3; | |
2160 } | |
2161 } | 1602 } |
2162 s_criticalSectionLocal.Unlock(); | 1603 s_criticalSectionLocal.Unlock(); |
2163 | 1604 |
2164 return bIsWhiteListed; | 1605 return bIsWhiteListed; |
2165 } | 1606 } |
2166 | 1607 |
2167 int CPluginSettings::GetWhiteListedDomainCount() const | 1608 int CPluginSettings::GetWhiteListedDomainCount() const |
2168 { | 1609 { |
2169 int count = 0; | 1610 int count = 0; |
2170 | 1611 |
2171 s_criticalSectionLocal.Lock(); | 1612 s_criticalSectionLocal.Lock(); |
2172 { | 1613 { |
2173 count = (int)m_whitelist.size(); | 1614 count = (int)m_whitelistedDomains.size(); |
2174 } | 1615 } |
2175 s_criticalSectionLocal.Unlock(); | 1616 s_criticalSectionLocal.Unlock(); |
2176 | 1617 |
2177 return count; | 1618 return count; |
2178 } | 1619 } |
2179 | 1620 |
2180 | 1621 |
2181 TDomainList CPluginSettings::GetWhiteListedDomainList(bool isToGo) const | 1622 std::vector<std::string> CPluginSettings::GetWhiteListedDomainList(bool isToGo) |
2182 { | 1623 { |
2183 TDomainList domainList; | 1624 bool r = ReadWhitelist(false); |
2184 | 1625 return m_whitelistedDomains; |
2185 s_criticalSectionLocal.Lock(); | |
2186 { | |
2187 if (isToGo) | |
2188 { | |
2189 domainList = m_whitelistToGo; | |
2190 } | |
2191 else | |
2192 { | |
2193 domainList = m_whitelist; | |
2194 } | |
2195 } | |
2196 s_criticalSectionLocal.Unlock(); | |
2197 | |
2198 return domainList; | |
2199 } | |
2200 | |
2201 | |
2202 void CPluginSettings::ReplaceWhiteListedDomains(const TDomainList& domains) | |
2203 { | |
2204 CPluginSettingsWhitelistLock lock; | |
2205 if (lock.IsLocked()) | |
2206 { | |
2207 ReadWhitelist(false); | |
2208 | |
2209 s_criticalSectionLocal.Lock(); | |
2210 { | |
2211 if (m_whitelist != domains) | |
2212 { | |
2213 m_whitelist = domains; | |
2214 m_isDirtyWhitelist = true; | |
2215 } | |
2216 | |
2217 // Delete entries in togo list | |
2218 bool isDeleted = true; | |
2219 | |
2220 while (isDeleted) | |
2221 { | |
2222 isDeleted = false; | |
2223 | |
2224 for (TDomainList::iterator it = m_whitelistToGo.begin(); it != m_whiteli stToGo.end(); ++it) | |
2225 { | |
2226 if (m_whitelist.find(it->first) != m_whitelist.end() || it->second == 3) | |
2227 { | |
2228 m_whitelistToGo.erase(it); | |
2229 | |
2230 // Force another round... | |
2231 isDeleted = true; | |
2232 break; | |
2233 } | |
2234 } | |
2235 } | |
2236 } | |
2237 s_criticalSectionLocal.Unlock(); | |
2238 | |
2239 WriteWhitelist(false); | |
2240 } | |
2241 } | |
2242 | |
2243 | |
2244 void CPluginSettings::RemoveWhiteListedDomainsToGo(const TDomainList& domains) | |
2245 { | |
2246 CPluginSettingsWhitelistLock lock; | |
2247 if (lock.IsLocked()) | |
2248 { | |
2249 ReadWhitelist(false); | |
2250 | |
2251 s_criticalSectionLocal.Lock(); | |
2252 { | |
2253 for (TDomainList::const_iterator it = domains.begin(); it != domains.end() ; ++it) | |
2254 { | |
2255 for (TDomainList::iterator itToGo = m_whitelistToGo.begin(); itToGo != m _whitelistToGo.end(); ++ itToGo) | |
2256 { | |
2257 if (it->first == itToGo->first) | |
2258 { | |
2259 m_whitelistToGo.erase(itToGo); | |
2260 m_isDirtyWhitelist = true; | |
2261 break; | |
2262 } | |
2263 } | |
2264 } | |
2265 } | |
2266 s_criticalSectionLocal.Unlock(); | |
2267 | |
2268 WriteWhitelist(false); | |
2269 } | |
2270 } | 1626 } |
2271 | 1627 |
2272 | 1628 |
2273 bool CPluginSettings::RefreshWhitelist() | 1629 bool CPluginSettings::RefreshWhitelist() |
2274 { | 1630 { |
2275 CPluginSettingsWhitelistLock lock; | 1631 CPluginSettingsWhitelistLock lock; |
2276 if (lock.IsLocked()) | 1632 if (lock.IsLocked()) |
2277 { | 1633 { |
2278 ReadWhitelist(true); | 1634 ReadWhitelist(true); |
2279 } | 1635 } |
(...skipping 14 matching lines...) Expand all Loading... | |
2294 | 1650 |
2295 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | 1651 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
2296 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); | 1652 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); |
2297 | 1653 |
2298 m_WindowsBuildNumber = osvi.dwBuildNumber; | 1654 m_WindowsBuildNumber = osvi.dwBuildNumber; |
2299 } | 1655 } |
2300 | 1656 |
2301 return m_WindowsBuildNumber; | 1657 return m_WindowsBuildNumber; |
2302 } | 1658 } |
2303 | 1659 |
1660 void CPluginSettings::SetSubscription(BSTR url) | |
1661 { | |
1662 std::string urlConverted = CT2A(url); | |
1663 SetSubscription(urlConverted); | |
1664 } | |
1665 | |
1666 void CPluginSettings::SetSubscription(std::string url) | |
1667 { | |
1668 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); | |
1669 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(url) ; | |
1670 subscription->AddToList(); | |
1671 } | |
1672 | |
1673 CString CPluginSettings::GetSubscription() | |
1674 { | |
1675 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); | |
1676 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetLis tedSubscriptions(); | |
1677 for (int i = 0; i < subscriptions.size(); i ++) | |
1678 { | |
1679 if (subscriptions[i]->IsListed()) | |
1680 { | |
1681 return CString(CA2T(subscriptions[i]->GetProperty("url", std::string()).c_ str())); | |
1682 } | |
1683 } | |
1684 return CString(L""); | |
1685 } | |
1686 | |
1687 | |
1688 void CPluginSettings::RefreshFilterlist() | |
1689 { | |
1690 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); | |
1691 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetLis tedSubscriptions(); | |
1692 for (int i = 0; i < subscriptions.size(); i ++) | |
1693 { | |
1694 if (subscriptions[i]->IsListed()) | |
1695 { | |
1696 subscriptions[i]->UpdateFilters(); | |
1697 } | |
1698 } | |
1699 } | |
1700 | |
2304 #endif // SUPPORT_WHITELIST | 1701 #endif // SUPPORT_WHITELIST |
LEFT | RIGHT |