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

Side by Side Diff: src/plugin/PluginSettings.cpp

Issue 10800092: Use libadblockplus update checker (Closed)
Patch Set: Addressed review comments Created June 7, 2013, 5:27 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
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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 s_criticalSectionLocal.Lock(); 253 s_criticalSectionLocal.Lock();
254 { 254 {
255 m_properties.clear(); 255 m_properties.clear();
256 256
257 m_properties[SETTING_PLUGIN_VERSION] = IEPLUGIN_VERSION; 257 m_properties[SETTING_PLUGIN_VERSION] = IEPLUGIN_VERSION;
258 m_properties[SETTING_LANGUAGE] = "en"; 258 m_properties[SETTING_LANGUAGE] = "en";
259 } 259 }
260 s_criticalSectionLocal.Unlock(); 260 s_criticalSectionLocal.Unlock();
261 } 261 }
262 262
263 bool CPluginSettings::MakeRequestForUpdate()
264 {
265 time_t updateTime = this->GetValue(SETTING_LAST_UPDATE_TIME);
266
267 if (time(NULL) <= updateTime)
268 return false;
269
270 CPluginHttpRequest httpRequest(PLUGIN_UPDATE_URL);
271
272 CPluginSystem* system = CPluginSystem::GetInstance();
273
274 httpRequest.Add("lang", this->GetString(SETTING_LANGUAGE, "err"));
275 httpRequest.Add("ie", system->GetBrowserVersion());
276 httpRequest.Add("ielang", system->GetBrowserLanguage());
277
278 httpRequest.AddOsInfo();
279
280 httpRequest.Send();
281
282 this->SetValue(SETTING_LAST_UPDATE_TIME, time(NULL) + (5 * 24 * 60 * 60) * ((r and() % 100) / 100 * 0.4 + 0.8));
283 if (httpRequest.IsValidResponse())
284 {
285 const std::auto_ptr<CPluginIniFile>& iniFile = httpRequest.GetResponseFile() ;
286
287 CPluginIniFile::TSectionData settingsData = iniFile->GetSectionData("Setting s");
288 CPluginIniFile::TSectionData::iterator it;
289
290 it = settingsData.find("pluginupdate");
291 if (it != settingsData.end())
292 {
293 CString url(it->second);
294 SetString(SETTING_PLUGIN_UPDATE_URL, url);
295 m_isDirty = true;
296 DEBUG_SETTINGS("Settings::Configuration plugin update url:" + it->second);
297 }
298
299 it = settingsData.find("pluginupdatev");
300 if (it != settingsData.end())
301 {
302 CString ver(it->second);
303 SetString(SETTING_PLUGIN_UPDATE_VERSION, ver);
304 m_isDirty = true;
305 DEBUG_SETTINGS("Settings::Configuration plugin update version:" + it->seco nd);
306 }
307 }
308
309 return true;
310 }
311
312 CString CPluginSettings::GetDataPath(const CString& filename) 263 CString CPluginSettings::GetDataPath(const CString& filename)
313 { 264 {
314 std::wstring path = ::GetAppDataPath() + L"\\" + static_cast<LPCWSTR>(filename ); 265 std::wstring path = ::GetAppDataPath() + L"\\" + static_cast<LPCWSTR>(filename );
315 return CString(path.c_str()); 266 return CString(path.c_str());
316 } 267 }
317 268
318 CString CPluginSettings::GetSystemLanguage() 269 CString CPluginSettings::GetSystemLanguage()
319 { 270 {
320 CString language; 271 CString language;
321 CString country; 272 CString country;
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 567 }
617 else 568 else
618 { 569 {
619 isWritten = false; 570 isWritten = false;
620 } 571 }
621 572
622 return isWritten; 573 return isWritten;
623 } 574 }
624 575
625 576
626 bool CPluginSettings::IsPluginUpdateAvailable() const
627 {
628 bool isAvailable = Has(SETTING_PLUGIN_UPDATE_VERSION);
629 if (isAvailable)
630 {
631 CString newVersion = GetString(SETTING_PLUGIN_UPDATE_VERSION);
632 CString curVersion = IEPLUGIN_VERSION;
633
634 isAvailable = newVersion != curVersion;
635 if (isAvailable)
636 {
637 int curPos = 0;
638 int curMajor = _wtoi(curVersion.Tokenize(L".", curPos));
639 int curMinor = _wtoi(curVersion.Tokenize(L".", curPos));
640 int curDev = _wtoi(curVersion.Tokenize(L".", curPos));
641
642 int newPos = 0;
643 int newMajor = _wtoi(newVersion.Tokenize(L".", newPos));
644 int newMinor = newPos > 0 ? _wtoi(newVersion.Tokenize(L".", newPos)) : 0;
645 int newDev = newPos > 0 ? _wtoi(newVersion.Tokenize(L".", newPos)) : 0;
646
647 isAvailable = newMajor > curMajor || newMajor == curMajor && newMinor > cu rMinor || newMajor == curMajor && newMinor == curMinor && newDev > curDev;
648 }
649 }
650
651 return isAvailable;
652 }
653
654 bool CPluginSettings::IsMainProcess(DWORD dwProcessId) const 577 bool CPluginSettings::IsMainProcess(DWORD dwProcessId) const
655 { 578 {
656 if (dwProcessId == 0) 579 if (dwProcessId == 0)
657 { 580 {
658 dwProcessId = ::GetCurrentProcessId(); 581 dwProcessId = ::GetCurrentProcessId();
659 } 582 }
660 return m_dwMainProcessId == dwProcessId; 583 return m_dwMainProcessId == dwProcessId;
661 } 584 }
662 585
663 void CPluginSettings::SetMainProcessId() 586 void CPluginSettings::SetMainProcessId()
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 return CString(L""); 1397 return CString(L"");
1475 } 1398 }
1476 1399
1477 1400
1478 void CPluginSettings::RefreshFilterlist() 1401 void CPluginSettings::RefreshFilterlist()
1479 { 1402 {
1480 CPluginClient::GetInstance()->UpdateAllSubscriptions(); 1403 CPluginClient::GetInstance()->UpdateAllSubscriptions();
1481 } 1404 }
1482 1405
1483 #endif // SUPPORT_WHITELIST 1406 #endif // SUPPORT_WHITELIST
OLDNEW

Powered by Google App Engine
This is Rietveld