| 469 | } |
| 470 | |
| 471 | void Analytics::Load() |
| 472 | { |
| 473 | // refuse to load if we were previously disabled, just in case this function is called somehow. We |
| 474 | // require a full restart with the analytics enabled for it to start collecting. |
| 475 | if(analyticsState == AnalyticsState::Disabled) |
| 476 | return; |
| 477 | |
| 478 | // allocate space for the Analytics singleton |
| 479 | Analytics::db = &actualDB; |
| 480 | |
| 481 | // find the filename where the analytics will be saved |
| 482 | analyticsSaveLocation = ConfigFilePath(lit("analytics.json")); |
| 483 | |
| 484 | QFile f(analyticsSaveLocation); |
| 485 | |
| 486 | // silently allow missing database |
| 487 | if(f.exists()) |
| 488 | { |
| 489 | if(f.open(QIODevice::ReadOnly | QIODevice::Text)) |
| 490 | { |
| 491 | QVariantMap values; |
| 492 | |
| 493 | bool success = LoadFromJSON(values, f, analyticsJSONMagic, analyticsJSONVersion); |
| 494 | |
| 495 | if(success) |
| 496 | AnalyticsSerialise(*Analytics::db, values, AnalyticsSerialiseType::Loading); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | // if year is 0, this was uninitialised meaning there was no previous analytics database. We set |
| 501 | // the current month, and mark a flag that we need to prompt the user about opting out of |
| 502 | // analytics. |
| 503 | int currentYear = QDateTime::currentDateTime().date().year(); |
| 504 | int currentMonth = QDateTime::currentDateTime().date().month(); |
| 505 | if(Analytics::db->Date.Year == 0) |
| 506 | { |
| 507 | Analytics::db->Date.Year = currentYear; |
| 508 | Analytics::db->Date.Month = currentMonth; |
| 509 | analyticsState = AnalyticsState::PromptFirstTime; |
| 510 | } |
| 511 | else if(Analytics::db->Date.Year != currentYear || Analytics::db->Date.Month != currentMonth) |
| 512 | { |
| 513 | // if the analytics is not from this month, submit the report. |
| 514 | analyticsState = AnalyticsState::SubmitReport; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | void Analytics::DocumentReport() |
| 519 | { |
no test coverage detected