| 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" | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 22 | 22 | 
| 23 #include <knownfolders.h> | 23 #include <knownfolders.h> | 
| 24 | 24 | 
| 25 class TSettings | 25 class TSettings | 
| 26 { | 26 { | 
| 27   DWORD processorId; | 27   DWORD processorId; | 
| 28 | 28 | 
| 29   char sPluginId[44]; | 29   char sPluginId[44]; | 
| 30 }; | 30 }; | 
| 31 | 31 | 
| 32 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription
      s); |  | 
| 33 |  | 
| 34 | 32 | 
| 35 class CPluginSettingsLock : public CPluginMutex | 33 class CPluginSettingsLock : public CPluginMutex | 
| 36 { | 34 { | 
| 37 public: | 35 public: | 
| 38   CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN
      GS_FILE) {} | 36   CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN
      GS_FILE) {} | 
| 39   ~CPluginSettingsLock() {} | 37   ~CPluginSettingsLock() {} | 
| 40 | 38 | 
| 41 }; | 39 }; | 
| 42 | 40 | 
| 43 | 41 | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 64 | 62 | 
| 65 CPluginSettings* CPluginSettings::s_instance = NULL; | 63 CPluginSettings* CPluginSettings::s_instance = NULL; | 
| 66 bool CPluginSettings::s_isLightOnly = false; | 64 bool CPluginSettings::s_isLightOnly = false; | 
| 67 | 65 | 
| 68 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; | 66 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; | 
| 69 #ifdef SUPPORT_WHITELIST | 67 #ifdef SUPPORT_WHITELIST | 
| 70 CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; | 68 CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; | 
| 71 #endif | 69 #endif | 
| 72 | 70 | 
| 73 | 71 | 
| 74 CPluginSettings::CPluginSettings() : | 72 CPluginSettings::CPluginSettings() : | 
| 75   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), | 
| 76   m_isDirtyTab(false), m_isPluginEnabledTab(true), m_tabNumber("1") | 74   m_isDirtyTab(false), m_isPluginEnabledTab(true), m_tabNumber("1") | 
| 77 { | 75 { | 
| 78 | 76 | 
| 79   CPluginSettings *lightInstance = s_instance; | 77   CPluginSettings *lightInstance = s_instance; | 
| 80   s_instance = NULL; | 78   s_instance = NULL; | 
| 81 | 79 | 
| 82   m_settingsFile = std::auto_ptr<CPluginIniFileW>(new CPluginIniFileW(GetDataPat
      h(SETTINGS_INI_FILE), false)); | 80   m_settingsFile = std::auto_ptr<CPluginIniFileW>(new CPluginIniFileW(GetDataPat
      h(SETTINGS_INI_FILE), false)); | 
| 83   m_settingsFileTab = std::auto_ptr<CPluginIniFileW>(new CPluginIniFileW(GetData
      Path(SETTINGS_INI_FILE_TAB), true)); | 81   m_settingsFileTab = std::auto_ptr<CPluginIniFileW>(new CPluginIniFileW(GetData
      Path(SETTINGS_INI_FILE_TAB), true)); | 
| 84 | 82 | 
| 85   m_WindowsBuildNumber = 0; | 83   m_WindowsBuildNumber = 0; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 96     CPluginSettingsLock lock; | 94     CPluginSettingsLock lock; | 
| 97     if (lock.IsLocked()) | 95     if (lock.IsLocked()) | 
| 98     { | 96     { | 
| 99       std::ifstream is; | 97       std::ifstream is; | 
| 100       is.open(GetDataPath(SETTINGS_INI_FILE), std::ios_base::in); | 98       is.open(GetDataPath(SETTINGS_INI_FILE), std::ios_base::in); | 
| 101       if (!is.is_open()) | 99       if (!is.is_open()) | 
| 102       { | 100       { | 
| 103         TCHAR pf[MAX_PATH]; | 101         TCHAR pf[MAX_PATH]; | 
| 104         SHGetSpecialFolderPath( | 102         SHGetSpecialFolderPath( | 
| 105           0, | 103           0, | 
| 106           pf, | 104           pf, | 
| 107           CSIDL_PROGRAM_FILESX86, | 105           CSIDL_PROGRAM_FILESX86, | 
| 108           FALSE ); | 106           FALSE ); | 
| 109         //No files found, copy from the dll location | 107         //No files found, copy from the dll location | 
| 110         CString pathToDll; | 108         CString pathToDll; | 
| 111         DWORD pathResult = GetModuleFileNameW((HINSTANCE)&__ImageBase, pathToDll
      .GetBufferSetLength(MAX_PATH), MAX_PATH); | 109         DWORD pathResult = GetModuleFileNameW((HINSTANCE)&__ImageBase, pathToDll
      .GetBufferSetLength(MAX_PATH), MAX_PATH); | 
| 112         if (pathResult > 0) | 110         if (pathResult > 0) | 
| 113         { | 111         { | 
| 114           CString cpyPath; | 112           CString cpyPath; | 
| 115           cpyPath = pathToDll.Left(pathToDll.ReverseFind('\\') + 1); | 113           cpyPath = pathToDll.Left(pathToDll.ReverseFind('\\') + 1); | 
| 116 | 114 | 
| 117           BOOL res = CopyFile(cpyPath + SETTINGS_INI_FILE, GetDataPath(SETTINGS_
      INI_FILE), TRUE); | 115           BOOL res = CopyFile(cpyPath + SETTINGS_INI_FILE, GetDataPath(SETTINGS_
      INI_FILE), TRUE); | 
| 118           res = CopyFile(cpyPath + DICTIONARY_INI_FILE, GetDataPath(DICTIONARY_I
      NI_FILE), TRUE); | 116           res = CopyFile(cpyPath + DICTIONARY_INI_FILE, GetDataPath(DICTIONARY_I
      NI_FILE), TRUE); | 
| 119           res = CopyFile(cpyPath + SETTING_PAGE_INI_FILE, GetDataPath(SETTING_PA
      GE_INI_FILE), TRUE); | 117           res = CopyFile(cpyPath + SETTING_PAGE_INI_FILE, GetDataPath(SETTING_PA
      GE_INI_FILE), TRUE); | 
| 120 | 118 | 
| 121           SHFILEOPSTRUCT pFileStruct; | 119           SHFILEOPSTRUCT pFileStruct; | 
| 122           ZeroMemory(&pFileStruct, sizeof(SHFILEOPSTRUCT)); | 120           ZeroMemory(&pFileStruct, sizeof(SHFILEOPSTRUCT)); | 
| 123           pFileStruct.hwnd  = NULL; | 121           pFileStruct.hwnd  = NULL; | 
| 124           pFileStruct.wFunc = FO_COPY; | 122           pFileStruct.wFunc = FO_COPY; | 
| 125           WCHAR fromPath[MAX_PATH + 2]; | 123           WCHAR fromPath[MAX_PATH + 2]; | 
| 126           WCHAR toPath[MAX_PATH + 2]; | 124           WCHAR toPath[MAX_PATH + 2]; | 
| 127 | 125 | 
| 128           CString source = cpyPath + "html\\*"; | 126           CString source = cpyPath + "html\\*"; | 
| 129           wcscpy(fromPath, source); | 127           wcscpy(fromPath, source); | 
| 130           fromPath[source.GetLength()] = '\0'; | 128           fromPath[source.GetLength()] = '\0'; | 
| 131           fromPath[source.GetLength() + 1] = '\0'; | 129           fromPath[source.GetLength() + 1] = '\0'; | 
| 132 | 130 | 
| 133           wcscpy(toPath, GetDataPath(L"html")); | 131           wcscpy(toPath, GetDataPath(L"html")); | 
| 134           toPath[GetDataPath(L"html").GetLength()] = '\0'; | 132           toPath[GetDataPath(L"html").GetLength()] = '\0'; | 
| 135           toPath[GetDataPath(L"html").GetLength() + 1] = '\0'; | 133           toPath[GetDataPath(L"html").GetLength() + 1] = '\0'; | 
| 136 | 134 | 
| 137           pFileStruct.pFrom = fromPath; | 135           pFileStruct.pFrom = fromPath; | 
| 138           pFileStruct.pTo =  toPath; | 136           pFileStruct.pTo =  toPath; | 
| 139           pFileStruct.fFlags = FOF_SILENT  | FOF_NOCONFIRMATION | FOF_NOCONFIRMM
      KDIR | FOF_NO_UI | FOF_RENAMEONCOLLISION; | 137           pFileStruct.fFlags = FOF_SILENT  | FOF_NOCONFIRMATION | FOF_NOCONFIRMM
      KDIR | FOF_NO_UI | FOF_RENAMEONCOLLISION; | 
| 140           bool i = pFileStruct.fAnyOperationsAborted ; |  | 
| 141           SHFileOperation(&pFileStruct); | 138           SHFileOperation(&pFileStruct); | 
| 142         } | 139         } | 
| 143         is.open(GetDataPath(SETTINGS_INI_FILE), std::ios_base::in); | 140         is.open(GetDataPath(SETTINGS_INI_FILE), std::ios_base::in); | 
| 144         if (!is.is_open()) | 141         if (!is.is_open()) | 
| 145         { | 142         { | 
| 146           m_isDirty = true; | 143           m_isDirty = true; | 
| 147         } | 144         } | 
| 148         else | 145         else | 
| 149         { | 146         { | 
| 150           is.close(); | 147           is.close(); | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 187 { | 184 { | 
| 188 | 185 | 
| 189   if (s_dataPathParent != NULL) | 186   if (s_dataPathParent != NULL) | 
| 190   { | 187   { | 
| 191     delete s_dataPathParent; | 188     delete s_dataPathParent; | 
| 192   } | 189   } | 
| 193   s_instance = NULL; | 190   s_instance = NULL; | 
| 194 } | 191 } | 
| 195 | 192 | 
| 196 | 193 | 
| 197 CPluginSettings* CPluginSettings::GetInstance() | 194 CPluginSettings* CPluginSettings::GetInstance() | 
| 198 { | 195 { | 
| 199   CPluginSettings* instance = NULL; | 196   CPluginSettings* instance = NULL; | 
| 200 | 197 | 
| 201   s_criticalSectionLocal.Lock(); | 198   s_criticalSectionLocal.Lock(); | 
| 202   { | 199   { | 
| 203     if ((!s_instance) || (s_isLightOnly)) | 200     if ((!s_instance) || (s_isLightOnly)) | 
| 204     { | 201     { | 
| 205       s_instance = new CPluginSettings(); | 202       s_instance = new CPluginSettings(); | 
| 206 #ifdef USE_CONSOLE | 203 #ifdef USE_CONSOLE | 
| 207       CONSOLE("Fetching Available Subscription\n"); | 204       CONSOLE("Fetching Available Subscription\n"); | 
| 208 #endif | 205 #endif | 
| 209       try | 206       CPluginSettings::GetInstance()->m_subscriptions = CPluginClient::GetInstan
      ce()->FetchAvailableSubscriptions(); | 
| 210       { |  | 
| 211         CPluginSettings::GetInstance()->m_subscriptions = CPluginClient::GetInst
      ance()->FetchAvailableSubscriptions(); |  | 
| 212       } |  | 
| 213       catch(std::exception ex) |  | 
| 214       { |  | 
| 215         DEBUG_GENERAL(ex.what()); |  | 
| 216         throw ex; |  | 
| 217       } |  | 
| 218       s_isLightOnly = false; | 207       s_isLightOnly = false; | 
| 219     } | 208     } | 
| 220 | 209 | 
| 221     instance = s_instance; | 210     instance = s_instance; | 
| 222   } | 211   } | 
| 223   s_criticalSectionLocal.Unlock(); | 212   s_criticalSectionLocal.Unlock(); | 
| 224 | 213 | 
| 225   return instance; | 214   return instance; | 
| 226 } | 215 } | 
| 227 | 216 | 
| 228 | 217 | 
| 229 bool CPluginSettings::HasInstance() | 218 bool CPluginSettings::HasInstance() | 
| 230 { | 219 { | 
| 231   bool hasInstance = true; | 220   bool hasInstance = true; | 
| 232 | 221 | 
| 233   s_criticalSectionLocal.Lock(); | 222   s_criticalSectionLocal.Lock(); | 
| 234   { | 223   { | 
| 235     hasInstance = s_instance != NULL; | 224     hasInstance = s_instance != NULL; | 
| 236   } | 225   } | 
| 237   s_criticalSectionLocal.Unlock(); | 226   s_criticalSectionLocal.Unlock(); | 
| 238 | 227 | 
| 239   return hasInstance; | 228   return hasInstance; | 
| 240 } | 229 } | 
| 241 | 230 | 
| 242 | 231 | 
| 243 bool CPluginSettings::Read(bool bDebug) | 232 bool CPluginSettings::Read(bool bDebug) | 
| 244 { | 233 { | 
| 245   bool isRead = true; | 234   bool isRead = true; | 
| 246 | 235 | 
| 247   DEBUG_SETTINGS(L"Settings::Read") | 236   DEBUG_SETTINGS(L"Settings::Read") | 
| 248   { | 237   { | 
| 249     if (bDebug) | 238     if (bDebug) | 
| 250     { | 239     { | 
| 251       DEBUG_GENERAL(L"*** Loading settings:" + m_settingsFile->GetFilePath()); | 240       DEBUG_GENERAL(L"*** Loading settings:" + m_settingsFile->GetFilePath()); | 
| 252     } | 241     } | 
| 253 | 242 | 
| 254     CPluginSettingsLock lock; | 243     CPluginSettingsLock lock; | 
| 255     if (lock.IsLocked()) | 244     if (lock.IsLocked()) | 
| 256     { | 245     { | 
| 257       isRead = m_settingsFile->Read(); | 246       isRead = m_settingsFile->Read(); | 
| 258       if (isRead) | 247       if (isRead) | 
| 259       { | 248       { | 
| 260         if (m_settingsFile->IsValidChecksum()) | 249         if (m_settingsFile->IsValidChecksum()) | 
| 261         { | 250         { | 
| 262           m_properties = m_settingsFile->GetSectionData("Settings"); | 251           m_properties = m_settingsFile->GetSectionData("Settings"); | 
| 263         } | 252         } | 
| 264         else | 253         else | 
| 265         { | 254         { | 
| 266           DEBUG_SETTINGS("Settings:Invalid checksum - Deleting file") | 255           DEBUG_SETTINGS("Settings:Invalid checksum - Deleting file") | 
| 267 | 256 | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 355       m_isDirty = true; | 344       m_isDirty = true; | 
| 356       DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->seco
      nd); | 345       DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->seco
      nd); | 
| 357     } | 346     } | 
| 358   } | 347   } | 
| 359 | 348 | 
| 360   return true; | 349   return true; | 
| 361 } | 350 } | 
| 362 | 351 | 
| 363 CString CPluginSettings::GetDataPathParent() | 352 CString CPluginSettings::GetDataPathParent() | 
| 364 { | 353 { | 
| 365   if (s_dataPathParent == NULL) | 354   if (s_dataPathParent == NULL) | 
| 366   { | 355   { | 
| 367     WCHAR* lpData = new WCHAR[MAX_PATH]; | 356     WCHAR* lpData = new WCHAR[MAX_PATH]; | 
| 368 | 357 | 
| 369     OSVERSIONINFO osVersionInfo; | 358     OSVERSIONINFO osVersionInfo; | 
| 370     ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); | 359     ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); | 
| 371 | 360 | 
| 372     osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 361     osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 
| 373 | 362 | 
| 374     ::GetVersionEx(&osVersionInfo); | 363     ::GetVersionEx(&osVersionInfo); | 
| 375 | 364 | 
| 376     //Windows Vista»    »       »       »       - 6.0 | 365     //Windows Vista       - 6.0 | 
| 377     //Windows Server 2003 R2»   - 5.2 | 366     //Windows Server 2003 R2  - 5.2 | 
| 378     //Windows Server 2003»      »       - 5.2 | 367     //Windows Server 2003   - 5.2 | 
| 379     //Windows XP»       »       »       »       - 5.1 | 368     //Windows XP        - 5.1 | 
| 380     if (osVersionInfo.dwMajorVersion >= 6) | 369     if (osVersionInfo.dwMajorVersion >= 6) | 
| 381     { | 370     { | 
| 382       if (::SHGetSpecialFolderPath(NULL, lpData, CSIDL_LOCAL_APPDATA, TRUE)) | 371       if (::SHGetSpecialFolderPath(NULL, lpData, CSIDL_LOCAL_APPDATA, TRUE)) | 
| 383       { | 372       { | 
| 384         wcscat(lpData, L"Low"); | 373         wcscat(lpData, L"Low"); | 
| 385       } | 374       } | 
| 386       else | 375       else | 
| 387       { | 376       { | 
| 388         DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYS
      INFO_GET_SPECIAL_FOLDER_LOCAL, "Settings::GetDataPath failed"); | 377         DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYS
      INFO_GET_SPECIAL_FOLDER_LOCAL, "Settings::GetDataPath failed"); | 
| 389       } | 378       } | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 408         DEBUG_ERROR_LOG(errorCode, PLUGIN_ERROR_SETTINGS, PLUGIN_ERROR_SETTINGS_
      CREATE_FOLDER, "Settings::CreateDirectory failed"); | 397         DEBUG_ERROR_LOG(errorCode, PLUGIN_ERROR_SETTINGS, PLUGIN_ERROR_SETTINGS_
      CREATE_FOLDER, "Settings::CreateDirectory failed"); | 
| 409       } | 398       } | 
| 410     } | 399     } | 
| 411   } | 400   } | 
| 412 | 401 | 
| 413   return s_dataPathParent; | 402   return s_dataPathParent; | 
| 414 } | 403 } | 
| 415 | 404 | 
| 416 CString CPluginSettings::GetDataPath(const CString& filename) | 405 CString CPluginSettings::GetDataPath(const CString& filename) | 
| 417 { | 406 { | 
| 418   if (s_dataPath == NULL) | 407   if (s_dataPath == NULL) | 
| 419   { | 408   { | 
| 420     WCHAR* lpData = new WCHAR[MAX_PATH]; | 409     WCHAR* lpData = new WCHAR[MAX_PATH]; | 
| 421 | 410 | 
| 422     OSVERSIONINFO osVersionInfo; | 411     OSVERSIONINFO osVersionInfo; | 
| 423     ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); | 412     ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); | 
| 424 | 413 | 
| 425     osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 414     osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 
| 426 | 415 | 
| 427     ::GetVersionEx(&osVersionInfo); | 416     ::GetVersionEx(&osVersionInfo); | 
| 428 | 417 | 
| 429     //Windows Vista»    »       »       »       - 6.0 | 418     //Windows Vista       - 6.0 | 
| 430     //Windows Server 2003 R2»   - 5.2 | 419     //Windows Server 2003 R2  - 5.2 | 
| 431     //Windows Server 2003»      »       - 5.2 | 420     //Windows Server 2003   - 5.2 | 
| 432     //Windows XP»       »       »       »       - 5.1 | 421     //Windows XP        - 5.1 | 
| 433     if (osVersionInfo.dwMajorVersion >= 6) | 422     if (osVersionInfo.dwMajorVersion >= 6) | 
| 434     { | 423     { | 
| 435       if (::SHGetSpecialFolderPath(NULL, lpData, CSIDL_LOCAL_APPDATA, TRUE)) | 424       if (::SHGetSpecialFolderPath(NULL, lpData, CSIDL_LOCAL_APPDATA, TRUE)) | 
| 436       { | 425       { | 
| 437         wcscat(lpData, L"Low"); | 426         wcscat(lpData, L"Low"); | 
| 438       } | 427       } | 
| 439       else | 428       else | 
| 440       { | 429       { | 
| 441         DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYS
      INFO_GET_SPECIAL_FOLDER_LOCAL, "Settings::GetDataPath failed"); | 430         DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYS
      INFO_GET_SPECIAL_FOLDER_LOCAL, "Settings::GetDataPath failed"); | 
| 442       } | 431       } | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 487   return lang; | 476   return lang; | 
| 488 | 477 | 
| 489 } | 478 } | 
| 490 | 479 | 
| 491 CString CPluginSettings::GetTempPath(const CString& filename) | 480 CString CPluginSettings::GetTempPath(const CString& filename) | 
| 492 { | 481 { | 
| 493   CString tempPath; | 482   CString tempPath; | 
| 494 | 483 | 
| 495   LPWSTR pwszCacheDir = NULL; | 484   LPWSTR pwszCacheDir = NULL; | 
| 496 | 485 | 
| 497   HRESULT hr = ::IEGetWriteableFolderPath(FOLDERID_InternetCache, &pwszCacheDir)
      ; | 486   HRESULT hr = ::IEGetWriteableFolderPath(FOLDERID_InternetCache, &pwszCacheDir)
      ; | 
| 498   if (SUCCEEDED(hr)) | 487   if (SUCCEEDED(hr)) | 
| 499   { | 488   { | 
| 500     tempPath = pwszCacheDir; | 489     tempPath = pwszCacheDir; | 
| 501   } | 490   } | 
| 502   // Not implemented in IE6 | 491   // Not implemented in IE6 | 
| 503   else if (hr == E_NOTIMPL) | 492   else if (hr == E_NOTIMPL) | 
| 504   { | 493   { | 
| 505     TCHAR path[MAX_PATH] = _T(""); | 494     TCHAR path[MAX_PATH] = _T(""); | 
| 506 | 495 | 
| 507     if (::SHGetSpecialFolderPath(NULL, path, CSIDL_INTERNET_CACHE, TRUE)) | 496     if (::SHGetSpecialFolderPath(NULL, path, CSIDL_INTERNET_CACHE, TRUE)) | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 564   } | 553   } | 
| 565   s_criticalSectionLocal.Unlock(); | 554   s_criticalSectionLocal.Unlock(); | 
| 566 | 555 | 
| 567   return hasKey; | 556   return hasKey; | 
| 568 } | 557 } | 
| 569 | 558 | 
| 570 | 559 | 
| 571 void CPluginSettings::Remove(const CString& key) | 560 void CPluginSettings::Remove(const CString& key) | 
| 572 { | 561 { | 
| 573   s_criticalSectionLocal.Lock(); | 562   s_criticalSectionLocal.Lock(); | 
| 574   { | 563   { | 
| 575     TProperties::iterator it = m_properties.find(key); | 564     TProperties::iterator it = m_properties.find(key); | 
| 576     if (it != m_properties.end()) | 565     if (it != m_properties.end()) | 
| 577     { | 566     { | 
| 578       m_properties.erase(it); | 567       m_properties.erase(it); | 
| 579       m_isDirty = true; | 568       m_isDirty = true; | 
| 580     } | 569     } | 
| 581   } | 570   } | 
| 582   s_criticalSectionLocal.Unlock(); | 571   s_criticalSectionLocal.Unlock(); | 
| 583 } | 572 } | 
| 584 | 573 | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 612     s_criticalSectionLocal.Lock(); | 601     s_criticalSectionLocal.Lock(); | 
| 613   { | 602   { | 
| 614     TProperties::iterator it = m_properties.find(key); | 603     TProperties::iterator it = m_properties.find(key); | 
| 615     if (it != m_properties.end() && it->second != value) | 604     if (it != m_properties.end() && it->second != value) | 
| 616     { | 605     { | 
| 617       it->second = value; | 606       it->second = value; | 
| 618       m_isDirty = true; | 607       m_isDirty = true; | 
| 619     } | 608     } | 
| 620     else if (it == m_properties.end()) | 609     else if (it == m_properties.end()) | 
| 621     { | 610     { | 
| 622       m_properties[key] = value; | 611       m_properties[key] = value; | 
| 623       m_isDirty = true; | 612       m_isDirty = true; | 
| 624     } | 613     } | 
| 625   } | 614   } | 
| 626   s_criticalSectionLocal.Unlock(); | 615   s_criticalSectionLocal.Unlock(); | 
| 627 } | 616 } | 
| 628 | 617 | 
| 629 | 618 | 
| 630 int CPluginSettings::GetValue(const CString& key, int defaultValue) const | 619 int CPluginSettings::GetValue(const CString& key, int defaultValue) const | 
| 631 { | 620 { | 
| 632   int val = defaultValue; | 621   int val = defaultValue; | 
| (...skipping 28 matching lines...) Expand all  Loading... | 
| 661     s_criticalSectionLocal.Lock(); | 650     s_criticalSectionLocal.Lock(); | 
| 662   { | 651   { | 
| 663     TProperties::iterator it = m_properties.find(key); | 652     TProperties::iterator it = m_properties.find(key); | 
| 664     if (it != m_properties.end() && it->second != sValue) | 653     if (it != m_properties.end() && it->second != sValue) | 
| 665     { | 654     { | 
| 666       it->second = sValue; | 655       it->second = sValue; | 
| 667       m_isDirty = true; | 656       m_isDirty = true; | 
| 668     } | 657     } | 
| 669     else if (it == m_properties.end()) | 658     else if (it == m_properties.end()) | 
| 670     { | 659     { | 
| 671       m_properties[key] = sValue; | 660       m_properties[key] = sValue; | 
| 672       m_isDirty = true; | 661       m_isDirty = true; | 
| 673     } | 662     } | 
| 674   } | 663   } | 
| 675   s_criticalSectionLocal.Unlock(); | 664   s_criticalSectionLocal.Unlock(); | 
| 676 } | 665 } | 
| 677 | 666 | 
| 678 | 667 | 
| 679 bool CPluginSettings::GetBool(const CString& key, bool defaultValue) const | 668 bool CPluginSettings::GetBool(const CString& key, bool defaultValue) const | 
| 680 { | 669 { | 
| 681   bool value = defaultValue; | 670   bool value = defaultValue; | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 701 { | 690 { | 
| 702   SetString(key, value ? "true":"false"); | 691   SetString(key, value ? "true":"false"); | 
| 703 } | 692 } | 
| 704 | 693 | 
| 705 | 694 | 
| 706 bool CPluginSettings::IsPluginEnabled() const | 695 bool CPluginSettings::IsPluginEnabled() const | 
| 707 { | 696 { | 
| 708   return m_isPluginEnabledTab; | 697   return m_isPluginEnabledTab; | 
| 709 } | 698 } | 
| 710 | 699 | 
| 711 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription
      s) |  | 
| 712 { |  | 
| 713   CPluginSettings::GetInstance()->m_subscriptions = subscriptions; |  | 
| 714   return; |  | 
| 715 } |  | 
| 716 |  | 
| 717 | 700 | 
| 718 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const | 701 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const | 
| 719 { | 702 { | 
| 720   std::map<CString, CString> filterList; | 703   std::map<CString, CString> filterList; | 
| 721   for (int i = 0; i < m_subscriptions.size(); i ++) | 704   for (size_t i = 0; i < m_subscriptions.size(); i ++) | 
| 722   { | 705   { | 
| 723     AdblockPlus::SubscriptionPtr it = m_subscriptions[i]; | 706     SubscriptionDescription it = m_subscriptions[i]; | 
| 724     std::string title = ""; | 707     filterList.insert(std::make_pair(CString(CA2T(it.url.c_str(), CP_UTF8)), CSt
      ring(CA2T(it.title.c_str(), CP_UTF8)))); | 
| 725     std::string url = ""; |  | 
| 726 |  | 
| 727     title = it.get()->GetProperty("specialization")->AsString(); |  | 
| 728     url = it.get()->GetProperty("url")->AsString(); |  | 
| 729 |  | 
| 730     filterList.insert(std::make_pair(CString(CA2T(url.c_str(), CP_UTF8)), CStrin
      g(CA2T(title.c_str(), CP_UTF8)))); |  | 
| 731   } | 708   } | 
| 732   return filterList; | 709   return filterList; | 
| 733 } | 710 } | 
| 734 | 711 | 
| 735 | 712 | 
| 736 bool CPluginSettings::Write(bool isDebug) | 713 bool CPluginSettings::Write(bool isDebug) | 
| 737 { | 714 { | 
| 738   bool isWritten = true; | 715   bool isWritten = true; | 
| 739 | 716 | 
| 740   if (!m_isDirty) | 717   if (!m_isDirty) | 
| 741   { | 718   { | 
| 742     return isWritten; | 719     return isWritten; | 
| 743   } | 720   } | 
| 744 | 721 | 
| 745   if (isDebug) | 722   if (isDebug) | 
| 746   { | 723   { | 
| 747     DEBUG_GENERAL(L"*** Writing changed settings") | 724     DEBUG_GENERAL(L"*** Writing changed settings") | 
| 748   } | 725   } | 
| 749 | 726 | 
| 750   CPluginSettingsLock lock; | 727   CPluginSettingsLock lock; | 
| 751   if (lock.IsLocked()) | 728   if (lock.IsLocked()) | 
| 752   { | 729   { | 
| 753     m_settingsFile->Clear(); | 730     m_settingsFile->Clear(); | 
| 754 | 731 | 
| 755     // Properties | 732     // Properties | 
| 756     CPluginIniFileW::TSectionData settings; | 733     CPluginIniFileW::TSectionData settings; | 
| 757 | 734 | 
| 758     s_criticalSectionLocal.Lock(); | 735     s_criticalSectionLocal.Lock(); | 
| 759     { | 736     { | 
| 760       for (TProperties::iterator it = m_properties.begin(); it != m_properties.e
      nd(); ++it) | 737       for (TProperties::iterator it = m_properties.begin(); it != m_properties.e
      nd(); ++it) | 
| 761       { | 738       { | 
| 762         settings[it->first] = it->second; | 739         settings[it->first] = it->second; | 
| 763       } | 740       } | 
| 764     } | 741     } | 
| 765     s_criticalSectionLocal.Unlock(); | 742     s_criticalSectionLocal.Unlock(); | 
| 766 | 743 | 
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 939 { | 916 { | 
| 940   bool isRead = true; | 917   bool isRead = true; | 
| 941 | 918 | 
| 942   DEBUG_SETTINGS(L"SettingsTab::Read tab") | 919   DEBUG_SETTINGS(L"SettingsTab::Read tab") | 
| 943 | 920 | 
| 944     if (bDebug) | 921     if (bDebug) | 
| 945     { | 922     { | 
| 946       DEBUG_GENERAL(L"*** Loading tab settings:" + m_settingsFileTab->GetFilePat
      h()); | 923       DEBUG_GENERAL(L"*** Loading tab settings:" + m_settingsFileTab->GetFilePat
      h()); | 
| 947     } | 924     } | 
| 948 | 925 | 
| 949     isRead = m_settingsFileTab->Read(); | 926     isRead = m_settingsFileTab->Read(); | 
| 950     if (isRead) | 927     if (isRead) | 
| 951     { | 928     { | 
| 952       ClearTab(); | 929       ClearTab(); | 
| 953 | 930 | 
| 954       if (m_settingsFileTab->IsValidChecksum()) | 931       if (m_settingsFileTab->IsValidChecksum()) | 
| 955       { | 932       { | 
| 956         s_criticalSectionLocal.Lock(); | 933         s_criticalSectionLocal.Lock(); | 
| 957         { | 934         { | 
| 958           m_propertiesTab = m_settingsFileTab->GetSectionData("Settings"); | 935           m_propertiesTab = m_settingsFileTab->GetSectionData("Settings"); | 
| 959 | 936 | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1002   } | 979   } | 
| 1003 | 980 | 
| 1004   if (isDebug) | 981   if (isDebug) | 
| 1005   { | 982   { | 
| 1006     DEBUG_GENERAL(L"*** Writing changed tab settings") | 983     DEBUG_GENERAL(L"*** Writing changed tab settings") | 
| 1007   } | 984   } | 
| 1008 | 985 | 
| 1009   m_settingsFileTab->Clear(); | 986   m_settingsFileTab->Clear(); | 
| 1010 | 987 | 
| 1011   // Properties & errors | 988   // Properties & errors | 
| 1012   CPluginIniFileW::TSectionData settings; | 989   CPluginIniFileW::TSectionData settings; | 
| 1013   CPluginIniFileW::TSectionData errors; | 990   CPluginIniFileW::TSectionData errors; | 
| 1014 | 991 | 
| 1015   s_criticalSectionLocal.Lock(); | 992   s_criticalSectionLocal.Lock(); | 
| 1016   { | 993   { | 
| 1017     for (TProperties::iterator it = m_propertiesTab.begin(); it != m_propertiesT
      ab.end(); ++it) | 994     for (TProperties::iterator it = m_propertiesTab.begin(); it != m_propertiesT
      ab.end(); ++it) | 
| 1018     { | 995     { | 
| 1019       settings[it->first] = it->second; | 996       settings[it->first] = it->second; | 
| 1020     } | 997     } | 
| 1021 | 998 | 
| 1022     for (TProperties::iterator it = m_errorsTab.begin(); it != m_errorsTab.end()
      ; ++it) | 999     for (TProperties::iterator it = m_errorsTab.begin(); it != m_errorsTab.end()
      ; ++it) | 
| 1023     { | 1000     { | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1070 | 1047 | 
| 1071     CString today; | 1048     CString today; | 
| 1072     today.Format(L"%d-%d-%d", systemTime.wYear, systemTime.wMonth, systemTime.wD
      ay); | 1049     today.Format(L"%d-%d-%d", systemTime.wYear, systemTime.wMonth, systemTime.wD
      ay); | 
| 1073 | 1050 | 
| 1074     ReadTab(false); | 1051     ReadTab(false); | 
| 1075 | 1052 | 
| 1076     s_criticalSectionLocal.Lock(); | 1053     s_criticalSectionLocal.Lock(); | 
| 1077     { | 1054     { | 
| 1078       TProperties::iterator it = m_propertiesTab.find(SETTING_TAB_COUNT); | 1055       TProperties::iterator it = m_propertiesTab.find(SETTING_TAB_COUNT); | 
| 1079       if (it != m_propertiesTab.end()) | 1056       if (it != m_propertiesTab.end()) | 
| 1080       { | 1057       { | 
| 1081         tabCount = _wtoi(it->second) + 1; | 1058         tabCount = _wtoi(it->second) + 1; | 
| 1082       } | 1059       } | 
| 1083 | 1060 | 
| 1084       it = m_propertiesTab.find(SETTING_TAB_START_TIME); | 1061       it = m_propertiesTab.find(SETTING_TAB_START_TIME); | 
| 1085 | 1062 | 
| 1086       //Is this a first IE instance? | 1063       //Is this a first IE instance? | 
| 1087       HWND ieWnd = FindWindow(L"IEFrame", NULL); | 1064       HWND ieWnd = FindWindow(L"IEFrame", NULL); | 
| 1088       if (ieWnd != NULL) | 1065       if (ieWnd != NULL) | 
| 1089       { | 1066       { | 
| 1090         ieWnd = FindWindowEx(NULL, ieWnd, L"IEFrame", NULL); | 1067         ieWnd = FindWindowEx(NULL, ieWnd, L"IEFrame", NULL); | 
| 1091 | 1068 | 
| 1092       } | 1069       } | 
| 1093       if ((it != m_propertiesTab.end() && it->second != today)) | 1070       if ((it != m_propertiesTab.end() && it->second != today)) | 
| 1094       { | 1071       { | 
| 1095         tabCount = 1; | 1072         tabCount = 1; | 
| 1096       } | 1073       } | 
| 1097       m_tabNumber.Format(L"%d", tabCount); | 1074       m_tabNumber.Format(L"%d", tabCount); | 
| 1098 | 1075 | 
| 1099       m_propertiesTab[SETTING_TAB_COUNT] = m_tabNumber; | 1076       m_propertiesTab[SETTING_TAB_COUNT] = m_tabNumber; | 
| 1100       m_propertiesTab[SETTING_TAB_START_TIME] = today; | 1077       m_propertiesTab[SETTING_TAB_START_TIME] = today; | 
| 1101 | 1078 | 
| 1102       // Main tab? | 1079       // Main tab? | 
| 1103       if (tabCount == 1) | 1080       if (tabCount == 1) | 
| 1104       { | 1081       { | 
| 1105         m_propertiesTab[SETTING_TAB_DICTIONARY_VERSION] = "1"; | 1082         m_propertiesTab[SETTING_TAB_DICTIONARY_VERSION] = "1"; | 
| 1106         m_propertiesTab[SETTING_TAB_SETTINGS_VERSION] = "1"; | 1083         m_propertiesTab[SETTING_TAB_SETTINGS_VERSION] = "1"; | 
| 1107 #ifdef SUPPORT_WHITELIST | 1084 #ifdef SUPPORT_WHITELIST | 
| 1108         m_propertiesTab[SETTING_TAB_WHITELIST_VERSION] = "1"; | 1085         m_propertiesTab[SETTING_TAB_WHITELIST_VERSION] = "1"; | 
| 1109 #endif | 1086 #endif | 
| 1110 #ifdef SUPPORT_FILTER | 1087 #ifdef SUPPORT_FILTER | 
| 1111         m_propertiesTab[SETTING_TAB_FILTER_VERSION] = "1"; | 1088         m_propertiesTab[SETTING_TAB_FILTER_VERSION] = "1"; | 
| 1112 #endif | 1089 #endif | 
| 1113 #ifdef SUPPORT_CONFIG | 1090 #ifdef SUPPORT_CONFIG | 
| 1114         m_propertiesTab[SETTING_TAB_CONFIG_VERSION] = "1"; | 1091         m_propertiesTab[SETTING_TAB_CONFIG_VERSION] = "1"; | 
| 1115 #endif | 1092 #endif | 
| 1116       } | 1093       } | 
| 1117     } | 1094     } | 
| 1118     s_criticalSectionLocal.Unlock(); | 1095     s_criticalSectionLocal.Unlock(); | 
| 1119 | 1096 | 
| 1120     m_isDirtyTab = true; | 1097     m_isDirtyTab = true; | 
| 1121 | 1098 | 
| 1122     WriteTab(false); | 1099     WriteTab(false); | 
| 1123   } | 1100   } | 
| 1124 | 1101 | 
| 1125   return tabCount == 1; | 1102   return tabCount == 1; | 
| 1126 } | 1103 } | 
| 1127 | 1104 | 
| 1128 | 1105 | 
| 1129 CString CPluginSettings::GetTabNumber() const | 1106 CString CPluginSettings::GetTabNumber() const | 
| 1130 { | 1107 { | 
| 1131   CString tabNumber; | 1108   CString tabNumber; | 
| 1132 | 1109 | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1170             m_propertiesTab.erase(it); | 1147             m_propertiesTab.erase(it); | 
| 1171           } | 1148           } | 
| 1172 | 1149 | 
| 1173           it = m_propertiesTab.find(SETTING_TAB_COUNT); | 1150           it = m_propertiesTab.find(SETTING_TAB_COUNT); | 
| 1174           if (it != m_propertiesTab.end()) | 1151           if (it != m_propertiesTab.end()) | 
| 1175           { | 1152           { | 
| 1176             m_propertiesTab.erase(it); | 1153             m_propertiesTab.erase(it); | 
| 1177           } | 1154           } | 
| 1178         } | 1155         } | 
| 1179 | 1156 | 
| 1180         m_isDirtyTab = true; | 1157         m_isDirtyTab = true; | 
| 1181       } | 1158       } | 
| 1182     } | 1159     } | 
| 1183     s_criticalSectionLocal.Unlock(); | 1160     s_criticalSectionLocal.Unlock(); | 
| 1184 | 1161 | 
| 1185     WriteTab(false); | 1162     WriteTab(false); | 
| 1186   } | 1163   } | 
| 1187 | 1164 | 
| 1188   return tabCount == 0; | 1165   return tabCount == 0; | 
| 1189 } | 1166 } | 
| 1190 | 1167 | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1255 | 1232 | 
| 1256     CPluginSettingsTabLock lock; | 1233     CPluginSettingsTabLock lock; | 
| 1257   if (lock.IsLocked()) | 1234   if (lock.IsLocked()) | 
| 1258   { | 1235   { | 
| 1259     ReadTab(false); | 1236     ReadTab(false); | 
| 1260 | 1237 | 
| 1261     s_criticalSectionLocal.Lock(); | 1238     s_criticalSectionLocal.Lock(); | 
| 1262     { | 1239     { | 
| 1263       if (m_errorsTab.find(error) == m_errorsTab.end()) | 1240       if (m_errorsTab.find(error) == m_errorsTab.end()) | 
| 1264       { | 1241       { | 
| 1265         m_errorsTab[error] = errorCode; | 1242         m_errorsTab[error] = errorCode; | 
| 1266         m_isDirtyTab = true; | 1243         m_isDirtyTab = true; | 
| 1267       } | 1244       } | 
| 1268     } | 1245     } | 
| 1269     s_criticalSectionLocal.Unlock(); | 1246     s_criticalSectionLocal.Unlock(); | 
| 1270 | 1247 | 
| 1271     WriteTab(false); | 1248     WriteTab(false); | 
| 1272   } | 1249   } | 
| 1273 } | 1250 } | 
| 1274 | 1251 | 
| 1275 | 1252 | 
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1450 | 1427 | 
| 1451       CString versionString; | 1428       CString versionString; | 
| 1452       versionString.Format(L"%d", version); | 1429       versionString.Format(L"%d", version); | 
| 1453 | 1430 | 
| 1454       m_propertiesTab[key] = versionString; | 1431       m_propertiesTab[key] = versionString; | 
| 1455     } | 1432     } | 
| 1456     s_criticalSectionLocal.Unlock(); | 1433     s_criticalSectionLocal.Unlock(); | 
| 1457 | 1434 | 
| 1458     m_isDirtyTab = true; | 1435     m_isDirtyTab = true; | 
| 1459 | 1436 | 
| 1460     WriteTab(false); | 1437     WriteTab(false); | 
| 1461   } | 1438   } | 
| 1462 } | 1439 } | 
| 1463 | 1440 | 
| 1464 | 1441 | 
| 1465 // ============================================================================ | 1442 // ============================================================================ | 
| 1466 // Whitelist settings | 1443 // Whitelist settings | 
| 1467 // ============================================================================ | 1444 // ============================================================================ | 
| 1468 | 1445 | 
| 1469 #ifdef SUPPORT_WHITELIST | 1446 #ifdef SUPPORT_WHITELIST | 
| 1470 | 1447 | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 1488     { | 1465     { | 
| 1489       DEBUG_GENERAL("*** Loading whitelist settings"); | 1466       DEBUG_GENERAL("*** Loading whitelist settings"); | 
| 1490     } | 1467     } | 
| 1491 | 1468 | 
| 1492     CPluginSettingsWhitelistLock lock; | 1469     CPluginSettingsWhitelistLock lock; | 
| 1493     if (lock.IsLocked()) | 1470     if (lock.IsLocked()) | 
| 1494     { | 1471     { | 
| 1495       ClearWhitelist(); | 1472       ClearWhitelist(); | 
| 1496 | 1473 | 
| 1497       s_criticalSectionLocal.Lock(); | 1474       s_criticalSectionLocal.Lock(); | 
| 1498       try | 1475       m_whitelistedDomains = CPluginClient::GetInstance()->GetExceptionDomains()
      ; | 
| 1499       { |  | 
| 1500       std::vector<AdblockPlus::FilterPtr> filters = CPluginClient::GetInstance()
      ->GetListedFilters(); |  | 
| 1501       for (int i = 0; i < filters.size(); i ++) |  | 
| 1502       { |  | 
| 1503         if (filters[i]->GetType() == AdblockPlus::Filter::Type::TYPE_EXCEPTION) |  | 
| 1504         { |  | 
| 1505           std::string text = filters[i]->GetProperty("text")->AsString(); |  | 
| 1506           //@@||example.com^$document |  | 
| 1507           size_t endPos = text.rfind("^$document"); |  | 
| 1508           if (endPos != std::string::npos) |  | 
| 1509           { |  | 
| 1510             size_t startPos = text.find("@@||") + 4; |  | 
| 1511             if (startPos != std::string::npos) |  | 
| 1512             { |  | 
| 1513               m_whitelistedDomains.push_back(text.substr(startPos, endPos - star
      tPos)); |  | 
| 1514             } |  | 
| 1515           } |  | 
| 1516         } |  | 
| 1517       } |  | 
| 1518       } |  | 
| 1519       catch(std::runtime_error ex) |  | 
| 1520       { |  | 
| 1521         DEBUG_GENERAL(ex.what()); |  | 
| 1522       } |  | 
| 1523       catch(std::exception ex) |  | 
| 1524       { |  | 
| 1525         DEBUG_GENERAL(ex.what()); |  | 
| 1526       } |  | 
| 1527       s_criticalSectionLocal.Unlock(); | 1476       s_criticalSectionLocal.Unlock(); | 
| 1528     } | 1477     } | 
| 1529     else | 1478     else | 
| 1530     { | 1479     { | 
| 1531       isRead = false; | 1480       isRead = false; | 
| 1532     } | 1481     } | 
| 1533 | 1482 | 
| 1534     return isRead; | 1483     return isRead; | 
| 1535 } | 1484 } | 
| 1536 | 1485 | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 1548     ReadWhitelist(false); | 1497     ReadWhitelist(false); | 
| 1549 | 1498 | 
| 1550     std::string newDomain = CW2A(domain, CP_UTF8); | 1499     std::string newDomain = CW2A(domain, CP_UTF8); | 
| 1551 | 1500 | 
| 1552     //Domain already present? | 1501     //Domain already present? | 
| 1553     if (std::find(m_whitelistedDomains.begin(), m_whitelistedDomains.end(), newD
      omain) != m_whitelistedDomains.end()) | 1502     if (std::find(m_whitelistedDomains.begin(), m_whitelistedDomains.end(), newD
      omain) != m_whitelistedDomains.end()) | 
| 1554     { | 1503     { | 
| 1555       return; | 1504       return; | 
| 1556     } | 1505     } | 
| 1557     s_criticalSectionLocal.Lock(); | 1506     s_criticalSectionLocal.Lock(); | 
| 1558     { | 1507     CPluginClient::GetInstance()->AddFilter(std::string("@@||").append(CW2A(doma
      in)).append("^$document")); | 
| 1559       AdblockPlus::FilterPtr whitelistFilter = CPluginClient::GetInstance()->Get
      Filter(std::string("@@||").append(CW2A(domain)).append("^$document")); |  | 
| 1560       whitelistFilter->AddToList(); |  | 
| 1561     } |  | 
| 1562     s_criticalSectionLocal.Unlock(); | 1508     s_criticalSectionLocal.Unlock(); | 
| 1563 | 1509 | 
| 1564   } | 1510   } | 
| 1565 | 1511 | 
| 1566   if (isForcingUpdateOnStart) | 1512   if (isForcingUpdateOnStart) | 
| 1567   { | 1513   { | 
| 1568     ForceConfigurationUpdateOnStart(); | 1514     ForceConfigurationUpdateOnStart(); | 
| 1569   } | 1515   } | 
| 1570 } | 1516 } | 
| 1571 | 1517 | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1636 } | 1582 } | 
| 1637 | 1583 | 
| 1638 void CPluginSettings::SetSubscription(BSTR url) | 1584 void CPluginSettings::SetSubscription(BSTR url) | 
| 1639 { | 1585 { | 
| 1640   std::string urlConverted = CT2A(url, CP_UTF8); | 1586   std::string urlConverted = CT2A(url, CP_UTF8); | 
| 1641   SetSubscription(urlConverted); | 1587   SetSubscription(urlConverted); | 
| 1642 } | 1588 } | 
| 1643 | 1589 | 
| 1644 void CPluginSettings::SetSubscription(std::string url) | 1590 void CPluginSettings::SetSubscription(std::string url) | 
| 1645 { | 1591 { | 
| 1646   try | 1592   CPluginClient::GetInstance()->SetSubscription(url); | 
| 1647   { | 1593   RefreshFilterlist(); | 
| 1648     std::vector<AdblockPlus::SubscriptionPtr> subscriptions = CPluginClient::Get
      Instance()->GetListedSubscriptions(); | 1594   RefreshWhitelist(); | 
| 1649     if (subscriptions.size() > 0) |  | 
| 1650     { |  | 
| 1651       for (int i = 0; i < subscriptions.size(); i ++) |  | 
| 1652       { |  | 
| 1653         subscriptions[i]->RemoveFromList(); |  | 
| 1654       } |  | 
| 1655     } |  | 
| 1656     AdblockPlus::SubscriptionPtr subscription = CPluginClient::GetInstance()->Ge
      tSubscription(url); |  | 
| 1657     subscription->AddToList(); |  | 
| 1658     RefreshFilterlist(); |  | 
| 1659     RefreshWhitelist(); |  | 
| 1660   } |  | 
| 1661   catch(std::exception ex) |  | 
| 1662   { |  | 
| 1663     DEBUG_GENERAL(ex.what()); |  | 
| 1664   } |  | 
| 1665   catch(std::runtime_error ex) |  | 
| 1666   { |  | 
| 1667     DEBUG_GENERAL(ex.what()); |  | 
| 1668   } |  | 
| 1669 } | 1595 } | 
| 1670 | 1596 | 
| 1671 std::vector<std::string> split(const std::string& s, char delim) { | 1597 std::vector<std::string> split(const std::string& s, char delim) { | 
| 1672     std::vector<std::string> retTokens; | 1598     std::vector<std::string> retTokens; | 
| 1673     std::stringstream ss(s); | 1599     std::stringstream ss(s); | 
| 1674     std::string item; | 1600     std::string item; | 
| 1675     while (std::getline(ss, item, delim)) { | 1601     while (std::getline(ss, item, delim)) { | 
| 1676         retTokens.push_back(item); | 1602         retTokens.push_back(item); | 
| 1677     } | 1603     } | 
| 1678     return retTokens; | 1604     return retTokens; | 
| 1679 } | 1605 } | 
| 1680 | 1606 | 
| 1681 | 1607 | 
| 1682 void CPluginSettings::SetDefaultSubscription() |  | 
| 1683 { |  | 
| 1684   CPluginSystem* system = CPluginSystem::GetInstance(); |  | 
| 1685   CString lng = system->GetBrowserLanguage().Left(2); |  | 
| 1686   std::string browserLanguage = CW2A(lng, CP_UTF8); |  | 
| 1687   std::vector<SubscriptionPtr> subscriptions = CPluginClient::GetInstance()->Fet
      chAvailableSubscriptions(); |  | 
| 1688   bool subscriptionSet = false; |  | 
| 1689   while (!subscriptionSet) |  | 
| 1690   { |  | 
| 1691     for (int i = 0; i < subscriptions.size(); i++) |  | 
| 1692     { |  | 
| 1693       std::string prefixes = subscriptions[i]->GetProperty("prefixes")->AsString
      (); |  | 
| 1694       std::vector<std::string> tokens = split(prefixes, ','); |  | 
| 1695       for (int j = 0; j < tokens.size(); j ++) |  | 
| 1696       { |  | 
| 1697         if (tokens[j] == browserLanguage) |  | 
| 1698         { |  | 
| 1699           SetSubscription(subscriptions[i]->GetProperty("url")->AsString()); |  | 
| 1700           subscriptionSet = true; |  | 
| 1701         } |  | 
| 1702       } |  | 
| 1703     } |  | 
| 1704 |  | 
| 1705     if (browserLanguage == "en") |  | 
| 1706       break; |  | 
| 1707     // failed to set the subscription for browser language. Try "en" |  | 
| 1708     browserLanguage = "en"; |  | 
| 1709 |  | 
| 1710   } |  | 
| 1711 } |  | 
| 1712 |  | 
| 1713 CString CPluginSettings::GetSubscription() | 1608 CString CPluginSettings::GetSubscription() | 
| 1714 { | 1609 { | 
| 1715   try | 1610   std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc
      e()->GetListedSubscriptions(); | 
| 1716   { | 1611   if (subscriptions.size() > 0) | 
| 1717    std::vector<AdblockPlus::SubscriptionPtr> subscriptions = CPluginClient::GetI
      nstance()->GetListedSubscriptions(); | 1612     return CString(CA2T(subscriptions.front().url.c_str(), CP_UTF8)); | 
| 1718 | 1613   else | 
| 1719     if (subscriptions.size() == 0) | 1614     return CString(L""); | 
| 1720     { |  | 
| 1721       SetDefaultSubscription(); |  | 
| 1722       subscriptions = CPluginClient::GetInstance()->GetListedSubscriptions(); |  | 
| 1723     } |  | 
| 1724     for (int i = 0; i < subscriptions.size(); i ++) |  | 
| 1725     { |  | 
| 1726       return CString(CA2T(subscriptions[i]->GetProperty("url")->AsString().c_str
      (), CP_UTF8)); |  | 
| 1727     } |  | 
| 1728   } |  | 
| 1729   catch(std::exception ex) |  | 
| 1730   { |  | 
| 1731     DEBUG_GENERAL(ex.what()); |  | 
| 1732   } |  | 
| 1733   catch(std::runtime_error ex) |  | 
| 1734   { |  | 
| 1735     DEBUG_GENERAL(ex.what()); |  | 
| 1736   } |  | 
| 1737   return CString(L""); |  | 
| 1738 } | 1615 } | 
| 1739 | 1616 | 
| 1740 | 1617 | 
| 1741 void CPluginSettings::RefreshFilterlist() | 1618 void CPluginSettings::RefreshFilterlist() | 
| 1742 { | 1619 { | 
| 1743   try | 1620   CPluginClient::GetInstance()->UpdateAllSubscriptions(); | 
| 1744   { |  | 
| 1745     // Make sure at least the default subscription is set |  | 
| 1746     CPluginSettings* settings = CPluginSettings::GetInstance(); |  | 
| 1747     settings->GetSubscription(); |  | 
| 1748 |  | 
| 1749     std::vector<AdblockPlus::SubscriptionPtr> subscriptions = CPluginClient::Get
      Instance()->GetListedSubscriptions(); |  | 
| 1750     for (int i = 0; i < subscriptions.size(); i ++) |  | 
| 1751     { |  | 
| 1752       subscriptions[i]->UpdateFilters(); |  | 
| 1753     } |  | 
| 1754   } |  | 
| 1755   catch(std::exception ex) |  | 
| 1756   { |  | 
| 1757     DEBUG_GENERAL(ex.what()); |  | 
| 1758   } |  | 
| 1759   catch(std::runtime_error ex) |  | 
| 1760   { |  | 
| 1761     DEBUG_GENERAL(ex.what()); |  | 
| 1762   } |  | 
| 1763 } | 1621 } | 
| 1764 | 1622 | 
| 1765 #endif // SUPPORT_WHITELIST | 1623 #endif // SUPPORT_WHITELIST | 
| OLD | NEW | 
|---|