public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.Functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed)
            {
                StringParser sp = new StringParser(res);

                string prefix  = "CL_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                int cmdrid = EDCommander.CurrentCmdrID;

                if (cmdname != null && cmdname.Equals("CMDR", StringComparison.InvariantCultureIgnoreCase))
                {
                    string name = sp.NextQuotedWord() ?? "-----!";

                    EDCommander cmdr = EDCommander.GetCommander(name);

                    if (cmdr != null)
                    {
                        cmdrid = cmdr.Id;
                    }
                    else
                    {
                        ap.ReportError("Commander not found");
                    }

                    cmdname = sp.NextWord();
                }

                List <CaptainsLogClass> cllist = GlobalCaptainsLogList.Instance.LogEntriesCmdrTimeOrder(cmdrid);

                EDDiscoveryForm discoveryform = (ap.ActionController as ActionController).DiscoveryForm;

                if (cmdname != null)
                {
                    if (cmdname.Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string wildcard = sp.NextQuotedWord() ?? "*";

                        Func <CaptainsLogClass, string, bool> validate = CheckSystemBody;

                        string field = sp.NextQuotedWord() ?? "--";
                        if (field.Equals("Body", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckBody;
                        }
                        else if (field.Equals("System", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckSystem;
                        }
                        else if (field.Equals("Tag", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckTags;
                        }
                        else if (field.Equals("Note", StringComparison.InvariantCultureIgnoreCase))
                        {
                            validate = CheckNote;
                        }
                        else if (field != "--")
                        {
                            ap.ReportError("Unknown field type to list");
                            return(true);
                        }

                        int count = 1;
                        foreach (CaptainsLogClass cl in cllist)       // only current commander ID considered
                        {
                            if (validate(cl, wildcard))
                            {
                                DumpCL(ap, prefix + count++.ToStringInvariant() + "_", cl);
                            }
                        }

                        ap[prefix + "MatchCount"] = (count - 1).ToStringInvariant();
                        ap[prefix + "TotalCount"] = cllist.Count.ToStringInvariant();
                    }
                    else if (cmdname.Equals("ADDHERE", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string note    = sp.NextQuotedWord();
                        string taglist = sp.NextQuotedWord();

                        HistoryEntry he = discoveryform.history.GetLast;

                        if (he != null)
                        {       // taglist can be null.. note must be set.
                            GlobalCaptainsLogList.Instance.AddOrUpdate(null, cmdrid, he.System.Name, he.WhereAmI, DateTime.UtcNow, note ?? "", taglist);
                        }
                        else
                        {
                            ap.ReportError("History has no locations");
                        }
                    }
                    else if (cmdname.Equals("ADD", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string   systemname = sp.NextQuotedWord();
                        string   bodyname   = sp.NextQuotedWord();
                        DateTime?dte        = sp.NextDateTime(System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal);
                        string   note       = sp.NextQuotedWord();
                        string   taglist    = sp.NextQuotedWord();

                        if (systemname != null && bodyname != null && dte != null)
                        {
                            GlobalCaptainsLogList.Instance.AddOrUpdate(null, cmdrid, systemname, bodyname, dte.Value, note ?? "", taglist);
                        }
                        else
                        {
                            ap.ReportError("Missing parameters in ADD");
                        }
                    }
                    else if (cmdname.Equals("TAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = EDDConfig.Instance.CaptainsLogTags;
                        ap[prefix + "Tags"] = tags;
                    }
                    else if (cmdname.Equals("SETTAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = sp.NextQuotedWord();
                        if (tags != null)
                        {
                            EDDConfig.Instance.CaptainsLogTags = tags;
                        }
                        else
                        {
                            ap.ReportError("Missing tag list");
                        }
                    }
                    else if (cmdname.Equals("APPENDTAGLIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string tags = sp.NextQuotedWord();
                        if (tags != null)
                        {
                            EDDConfig.Instance.CaptainsLogTags = EDDConfig.Instance.CaptainsLogTags.AppendPrePad(tags, ";");
                        }
                        else
                        {
                            ap.ReportError("Missing tag list");
                        }
                    }
                    else
                    {   // ********************** Iterator forms, FROM/LAST/FIRST/TIME [Forward|Backward]
                        long?cid = -1;

                        if (cmdname.Equals("From", StringComparison.InvariantCultureIgnoreCase))
                        {
                            cid = sp.NextWord().InvariantParseLongNull();

                            if (cid == null)
                            {
                                ap.ReportError("Non integer CID after FROM");
                                return(true);
                            }
                        }
                        else if (cmdname.Equals("First", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (cllist.Count > 0) //prevent crash if cllist is empty
                            {
                                var mintime = cllist.Min(x => x.TimeUTC);
                                cid = cllist.First(x => x.TimeUTC == mintime).ID;
                            }
                        }
                        else if (cmdname.Equals("Last", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (cllist.Count > 0)
                            {
                                var maxtime = cllist.Max(x => x.TimeUTC);
                                cid = cllist.Last(x => x.TimeUTC == maxtime).ID;
                            }
                        }
                        else if (cmdname.Equals("Time", StringComparison.InvariantCultureIgnoreCase))
                        {
                            DateTime?dte = sp.NextDateTime(System.Globalization.CultureInfo.GetCultureInfo("en-us"), System.Globalization.DateTimeStyles.AssumeUniversal | System.Globalization.DateTimeStyles.AdjustToUniversal);
                            if (dte != null)
                            {
                                if (cllist.Count > 0)
                                {
                                    var firstafter = cllist.FirstOrDefault(x => x.TimeUTC >= dte);

                                    if (firstafter != null)
                                    {
                                        cid = firstafter.ID;
                                    }
                                }
                            }
                            else
                            {
                                ap.ReportError("Missing US date from Time");
                                return(true);
                            }
                        }
                        else
                        {
                            ap.ReportError("Unknown command");
                            return(true);
                        }

                        int indexof = cllist.FindIndex(x => x.ID == cid);   // -1 if not found..

                        string nextcmd = sp.NextWord();

                        if (nextcmd != null)
                        {
                            if (nextcmd.Equals("FORWARD", StringComparison.InvariantCultureIgnoreCase))
                            {
                                if (indexof >= 0)   // don't ruin -1 if set
                                {
                                    indexof++;
                                }

                                nextcmd = sp.NextWord();
                            }
                            else if (nextcmd.Equals("BACKWARD", StringComparison.InvariantCultureIgnoreCase))
                            {
                                indexof--;      // if -1, its okay to make it -2.

                                nextcmd = sp.NextWord();
                            }
                        }

                        bool validindex = indexof >= 0 && indexof < cllist.Count;

                        if (nextcmd != null)
                        {
                            if (!validindex)     // these must have a valid target..
                            {
                                ap.ReportError("Entry is not found");
                            }
                            else
                            {
                                CaptainsLogClass cl = cllist[indexof];

                                if (nextcmd.Equals("DELETE", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    GlobalCaptainsLogList.Instance.Delete(cl);
                                }
                                else
                                {
                                    string text = sp.NextQuotedWord();

                                    if (text != null && sp.IsEOL)
                                    {
                                        if (nextcmd.Equals("NOTE", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, cl.SystemName, cl.BodyName, cl.TimeUTC,
                                                                                       text, cl.Tags, cl.Parameters);
                                        }
                                        else if (nextcmd.Equals("SYSTEM", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, text, cl.BodyName, cl.TimeUTC,
                                                                                       cl.Note, cl.Tags, cl.Parameters);
                                        }
                                        else if (nextcmd.Equals("BODY", StringComparison.InvariantCultureIgnoreCase))
                                        {
                                            GlobalCaptainsLogList.Instance.AddOrUpdate(cl, cl.Commander, cl.SystemName, text, cl.TimeUTC,
                                                                                       cl.Note, cl.Tags, cl.Parameters);
                                        }
                                        else
                                        {
                                            ap.ReportError("Unknown command " + nextcmd);
                                        }
                                    }
                                    else
                                    {
                                        ap.ReportError("Missing text or unquoted spaced text after " + nextcmd);
                                    }
                                }
                            }

                            return(true);
                        }


                        if (nextcmd != null)
                        {
                            ap.ReportError("Unknown iterator or command " + nextcmd);
                        }
                        else
                        {       // straight report
                            if (validindex)
                            {
                                DumpCL(ap, prefix, cllist[indexof]);
                            }
                            else
                            {
                                ap[prefix + "Id"] = "-1";
                            }
                        }

                        return(true);
                    }
                }
                else
                {
                    ap.ReportError("Missing command");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
Esempio n. 2
0
 public EDSMLogFetcher(int cmdrid, Action <string> logline)
 {
     Commander = EDCommander.GetCommander(cmdrid);
     LogLine   = logline;
 }
Esempio n. 3
0
 private void comboBoxCommanders_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedCommander = (EDCommander)comboBoxCommanders.SelectedItem;
 }
Esempio n. 4
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.Functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed)
            {
                StringParser sp = new StringParser(res);

                string prefix  = "CMDR_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                int cmdrid = EDCommander.CurrentCmdrID;

                if (cmdname != null && cmdname.Equals("CMDR", StringComparison.InvariantCultureIgnoreCase))
                {
                    string name = sp.NextQuotedWord() ?? "-----!";

                    EDCommander cmdr = EDCommander.GetCommander(name);

                    if (cmdr != null)
                    {
                        cmdrid = cmdr.Id;
                    }
                    else
                    {
                        ap.ReportError("Commander not found");
                    }

                    cmdname = sp.NextWord();
                }

                EDDiscoveryForm discoveryform = (ap.ActionController as ActionController).DiscoveryForm;

                List <EDCommander> cmdrlist = EDCommander.GetListCommanders();

                if (cmdname != null)
                {
                    if (cmdname.Equals("LIST", StringComparison.InvariantCultureIgnoreCase))
                    {
                        string wildcard = sp.NextQuotedWord() ?? "*";

                        int count = 1;
                        foreach (var cmdr in cmdrlist)       // only current commander ID considered
                        {
                            if (cmdr.Name.WildCardMatch(wildcard))
                            {
                                DumpCMDR(ap, prefix + count++.ToStringInvariant() + "_", cmdr);
                            }
                        }

                        ap[prefix + "MatchCount"] = (count - 1).ToStringInvariant();
                        ap[prefix + "TotalCount"] = cmdrlist.Count.ToStringInvariant();
                    }
                    else if (cmdname.Equals("CHANGETO", StringComparison.InvariantCultureIgnoreCase))
                    {
                        discoveryform.ChangeToCommander(cmdrid);                                   // which will cause DIsplay to be called as some point
                    }
                    else
                    {
                        ap.ReportError("Unknown command");
                    }
                }
                else
                {
                    ap.ReportError("Missing command");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }
        static private bool SendToEDSM(List <HistoryEntry> hl, EDCommander cmdr, out string errmsg, out string firstdiscovers)
        {
            EDSMClass edsm = new EDSMClass(cmdr);       // Ensure we use the commanders EDSM credentials.

            errmsg         = null;
            firstdiscovers = "";

            List <JObject> entries = new List <JObject>();

            foreach (HistoryEntry he in hl)
            {
                JournalEntry je = he.journalEntry;

                if (je == null)
                {
                    je = JournalEntry.Get(he.Journalid);
                }

                JObject json = je.GetJsonCloned();

                if (json == null)
                {
                    continue;
                }

                RemoveCommonKeys(json);
                if (je.EventTypeID == JournalTypeEnum.FSDJump && json["FuelUsed"].Empty())
                {
                    json["_convertedNetlog"] = true;
                }
                if (json["StarPosFromEDSM"].Bool(false)) // Remove star pos from EDSM
                {
                    json.Remove("StarPos");
                }
                json.Remove("StarPosFromEDSM");
                json["_systemName"]        = he.System.Name;
                json["_systemCoordinates"] = new JArray(he.System.X, he.System.Y, he.System.Z);
                if (he.System.SystemAddress != null)
                {
                    json["_systemAddress"] = he.System.SystemAddress;
                }
                if (he.IsDocked)
                {
                    json["_stationName"] = he.WhereAmI;
                    if (he.MarketID != null)
                    {
                        json["_stationMarketId"] = he.MarketID;
                    }
                }
                json["_shipId"] = he.ShipId;
                entries.Add(json);
            }

            List <JObject> results = edsm.SendJournalEvents(entries, out errmsg);

            if (results == null)
            {
                return(false);
            }
            else
            {
                firstdiscovers = UserDatabase.Instance.ExecuteWithDatabase <string>(cn =>
                {
                    string firsts = "";
                    using (var txn = cn.Connection.BeginTransaction())
                    {
                        for (int i = 0; i < hl.Count && i < results.Count; i++)
                        {
                            HistoryEntry he = hl[i];
                            JObject result  = results[i];
                            int msgnr       = result["msgnum"].Int();
                            int systemId    = result["systemId"].Int();

                            if ((msgnr >= 100 && msgnr < 200) || msgnr == 500)
                            {
                                if (he.IsLocOrJump)
                                {
                                    if (systemId != 0)
                                    {
                                        he.System.EDSMID = systemId;
                                        JournalEntry.UpdateEDSMIDPosJump(he.Journalid, he.System, false, 0, cn.Connection, txn);
                                    }
                                }

                                if (he.EntryType == JournalTypeEnum.FSDJump)       // only on FSD, confirmed with Anthor.  25/4/2018
                                {
                                    bool systemCreated = result["systemCreated"].Bool();

                                    if (systemCreated)
                                    {
                                        System.Diagnostics.Debug.WriteLine("** EDSM indicates first entry for " + he.System.Name);
                                        (he.journalEntry as JournalFSDJump).UpdateFirstDiscover(true, cn.Connection, txn);
                                        firsts = firsts.AppendPrePad(he.System.Name, ";");
                                    }
                                }

                                he.journalEntry.SetEdsmSync(cn.Connection, txn);

                                if (msgnr == 500)
                                {
                                    System.Diagnostics.Trace.WriteLine($"EDSM Warning submitting event {he.Journalid} \"{he.EventSummary}\": {msgnr} {result["msg"].Str()}");
                                }
                            }
                            else
                            {
                                System.Diagnostics.Trace.WriteLine($"EDSM Error submitting event {he.Journalid} \"{he.EventSummary}\": {msgnr} {result["msg"].Str()}");
                            }
                        }

                        txn.Commit();
                        return(firsts);
                    }
                });

                return(true);
            }
        }
Esempio n. 6
0
        private void Sync(EDSMClass edsm, HistoryList hl)
        {
            try
            {
                // Make sure the EDSM class has this history's commander set
                int         cmdrid = hl.CommanderId;
                EDCommander cmdr   = EDCommander.GetCommander(cmdrid);
                if (cmdr != null)
                {
                    edsm.commanderName = cmdr.EdsmName ?? cmdr.Name;
                    edsm.apiKey        = cmdr.APIKey;
                }

                logout("EDSM sync begin");

                List <HistoryEntry> hlfsdunsyncedlist = hl.FilterByNotEDSMSyncedAndFSD; // first entry is oldest

                if (_syncTo && hlfsdunsyncedlist.Count > 0)                             // send systems to edsm (verified with dates, 29/9/2016, utc throughout)
                {
                    DateTime logstarttime = DateTime.MinValue;
                    DateTime logendtime   = DateTime.MinValue;

                    logout("EDSM: Sending " + hlfsdunsyncedlist.Count.ToString() + " flightlog entries");

                    List <HistoryEntry> edsmsystemlog = null;

                    int edsmsystemssent = 0;

                    foreach (var he in hlfsdunsyncedlist)
                    {
                        if (Exit)
                        {
                            running = false;
                            return;
                        }

                        if (edsmsystemlog == null || he.EventTimeUTC >= logendtime.AddDays(-1))
                        {
                            edsm.GetLogs(he.EventTimeUTC.AddDays(-1), null, out edsmsystemlog, out logstarttime, out logendtime);        // always returns a log, time is in UTC as per HistoryEntry and JournalEntry
                        }

                        if (logendtime < logstarttime)
                        {
                            running = false;
                            return;
                        }

                        if (edsmsystemlog == null)
                        {
                            running = false;
                            return;
                        }

                        HistoryEntry ps2 = (from c in edsmsystemlog where c.System.name == he.System.name && c.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks select c).FirstOrDefault();

                        if (ps2 != null)                // it did, just make sure EDSM sync flag is set..
                        {
                            he.SetEdsmSync();
                        }
                        else
                        {
                            string errmsg;              // (verified with EDSM 29/9/2016)
                            bool   firstdiscover;
                            int    edsmid;

                            if (edsm.SendTravelLog(he.System.name, he.EventTimeUTC, he.System.HasCoordinate && !he.IsStarPosFromEDSM, he.System.x, he.System.y, he.System.z, out errmsg, out firstdiscover, out edsmid))
                            {
                                if (edsmid != 0 && he.System.id_edsm <= 0)
                                {
                                    he.System.id_edsm = edsmid;
                                    JournalEntry.UpdateEDSMIDPosJump(he.Journalid, he.System, false, -1);
                                }

                                if (firstdiscover)
                                {
                                    he.SetFirstDiscover();
                                }

                                he.SetEdsmSync();
                                edsmsystemssent++;
                            }

                            if (errmsg.Length > 0)
                            {
                                logout(errmsg);
                                break;
                            }
                        }
                    }

                    logout(string.Format("EDSM Systems sent {0}", edsmsystemssent));
                }

                // TBD Comments to edsm?

                if (_syncFrom)                                                              // Verified ok with time 29/9/2016
                {
                    var json = edsm.GetComments(new DateTime(2011, 1, 1));

                    if (json != null)
                    {
                        JObject msg   = JObject.Parse(json);
                        int     msgnr = msg["msgnum"].Value <int>();

                        JArray comments = (JArray)msg["comments"];
                        if (comments != null)
                        {
                            int commentsadded = 0;

                            foreach (JObject jo in comments)
                            {
                                string name    = jo["system"].Value <string>();
                                string note    = jo["comment"].Value <string>();
                                string utctime = jo["lastUpdate"].Value <string>();
                                int    edsmid  = 0;

                                if (!Int32.TryParse(jo["systemId"].Str("0"), out edsmid))
                                {
                                    edsmid = 0;
                                }

                                DateTime localtime = DateTime.ParseExact(utctime, "yyyy-MM-dd HH:mm:ss",
                                                                         CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();

                                SystemNoteClass curnote = SystemNoteClass.GetNoteOnSystem(name, edsmid);

                                if (curnote != null)                          // curnote uses local time to store
                                {
                                    if (localtime.Ticks > curnote.Time.Ticks) // if newer, add on (verified with EDSM 29/9/2016)
                                    {
                                        curnote.UpdateNote(curnote.Note + ". EDSM: " + note, true, localtime, edsmid, true);
                                        commentsadded++;
                                    }
                                }
                                else
                                {
                                    SystemNoteClass.MakeSystemNote(note, localtime, name, 0, edsmid, true);   // new one!  its an FSD one as well
                                    commentsadded++;
                                }
                            }

                            logout(string.Format("EDSM Comments downloaded/updated {0}", commentsadded));
                        }
                    }
                }

                logout("EDSM sync Done");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                logout("EDSM sync Exception " + ex.Message);
            }
        }
Esempio n. 7
0
        public override void Init()
        {
            extComboBoxGameTime.Items.Add("Local".T(EDTx.UserControlSettings_Local));
            extComboBoxGameTime.Items.Add("UTC");
            extComboBoxGameTime.Items.Add("Game Time".T(EDTx.UserControlSettings_GameTime));

            BaseUtils.Translator.Instance.Translate(this);
            BaseUtils.Translator.Instance.Translate(toolTip, this);

            ResetThemeList();
            SetEntryThemeComboBox();

            btnDeleteCommander.Enabled = EDCommander.NumberOfCommanders > 1;

            comboBoxClickThruKey.Items                 = KeyObjectExtensions.KeyListString(inclshifts: true);
            comboBoxClickThruKey.SelectedItem          = EDDConfig.Instance.ClickThruKey.VKeyToString();
            comboBoxClickThruKey.SelectedIndexChanged += comboBoxClickThruKey_SelectedIndexChanged;

            comboBoxCustomLanguage.Items.AddRange(BaseUtils.Translator.EnumerateLanguageNames(EDDOptions.Instance.TranslatorFolders()));

            comboBoxCustomLanguage.Items.Add("Auto");
            comboBoxCustomLanguage.Items.Add("Default (English)");
            if (comboBoxCustomLanguage.Items.Contains(EDDConfig.Instance.Language))
            {
                comboBoxCustomLanguage.SelectedItem = EDDConfig.Instance.Language;
            }
            else
            {
                comboBoxCustomLanguage.SelectedIndex = comboBoxCustomLanguage.Items.Count - 1;
            }
            comboBoxCustomLanguage.SelectedIndexChanged += ComboBoxCustomLanguage_SelectedIndexChanged;

            discoveryform.OnRefreshCommanders += DiscoveryForm_OnRefreshCommanders;

            checkBoxOrderRowsInverted.Checked    = EDDiscoveryForm.EDDConfig.OrderRowsInverted;
            checkBoxMinimizeToNotifyIcon.Checked = EDDiscoveryForm.EDDConfig.MinimizeToNotifyIcon;
            checkBoxKeepOnTop.Checked            = EDDiscoveryForm.EDDConfig.KeepOnTop;
            checkBoxPanelSortOrder.Checked       = EDDConfig.Instance.SortPanelsByName;
            checkBoxUseNotifyIcon.Checked        = EDDiscoveryForm.EDDConfig.UseNotifyIcon;
            checkBoxCustomResize.Checked         = EDDiscoveryForm.EDDConfig.DrawDuringResize;

            extComboBoxGameTime.SelectedIndex = EDDiscoveryForm.EDDConfig.DisplayTimeIndex;

            checkBoxOrderRowsInverted.CheckedChanged    += checkBoxOrderRowsInverted_CheckedChanged;
            checkBoxMinimizeToNotifyIcon.CheckedChanged += checkBoxMinimizeToNotifyIcon_CheckedChanged;
            checkBoxKeepOnTop.CheckedChanged            += checkBoxKeepOnTop_CheckedChanged;
            checkBoxPanelSortOrder.CheckedChanged       += checkBoxPanelSortOrder_CheckedChanged;
            checkBoxUseNotifyIcon.CheckedChanged        += checkBoxUseNotifyIcon_CheckedChanged;
            extComboBoxGameTime.SelectedIndexChanged    += ExtComboBoxGameTime_SelectedIndexChanged;
            checkBoxCustomResize.CheckedChanged         += checkBoxCustomResize_CheckedChanged;

            checkBoxMinimizeToNotifyIcon.Enabled = EDDiscoveryForm.EDDConfig.UseNotifyIcon;

            dataGridViewCommanders.AutoGenerateColumns = false;             // BEFORE assigned to list..
            dataGridViewCommanders.DataSource          = EDCommander.GetListCommanders();

            this.comboBoxTheme.SelectedIndexChanged += this.comboBoxTheme_SelectedIndexChanged;    // now turn on the handler..

            checkBoxCustomEnableScreenshots.Checked              = discoveryform.screenshotconverter.AutoConvert;
            this.checkBoxCustomEnableScreenshots.CheckedChanged += new System.EventHandler(this.checkBoxCustomEnableScreenshots_CheckedChanged);

            checkBoxCustomEDSMDownload.Checked              = EDDConfig.Instance.EDSMDownload;
            this.checkBoxCustomEDSMDownload.CheckedChanged += new System.EventHandler(this.checkBoxCustomEDSMDownload_CheckedChanged);

            comboBoxCustomHistoryLoadTime.Items = new string[] { "Disabled-Load All".T(EDTx.UserControlSettings_DLA), ">7 days old".T(EDTx.UserControlSettings_7daysold),
                                                                 ">30 days old".T(EDTx.UserControlSettings_30daysold), ">60 days old".T(EDTx.UserControlSettings_60daysold), ">90 days old".T(EDTx.UserControlSettings_90daysold),
                                                                 ">180 days old".T(EDTx.UserControlSettings_180daysold), ">270 days old".T(EDTx.UserControlSettings_270daysold), "> 365 days old".T(EDTx.UserControlSettings_365daysold) };

            comboBoxCustomHistoryLoadTime.Tag = new int[] { 0, 7, 30, 60, 90, 180, 270, 365 };
            int ix = Array.FindIndex(comboBoxCustomHistoryLoadTime.Tag as int[], x => x == EDDConfig.Instance.FullHistoryLoadDayLimit);

            comboBoxCustomHistoryLoadTime.SelectedIndex         = ix >= 0 ? ix : 0;
            comboBoxCustomHistoryLoadTime.SelectedIndexChanged += ComboBoxCustomHistoryLoadTime_SelectedIndexChanged;

            var eetn = new string[] { nameof(JournalEssentialEvents.EssentialEvents), nameof(JournalEssentialEvents.FullStatsEssentialEvents), nameof(JournalEssentialEvents.JumpScanEssentialEvents), nameof(JournalEssentialEvents.JumpEssentialEvents), nameof(JournalEssentialEvents.NoEssentialEvents) };

            comboBoxCustomEssentialEntries.Items = new string[] { "Scans,Cargo,Missions,State,Jumps etc".T(EDTx.UserControlSettings_ESM), "All entries for Statistics".T(EDTx.UserControlSettings_FS),
                                                                  "Jumps and Scans".T(EDTx.UserControlSettings_EJS),
                                                                  "Jumps".T(EDTx.UserControlSettings_EJ), "Nothing".T(EDTx.UserControlSettings_EN) };

            comboBoxCustomEssentialEntries.Tag = eetn;
            ix = Array.FindIndex(eetn, x => x == EDDConfig.Instance.EssentialEventTypes);
            comboBoxCustomEssentialEntries.SelectedIndex         = ix >= 0 ? ix : 0;
            comboBoxCustomEssentialEntries.SelectedIndexChanged += ComboBoxCustomEssentialEntries_SelectedIndexChanged;

            extCheckBoxWebServerEnable.Checked = false;
            extButtonTestWeb.Enabled           = numberBoxLongPortNo.Enabled = false;
            numberBoxLongPortNo.Value          = EDDConfig.Instance.WebServerPort;
            tm.Tick    += PeriodicCheck;
            tm.Interval = 1000;
            tm.Start();

            extCheckBoxWebServerEnable.CheckedChanged += ExtCheckBoxWebServerEnable_CheckedChanged;
        }
Esempio n. 8
0
        protected JournalEntry ProcessLine(string line, bool resetOnError)
        {
            int cmdrid = -2;        //-1 is hidden, -2 is never shown

            if (TravelLogUnit.CommanderId.HasValue)
            {
                cmdrid = TravelLogUnit.CommanderId.Value;
                // System.Diagnostics.Trace.WriteLine(string.Format("TLU says commander {0} at {1}", cmdrid, TravelLogUnit.Name));
            }

            if (line.Length == 0)
            {
                return(null);
            }

            JournalEntry je = null;

            try
            {
                je = JournalEntry.CreateJournalEntry(line);
            }
            catch
            {
                System.Diagnostics.Trace.WriteLine($"Bad journal line:\n{line}");

                if (resetOnError)
                {
                    throw;
                }
                else
                {
                    return(null);
                }
            }

            if (je.EventTypeID == JournalTypeEnum.Fileheader)
            {
                JournalEvents.JournalFileheader header = (JournalEvents.JournalFileheader)je;

                if (header.Beta && !disable_beta_commander_check)
                {
                    TravelLogUnit.type |= 0x8000;
                }
            }
            else if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                string newname = (je as JournalEvents.JournalLoadGame).LoadGameCommander;

                if ((TravelLogUnit.type & 0x8000) == 0x8000)
                {
                    newname = "[BETA] " + newname;
                }

                EDCommander _commander = EDDiscovery2.EDDConfig.Instance.ListOfCommanders.FirstOrDefault(c => c.Name.Equals(newname, StringComparison.InvariantCultureIgnoreCase));

                if (_commander == null)
                {
                    if (EDDiscovery2.EDDConfig.Instance.ListOfCommanders.Count == 1 && EDDiscovery2.EDDConfig.Instance.ListOfCommanders[0].Name == "Jameson (Default)")
                    {
                        EDDiscovery2.EDDConfig.Instance.ListOfCommanders[0].Name     = newname;
                        EDDiscovery2.EDDConfig.Instance.ListOfCommanders[0].EdsmName = newname;
                        EDDiscovery2.EDDConfig.Instance.UpdateCommanders(EDDiscovery2.EDDConfig.Instance.ListOfCommanders); // replaces it
                    }
                    else
                    {
                        _commander = EDDiscovery2.EDDConfig.Instance.GetNewCommander(newname, null, EDJournalClass.GetDefaultJournalDir().Equals(TravelLogUnit.Path) ? "" : TravelLogUnit.Path);
                    }
                }

                cmdrid = _commander.Nr;

                if (!TravelLogUnit.CommanderId.HasValue)
                {
                    TravelLogUnit.CommanderId = cmdrid;
                    TravelLogUnit.Update();
                    System.Diagnostics.Trace.WriteLine(string.Format("TLU {0} updated with commander {1}", TravelLogUnit.Path, cmdrid));
                }
            }

            je.TLUId       = (int)TravelLogUnit.id;
            je.CommanderId = cmdrid;

            return(je);
        }
 public void UpdateCommandersListBox()
 {
     dataGridViewCommanders.DataSource = null;
     dataGridViewCommanders.DataSource = EDCommander.GetListCommanders();
     dataGridViewCommanders.Update();
 }
Esempio n. 10
0
        public override void Init()
        {
            BaseUtils.Translator.Instance.Translate(this);
            BaseUtils.Translator.Instance.Translate(toolTip, this);

            ResetThemeList();
            SetEntryThemeComboBox();

            textBoxHomeSystem.SetAutoCompletor(SystemCache.ReturnSystemAutoCompleteList, true);

            btnDeleteCommander.Enabled = EDCommander.NumberOfCommanders > 1;

            comboBoxClickThruKey.Items                 = KeyObjectExtensions.KeyListString(inclshifts: true);
            comboBoxClickThruKey.SelectedItem          = EDDConfig.Instance.ClickThruKey.VKeyToString();
            comboBoxClickThruKey.SelectedIndexChanged += comboBoxClickThruKey_SelectedIndexChanged;

            comboBoxCustomLanguage.Items.AddRange(BaseUtils.Translator.EnumerateLanguageNames(EDDOptions.Instance.TranslatorFolders()));

            comboBoxCustomLanguage.Items.Add("Auto");
            comboBoxCustomLanguage.Items.Add("Default (English)");
            if (comboBoxCustomLanguage.Items.Contains(EDDConfig.Instance.Language))
            {
                comboBoxCustomLanguage.SelectedItem = EDDConfig.Instance.Language;
            }
            else
            {
                comboBoxCustomLanguage.SelectedIndex = comboBoxCustomLanguage.Items.Count - 1;
            }
            comboBoxCustomLanguage.SelectedIndexChanged += ComboBoxCustomLanguage_SelectedIndexChanged;

            discoveryform.OnRefreshCommanders += DiscoveryForm_OnRefreshCommanders;

            checkBoxOrderRowsInverted.Checked    = EDDiscoveryForm.EDDConfig.OrderRowsInverted;
            checkBoxMinimizeToNotifyIcon.Checked = EDDiscoveryForm.EDDConfig.MinimizeToNotifyIcon;
            checkBoxKeepOnTop.Checked            = EDDiscoveryForm.EDDConfig.KeepOnTop;
            checkBoxPanelSortOrder.Checked       = EDDConfig.Instance.SortPanelsByName;
            checkBoxUseNotifyIcon.Checked        = EDDiscoveryForm.EDDConfig.UseNotifyIcon;
            checkBoxUTC.Checked          = EDDiscoveryForm.EDDConfig.DisplayUTC;
            checkBoxCustomResize.Checked = EDDiscoveryForm.EDDConfig.DrawDuringResize;

            checkBoxOrderRowsInverted.CheckedChanged    += checkBoxOrderRowsInverted_CheckedChanged;
            checkBoxMinimizeToNotifyIcon.CheckedChanged += checkBoxMinimizeToNotifyIcon_CheckedChanged;
            checkBoxKeepOnTop.CheckedChanged            += checkBoxKeepOnTop_CheckedChanged;
            checkBoxPanelSortOrder.CheckedChanged       += checkBoxPanelSortOrder_CheckedChanged;
            checkBoxUseNotifyIcon.CheckedChanged        += checkBoxUseNotifyIcon_CheckedChanged;
            checkBoxUTC.CheckedChanged          += checkBoxUTC_CheckedChanged;
            checkBoxCustomResize.CheckedChanged += checkBoxCustomResize_CheckedChanged;

            checkBoxMinimizeToNotifyIcon.Enabled = EDDiscoveryForm.EDDConfig.UseNotifyIcon;

            textBoxHomeSystem.Text = EDDConfig.Instance.HomeSystem.Name;

            textBoxDefaultZoom.ValueNoChange = EDDConfig.Instance.MapZoom;

            textBoxDefaultZoom.ValueChanged += textBoxDefaultZoom_ValueChanged;

            bool selectionCentre = EDDConfig.Instance.MapCentreOnSelection;

            radioButtonHistorySelection.Checked = selectionCentre;
            radioButtonCentreHome.Checked       = !selectionCentre;

            radioButtonCentreHome.CheckedChanged += radioButtonCentreHome_CheckedChanged;

            dataGridViewCommanders.AutoGenerateColumns = false;             // BEFORE assigned to list..
            dataGridViewCommanders.DataSource          = EDCommander.GetListCommanders();

            panel_defaultmapcolor.BackColor = Color.FromArgb(EDDConfig.Instance.DefaultMapColour);

            this.comboBoxTheme.SelectedIndexChanged += this.comboBoxTheme_SelectedIndexChanged;    // now turn on the handler..

            checkBoxCustomRemoveOriginals.Checked   = discoveryform.screenshotconverter.RemoveOriginal;
            checkBoxCustomMarkHiRes.Checked         = discoveryform.screenshotconverter.MarkHiRes;
            checkBoxCustomEnableScreenshots.Checked = discoveryform.screenshotconverter.AutoConvert;
            checkBoxCustomCopyToClipboard.Checked   = discoveryform.screenshotconverter.CopyToClipboard;

            this.checkBoxCustomRemoveOriginals.CheckedChanged   += new System.EventHandler(this.checkBoxCustomRemoveOriginals_CheckedChanged);
            this.checkBoxCustomMarkHiRes.CheckedChanged         += new System.EventHandler(this.checkBoxCustomMarkHiRes_CheckedChanged);
            this.checkBoxCustomEnableScreenshots.CheckedChanged += new System.EventHandler(this.checkBoxCustomEnableScreenshots_CheckedChanged);
            this.checkBoxCustomCopyToClipboard.CheckedChanged   += new System.EventHandler(this.checkBoxCustomCopyToClipboard_CheckedChanged);

            checkBoxCustomEDSMEDDBDownload.Checked              = EDDConfig.Instance.EDSMEDDBDownload;
            this.checkBoxCustomEDSMEDDBDownload.CheckedChanged += new System.EventHandler(this.checkBoxCustomEDSMDownload_CheckedChanged);

            comboBoxCustomHistoryLoadTime.Items = new string[] { "Disabled-Load All".Tx(this, "DLA"), ">7 days old".Tx(this), ">30 days old".Tx(this), ">60 days old".Tx(this), ">90 days old".Tx(this), ">180 days old".Tx(this), ">270 days old".Tx(this), "> 365 days old".Tx(this) };
            comboBoxCustomHistoryLoadTime.Tag   = new int[] { 0, 7, 30, 60, 90, 180, 270, 365 };
            int ix = Array.FindIndex(comboBoxCustomHistoryLoadTime.Tag as int[], x => x == EDDConfig.Instance.FullHistoryLoadDayLimit);

            comboBoxCustomHistoryLoadTime.SelectedIndex         = ix >= 0 ? ix : 0;
            comboBoxCustomHistoryLoadTime.SelectedIndexChanged += ComboBoxCustomHistoryLoadTime_SelectedIndexChanged;

            var eetn = new string[] { nameof(JournalEssentialEvents.EssentialEvents), nameof(JournalEssentialEvents.FullStatsEssentialEvents), nameof(JournalEssentialEvents.JumpScanEssentialEvents), nameof(JournalEssentialEvents.JumpEssentialEvents), nameof(JournalEssentialEvents.NoEssentialEvents) };

            comboBoxCustomEssentialEntries.Items = new string[] { "Scans,Cargo,Missions,State,Jumps etc".Tx(this, "ESM"), "All entries for Statistics".Tx(this, "FS"), "Jumps and Scans".Tx(this, "EJS"), "Jumps".Tx(this, "EJ"), "Nothing".Tx(this, "EN") };
            comboBoxCustomEssentialEntries.Tag   = eetn;
            ix = Array.FindIndex(eetn, x => x == EDDConfig.Instance.EssentialEventTypes);
            comboBoxCustomEssentialEntries.SelectedIndex         = ix >= 0 ? ix : 0;
            comboBoxCustomEssentialEntries.SelectedIndexChanged += ComboBoxCustomEssentialEntries_SelectedIndexChanged;
        }
Esempio n. 11
0
        private bool GetOutputSubFolder()
        {
            if (String.IsNullOrWhiteSpace(OutputFolder))
            {
                OutputFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Frontier Developments", "Elite Dangerous", "Converted");
            }

            switch (FolderFormatIndex)
            {
            case 1:         // system name
                OutputFolder += "\\" + SystemName.SafeFileString();
                break;

            case 2:         // "YYYY-MM-DD"
                OutputFolder += "\\" + Timestamp.ToString("yyyy-MM-dd");
                break;

            case 3:         // "DD-MM-YYYY"
                OutputFolder += "\\" + Timestamp.ToString("dd-MM-yyyy");
                break;

            case 4:         // "MM-DD-YYYY"
                OutputFolder += "\\" + Timestamp.ToString("MM-dd-yyyy");
                break;

            case 5:      //"YYYY-MM-DD Sysname",
                OutputFolder += "\\" + Timestamp.ToString("yyyy-MM-dd") + " " + SystemName.SafeFileString();
                break;

            case 6:      //"DD-MM-YYYY Sysname",
                OutputFolder += "\\" + Timestamp.ToString("dd-MM-yyyy") + " " + SystemName.SafeFileString();
                break;

            case 7:     //"MM-DD-YYYY Sysname"
                OutputFolder += "\\" + Timestamp.ToString("MM-dd-yyyy") + " " + SystemName.SafeFileString();
                break;

            case 8:     // CMDR name
                OutputFolder += "\\" + (EDCommander.GetCommander(CommanderID)?.Name ?? $"CmdrId{CommanderID}").SafeFileString();
                break;

            case 9:     // CMDR name at sysname
                OutputFolder += "\\" + (EDCommander.GetCommander(CommanderID)?.Name ?? $"CmdrId{CommanderID}").SafeFileString() + " at " + SystemName.SafeFileString();
                break;

            case 10:     // YYYY - MM - DD CMDR name at sysname
                OutputFolder += "\\" + Timestamp.ToString("yyyy-MM-dd") + " " +
                                (EDCommander.GetCommander(CommanderID)?.Name ?? $"CmdrId{CommanderID}").SafeFileString() + " at " + SystemName.SafeFileString();
                break;

            case 11:     // CMDR Name \ SystemName
                OutputFolder += "\\" + (EDCommander.GetCommander(CommanderID)?.Name ?? $"CmdrId{CommanderID}").SafeFileString() + "\\" + SystemName.SafeFileString();
                break;
            }

            if (!Directory.Exists(OutputFolder))
            {
                Directory.CreateDirectory(OutputFolder);
            }

            return(!(OutputFolder.Equals(InputFolder) && OutputExtension.Equals("." + InputExtension)));
        }
Esempio n. 12
0
        static private bool SendToEDSM(List <HistoryEntry> hl, EDCommander cmdr, out string errmsg)
        {
            EDSMClass edsm = new EDSMClass(cmdr);       // Ensure we use the commanders EDSM credentials.

            errmsg = null;

            List <JObject> entries = new List <JObject>();

            foreach (HistoryEntry he in hl)
            {
                JournalEntry je = he.journalEntry;

                if (je == null)
                {
                    je = JournalEntry.Get(he.Journalid);
                }

                JObject json = je.GetJson();
                RemoveCommonKeys(json);
                if (je.EventTypeID == JournalTypeEnum.FSDJump && json["FuelUsed"].Empty())
                {
                    json["_convertedNetlog"] = true;
                }
                if (json["StarPosFromEDSM"].Bool(false)) // Remove star pos from EDSM
                {
                    json.Remove("StarPos");
                }
                json.Remove("StarPosFromEDSM");
                json["_systemName"]        = he.System.Name;
                json["_systemCoordinates"] = new JArray(he.System.X, he.System.Y, he.System.Z);
                if (he.System.SystemAddress != null)
                {
                    json["_systemAddress"] = he.System.SystemAddress;
                }
                if (he.IsDocked)
                {
                    json["_stationName"] = he.StationName;
                    if (he.MarketID != null)
                    {
                        json["_stationMarketId"] = he.MarketID;
                    }
                }
                json["_shipId"] = he.ShipId;
                entries.Add(json);
            }

            List <JObject> results = edsm.SendJournalEvents(entries, out errmsg);

            if (results == null)
            {
                return(false);
            }
            else
            {
                using (var cn = new SQLiteConnectionUser(utc: true))
                {
                    using (var txn = cn.BeginTransaction())
                    {
                        for (int i = 0; i < hl.Count && i < results.Count; i++)
                        {
                            HistoryEntry he            = hl[i];
                            JObject      result        = results[i];
                            int          msgnr         = result["msgnum"].Int();
                            int          systemId      = result["systemId"].Int();
                            bool         systemCreated = result["systemCreated"].Bool();

                            if ((msgnr >= 100 && msgnr < 200) || msgnr == 500)
                            {
                                if (he.EntryType == JournalTypeEnum.FSDJump || he.EntryType == JournalTypeEnum.Location)
                                {
                                    if (systemId != 0)
                                    {
                                        he.System.EDSMID = systemId;
                                        JournalEntry.UpdateEDSMIDPosJump(he.Journalid, he.System, false, 0, cn, txn);
                                    }

                                    if (systemCreated)
                                    {
                                        he.SetFirstDiscover(true);
                                    }
                                }

                                he.SetEdsmSync(cn, txn);

                                if (msgnr == 500)
                                {
                                    System.Diagnostics.Trace.WriteLine($"Warning submitting event {he.Journalid} \"{he.EventSummary}\": {msgnr} {result["msg"].Str()}");
                                }
                            }
                            else
                            {
                                System.Diagnostics.Trace.WriteLine($"Error submitting event {he.Journalid} \"{he.EventSummary}\": {msgnr} {result["msg"].Str()}");
                            }
                        }

                        txn.Commit();
                    }
                }

                return(true);
            }
        }
Esempio n. 13
0
        public void NewJournalEntry(JournalEntry je)       // will be in UI thread
        {
            System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);

            if (je.EventTypeID == JournalTypeEnum.Screenshot)
            {
                JournalScreenshot ss = je as JournalScreenshot;
                System.Diagnostics.Trace.WriteLine("Journal Screenshot " + ss.Filename);

                string ssname = ss.Filename;

                if (ssname.StartsWith("\\ED_Pictures\\"))   // cut to basename for the ID
                {
                    ssname = ssname.Substring(13);
                }

                if (!JournalScreenshotted.ContainsKey(ssname)) // ensure no repeats
                {
                    JournalScreenshotted[ssname] = ss;         // record we processed it this way

                    invokeonui?.Invoke(cp => ProcessScreenshot(ss.Filename, ss.System, ss.Body, EDCommander.GetCommander(ss.CommanderId).Name ?? "Unknown", cp));

                    System.Diagnostics.Trace.WriteLine("Journal Screenshot over " + ss.Filename + " recorded as " + ssname);
                }
                else
                {
                    System.Diagnostics.Trace.WriteLine("Journal Screenshot repeat and ignored " + ss.Filename + " recorded as " + ssname);
                }
            }
        }
Esempio n. 14
0
        public void Entry(JournalEntry je, bool stored, bool recent)        // on UI thread. hooked into journal monitor and receives new entries.. Also call if you programatically add an entry
        {
            System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);

            if (je.EventTimeUTC >= lastutc)     // in case we get them fed in the wrong order, or during stored reply we have two playing, only take the latest one
            {
                System.Diagnostics.Debug.WriteLine("JE " + stored + ":" + recent + ":" + EDCommander.GetCommander(je.CommanderId).Name + ":" + je.EventTypeStr);

                if (je.CommanderId != currentcmdrnr)
                {
                    Reset(false);
                    currentcmdrnr             = je.CommanderId;
                    EDCommander.CurrentCmdrID = currentcmdrnr;
                }

                HistoryEntry he = HistoryEntry.FromJournalEntry(je, currenthe, false, out bool unusedjournalupdate);
                he.UpdateMaterials(je, currenthe);

                cashledger.Process(je);
                he.Credits = cashledger.CashTotal;

                he.UpdateMissionList(missionlistaccumulator.Process(je, he.System, he.WhereAmI));

                currenthe = he;
                lastutc   = je.EventTimeUTC;
                outfitting.Process(je);

                Tuple <ShipInformation, ModulesInStore> ret = shipinformationlist.Process(je, he.WhereAmI, he.System);
                he.UpdateShipInformation(ret.Item1);
                he.UpdateShipStoredModules(ret.Item2);

                NewEntry?.Invoke(he, stored, recent);
            }
            else
            {
                //System.Diagnostics.Debug.WriteLine("Rejected older JE " + stored + ":" + recent + ":" + EDCommander.GetCommander(je.CommanderId).Name + " " + je.EventTypeStr);
            }
        }