Beispiel #1
0
        /*
         * private void GetRedWizzardFiles()
         * {
         *  WebClient web = new WebClient();
         *
         *  try
         *  {
         *      LogText("Checking for new EDDiscovery data" + Environment.NewLine);
         *
         *      //GetNewRedWizzardFile(_fileTgcSystems, "http://robert.astronet.se/Elite/ed-systems/tgcsystems.json");
         *      //GetNewRedWizzardFile(fileTgcDistances, "http://robert.astronet.se/Elite/ed-systems/tgcdistances.json");
         *  }
         *  catch (Exception ex)
         *  {
         *      LogText("GetRedWizzardFiles exception:" + ex.Message + Environment.NewLine);
         *      return;
         *  }
         * }
         *
         * private void GetNewRedWizzardFile(string filename, string url)
         * {
         *  string etagFilename = filename + ".etag";
         *
         *  var request = (HttpWebRequest) HttpWebRequest.Create(url);
         *  request.UserAgent = "EDDiscovery v" + Assembly.GetExecutingAssembly().FullName.Split(',')[1].Split('=')[1];
         *  request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
         *
         *  if (File.Exists(etagFilename))
         *  {
         *      var etag = File.ReadAllText(etagFilename);
         *      if (etag != "")
         *      {
         *         request.Headers[HttpRequestHeader.IfNoneMatch] = etag;
         *      }
         *  }
         *
         *  try {
         *      var response = (HttpWebResponse) request.GetResponse();
         *
         *      LogText("Downloading " + filename + "..." + Environment.NewLine);
         *
         *      File.WriteAllText(filename + ".etag.tmp", response.Headers[HttpResponseHeader.ETag]);
         *      var destFileStream = File.Open(filename + ".tmp", FileMode.Create, FileAccess.Write);
         *      response.GetResponseStream().CopyTo(destFileStream);
         *
         *      destFileStream.Close();
         *      response.Close();
         *
         *      if (File.Exists(filename))
         *          File.Delete(filename);
         *      if (File.Exists(etagFilename))
         *          File.Delete(etagFilename);
         *
         *      File.Move(filename + ".tmp", filename);
         *      File.Move(etagFilename + ".tmp", etagFilename);
         *  } catch (WebException e)
         *  {
         *      var code = ((HttpWebResponse) e.Response).StatusCode;
         *      if (code == HttpStatusCode.NotModified)
         *      {
         *          LogText(filename + " is up to date." + Environment.NewLine);
         *      } else
         *      {
         *          throw e;
         *      }
         *  }
         * }
         */

        private void GetEDSMSystems()
        {
            try
            {
                EDSMClass edsm      = new EDSMClass();
                string    rwsystime = _db.GetSettingString("EDSMLastSystems", "2000-01-01 00:00:00"); // Latest time from RW file.

                CommanderName = EDDConfig.CurrentCommander.Name;
                //Invoke((MethodInvoker) delegate {
                //    travelHistoryControl1.textBoxCmdrName.Text = CommanderName;
                //});


                //                List<SystemClass> systems = SystemClass.ParseEDSC(json, ref rwsysfiletime);
                DateTime edsmdate = DateTime.Parse(rwsystime, new CultureInfo("sv-SE"));

                if (DateTime.Now.Subtract(edsmdate).TotalDays > 7)  // Over 7 days do a sync from EDSM
                {
                    SyncAllEDSMSystems();
                }
                else
                {
                    if (CanSkipSlowUpdates())
                    {
                        LogLine("Skipping loading updates (DEBUG option).");
                        LogLine("  Need to turn this back on again? Look in the Settings tab.");
                    }
                    else
                    {
                        string retstr = edsm.GetNewSystems(_db);
                        Invoke((MethodInvoker) delegate
                        {
                            TravelHistoryControl.LogText(retstr);
                        });
                    }
                }

                _db.GetAllSystemNotes();
                _db.GetAllSystems();



                SystemNames.Clear();
                foreach (SystemClass system in SystemData.SystemList)
                {
                    SystemNames.Add(system.name);
                }
            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate {
                    TravelHistoryControl.LogText("GetEDSMSystems exception:" + ex.Message + Environment.NewLine);
                    TravelHistoryControl.LogText(ex.StackTrace + Environment.NewLine);
                });
            }

            GC.Collect();
        }
Beispiel #2
0
 private void CheckIfEliteDangerousIsRunning()
 {
     if (EliteDangerous.EDRunning)
     {
         TravelHistoryControl.LogText("EliteDangerous is running." + Environment.NewLine);
     }
     else
     {
         TravelHistoryControl.LogText("EliteDangerous is not running ." + Environment.NewLine);
     }
 }
Beispiel #3
0
 private void LogText(string text, Color col)
 {
     try
     {
         Invoke((MethodInvoker) delegate
         {
             TravelHistoryControl.LogText(text, col);
         });
     }
     catch
     {
     }
 }
