| OLD | NEW |
| 1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
| 2 | 2 |
| 3 #include <ctime> | 3 #include <ctime> |
| 4 | 4 |
| 5 #include "PluginClass.h" | 5 #include "PluginClass.h" |
| 6 #include "PluginDictionary.h" | 6 #include "PluginDictionary.h" |
| 7 #include "PluginSettings.h" | 7 #include "PluginSettings.h" |
| 8 #include "PluginSystem.h" | 8 #include "PluginSystem.h" |
| 9 #include "PluginConfiguration.h" | 9 #include "PluginConfiguration.h" |
| 10 #ifdef SUPPORT_FILTER | 10 #ifdef SUPPORT_FILTER |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 CString debugText; | 43 CString debugText; |
| 44 | 44 |
| 45 CString threadInfo; | 45 CString threadInfo; |
| 46 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId())
; | 46 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId())
; |
| 47 | 47 |
| 48 debugText += L"=============================================================
==================="; | 48 debugText += L"=============================================================
==================="; |
| 49 debugText += L"\nMAIN THREAD " + threadInfo + L" Plugin version:" + CString(
IEPLUGIN_VERSION); | 49 debugText += L"\nMAIN THREAD " + threadInfo + L" Plugin version:" + CString(
IEPLUGIN_VERSION); |
| 50 debugText += L"\n===========================================================
====================="; | 50 debugText += L"\n===========================================================
====================="; |
| 51 | 51 |
| 52 debugText += L"\nPlugin version: " + CString(IEPLUGIN_VERSION); | 52 debugText += L"\nPlugin version: " + CString(IEPLUGIN_VERSION); |
| 53 debugText += L"\nPlugin id: " + system->GetPluginId(); | |
| 54 debugText += L"\nMAC address: " + system->GetMacId(true); | |
| 55 debugText += L"\nComputer name: " + system->GetComputerName(); | |
| 56 debugText += L"\nUser id: " + settings->GetString(SETTING_USER_ID,
"N/A"); | |
| 57 debugText += L"\nUser name: " + system->GetUserName(); | |
| 58 debugText += L"\nBrowser version: " + system->GetBrowserVersion(); | 53 debugText += L"\nBrowser version: " + system->GetBrowserVersion(); |
| 59 debugText += L"\nBrowser language: " + system->GetBrowserLanguage(); | 54 debugText += L"\nBrowser language: " + system->GetBrowserLanguage(); |
| 60 | 55 |
| 61 DWORD osVersion = ::GetVersion(); | 56 DWORD osVersion = ::GetVersion(); |
| 62 | 57 |
| 63 CString ver; | 58 CString ver; |
| 64 ver.Format(L"%d.%d", LOBYTE(LOWORD(osVersion)), HIBYTE(LOWORD(osVersion))); | 59 ver.Format(L"%d.%d", LOBYTE(LOWORD(osVersion)), HIBYTE(LOWORD(osVersion))); |
| 65 | 60 |
| 66 debugText += L"\nWindows version: " + ver; | 61 debugText += L"\nWindows version: " + ver; |
| 67 | 62 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 settings->Remove(SETTING_PLUGIN_INFO_PANEL); | 137 settings->Remove(SETTING_PLUGIN_INFO_PANEL); |
| 143 settings->Write(); | 138 settings->Write(); |
| 144 } | 139 } |
| 145 } | 140 } |
| 146 } | 141 } |
| 147 | 142 |
| 148 // -------------------------------------------------------------------- | 143 // -------------------------------------------------------------------- |
| 149 // Should update plugin ? | 144 // Should update plugin ? |
| 150 // -------------------------------------------------------------------- | 145 // -------------------------------------------------------------------- |
| 151 | 146 |
| 152 #ifndef ENTERPRISE | |
| 153 if (!IsMainThreadDone(hMainThread) && settings->IsPluginUpdateAvailable()) | 147 if (!IsMainThreadDone(hMainThread) && settings->IsPluginUpdateAvailable()) |
| 154 { | 148 { |
| 155 DEBUG_THREAD(L"Thread::Should update plugin"); | 149 DEBUG_THREAD(L"Thread::Should update plugin"); |
| 156 | 150 |
| 157 CString lastUpdateStr = settings->GetString(SETTING_PLUGIN_UPDATE_TI
ME); | 151 CString lastUpdateStr = settings->GetString(SETTING_PLUGIN_UPDATE_TI
ME); |
| 158 | 152 |
| 159 std::time_t today = std::time(NULL); | 153 std::time_t today = std::time(NULL); |
| 160 std::time_t lastUpdate = lastUpdateStr.IsEmpty() ? today : _wtoi(las
tUpdateStr.GetBuffer()); | 154 std::time_t lastUpdate = lastUpdateStr.IsEmpty() ? today : _wtoi(las
tUpdateStr.GetBuffer()); |
| 161 | 155 |
| 162 if (today != (std::time_t)(-1) && lastUpdate != (std::time_t)(-1)) | 156 if (today != (std::time_t)(-1) && lastUpdate != (std::time_t)(-1)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 176 { | 170 { |
| 177 s_isPluginToBeUpdated = true; | 171 s_isPluginToBeUpdated = true; |
| 178 } | 172 } |
| 179 | 173 |
| 180 settings->SetValue(SETTING_PLUGIN_UPDATE_TIME, (int)
today); | 174 settings->SetValue(SETTING_PLUGIN_UPDATE_TIME, (int)
today); |
| 181 settings->Write(); | 175 settings->Write(); |
| 182 } | 176 } |
| 183 } | 177 } |
| 184 } | 178 } |
| 185 | 179 |
| 186 #endif | |
| 187 // -------------------------------------------------------------------- | 180 // -------------------------------------------------------------------- |
| 188 // Main loop | 181 // Main loop |
| 189 // -------------------------------------------------------------------- | 182 // -------------------------------------------------------------------- |
| 190 | 183 |
| 191 DWORD mainLoopIteration = 1; | 184 DWORD mainLoopIteration = 1; |
| 192 » | 185 » » » » » |
| 193 » bool hasUser = false; | |
| 194 » int regAttempts = 1; | |
| 195 » int regAttemptsThread = 1; | |
| 196 » » » » | |
| 197 while (!IsMainThreadDone(hMainThread)) | 186 while (!IsMainThreadDone(hMainThread)) |
| 198 { | 187 { |
| 199 CString sMainLoopIteration; | 188 CString sMainLoopIteration; |
| 200 sMainLoopIteration.Format(L"%u", mainLoopIteration); | 189 sMainLoopIteration.Format(L"%u", mainLoopIteration); |
| 201 | 190 |
| 202 CString debugText; | 191 CString debugText; |
| 203 | 192 |
| 204 debugText += L"---------------------------------------------------------
-----------------------"; | 193 debugText += L"---------------------------------------------------------
-----------------------"; |
| 205 debugText += L"\nLoop iteration " + sMainLoopIteration; | 194 debugText += L"\nLoop iteration " + sMainLoopIteration; |
| 206 debugText += L"\n-------------------------------------------------------
-------------------------"; | 195 debugText += L"\n-------------------------------------------------------
-------------------------"; |
| 207 | 196 |
| 208 DEBUG_GENERAL(debugText) | 197 DEBUG_GENERAL(debugText) |
| 209 | 198 |
| 210 if (settings->Has(SETTING_REG_SUCCEEDED)) | |
| 211 { | |
| 212 regAttempts = REGISTRATION_MAX_ATTEMPTS; | |
| 213 } | |
| 214 else | |
| 215 { | |
| 216 regAttempts = settings->GetValue(SETTING_REG_ATTEMPTS); | |
| 217 } | |
| 218 regAttempts = max(regAttempts, regAttemptsThread) + 1; | |
| 219 | |
| 220 // -----------------------------------------------------------------
--- | |
| 221 // Register user | |
| 222 // -----------------------------------------------------------------
--- | |
| 223 | |
| 224 if (!IsMainThreadDone(hMainThread)) | |
| 225 { | |
| 226 DEBUG_THREAD("Thread::Register user"); | |
| 227 | |
| 228 hasUser = settings->Has(SETTING_USER_ID); | |
| 229 | |
| 230 if (!hasUser && regAttempts <= REGISTRATION_MAX_ATTEMPTS) | |
| 231 { | |
| 232 DWORD nUserTimerBase = GetTickCount() / TIMER_INTERVAL_U
SER_REGISTRATION; | |
| 233 | |
| 234 if (nUserTimerBase >= nNextUserTimerBase || main
LoopIteration == 1 && !settings->IsFirstRun()) | |
| 235 { | |
| 236 DEBUG_THREAD("Thread::Register user (action)"); | |
| 237 | |
| 238 try | |
| 239 { | |
| 240 isConfigutationLoaded = configuration->Downl
oad(); | |
| 241 } | |
| 242 catch (...) | |
| 243 { | |
| 244 } | |
| 245 | |
| 246 nNextUserTimerBase = nUserTimerBase + nUserTimer
BaseStep; | |
| 247 nUserTimerBaseStep *= 2; | |
| 248 | |
| 249 regAttemptsThread++; | |
| 250 } | |
| 251 } | |
| 252 } | |
| 253 | |
| 254 // -----------------------------------------------------------------
--- | 199 // -----------------------------------------------------------------
--- |
| 255 // Load configuration | 200 // Load configuration |
| 256 // -----------------------------------------------------------------
--- | 201 // -----------------------------------------------------------------
--- |
| 257 | 202 |
| 258 if (!IsMainThreadDone(hMainThread)) | 203 if (!IsMainThreadDone(hMainThread)) |
| 259 { | 204 { |
| 260 DEBUG_THREAD("Thread::Load configuration"); | 205 DEBUG_THREAD("Thread::Load configuration"); |
| 261 | 206 |
| 262 » if (hasUser && !isConfigutationLoaded && regAttempts <= REGISTRA
TION_MAX_ATTEMPTS) | 207 » if (!isConfigutationLoaded) |
| 263 { | 208 { |
| 264 // Initialize serverClient module | 209 // Initialize serverClient module |
| 265 // we try an initialization in each loop | 210 // we try an initialization in each loop |
| 266 DWORD nServerClientTimerBase = GetTickCount() / TIMER_IN
TERVAL_SERVER_CLIENT_INIT; | 211 DWORD nServerClientTimerBase = GetTickCount() / TIMER_IN
TERVAL_SERVER_CLIENT_INIT; |
| 267 | 212 |
| 268 if (nServerClientTimerBase >= nNextServerClientTimerBase
|| mainLoopIteration == 1) | 213 if (nServerClientTimerBase >= nNextServerClientTimerBase
|| mainLoopIteration == 1) |
| 269 { | 214 { |
| 270 DEBUG_THREAD("Thread::Load configuration (action)"); | 215 DEBUG_THREAD("Thread::Load configuration (action)"); |
| 271 | 216 |
| 272 try | 217 try |
| 273 { | 218 { |
| 274 isConfigutationLoaded = configuration->Downl
oad(); | 219 isConfigutationLoaded = configuration->Downl
oad(); |
| 275 } | 220 } |
| 276 catch (...) | 221 catch (...) |
| 277 { | 222 { |
| 278 } | 223 } |
| 279 | 224 |
| 280 nNextServerClientTimerBase = nServerClientTimerB
ase + nServerClientTimerBaseStep; | 225 nNextServerClientTimerBase = nServerClientTimerB
ase + nServerClientTimerBaseStep; |
| 281 nServerClientTimerBaseStep *= 2; | 226 nServerClientTimerBaseStep *= 2; |
| 282 | |
| 283 regAttemptsThread++; | |
| 284 } | 227 } |
| 285 } | 228 } |
| 286 } | 229 } |
| 287 | 230 |
| 288 // -----------------------------------------------------------------
--- | 231 // -----------------------------------------------------------------
--- |
| 289 // Update settings | 232 // Update settings |
| 290 // -----------------------------------------------------------------
--- | 233 // -----------------------------------------------------------------
--- |
| 291 | 234 |
| 292 if (!IsMainThreadDone(hMainThread)) | 235 if (!IsMainThreadDone(hMainThread)) |
| 293 { | 236 { |
| 294 DEBUG_THREAD("Thread::Update settings"); | 237 DEBUG_THREAD("Thread::Update settings"); |
| 295 | 238 |
| 296 if (configuration->IsValid()) | 239 if (configuration->IsValid()) |
| 297 { | 240 { |
| 298 bool isNewDictionaryVersion = false; | 241 bool isNewDictionaryVersion = false; |
| 299 #ifdef SUPPORT_FILTER | 242 #ifdef SUPPORT_FILTER |
| 300 bool isNewFilterVersion = false; | 243 bool isNewFilterVersion = false; |
| 301 #endif | 244 #endif |
| 302 #ifdef SUPPORT_CONFIG | 245 #ifdef SUPPORT_CONFIG |
| 303 bool isNewConfig = false; | 246 bool isNewConfig = false; |
| 304 #endif | 247 #endif |
| 305 | 248 |
| 306 DEBUG_THREAD("Thread::Update settings (action)"); | 249 DEBUG_THREAD("Thread::Update settings (action)"); |
| 307 | 250 |
| 308 settings->ForceConfigurationUpdateOnStart(false); | 251 settings->ForceConfigurationUpdateOnStart(false); |
| 309 | 252 |
| 310 if (configuration->IsValidPluginExpired()) | |
| 311 { | |
| 312 settings->SetBool(SETTING_PLUGIN_EXPIRED, configuration->IsP
luginExpired()); | |
| 313 } | |
| 314 | |
| 315 if (configuration->IsValidUserId()) | |
| 316 { | |
| 317 settings->SetString(SETTING_USER_ID, configu
ration->GetUserId()); | |
| 318 } | |
| 319 | |
| 320 if (configuration->IsValidPluginUpdate() && configur
ation->GetPluginUpdateVersion() != IEPLUGIN_VERSION) | 253 if (configuration->IsValidPluginUpdate() && configur
ation->GetPluginUpdateVersion() != IEPLUGIN_VERSION) |
| 321 { | 254 { |
| 322 settings->SetString(SETTING_PLUGIN_UPDATE_URL, configuration
->GetPluginUpdateUrl()); | 255 settings->SetString(SETTING_PLUGIN_UPDATE_URL, configuration
->GetPluginUpdateUrl()); |
| 323 settings->SetString(SETTING_PLUGIN_UPDATE_VERSION, configura
tion->GetPluginUpdateVersion()); | 256 settings->SetString(SETTING_PLUGIN_UPDATE_VERSION, configura
tion->GetPluginUpdateVersion()); |
| 324 } | 257 } |
| 325 else | 258 else |
| 326 { | 259 { |
| 327 settings->Remove(SETTING_PLUGIN_UPDATE_VERSION); | 260 settings->Remove(SETTING_PLUGIN_UPDATE_VERSION); |
| 328 settings->Remove(SETTING_PLUGIN_UPDATE_URL); | 261 settings->Remove(SETTING_PLUGIN_UPDATE_URL); |
| 329 } | 262 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 #endif // SUPPORT_FILTER | 301 #endif // SUPPORT_FILTER |
| 369 | 302 |
| 370 #ifdef SUPPORT_WHITELIST | 303 #ifdef SUPPORT_WHITELIST |
| 371 // Update white list | 304 // Update white list |
| 372 if (configuration->IsValidWhiteList()) | 305 if (configuration->IsValidWhiteList()) |
| 373 { | 306 { |
| 374 settings->ReplaceWhiteListedDomains(configuration->GetWhiteL
ist()); | 307 settings->ReplaceWhiteListedDomains(configuration->GetWhiteL
ist()); |
| 375 } | 308 } |
| 376 #endif // SUPPORT_WHITELIST | 309 #endif // SUPPORT_WHITELIST |
| 377 | 310 |
| 378 // Check pluginID | |
| 379 CString newPluginId = system->GetPluginId(); | |
| 380 | |
| 381 if (newPluginId != settings->GetString(SETTING_PLUGIN_ID)) | |
| 382 { | |
| 383 DEBUG_GENERAL(L"*** pluginId has changed from " + settings->
GetString(SETTING_PLUGIN_ID) + CString(L" to ") + newPluginId) | |
| 384 | |
| 385 settings->SetString(SETTING_PLUGIN_ID, newPluginId);
| |
| 386 } | |
| 387 | |
| 388 settings->SetString(SETTING_REG_SUCCEEDED, "true"); | |
| 389 | |
| 390 settings->SetBool(SETTING_PLUGIN_REGISTRATION, c
onfiguration->IsPluginRegistered()); | |
| 391 #ifdef PRODUCT_SIMPLEADBLOCK | |
| 392 settings->SetValue(SETTING_PLUGIN_ADBLOCKLIMIT,
configuration->GetAdBlockLimit()); | |
| 393 #endif | |
| 394 settings->Write(); | 311 settings->Write(); |
| 395 | 312 |
| 396 configuration->Invalidate(); | 313 configuration->Invalidate(); |
| 397 | 314 |
| 398 // Update dictionary | 315 // Update dictionary |
| 399 if (isNewDictionaryVersion) | 316 if (isNewDictionaryVersion) |
| 400 { | 317 { |
| 401 CPluginDictionary* dictionary = CPluginD
ictionary::GetInstance(); | 318 CPluginDictionary* dictionary = CPluginD
ictionary::GetInstance(); |
| 402 | 319 |
| 403 if (dictionary->Download(configuration->GetDictionaryUrl(),
CPluginSettings::GetDataPath(DICTIONARY_INI_FILE))) | 320 if (dictionary->Download(configuration->GetDictionaryUrl(),
CPluginSettings::GetDataPath(DICTIONARY_INI_FILE))) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 settings->SetFilterFileNamesList(fileNam
esList); | 378 settings->SetFilterFileNamesList(fileNam
esList); |
| 462 settings->SetValue(SETTING_FILTER_VERSION, configuration->Ge
tFilterVersion()); | 379 settings->SetValue(SETTING_FILTER_VERSION, configuration->Ge
tFilterVersion()); |
| 463 settings->Write(); | 380 settings->Write(); |
| 464 | 381 |
| 465 settings->IncrementTabVersion(SETTING_TAB_FILTER_VERSION); | 382 settings->IncrementTabVersion(SETTING_TAB_FILTER_VERSION); |
| 466 | 383 |
| 467 tab->OnUpdate(); | 384 tab->OnUpdate(); |
| 468 } | 385 } |
| 469 #endif // SUPPORT_FILTER | 386 #endif // SUPPORT_FILTER |
| 470 } | 387 } |
| 471 // Plugin not loaded | |
| 472 else if (regAttempts <= REGISTRATION_MAX_ATTEMPTS) | |
| 473 { | |
| 474 settings->SetValue(SETTING_REG_ATTEMPTS, regAttempts); | |
| 475 settings->Write(); | |
| 476 } | |
| 477 } | 388 } |
| 478 | 389 |
| 479 // -----------------------------------------------------------------
--- | 390 // -----------------------------------------------------------------
--- |
| 480 // Check filters | 391 // Check filters |
| 481 // -----------------------------------------------------------------
--- | 392 // -----------------------------------------------------------------
--- |
| 482 #ifdef SUPPORT_FILTER | 393 #ifdef SUPPORT_FILTER |
| 483 | 394 |
| 484 DEBUG_THREAD(L"Thread::Check filters"); | 395 DEBUG_THREAD(L"Thread::Check filters"); |
| 485 | 396 |
| 486 if (!IsMainThreadDone(hMainThread)) | 397 if (!IsMainThreadDone(hMainThread)) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 if (!IsMainThreadDone(hMainThread)) | 447 if (!IsMainThreadDone(hMainThread)) |
| 537 { | 448 { |
| 538 bool isDone = false; | 449 bool isDone = false; |
| 539 DWORD sleepLoopIteration = 1; | 450 DWORD sleepLoopIteration = 1; |
| 540 | 451 |
| 541 // Sleep loop | 452 // Sleep loop |
| 542 while (!isDone && !IsMainThreadDone(hMainThread) && !s_isPlu
ginToBeUpdated) | 453 while (!isDone && !IsMainThreadDone(hMainThread) && !s_isPlu
ginToBeUpdated) |
| 543 { | 454 { |
| 544 // Non-hanging sleep | 455 // Non-hanging sleep |
| 545 Sleep(50); | 456 Sleep(50); |
| 546 | 457 » » » » |
| 547 » » » if (hasUser || regAttempts >= REGISTRATION_MAX_ATTEM
PTS) | 458 » » » » if (sleepLoopIteration++ % (TIMER_THREAD_SLEEP_U
SER_REGISTRATION / 50) == 0) |
| 548 » » » { | |
| 549 » » » » if (sleepLoopIteration++ % (TIMER_THREAD_SLE
EP_MAIN_LOOP / 50) == 0) | |
| 550 » » » » { | |
| 551 » » » » » isDone = true; | |
| 552 » » » » } | |
| 553 » » » } | |
| 554 » » » else if (sleepLoopIteration++ % (TIMER_THREAD_SLEEP_
USER_REGISTRATION / 50) == 0) | |
| 555 { | 459 { |
| 556 isDone = true; | 460 isDone = true; |
| 557 } | 461 } |
| 558 } | 462 } |
| 559 } | 463 } |
| 560 | 464 |
| 561 mainLoopIteration++; | 465 mainLoopIteration++; |
| 562 } | 466 } |
| 563 | 467 |
| 564 return 0; | 468 return 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 584 bool isDone = false; | 488 bool isDone = false; |
| 585 | 489 |
| 586 s_criticalSectionLocal.Lock(); | 490 s_criticalSectionLocal.Lock(); |
| 587 { | 491 { |
| 588 isDone = s_isMainThreadDone || mainThread != s_hMainThread; | 492 isDone = s_isMainThreadDone || mainThread != s_hMainThread; |
| 589 } | 493 } |
| 590 s_criticalSectionLocal.Unlock(); | 494 s_criticalSectionLocal.Unlock(); |
| 591 | 495 |
| 592 return isDone; | 496 return isDone; |
| 593 } | 497 } |
| OLD | NEW |