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

Side by Side Diff: Shared/PluginSettings.cpp

Issue 9451102: Filterlists downloads changes (Closed)
Patch Set: Created Feb. 28, 2013, 10:32 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Shared/PluginHttpRequest.cpp ('k') | Shared/PluginSystem.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 232
233 CPluginSettingsLock lock; 233 CPluginSettingsLock lock;
234 if (lock.IsLocked()) 234 if (lock.IsLocked())
235 { 235 {
236 isRead = m_settingsFile->Read(); 236 isRead = m_settingsFile->Read();
237 if (isRead) 237 if (isRead)
238 { 238 {
239 if (m_settingsFile->IsValidChecksum()) 239 if (m_settingsFile->IsValidChecksum())
240 { 240 {
241 m_properties = m_settingsFile->GetSectio nData("Settings");
242
241 #ifdef SUPPORT_FILTER 243 #ifdef SUPPORT_FILTER
242 // Unpack filter URLs 244 // Unpack filter URLs
243 CPluginIniFileW::TSectionData filters = m_settingsFile->GetS ectionData("Filters"); 245 CPluginIniFileW::TSectionData filters = m_settingsFile->GetS ectionData("Filters");
244 int filterCount = 0; 246 int filterCount = 0;
245 bool bContinue = true; 247 bool bContinue = true;
246 248
247 s_criticalSectionFilters.Lock(); 249 s_criticalSectionFilters.Lock();
248 { 250 {
249 m_filterUrlList.clear(); 251 m_filterUrlList.clear();
250 252
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 m_filterDownloadTimesList[CString(FILTERS_PROTOCOL) + CString(FI LTERS_HOST) + "/easylist.txt"] = time(NULL); 354 m_filterDownloadTimesList[CString(FILTERS_PROTOCOL) + CString(FI LTERS_HOST) + "/easylist.txt"] = time(NULL);
353 */ 355 */
354 } 356 }
355 s_criticalSectionFilters.Unlock(); 357 s_criticalSectionFilters.Unlock();
356 358
357 #endif // SUPPORT_FILTER 359 #endif // SUPPORT_FILTER
358 } 360 }
359 361
360 bool CPluginSettings::MakeRequestForUpdate() 362 bool CPluginSettings::MakeRequestForUpdate()
361 { 363 {
364 time_t updateTime = this->GetValue(SETTING_LAST_UPDATE_TIME);
365
366 if (time(NULL) <= updateTime)
367 return false;
368
362 CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL); 369 CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL);
363 370
364 CPluginSystem* system = CPluginSystem::GetInstance(); 371 CPluginSystem* system = CPluginSystem::GetInstance();
365 372
366 httpRequest.Add("lang", this->GetString(SETTING_LANGUAGE, "err")); 373 httpRequest.Add("lang", this->GetString(SETTING_LANGUAGE, "err"));
367 httpRequest.Add("ie", system->GetBrowserVersion()); 374 httpRequest.Add("ie", system->GetBrowserVersion());
368 httpRequest.Add("ielang", system->GetBrowserLanguage()); 375 httpRequest.Add("ielang", system->GetBrowserLanguage());
369 376
370 httpRequest.AddOsInfo(); 377 httpRequest.AddOsInfo();
371 378
372 httpRequest.Send(); 379 httpRequest.Send();
373 380
381 this->SetValue(SETTING_LAST_UPDATE_TIME, time(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8));
374 if (httpRequest.IsValidResponse()) 382 if (httpRequest.IsValidResponse())
375 { 383 {
376 const std::auto_ptr<CPluginIniFile>& iniFile = httpRequest.GetRe sponseFile(); 384 const std::auto_ptr<CPluginIniFile>& iniFile = httpRequest.GetRe sponseFile();
377 385
378 CPluginIniFile::TSectionData settingsData = iniFile->GetSectionD ata("Settings"); 386 CPluginIniFile::TSectionData settingsData = iniFile->GetSectionD ata("Settings");
379 CPluginIniFile::TSectionData::iterator it; 387 CPluginIniFile::TSectionData::iterator it;
380 388
381 it = settingsData.find("pluginupdate"); 389 it = settingsData.find("pluginupdate");
382 if (it != settingsData.end()) 390 if (it != settingsData.end())
383 { 391 {
(...skipping 10 matching lines...) Expand all
394 SetString(SETTING_PLUGIN_UPDATE_VERSION, ver); 402 SetString(SETTING_PLUGIN_UPDATE_VERSION, ver);
395 m_isDirty = true; 403 m_isDirty = true;
396 DEBUG_SETTINGS("Settings::Configuration plugin update ve rsion:" + it->second); 404 DEBUG_SETTINGS("Settings::Configuration plugin update ve rsion:" + it->second);
397 } 405 }
398 } 406 }
399 407
400 return true; 408 return true;
401 } 409 }
402 bool CPluginSettings::CheckFilterAndDownload() 410 bool CPluginSettings::CheckFilterAndDownload()
403 { 411 {
404 TFilterUrlList currentFilterUrlList = this->GetFilterUrlList(); 412 » s_criticalSectionLocal.Lock();
405 std::map<CString, CString> fileNamesList = this->GetFilterFileNamesList( ); 413 TFilterUrlList currentFilterUrlList = this->GetFilterUrlList();
414 std::map<CString, CString> fileNamesList = this->GetFilterFileNamesList();
406 415
407 for (TFilterUrlList::iterator it = currentFilterUrlList.begin(); it != c urrentFilterUrlList.end(); ++it) 416 » bool filterAvailable = false;
417 for (TFilterUrlList::iterator it = currentFilterUrlList.begin(); it != curre ntFilterUrlList.end(); ++it)
418 {
419 CString downloadFilterName = it->first;
420
421 » » std::map<CString, CString>::const_iterator fni = fileNamesList.f ind(downloadFilterName);» »
422 » » CString filename = "";
423 » » if (fni != fileNamesList.end())
424 » » {
425 » » » filename = fni->second;
426 » » }
427 » » else
428 » » {
429 » » » filename = downloadFilterName.Trim().Right(downloadFilte rName.GetLength() - downloadFilterName.ReverseFind('/') - 1).Trim();
430 » » }
431 int version = it->second;
432 if ((this->FilterShouldLoad(downloadFilterName)))
408 { 433 {
409 CString downloadFilterName = it->first; 434 » » » filterAvailable = true;
410 435 » » » if (this->FilterlistExpired(downloadFilterName))
411 » » » std::map<CString, CString>::const_iterator fni = fileNam esList.find(downloadFilterName);» »
412 » » » CString filename = "";
413 » » » if (fni != fileNamesList.end())
414 { 436 {
415 » » » » filename = fni->second; 437 » » » » CPluginFilter::DownloadFilterFile(downloadFilter Name, filename);
416 » » » }
417 » » » else
418 » » » {
419 » » » » filename = downloadFilterName.Trim().Right(downl oadFilterName.GetLength() - downloadFilterName.ReverseFind('/') - 1).Trim();
420 » » » }
421 int version = it->second;
422
423 if (this->FilterlistExpired(downloadFilterName) && (this->FilterShou ldLoad(downloadFilterName)))
424 {
425 CPluginFilter::DownloadFilterFile(downloadFilterName, filename);
426 this->SetFilterRefreshDate(downloadFilterName, t ime(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8)); 438 this->SetFilterRefreshDate(downloadFilterName, t ime(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8));
427 }
428 else
429 {
430 //Cleanup, since we don't need the filter defini tion
431 DeleteFile(CPluginSettings::GetDataPath(filename ));
432 this->SetFilterRefreshDate(downloadFilterName, 0 );
433 } 439 }
434 } 440 }
441 else
442 {
443 //Cleanup, since we don't need the filter definition
444 DeleteFile(CPluginSettings::GetDataPath(filename));
445 this->SetFilterRefreshDate(downloadFilterName, 0);
446 }
447 }
435 448
436 this->Write(); 449 » if (!filterAvailable)
450 » {
451 » » //If no filter list found, default to "en"
437 452
438 this->IncrementTabVersion(SETTING_TAB_FILTER_VERSION); 453 » this->SetString(SETTING_LANGUAGE, (BSTR)L"en");
439 454
440 » » return true; 455 » » CPluginDictionary* dict = CPluginDictionary::GetInstance();
456 » » dict->SetLanguage(L"en");
457
458 » » for (std::map<CString, CString>::iterator it = m_filterLanguages List.begin(); it != m_filterLanguagesList.end(); ++it)
459 » » {
460 » » » if (it->second == L"en")
461 » » » {
462 » » » » CPluginFilter::DownloadFilterFile(it->first, m_f ilterFileNameList.find(it->first)->second);
463 » » » » this->SetFilterRefreshDate(it->first, time(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8));
464 » » » }
465 » » }
466 » }
467
468 this->Write();
469
470 this->IncrementTabVersion(SETTING_TAB_FILTER_VERSION);
471
472 » s_criticalSectionLocal.Unlock();
473 » return true;
441 } 474 }
442 475
443 CString CPluginSettings::GetDataPathParent() 476 CString CPluginSettings::GetDataPathParent()
444 { 477 {
445 if (s_dataPathParent == NULL) 478 if (s_dataPathParent == NULL)
446 { 479 {
447 WCHAR* lpData = new WCHAR[MAX_PATH]; 480 WCHAR* lpData = new WCHAR[MAX_PATH];
448 481
449 OSVERSIONINFO osVersionInfo; 482 OSVERSIONINFO osVersionInfo;
450 ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO)); 483 ::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFO));
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 2217 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
2185 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); 2218 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi);
2186 2219
2187 m_WindowsBuildNumber = osvi.dwBuildNumber; 2220 m_WindowsBuildNumber = osvi.dwBuildNumber;
2188 } 2221 }
2189 2222
2190 return m_WindowsBuildNumber; 2223 return m_WindowsBuildNumber;
2191 } 2224 }
2192 2225
2193 #endif // SUPPORT_WHITELIST 2226 #endif // SUPPORT_WHITELIST
OLDNEW
« no previous file with comments | « Shared/PluginHttpRequest.cpp ('k') | Shared/PluginSystem.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld