public static void PerformSync(Func <bool> cancelRequested, Action <int, string> reportProgress, Action <string> logLine, Action <string> logError, SystemsSyncState state) // big check.. done in a thread. { reportProgress(-1, ""); state.performhistoryrefresh = false; state.syncwasfirstrun = SystemClassDB.IsSystemsTableEmpty(); // remember if DB is empty // Force a full sync if newest data is more than 14 days old bool outoforder = SQLiteConnectionSystem.GetSettingBool("EDSMSystemsOutOfOrder", true); DateTime lastmod = outoforder ? SystemClassDB.GetLastSystemModifiedTime() : SystemClassDB.GetLastSystemModifiedTimeFast(); if (DateTime.UtcNow.Subtract(lastmod).TotalDays >= 14) { state.performedsmsync = true; } bool edsmoreddbsync = state.performedsmsync || state.performeddbsync; // remember if we are syncing state.syncwaseddboredsm = edsmoreddbsync; if (state.performedsmsync || state.performeddbsync) { if (state.performedsmsync && !cancelRequested()) { // Download new systems try { state.performhistoryrefresh |= PerformEDSMFullSync(cancelRequested, reportProgress, logLine, logError); state.performedsmsync = false; } catch (Exception ex) { logError("GetAllEDSMSystems exception:" + ex.Message); } } if (!cancelRequested()) { logLine("Indexing systems table"); SQLiteConnectionSystem.CreateSystemsTableIndexes(); try { EliteDangerousCore.EDDB.SystemClassEDDB.PerformEDDBFullSync(cancelRequested, reportProgress, logLine, logError); state.performeddbsync = false; } catch (Exception ex) { logError("GetEDDBUpdate exception: " + ex.Message); } state.performhistoryrefresh = true; } } if (!cancelRequested()) { logLine("Indexing systems table"); SQLiteConnectionSystem.CreateSystemsTableIndexes(); lastmod = outoforder ? SystemClassDB.GetLastSystemModifiedTime() : SystemClassDB.GetLastSystemModifiedTimeFast(); if (DateTime.UtcNow.Subtract(lastmod).TotalHours >= 1) { logLine("Checking for new EDSM systems (may take a few moments)."); EDSMClass edsm = new EDSMClass(); long updates = edsm.GetNewSystems(cancelRequested, reportProgress, logLine); logLine($"EDSM updated {updates:N0} systems."); state.performhistoryrefresh |= (updates > 0); } } reportProgress(-1, ""); }