Beispiel #4
0
        private void CheckIfVerboseLoggingIsTurnedOn()
        {
            if (!EliteDangerous.CheckStationLogging())
            {
                TravelHistoryControl.LogTextHighlight("Elite Dangerous is not logging system names!!! ");
                TravelHistoryControl.LogText("Add ");
                TravelHistoryControl.LogText("VerboseLogging=\"1\" ");
                TravelHistoryControl.LogText("to <Network  section in File: " + Path.Combine(EliteDangerous.EDDirectory, "AppConfig.xml") + " or AppConfigLocal.xml  Remember to restart Elite!" + Environment.NewLine);

                labelPanelText.Text = "Elite Dangerous is not logging system names!";
                panelInfo.BackColor = Color.Salmon;
            }
        }
Beispiel #5
0
 public void LogLine(string text)
 {
     try
     {
         Invoke((MethodInvoker) delegate
         {
             TravelHistoryControl.LogText(text + Environment.NewLine);
         });
     }
     catch
     {
     }
 }
Beispiel #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                // Click once   System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVe‌​rsion
                var assemblyFullName = Assembly.GetExecutingAssembly().FullName;
                var version          = assemblyFullName.Split(',')[1].Split('=')[1];
                Text = string.Format("EDDiscovery v{0}", version);
                EliteDangerous.CheckED();
                SQLiteDBClass db = new SQLiteDBClass();

                labelPanelText.Text = "Loading. Please wait!";
                panelInfo.Visible   = true;
                panelInfo.BackColor = Color.Gold;

                SystemData sdata = new SystemData();
                routeControl1.travelhistorycontrol1 = travelHistoryControl1;

                // Default directory
                string datapath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Frontier_Developments\\Products"); // \\FORC-FDEV-D-1001\\Logs\\";

                bool auto = db.GetSettingBool("NetlogDirAutoMode", true);
                if (auto)
                {
                    datapath = db.GetSettingString("Netlogdir", datapath);
                    textBoxNetLogDir.Text    = datapath;
                    radioButton_Auto.Checked = true;
                }
                else
                {
                    radioButton_Manual.Checked = true;
                    textBoxNetLogDir.Text      = datapath = db.GetSettingString("Netlogdir", datapath);;
                }


                if (EliteDangerous.EDRunning)
                {
                    TravelHistoryControl.LogText("EliteDangerous " + EliteDangerous.EDVersion + " is running." + Environment.NewLine);
                }
                else
                {
                    TravelHistoryControl.LogText("EliteDangerous is not running ." + Environment.NewLine);
                }

                if (!EliteDangerous.CheckStationLogging())
                {
                    TravelHistoryControl.LogText("Elite Dangerous is not logging system names!!! ", Color.Red);
                    TravelHistoryControl.LogText("Add ");
                    TravelHistoryControl.LogText("VerboseLogging=\"1\" ", Color.Blue);
                    TravelHistoryControl.LogText("to <Network  section in File: " + Path.Combine(EliteDangerous.EDDirectory, "AppConfig.xml") + " or AppConfigLocal.xml  Remeber to restart Elite!" + Environment.NewLine);

                    labelPanelText.Text = "Elite Dangerous is not logging system names!";
                    panelInfo.BackColor = Color.Salmon;
                }


                if (File.Exists("test.txt"))
                {
                    button1.Visible = true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Form1_Load exception: " + ex.Message);
                System.Windows.Forms.MessageBox.Show("Trace: " + ex.StackTrace);
            }
        }
Beispiel #7
0
        private void  GetEDDBUpdate()
        {
            try
            {
                EDDBClass eddb = new EDDBClass();
                string    timestr;
                DateTime  time;

                Thread.Sleep(1000);

                SQLiteDBClass db = new SQLiteDBClass();
                timestr = db.GetSettingString("EDDBSystemsTime", "0");
                time    = new DateTime(Convert.ToInt64(timestr), DateTimeKind.Utc);
                bool updatedb = false;

                if (DateTime.UtcNow.Subtract(time).TotalDays > 0.5)
                {
                    LogText("Get systems from EDDB. ");

                    if (eddb.GetSystems())
                    {
                        LogText("OK." + Environment.NewLine);

                        db.PutSettingString("EDDBSystemsTime", DateTime.UtcNow.Ticks.ToString());
                        updatedb = true;
                    }
                    else
                    {
                        LogText("Failed." + Environment.NewLine, Color.Red);
                    }


                    eddb.GetCommodities();
                }


                timestr = db.GetSettingString("EDDBStationsLiteTime", "0");
                time    = new DateTime(Convert.ToInt64(timestr), DateTimeKind.Utc);

                if (DateTime.UtcNow.Subtract(time).TotalDays > 0.5)
                {
                    LogText("Get stations from EDDB. ");
                    if (eddb.GetStationsLite())
                    {
                        LogText("OK." + Environment.NewLine);
                        db.PutSettingString("EDDBStationsLiteTime", DateTime.UtcNow.Ticks.ToString());
                        updatedb = true;
                    }
                    else
                    {
                        LogText("Failed." + Environment.NewLine, Color.Red);
                    }
                }


                if (updatedb)
                {
                    DBUpdateEDDB(eddb);
                }

                return;
            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate
                {
                    TravelHistoryControl.LogText("GetEDSCSystems exception:" + ex.Message + Environment.NewLine);
                });
            }
        }
