private void checkBoxCustomEDSMDownload_CheckedChanged(object sender, EventArgs e) { EDDConfig.Instance.EDSMEDDBDownload = checkBoxCustomEDSMEDDBDownload.Checked; if (EDDConfig.Instance.EDSMEDDBDownload == true) // if turned on { int gridsel = 0; bool[] grids = new bool[GridId.MaxGridID]; foreach (int i in GridId.FromString(EDDConfig.Instance.EDSMGridIDs)) { gridsel++; } if (gridsel == 0) // but we have zero grids selected, force the user to select again { buttonExtEDSMConfigureArea_Click(sender, e); } } }
private void DoPerformSync() // in Background worker { InvokeAsyncOnUiThread.Invoke(() => OnSyncStarting?.Invoke()); // tell listeners sync is starting resyncEDSMRequestedFlag = 1; // sync is happening, stop any async requests.. // check for 102, if so, upgrade it.. SystemsDatabase.Instance.UpgradeSystemTableFrom102TypeDB(() => PendingClose, ReportSyncProgress, syncstate.perform_edsm_fullsync); if (EDDConfig.Instance.EDSMDownload) // if no system off, and EDSM download on { Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Perform System Data Download from EDSM"); try { bool[] grids = new bool[GridId.MaxGridID]; foreach (int i in GridId.FromString(EDDConfig.Instance.EDSMGridIDs)) { grids[i] = true; } syncstate.ClearCounters(); if (syncstate.perform_edsm_fullsync || syncstate.perform_edsm_alias_sync) { if (syncstate.perform_edsm_fullsync && !PendingClose) { // Download new systems try { string edsmsystems = Path.Combine(EDDOptions.Instance.AppDataDirectory, "edsmsystems.json.gz"); ReportSyncProgress("Performing full download of System Data from EDSM"); Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Full system download using URL " + EDDConfig.Instance.EDSMFullSystemsURL); bool success = BaseUtils.DownloadFile.HTTPDownloadFile(EDDConfig.Instance.EDSMFullSystemsURL, edsmsystems, false, out bool newfile); syncstate.perform_edsm_fullsync = false; if (success) { syncstate.edsm_fullsync_count = SystemsDatabase.Instance.UpgradeSystemTableFromFile(edsmsystems, grids, () => PendingClose, ReportSyncProgress); if (syncstate.edsm_fullsync_count < 0) // this should always update something, the table is replaced. If its not, its been cancelled { return; } BaseUtils.FileHelpers.DeleteFileNoError(edsmsystems); // remove file - don't hold in storage } else { ReportSyncProgress(""); LogLineHighlight("Failed to download full EDSM systems file. Try re-running EDD later"); BaseUtils.FileHelpers.DeleteFileNoError(edsmsystems); // remove file - don't hold in storage return; // new! if we failed to download, fail here, wait for another time } } catch (Exception ex) { LogLineHighlight("GetAllEDSMSystems exception:" + ex.Message); } } if (!PendingClose && syncstate.perform_edsm_alias_sync) { try { EDSMClass edsm = new EDSMClass(); string edsmhiddensystems = Path.Combine(EDDOptions.Instance.AppDataDirectory, "edsmhiddensystems.json"); string jsonhidden = edsm.GetHiddenSystems(edsmhiddensystems); if (jsonhidden != null) { SystemsDB.ParseAliasString(jsonhidden); syncstate.perform_edsm_alias_sync = false; SystemsDatabase.Instance.SetLastEDSMAliasDownloadTime(); } } catch (Exception ex) { LogLineHighlight("GetEDSMAlias exception: " + ex.Message); } } } if (!PendingClose) // perform an update sync to get any new EDSM data { syncstate.edsm_updatesync_count = UpdateSync(grids, () => PendingClose, ReportSyncProgress); } } catch (OperationCanceledException) { // Swallow Operation Cancelled exceptions } catch (Exception ex) { LogLineHighlight("Check Systems exception: " + ex.Message + Environment.NewLine + "Trace: " + ex.StackTrace); } } InvokeAsyncOnUiThread(() => PerformSyncCompletedonUI()); }
private void DoPerformSync() // in Background worker { InvokeAsyncOnUiThread.Invoke(() => OnSyncStarting?.Invoke()); // tell listeners sync is starting resyncEDSMEDDBRequestedFlag = 1; // sync is happening, stop any async requests.. Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Perform EDSM/EDDB sync"); try { bool[] grids = new bool[GridId.MaxGridID]; foreach (int i in GridId.FromString(EDDConfig.Instance.EDSMGridIDs)) { grids[i] = true; } syncstate.ClearCounters(); if (syncstate.perform_edsm_fullsync || syncstate.perform_eddb_sync) { if (syncstate.perform_edsm_fullsync && !PendingClose) { // Download new systems try { syncstate.edsm_fullsync_count = SystemClassEDSM.PerformEDSMFullSync(grids, () => PendingClose, ReportSyncProgress, LogLine, LogLineHighlight); syncstate.perform_edsm_fullsync = false; } catch (Exception ex) { LogLineHighlight("GetAllEDSMSystems exception:" + ex.Message); } } if (!PendingClose) { SQLiteConnectionSystem.CreateSystemsTableIndexes(); // again check indexes.. sometimes SQL does not create them due to schema change try { syncstate.eddb_sync_count = EliteDangerousCore.EDDB.SystemClassEDDB.PerformEDDBFullSync(() => PendingClose, ReportSyncProgress, LogLine, LogLineHighlight); syncstate.perform_eddb_sync = false; } catch (Exception ex) { LogLineHighlight("GetEDDBUpdate exception: " + ex.Message); } } } if (!PendingClose) { SQLiteConnectionSystem.CreateSystemsTableIndexes(); // again check indexes.. sometimes SQL does not create them due to schema change syncstate.edsm_updatesync_count = EliteDangerousCore.EDSM.SystemClassEDSM.PerformEDSMUpdateSync(grids, () => PendingClose, ReportSyncProgress, LogLine, LogLineHighlight); } } catch (OperationCanceledException) { // Swallow Operation Cancelled exceptions } catch (Exception ex) { LogLineHighlight("Check Systems exception: " + ex.Message + Environment.NewLine + "Trace: " + ex.StackTrace); } InvokeAsyncOnUiThread(() => PerformSyncCompleted()); }
private void DoPerformSync() // in Background worker { InvokeAsyncOnUiThread.Invoke(() => OnSyncStarting?.Invoke()); // tell listeners sync is starting resyncEDSMEDDBRequestedFlag = 1; // sync is happening, stop any async requests.. Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Perform EDSM/EDDB sync"); try { bool[] grids = new bool[GridId.MaxGridID]; foreach (int i in GridId.FromString(EDDConfig.Instance.EDSMGridIDs)) { grids[i] = true; } syncstate.ClearCounters(); if (syncstate.perform_edsm_fullsync || syncstate.perform_eddb_edsmalias_sync) { if (syncstate.perform_edsm_fullsync && !PendingClose) { // Download new systems try { string edsmsystems = Path.Combine(EliteConfigInstance.InstanceOptions.AppDataDirectory, "edsmsystems.json"); ReportSyncProgress("Performing full download of EDSM Database from server"); bool success = BaseUtils.DownloadFile.HTTPDownloadFile(EliteConfigInstance.InstanceConfig.EDSMFullSystemsURL, edsmsystems, false, out bool newfile); syncstate.perform_edsm_fullsync = false; if (success) { syncstate.edsm_fullsync_count = SQLiteConnectionSystem.UpgradeSystemTableFromFile(edsmsystems, grids, () => PendingClose, ReportSyncProgress); if (syncstate.edsm_fullsync_count < 0) // this should always update something, the table is replaced. If its not, its been cancelled { return; } BaseUtils.FileHelpers.DeleteFileNoError(edsmsystems); // remove file - don't hold in storage } } catch (Exception ex) { LogLineHighlight("GetAllEDSMSystems exception:" + ex.Message); } } if (!PendingClose) { try { EDSMClass edsm = new EDSMClass(); string jsonhidden = edsm.GetHiddenSystems(); if (jsonhidden != null) { SystemsDB.ParseAliasString(jsonhidden); string eddbsystems = Path.Combine(EliteConfigInstance.InstanceOptions.AppDataDirectory, "eddbsystems.json"); bool success = BaseUtils.DownloadFile.HTTPDownloadFile(EliteConfigInstance.InstanceConfig.EDDBSystemsURL, eddbsystems, false, out bool newfile); syncstate.perform_eddb_edsmalias_sync = false; if (success) { syncstate.eddb_sync_count = SystemsDB.ParseEDDBJSONFile(eddbsystems, () => PendingClose); if (syncstate.eddb_sync_count < 0) // on a cancel or error { return; } SQLiteConnectionSystem.SetLastEDDBDownloadTime(); BaseUtils.FileHelpers.DeleteFileNoError(eddbsystems); // remove file - don't hold in storage } } } catch (Exception ex) { LogLineHighlight("GetEDDBUpdate exception: " + ex.Message); } } } if (!PendingClose) { syncstate.edsm_updatesync_count = UpdateSync(grids, () => PendingClose, ReportSyncProgress); } } catch (OperationCanceledException) { // Swallow Operation Cancelled exceptions } catch (Exception ex) { LogLineHighlight("Check Systems exception: " + ex.Message + Environment.NewLine + "Trace: " + ex.StackTrace); } InvokeAsyncOnUiThread(() => PerformSyncCompletedonUI()); }