private void GetEDSCDistances() { try { SQLiteDBClass db = new SQLiteDBClass(); //EDSCClass edsc = new EDSCClass(); EDSMClass edsm = new EDSMClass(); string lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); string json; // Get distances string rwdisttime = db.GetSettingString("RWLastDist", "2000-01-01 00:00:00"); // Latest time from RW file. string rwdistfiletime = ""; lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); List <DistanceClass> dists = new List <DistanceClass>(); json = LoadJsonArray(fileTgcDistances); dists = DistanceClass.ParseEDSC(json, ref rwdistfiletime); if (!rwdisttime.Equals(rwdistfiletime)) // New distance file from Redwizzard { DistanceClass.Delete(DistancsEnum.EDSC); // Remove all EDSC distances. lstdist = "2010-01-01 00:00:00"; db.PutSettingString("RWLastDist", rwdistfiletime); } if (lstdist.Equals("2010-01-01 00:00:00")) { LogText("Adding data from tgcdistances.json " + Environment.NewLine); lstdist = rwdistfiletime; if (json == null) { LogText("Couldn't read file." + Environment.NewLine); } else { LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine); DistanceClass.Store(dists); db.PutSettingString("EDSCLastDist", lstdist); } } LogText("Checking for new distances from EDSM. "); Application.DoEvents(); json = edsm.RequestDistances(lstdist); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(json, ref lstdist); if (json == null) { LogText("No response from server." + Environment.NewLine); } else { LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine); } Application.DoEvents(); DistanceClass.Store(dists); db.PutSettingString("EDSCLastDist", lstdist); db.GetAllDistances(); OnDistancesLoaded(); // Check for a new installer CheckForNewInstaller(); } catch (Exception ex) { LogText("GetEDSCDistances exception:" + ex.Message + Environment.NewLine); } }
private void GetEDSMDistances() { try { if (EDDConfig.UseDistances) { EDSMClass edsm = new EDSMClass(); EDDBClass eddb = new EDDBClass(); string lstdist = _db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); string json; // Get distances lstdist = _db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00"); List <DistanceClass> dists = new List <DistanceClass>(); if (lstdist.Equals("2010-01-01 00:00:00")) { LogText("Downloading mirrored EDSM distance data. (Might take some time)" + Environment.NewLine); eddb.GetEDSMDistances(); json = LoadJsonFile(_fileEDSMDistances); if (json != null) { LogText("Adding mirrored EDSM distance data." + Environment.NewLine); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(json, ref lstdist); LogText("Found " + dists.Count.ToString() + " distances." + Environment.NewLine); Application.DoEvents(); DistanceClass.Store(dists); _db.PutSettingString("EDSCLastDist", lstdist); } } LogText("Checking for new distances from EDSM. "); Application.DoEvents(); json = edsm.RequestDistances(lstdist); dists = new List <DistanceClass>(); dists = DistanceClass.ParseEDSM(json, ref lstdist); if (json == null) { LogText("No response from server." + Environment.NewLine); } else { LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine); } Application.DoEvents(); DistanceClass.Store(dists); _db.PutSettingString("EDSCLastDist", lstdist); } _db.GetAllDistances(EDDConfig.UseDistances); // Load user added distances updateMapData(); OnDistancesLoaded(); GC.Collect(); } catch (Exception ex) { LogText("GetEDSMDistances exception:" + ex.Message + Environment.NewLine); LogText(ex.StackTrace + Environment.NewLine); } }