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

Unified Diff: Shared/PluginSettings.cpp

Issue 9451102: Filterlists downloads changes (Closed)
Patch Set: Created Feb. 28, 2013, 10:32 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Shared/PluginHttpRequest.cpp ('k') | Shared/PluginSystem.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Shared/PluginSettings.cpp
===================================================================
--- a/Shared/PluginSettings.cpp
+++ b/Shared/PluginSettings.cpp
@@ -238,6 +238,8 @@
{
if (m_settingsFile->IsValidChecksum())
{
+ m_properties = m_settingsFile->GetSectionData("Settings");
+
#ifdef SUPPORT_FILTER
// Unpack filter URLs
CPluginIniFileW::TSectionData filters = m_settingsFile->GetSectionData("Filters");
@@ -359,6 +361,11 @@
bool CPluginSettings::MakeRequestForUpdate()
{
+ time_t updateTime = this->GetValue(SETTING_LAST_UPDATE_TIME);
+
+ if (time(NULL) <= updateTime)
+ return false;
+
CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL);
CPluginSystem* system = CPluginSystem::GetInstance();
@@ -371,6 +378,7 @@
httpRequest.Send();
+ this->SetValue(SETTING_LAST_UPDATE_TIME, time(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8));
if (httpRequest.IsValidResponse())
{
const std::auto_ptr<CPluginIniFile>& iniFile = httpRequest.GetResponseFile();
@@ -401,43 +409,68 @@
}
bool CPluginSettings::CheckFilterAndDownload()
{
- TFilterUrlList currentFilterUrlList = this->GetFilterUrlList();
- std::map<CString, CString> fileNamesList = this->GetFilterFileNamesList();
+ s_criticalSectionLocal.Lock();
+ TFilterUrlList currentFilterUrlList = this->GetFilterUrlList();
+ std::map<CString, CString> fileNamesList = this->GetFilterFileNamesList();
- for (TFilterUrlList::iterator it = currentFilterUrlList.begin(); it != currentFilterUrlList.end(); ++it)
+ bool filterAvailable = false;
+ for (TFilterUrlList::iterator it = currentFilterUrlList.begin(); it != currentFilterUrlList.end(); ++it)
+ {
+ CString downloadFilterName = it->first;
+
+ std::map<CString, CString>::const_iterator fni = fileNamesList.find(downloadFilterName);
+ CString filename = "";
+ if (fni != fileNamesList.end())
+ {
+ filename = fni->second;
+ }
+ else
+ {
+ filename = downloadFilterName.Trim().Right(downloadFilterName.GetLength() - downloadFilterName.ReverseFind('/') - 1).Trim();
+ }
+ int version = it->second;
+ if ((this->FilterShouldLoad(downloadFilterName)))
{
- CString downloadFilterName = it->first;
-
- std::map<CString, CString>::const_iterator fni = fileNamesList.find(downloadFilterName);
- CString filename = "";
- if (fni != fileNamesList.end())
+ filterAvailable = true;
+ if (this->FilterlistExpired(downloadFilterName))
{
- filename = fni->second;
- }
- else
- {
- filename = downloadFilterName.Trim().Right(downloadFilterName.GetLength() - downloadFilterName.ReverseFind('/') - 1).Trim();
- }
- int version = it->second;
-
- if (this->FilterlistExpired(downloadFilterName) && (this->FilterShouldLoad(downloadFilterName)))
- {
- CPluginFilter::DownloadFilterFile(downloadFilterName, filename);
+ CPluginFilter::DownloadFilterFile(downloadFilterName, filename);
this->SetFilterRefreshDate(downloadFilterName, time(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8));
- }
- else
- {
- //Cleanup, since we don't need the filter definition
- DeleteFile(CPluginSettings::GetDataPath(filename));
- this->SetFilterRefreshDate(downloadFilterName, 0);
}
}
+ else
+ {
+ //Cleanup, since we don't need the filter definition
+ DeleteFile(CPluginSettings::GetDataPath(filename));
+ this->SetFilterRefreshDate(downloadFilterName, 0);
+ }
+ }
- this->Write();
+ if (!filterAvailable)
+ {
+ //If no filter list found, default to "en"
- this->IncrementTabVersion(SETTING_TAB_FILTER_VERSION);
+ this->SetString(SETTING_LANGUAGE, (BSTR)L"en");
- return true;
+ CPluginDictionary* dict = CPluginDictionary::GetInstance();
+ dict->SetLanguage(L"en");
+
+ for (std::map<CString, CString>::iterator it = m_filterLanguagesList.begin(); it != m_filterLanguagesList.end(); ++it)
+ {
+ if (it->second == L"en")
+ {
+ CPluginFilter::DownloadFilterFile(it->first, m_filterFileNameList.find(it->first)->second);
+ this->SetFilterRefreshDate(it->first, time(NULL) + (5 * 24 * 60 * 60) * ((rand() % 100) / 100 * 0.4 + 0.8));
+ }
+ }
+ }
+
+ this->Write();
+
+ this->IncrementTabVersion(SETTING_TAB_FILTER_VERSION);
+
+ s_criticalSectionLocal.Unlock();
+ return true;
}
CString CPluginSettings::GetDataPathParent()
« 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