OLD | NEW |
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 | 17 |
18 // IE functions | 18 // IE functions |
19 #pragma comment(lib, "iepmapi.lib") | 19 #pragma comment(lib, "iepmapi.lib") |
20 | 20 |
21 #include <knownfolders.h> | 21 #include <knownfolders.h> |
22 | 22 |
23 class TSettings | 23 class TSettings |
24 { | 24 { |
25 DWORD processorId; | 25 DWORD processorId; |
26 | 26 |
27 char sPluginId[44]; | 27 char sPluginId[44]; |
28 }; | 28 }; |
29 | 29 |
| 30 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription
s); |
| 31 |
30 | 32 |
31 class CPluginSettingsLock : public CPluginMutex | 33 class CPluginSettingsLock : public CPluginMutex |
32 { | 34 { |
33 public: | 35 public: |
34 CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN
GS_FILE) {} | 36 CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN
GS_FILE) {} |
35 ~CPluginSettingsLock() {} | 37 ~CPluginSettingsLock() {} |
36 | 38 |
37 }; | 39 }; |
38 | 40 |
39 | 41 |
(...skipping 15 matching lines...) Expand all Loading... |
55 | 57 |
56 #endif | 58 #endif |
57 | 59 |
58 WCHAR* CPluginSettings::s_dataPath; | 60 WCHAR* CPluginSettings::s_dataPath; |
59 WCHAR* CPluginSettings::s_dataPathParent; | 61 WCHAR* CPluginSettings::s_dataPathParent; |
60 | 62 |
61 CPluginSettings* CPluginSettings::s_instance = NULL; | 63 CPluginSettings* CPluginSettings::s_instance = NULL; |
62 bool CPluginSettings::s_isLightOnly = false; | 64 bool CPluginSettings::s_isLightOnly = false; |
63 | 65 |
64 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; | 66 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; |
65 #ifdef SUPPORT_FILTER | |
66 CComAutoCriticalSection CPluginSettings::s_criticalSectionFilters; | |
67 #endif | |
68 #ifdef SUPPORT_WHITELIST | 67 #ifdef SUPPORT_WHITELIST |
69 CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; | 68 CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; |
70 #endif | 69 #endif |
71 | 70 |
72 | 71 |
73 CPluginSettings::CPluginSettings() : | 72 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), | 73 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") | 74 m_isDirtyTab(false), m_isPluginEnabledTab(true), m_tabNumber("1") |
76 { | 75 { |
77 | 76 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 218 |
220 CPluginSettings* CPluginSettings::GetInstance() | 219 CPluginSettings* CPluginSettings::GetInstance() |
221 { | 220 { |
222 CPluginSettings* instance = NULL; | 221 CPluginSettings* instance = NULL; |
223 | 222 |
224 s_criticalSectionLocal.Lock(); | 223 s_criticalSectionLocal.Lock(); |
225 { | 224 { |
226 if ((!s_instance) || (s_isLightOnly)) | 225 if ((!s_instance) || (s_isLightOnly)) |
227 { | 226 { |
228 s_instance = new CPluginSettings(); | 227 s_instance = new CPluginSettings(); |
| 228 CPluginClient::GetInstance()->GetFilterEngine()->FetchAvailableSubscriptio
ns((AdblockPlus::SubscriptionsCallback)&SubsCallback); |
229 s_isLightOnly = false; | 229 s_isLightOnly = false; |
230 } | 230 } |
231 | 231 |
232 instance = s_instance; | 232 instance = s_instance; |
233 } | 233 } |
234 s_criticalSectionLocal.Unlock(); | 234 s_criticalSectionLocal.Unlock(); |
235 | 235 |
236 return instance; | 236 return instance; |
237 } | 237 } |
238 | 238 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 283 |
284 CPluginSettingsLock lock; | 284 CPluginSettingsLock lock; |
285 if (lock.IsLocked()) | 285 if (lock.IsLocked()) |
286 { | 286 { |
287 isRead = m_settingsFile->Read(); | 287 isRead = m_settingsFile->Read(); |
288 if (isRead) | 288 if (isRead) |
289 { | 289 { |
290 if (m_settingsFile->IsValidChecksum()) | 290 if (m_settingsFile->IsValidChecksum()) |
291 { | 291 { |
292 m_properties = m_settingsFile->GetSectionData("Settings"); | 292 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 } | 293 } |
347 else | 294 else |
348 { | 295 { |
349 DEBUG_SETTINGS("Settings:Invalid checksum - Deleting file") | 296 DEBUG_SETTINGS("Settings:Invalid checksum - Deleting file") |
350 | 297 |
351 Clear(); | 298 Clear(); |
352 | 299 |
353 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS,
PLUGIN_ERROR_SETTINGS_FILE_READ_CHECKSUM, "Settings::Read - Checksum") | 300 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS,
PLUGIN_ERROR_SETTINGS_FILE_READ_CHECKSUM, "Settings::Read - Checksum") |
354 isRead = false; | 301 isRead = false; |
355 m_isDirty = true; | 302 m_isDirty = true; |
356 } | 303 } |
357 } | 304 } |
358 else if (m_settingsFile->GetLastError() == ERROR_FILE_NOT_FOUND) | 305 else if (m_settingsFile->GetLastError() == ERROR_FILE_NOT_FOUND) |
359 { | 306 { |
360 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, P
LUGIN_ERROR_SETTINGS_FILE_READ, "Settings::Read") | 307 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, P
LUGIN_ERROR_SETTINGS_FILE_READ, "Settings::Read") |
361 m_isDirty = true; | 308 m_isDirty = true; |
362 } | 309 } |
363 else | 310 else |
364 { | 311 { |
(...skipping 20 matching lines...) Expand all Loading... |
385 { | 332 { |
386 // Default settings | 333 // Default settings |
387 s_criticalSectionLocal.Lock(); | 334 s_criticalSectionLocal.Lock(); |
388 { | 335 { |
389 m_properties.clear(); | 336 m_properties.clear(); |
390 | 337 |
391 m_properties[SETTING_PLUGIN_VERSION] = IEPLUGIN_VERSION; | 338 m_properties[SETTING_PLUGIN_VERSION] = IEPLUGIN_VERSION; |
392 m_properties[SETTING_LANGUAGE] = "en"; | 339 m_properties[SETTING_LANGUAGE] = "en"; |
393 } | 340 } |
394 s_criticalSectionLocal.Unlock(); | 341 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 } | 342 } |
407 | 343 |
408 bool CPluginSettings::MakeRequestForUpdate() | 344 bool CPluginSettings::MakeRequestForUpdate() |
409 { | 345 { |
410 time_t updateTime = this->GetValue(SETTING_LAST_UPDATE_TIME); | 346 time_t updateTime = this->GetValue(SETTING_LAST_UPDATE_TIME); |
411 | 347 |
412 if (time(NULL) <= updateTime) | 348 if (time(NULL) <= updateTime) |
413 return false; | 349 return false; |
414 | 350 |
415 CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL); | 351 CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL); |
(...skipping 30 matching lines...) Expand all Loading... |
446 { | 382 { |
447 CString ver(it->second); | 383 CString ver(it->second); |
448 SetString(SETTING_PLUGIN_UPDATE_VERSION, ver); | 384 SetString(SETTING_PLUGIN_UPDATE_VERSION, ver); |
449 m_isDirty = true; | 385 m_isDirty = true; |
450 DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->seco
nd); | 386 DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->seco
nd); |
451 } | 387 } |
452 } | 388 } |
453 | 389 |
454 return true; | 390 return true; |
455 } | 391 } |
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); | |
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; | |
525 } | |
526 | 392 |
527 CString CPluginSettings::GetDataPathParent() | 393 CString CPluginSettings::GetDataPathParent() |
528 { | 394 { |
529 if (s_dataPathParent == NULL) | 395 if (s_dataPathParent == NULL) |
530 { | 396 { |
531 WCHAR* lpData = new WCHAR[MAX_PATH]; | 397 WCHAR* lpData = new WCHAR[MAX_PATH]; |
532 | 398 |
533 OSVERSIONINFO osVersionInfo; | 399 OSVERSIONINFO osVersionInfo; |
534 ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); | 400 ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); |
535 | 401 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 { | 731 { |
866 SetString(key, value ? "true":"false"); | 732 SetString(key, value ? "true":"false"); |
867 } | 733 } |
868 | 734 |
869 | 735 |
870 bool CPluginSettings::IsPluginEnabled() const | 736 bool CPluginSettings::IsPluginEnabled() const |
871 { | 737 { |
872 return m_isPluginEnabledTab; | 738 return m_isPluginEnabledTab; |
873 } | 739 } |
874 | 740 |
875 | 741 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription
s) |
876 #ifdef SUPPORT_FILTER | |
877 | |
878 void CPluginSettings::SetFilterUrlList(const TFilterUrlList& filters) | |
879 { | 742 { |
880 DEBUG_SETTINGS(L"Settings::SetFilterUrlList") | 743 CPluginSettings::GetInstance()->m_subscriptions = subscriptions; |
881 | 744 return; |
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 } | 745 } |
934 | 746 |
935 | 747 |
936 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const | 748 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const |
937 { | 749 { |
938 std::map<CString, CString> filterList; | 750 std::map<CString, CString> filterList; |
| 751 for (int i = 0; i < m_subscriptions.size(); i ++) |
| 752 { |
| 753 AdblockPlus::SubscriptionPtr it = m_subscriptions[i]; |
| 754 std::string title = ""; |
| 755 std::string url = ""; |
939 | 756 |
940 s_criticalSectionFilters.Lock(); | 757 //TODO: Property for language name? |
941 { | 758 title = it.get()->GetProperty("title", title); |
942 filterList = m_filterLanguageTitleList; | 759 url = it.get()->GetProperty("url", url); |
| 760 |
| 761 filterList.insert(std::make_pair(CString(CA2T(url.c_str(), CP_UTF8)), CStrin
g(CA2T(title.c_str(), CP_UTF8)))); |
943 } | 762 } |
944 s_criticalSectionFilters.Unlock(); | |
945 | |
946 return filterList; | 763 return filterList; |
947 } | 764 } |
948 | 765 |
949 | 766 |
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 | |
1007 bool CPluginSettings::Write(bool isDebug) | 767 bool CPluginSettings::Write(bool isDebug) |
1008 { | 768 { |
1009 bool isWritten = true; | 769 bool isWritten = true; |
1010 | 770 |
1011 if (!m_isDirty) | 771 if (!m_isDirty) |
1012 { | 772 { |
1013 return isWritten; | 773 return isWritten; |
1014 } | 774 } |
1015 | 775 |
1016 if (isDebug) | 776 if (isDebug) |
(...skipping 13 matching lines...) Expand all Loading... |
1030 { | 790 { |
1031 for (TProperties::iterator it = m_properties.begin(); it != m_properties.e
nd(); ++it) | 791 for (TProperties::iterator it = m_properties.begin(); it != m_properties.e
nd(); ++it) |
1032 { | 792 { |
1033 settings[it->first] = it->second; | 793 settings[it->first] = it->second; |
1034 } | 794 } |
1035 } | 795 } |
1036 s_criticalSectionLocal.Unlock(); | 796 s_criticalSectionLocal.Unlock(); |
1037 | 797 |
1038 m_settingsFile->UpdateSection("Settings", settings); | 798 m_settingsFile->UpdateSection("Settings", settings); |
1039 | 799 |
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 | |
1106 // Write file | 800 // Write file |
1107 isWritten = m_settingsFile->Write(); | 801 isWritten = m_settingsFile->Write(); |
1108 if (!isWritten) | 802 if (!isWritten) |
1109 { | 803 { |
1110 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, PLU
GIN_ERROR_SETTINGS_FILE_WRITE, "Settings::Write") | 804 DEBUG_ERROR_LOG(m_settingsFile->GetLastError(), PLUGIN_ERROR_SETTINGS, PLU
GIN_ERROR_SETTINGS_FILE_WRITE, "Settings::Write") |
1111 } | 805 } |
1112 | 806 |
1113 m_isDirty = false; | 807 m_isDirty = false; |
1114 | 808 |
1115 IncrementTabVersion(SETTING_TAB_SETTINGS_VERSION); | 809 IncrementTabVersion(SETTING_TAB_SETTINGS_VERSION); |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 | 1988 |
2295 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | 1989 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
2296 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); | 1990 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); |
2297 | 1991 |
2298 m_WindowsBuildNumber = osvi.dwBuildNumber; | 1992 m_WindowsBuildNumber = osvi.dwBuildNumber; |
2299 } | 1993 } |
2300 | 1994 |
2301 return m_WindowsBuildNumber; | 1995 return m_WindowsBuildNumber; |
2302 } | 1996 } |
2303 | 1997 |
| 1998 void CPluginSettings::SetSubscription(BSTR url) |
| 1999 { |
| 2000 std::string urlConverted = CT2A(url); |
| 2001 SetSubscription(urlConverted); |
| 2002 } |
| 2003 |
| 2004 void CPluginSettings::SetSubscription(std::string url) |
| 2005 { |
| 2006 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); |
| 2007 AdblockPlus::Subscription subscription = filterEngine->GetSubscription(url); |
| 2008 subscription.AddToList(); |
| 2009 } |
| 2010 |
| 2011 CString CPluginSettings::GetSubscription() |
| 2012 { |
| 2013 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); |
| 2014 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetLis
tedSubscriptions(); |
| 2015 for (int i = 0; i < subscriptions.size(); i ++) |
| 2016 { |
| 2017 if (subscriptions[i]->IsListed()) |
| 2018 { |
| 2019 return CString(CA2T(subscriptions[i]->GetProperty("url", std::string()).c_
str())); |
| 2020 } |
| 2021 } |
| 2022 return CString(L""); |
| 2023 } |
| 2024 |
| 2025 |
| 2026 void CPluginSettings::RefreshFilterlist() |
| 2027 { |
| 2028 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); |
| 2029 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetLis
tedSubscriptions(); |
| 2030 for (int i = 0; i < subscriptions.size(); i ++) |
| 2031 { |
| 2032 if (subscriptions[i]->IsListed()) |
| 2033 { |
| 2034 subscriptions[i]->UpdateFilters(); |
| 2035 } |
| 2036 } |
| 2037 } |
| 2038 |
2304 #endif // SUPPORT_WHITELIST | 2039 #endif // SUPPORT_WHITELIST |
OLD | NEW |