Beispiel #8
0
        private void GetEDSCSystems()
        {
            try
            {
                SQLiteDBClass db   = new SQLiteDBClass();
                EDSMClass     edsm = new EDSMClass();


                string json;

                string rwsystime     = db.GetSettingString("RWLastSystems", "2000-01-01 00:00:00"); // Latest time from RW file.
                string rwsysfiletime = "";

                CommanderName = db.GetSettingString("CommanderName", "");
                Invoke((MethodInvoker) delegate {
                    travelHistoryControl1.textBoxCmdrName.Text = CommanderName;
                });


                json = LoadJsonArray(fileTgcSystems);
                List <SystemClass> systems = SystemClass.ParseEDSC(json, ref rwsysfiletime);


                if (!rwsystime.Equals(rwsysfiletime))          // New distance file from Redwizzard
                {
                    SystemClass.Delete(SystemStatusEnum.EDSC); // Remove all EDSC systems.

                    db.PutSettingString("RWLastSystems", rwsysfiletime);
                    db.PutSettingString("EDSMLastSystems", rwsysfiletime);
                    Invoke((MethodInvoker) delegate {
                        TravelHistoryControl.LogText("Adding data from tgcsystems.json " + Environment.NewLine);
                    });
                    SystemClass.Store(systems);
                    EDDBClass eddb = new EDDBClass();
                    DBUpdateEDDB(eddb);
                }

                string retstr = edsm.GetNewSystems(db);
                Invoke((MethodInvoker) delegate
                {
                    TravelHistoryControl.LogText(retstr);
                });



                db.GetAllSystemNotes();
                db.GetAllSystems();



                SystemNames.Clear();
                foreach (SystemClass system in SystemData.SystemList)
                {
                    SystemNames.Add(system.name);
                }
            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate {
                    TravelHistoryControl.LogText("GetEDSCSystems exception:" + ex.Message + Environment.NewLine);
                });
            }
        }
