예제 #1
0
 public void UpdateCommandersListBox()
 {
     dataGridViewCommanders.DataSource = null;
     dataGridViewCommanders.DataSource = EDCommander.GetList();
     dataGridViewCommanders.Update();
 }
예제 #2
0
        private void BackgroundWorkerThread()
        {
            // check first and download items

            StarScan.LoadBodyDesignationMap();

            Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems");
            ReportSyncProgress("");

            bool checkGithub = EDDOptions.Instance.CheckGithubFiles;

            if (checkGithub)      // not normall in debug, due to git hub chokeing
            {
                // Async load of maps in another thread
                DownloadMaps(() => PendingClose);

                // and Expedition data
                DownloadExpeditions(() => PendingClose);

                // and Exploration data
                DownloadExploration(() => PendingClose);
            }

            if (!EDDOptions.Instance.NoSystemsLoad)
            {
                // New Galmap load - it was not doing a refresh if EDSM sync kept on happening. Now has its own timer

                DateTime galmaptime = SQLiteConnectionSystem.GetSettingDate("EDSMGalMapLast", DateTime.MinValue); // Latest time from RW file.

                if (DateTime.Now.Subtract(galmaptime).TotalDays > 14 || !galacticMapping.GalMapFilePresent())     // Over 14 days do a sync from EDSM for galmap
                {
                    LogLine("Get galactic mapping from EDSM.".T(EDTx.EDDiscoveryController_EDSM));
                    if (galacticMapping.DownloadFromEDSM())
                    {
                        SQLiteConnectionSystem.PutSettingDate("EDSMGalMapLast", DateTime.UtcNow);
                    }
                }

                Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems complete");
            }

            galacticMapping.ParseData();                            // at this point, gal map data has been uploaded - get it into memory
            SystemCache.AddToAutoCompleteList(galacticMapping.GetGMONames());
            SystemNoteClass.GetAllSystemNotes();

            LogLine("Loaded Notes, Bookmarks and Galactic mapping.".T(EDTx.EDDiscoveryController_LN));

            if (EliteDangerousCore.EDDN.EDDNClass.CheckforEDMC()) // EDMC is running
            {
                if (EDCommander.Current.SyncToEddn)               // Both EDD and EDMC should not sync to EDDN.
                {
                    LogLineHighlight("EDDiscovery and EDMarketConnector should not both sync to EDDN. Stop EDMC or uncheck 'send to EDDN' in settings tab!".T(EDTx.EDDiscoveryController_EDMC));
                }
            }

            if (!EDDOptions.Instance.NoLoad)        // here in this thread, we do a refresh of history.
            {
                LogLine("Reading travel history".T(EDTx.EDDiscoveryController_RTH));

                if (EDDOptions.Instance.Commander != null)
                {
                    EDCommander switchto = EDCommander.GetCommander(EDDOptions.Instance.Commander);
                    if (switchto != null)
                    {
                        EDCommander.CurrentCmdrID = switchto.Nr;
                    }
                }

                DoRefreshHistory(new RefreshWorkerArgs {
                    CurrentCommander = EDCommander.CurrentCmdrID
                });                                                                                             // kick the background refresh worker thread into action
            }

            CheckForSync();     // see if any EDSM/EDDB sync is needed - this just sets some variables up

            System.Diagnostics.Debug.WriteLine("Background worker setting up refresh worker");

            backgroundRefreshWorker = new Thread(BackgroundHistoryRefreshWorkerThread)
            {
                Name = "Background Refresh Worker", IsBackground = true
            };
            backgroundRefreshWorker.Start();        // start the refresh worker, another thread which does subsequenct (not the primary one) refresh work in the background..

            try
            {
                if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMEDDBDownload) // if no system off, and EDSM download on
                {
                    DoPerformSync();                                                           // this is done after the initial history load..
                }

                while (!PendingClose)
                {
                    int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, resyncRequestedEvent });

                    System.Diagnostics.Debug.WriteLine("Background worker kicked by " + wh);

                    if (PendingClose)
                    {
                        break;
                    }

                    if (wh == 1)
                    {
                        if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMEDDBDownload)      // if no system off, and EDSM download on
                        {
                            DoPerformSync();
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }

            backgroundRefreshWorker.Join();     // this should terminate due to closeRequested..

            // Now we have been ordered to close down, so go thru the process

            closeRequested.WaitOne();

            InvokeAsyncOnUiThread(() =>
            {
                OnFinalClose?.Invoke();
            });
        }
        private void BackgroundWorkerThread()
        {
            // check first and download items

            string desigmapfile = Path.Combine(EDDOptions.Instance.AppDataDirectory, "bodydesignations.csv");

            if (!File.Exists(desigmapfile))
            {
                desigmapfile = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "bodydesignations.csv");
            }

            BodyDesignations.LoadBodyDesignationMap(desigmapfile);

            Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems");
            ReportSyncProgress("");

            bool checkGithub = EDDOptions.Instance.CheckGithubFiles;

            if (checkGithub)      // not normal in debug, due to git hub choking
            {
                DateTime lastdownloadtime = UserDatabase.Instance.GetSettingDate("DownloadFilesLastTime", DateTime.MinValue);

                if (DateTime.UtcNow - lastdownloadtime >= new TimeSpan(24, 0, 0))       // only update once per day
                {
                    // Expedition data
                    DownloadExpeditions(() => PendingClose);

                    // and Exploration data
                    DownloadExploration(() => PendingClose);

                    // and Help files
                    DownloadHelp(() => PendingClose);

                    UserDatabase.Instance.PutSettingDate("DownloadFilesLastTime", DateTime.UtcNow);
                }
            }

            string gmofile = Path.Combine(EDDOptions.Instance.AppDataDirectory, "galacticmapping.json");

            if (!EDDOptions.Instance.NoSystemsLoad)
            {
                // New Galmap load - it was not doing a refresh if EDSM sync kept on happening. Now has its own timer

                DateTime galmaptime = SystemsDatabase.Instance.GetEDSMGalMapLast();            // Latest time from RW file.

                if (DateTime.Now.Subtract(galmaptime).TotalDays > 14 || !File.Exists(gmofile)) // Over 14 days do a sync from EDSM for galmap
                {
                    LogLine("Get galactic mapping from EDSM.".T(EDTx.EDDiscoveryController_EDSM));
                    if (galacticMapping.DownloadFromEDSM(gmofile))
                    {
                        SystemsDatabase.Instance.SetEDSMGalMapLast(DateTime.UtcNow);
                    }
                }

                Debug.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Check systems complete");
            }

            if (File.Exists(gmofile))
            {
                galacticMapping.Parse(gmofile);                            // at this point, gal map data has been uploaded - get it into memory
            }
            SystemCache.AddToAutoCompleteList(galacticMapping.GetGMONames());
            SystemNoteClass.GetAllSystemNotes();

            LogLine("Loaded Notes, Bookmarks and Galactic mapping.".T(EDTx.EDDiscoveryController_LN));

            if (!EDDOptions.Instance.NoLoad)        // here in this thread, we do a refresh of history.
            {
                LogLine("Reading travel history".T(EDTx.EDDiscoveryController_RTH));

                if (EDDOptions.Instance.Commander != null)
                {
                    EDCommander switchto = EDCommander.GetCommander(EDDOptions.Instance.Commander);
                    if (switchto != null)
                    {
                        EDCommander.CurrentCmdrID = switchto.Id;
                    }
                }

                DoRefreshHistory(new RefreshWorkerArgs {
                    CurrentCommander = EDCommander.CurrentCmdrID
                });                                                                                             // kick the background refresh worker thread into action
            }

            CheckForSync();     // see if any EDSM sync is needed - this just sets some variables up

            System.Diagnostics.Debug.WriteLine("Background worker setting up refresh worker");

            backgroundRefreshWorker = new Thread(BackgroundHistoryRefreshWorkerThread)
            {
                Name = "Background Refresh Worker", IsBackground = true
            };
            backgroundRefreshWorker.Start();        // start the refresh worker, another thread which does subsequenct (not the primary one) refresh work in the background..

            try
            {
                if (!EDDOptions.Instance.NoSystemsLoad)
                {
                    SystemsDatabase.Instance.WithReadWrite(() => DoPerformSync());        // this is done after the initial history load..
                }

                SystemsDatabase.Instance.SetReadOnly();

                while (!PendingClose)
                {
                    int wh = WaitHandle.WaitAny(new WaitHandle[] { closeRequested, resyncRequestedEvent });

                    System.Diagnostics.Debug.WriteLine("Background worker kicked by " + wh);

                    if (PendingClose)
                    {
                        break;
                    }

                    if (wh == 1)
                    {
                        if (!EDDOptions.Instance.NoSystemsLoad && EDDConfig.Instance.EDSMDownload)      // if no system off, and EDSM download on
                        {
                            SystemsDatabase.Instance.WithReadWrite(() => DoPerformSync());
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
            }

            backgroundRefreshWorker.Join();     // this should terminate due to closeRequested..

            System.Diagnostics.Debug.WriteLine("BW Refresh joined");

            // Now we have been ordered to close down, so go thru the process

            closeRequested.WaitOne();

            InvokeAsyncOnUiThread(() =>
            {
                System.Diagnostics.Debug.WriteLine("Final close");
                OnFinalClose?.Invoke();
            });
        }
예제 #4
0
 /// <summary>
 /// Constructs a new CurrentCommanderChangedEventArgs class in preparation to send it off in an event.
 /// </summary>
 /// <param name="index">The index of the commander in the list.</param>
 public CurrentCommanderChangedEventArgs(int index)
 {
     Index     = index;
     Commander = EDCommander.GetCommander(index);
 }
예제 #5
0
        /// <summary>
        /// Loads the commanders from storage
        /// </summary>
        /// <param name="write">True if any migrated commanders should be written to storage</param>
        /// <param name="conn">SQLite connection</param>
        public static void Load(bool write = true, SQLiteConnectionUser conn = null)
        {
            if (_commandersDict == null)
            {
                _commandersDict = new Dictionary <int, EDCommander>();
            }

            lock (_commandersDict)
            {
                _commandersDict.Clear();

                var cmdrs = SQLiteConnectionUser.GetCommanders(conn);
                int maxnr = cmdrs.Count == 0 ? 0 : cmdrs.Max(c => c.Nr);

                foreach (EDCommander cmdr in cmdrs)
                {
                    if (!cmdr.Deleted)
                    {
                        _commandersDict[cmdr.Nr] = cmdr;
                    }
                }

                if (_commandersDict.Count == 0)
                {
                    if (write)
                    {
                        Create("Jameson (Default)");
                    }
                    else
                    {
                        _commandersDict[maxnr + 1] = new EDCommander(maxnr + 1, "Jameson (Default)", "", false, false, false);
                    }
                }
            }

            // For  some people sharing their user DB between different computers and having different paths to their journals on those computers.
            if (File.Exists(Path.Combine(EDDConfig.Options.AppDataDirectory, "CommanderPaths.json")))
            {
                JObject jo;

                using (Stream stream = File.OpenRead(Path.Combine(EDDConfig.Options.AppDataDirectory, "CommanderPaths.json")))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        using (JsonTextReader jreader = new JsonTextReader(reader))
                        {
                            jo = JObject.Load(jreader);
                        }
                    }
                }

                foreach (var kvp in jo)
                {
                    string      name  = kvp.Key;
                    JObject     props = kvp.Value as JObject;
                    EDCommander cmdr  = GetCommander(name);
                    if (props != null && cmdr != null)
                    {
                        cmdr.JournalDir = props["JournalDir"].Str(cmdr.JournalDir);
                    }
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Generate a new commander with the specified parameters, save it to backing storage, and refresh the instantiated list.
        /// </summary>
        /// <param name="name">The in-game name for this commander.</param>
        /// <param name="edsmName">The name for this commander as shown on EDSM.</param>
        /// <param name="edsmApiKey">The API key to interface with EDSM.</param>
        /// <param name="journalpath">Where EDD should monitor for this commander's logs.</param>
        /// <returns>The newly-generated commander.</returns>

        public static EDCommander Create(EDCommander other)
        {
            return(Create(other.name, other.EdsmName, other.APIKey, other.JournalDir, other.syncToEdsm, other.SyncFromEdsm, other.SyncToEddn));
        }
예제 #7
0
 /// <summary>
 /// Delete a commander from backing storage and refresh instantiated list.
 /// </summary>
 /// <param name="cmdr">The commander to be deleted.</param>
 public static void Delete(EDCommander cmdr)
 {
     Delete(cmdr.Nr);
 }