Beispiel #9
0
        private void EDDiscoveryForm_Shown(object sender, EventArgs e)
        {
            try
            {
                travelHistoryControl1.Enabled = false;

                var redWizzardThread = new Thread(GetRedWizzardFiles)
                {
                    Name = "Downloading Red Wizzard Files"
                };
                var edscThread = new Thread(GetEDSCSystems)
                {
                    Name = "Downloading EDSC Systems"
                };
                var downloadmapsThread = new Thread(DownloadMaps)
                {
                    Name = "Downloading map Files"
                };
                redWizzardThread.Start();
                edscThread.Start();
                downloadmapsThread.Start();

                while (redWizzardThread.IsAlive || edscThread.IsAlive || downloadmapsThread.IsAlive)
                {
                    Thread.Sleep(50);
                    Application.DoEvents();
                }

                redWizzardThread.Join();
                edscThread.Join();
                downloadmapsThread.Join();

                OnDistancesLoaded += new DistancesLoaded(this.DistancesLoaded);


                GetEDSCDistancesAsync();
                //Application.DoEvents();
                GetEDDBAsync();


                if (SystemData.SystemList.Count == 0)
                {
                    //sdata.ReadData();
                }



                routeControl1.textBox_From.AutoCompleteCustomSource = SystemNames;
                routeControl1.textBox_To.AutoCompleteCustomSource   = SystemNames;

                Text += "         Systems:  " + SystemData.SystemList.Count;

                routeControl1.travelhistorycontrol1         = travelHistoryControl1;
                travelHistoryControl1.netlog.OnNewPosition += new NetLogEventHandler(routeControl1.NewPosition);
                travelHistoryControl1.netlog.OnNewPosition += new NetLogEventHandler(travelHistoryControl1.NewPosition);

                TravelHistoryControl.LogText("Reading travelhistory ");
                travelHistoryControl1.RefreshHistory();
                travelHistoryControl1.netlog.StartMonitor();

                travelHistoryControl1.Enabled = true;
                if (EliteDangerous.CheckStationLogging())
                {
                    panelInfo.Visible = false;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Form1_Load exception: " + ex.Message);
                System.Windows.Forms.MessageBox.Show("Trace: " + ex.StackTrace);
                travelHistoryControl1.Enabled = true;
            }
        }
Beispiel #10
0
        private void SyncAllEDSMSystems()
        {
            try
            {
                EDDBClass eddb = new EDDBClass();
                EDSMClass edsm = new EDSMClass();

                string edsmsystems   = Path.Combine(Tools.GetAppDataDirectory(), "edsmsystems.json");
                bool   newfile       = false;
                string rwsysfiletime = "2014-01-01 00:00:00";
                LogText("Get systems from EDSM." + Environment.NewLine);

                eddb.DownloadFile("http://www.edsm.net/dump/systemsWithCoordinates.json", edsmsystems, out newfile);

                if (newfile)
                {
                    LogText("Adding EDSM systems." + Environment.NewLine);
                    _db.GetAllSystems();
                    string             json    = LoadJsonFile(edsmsystems);
                    List <SystemClass> systems = SystemClass.ParseEDSM(json, ref rwsysfiletime);


                    List <SystemClass> systems2Store = new List <SystemClass>();

                    foreach (SystemClass system in systems)
                    {
                        // Check if sys exists first
                        SystemClass sys = SystemData.GetSystem(system.name);
                        if (sys == null)
                        {
                            systems2Store.Add(system);
                        }
                        else if (!sys.name.Equals(system.name) || sys.x != system.x || sys.y != system.y || sys.z != system.z)  // Case or position changed
                        {
                            systems2Store.Add(system);
                        }
                    }
                    SystemClass.Store(systems2Store);
                    systems.Clear();
                    systems = null;
                    systems2Store.Clear();
                    systems2Store = null;
                    json          = null;

                    _db.PutSettingString("EDSMLastSystems", rwsysfiletime);
                    _db.GetAllSystems();
                }
                else
                {
                    LogText("No new file." + Environment.NewLine);
                }

                string retstr = edsm.GetNewSystems(_db);
                Invoke((MethodInvoker) delegate
                {
                    TravelHistoryControl.LogText(retstr);
                });

                GC.Collect();
            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate
                {
                    TravelHistoryControl.LogText("GetAllEDSMSystems exception:" + ex.Message + Environment.NewLine);
                });
            }
        }
Beispiel #11
0
        private void EDDiscoveryForm_Shown(object sender, EventArgs e)
        {
            try
            {
                travelHistoryControl1.Enabled = false;

                var edsmThread = new Thread(GetEDSMSystems)
                {
                    Name = "Downloading EDSM Systems", IsBackground = true
                };
                var downloadmapsThread = new Thread(DownloadMaps)
                {
                    Name = "Downloading map Files", IsBackground = true
                };
                edsmThread.Start();
                downloadmapsThread.Start();

                while (edsmThread.IsAlive || downloadmapsThread.IsAlive)
                {
                    Thread.Sleep(50);
                    Application.DoEvents();
                }

                edsmThread.Join();
                downloadmapsThread.Join();

                OnDistancesLoaded += new DistancesLoaded(this.DistancesLoaded);

                GetEDSMDistancesAsync();

                //Application.DoEvents();
                GetEDDBAsync(false);

                routeControl1.textBox_From.AutoCompleteCustomSource = SystemNames;
                routeControl1.textBox_To.AutoCompleteCustomSource   = SystemNames;

                imageHandler1.StartWatcher();
                routeControl1.EnableRouteTab(); // now we have systems, we can update this..

                routeControl1.travelhistorycontrol1            = travelHistoryControl1;
                travelHistoryControl1.netlog.OnNewPosition    += new NetLogEventHandler(routeControl1.NewPosition);
                travelHistoryControl1.netlog.OnNewPosition    += new NetLogEventHandler(travelHistoryControl1.NewPosition);
                travelHistoryControl1.sync.OnNewEDSMTravelLog += new EDSMNewSystemEventHandler(travelHistoryControl1.RefreshEDSMEvent);

                TravelHistoryControl.LogText("Reading travel history " + Environment.NewLine);
                travelHistoryControl1.RefreshHistory();
                travelHistoryControl1.netlog.StartMonitor(this);

                travelHistoryControl1.Enabled = true;
                if (EliteDangerous.CheckStationLogging())
                {
                    panelInfo.Visible = false;
                }


                // Check for a new installer
                CheckForNewInstaller();

                LogLine("Total number of systems " + SystemData.SystemList.Count().ToString() + Environment.NewLine);
                LogLineSuccess("Loading completed!" + Environment.NewLine);

                panel_close.Enabled = true;                            // now we can safely close
                tabControl1.Enabled = true;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("EDDiscovery_Load exception: " + ex.Message);
                System.Windows.Forms.MessageBox.Show("Trace: " + ex.StackTrace);
                travelHistoryControl1.Enabled = true;
            }
        }