Esempio n. 1
0
        // called thru CallWithConverter in UI main class to give us a ScreenShotImageConverter
        // fileid may not be the whole name if picked up thru ss system - like \EDPICTURES\
        // ss is not null if it was a screenshot
        // return if original is left in place

        private bool ProcessScreenshot(string filenamepart, JournalScreenshot ss, ScreenShotImageConverter cp)
        {
            System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);  // UI thread

            var r = getcurinfo();

            string sysname  = (ss == null ? r.Item1 : ss.System) ?? "Unknown";
            string bodyname = (ss == null ? r.Item2 : ss.Body) ?? "Unknown";
            string cmdrname = (ss == null ? r.Item3 : EDCommander.GetCommander(ss.CommanderId)?.Name) ?? "Unknown";

            System.Diagnostics.Debug.WriteLine("Process {0} s={1} b={2} c={3}", filenamepart, sysname, bodyname, cmdrname);

            try
            {
                string filein = TryGetScreenshot(filenamepart, out Bitmap bmp, out DateTime timestamputc);

                if (filein != null)
                {
                    // return input filename now, output filename and size
                    var fs = cp.Convert(bmp, filein, timestamputc, outputfolder, bodyname, sysname, cmdrname, logit);

                    if (fs != null)
                    {
                        OnScreenshot?.Invoke(fs.Item1, fs.Item2, fs.Item3, ss);
                    }

                    return(cp.OriginalImageOption == ScreenShotImageConverter.OriginalImageOptions.Leave);
                }
                else
                {
                    logit(string.Format("Failed to read screenshot {0}", filenamepart));
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception watcher: " + ex.Message);
                System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace);
                logit("Error in executing image conversion, try another screenshot, check output path settings. (Exception ".T(EDTx.ScreenshotDirectoryWatcher_Excp) + ex.Message + ")");
            }
            return(false);
        }
Esempio n. 2
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  = "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.Nr;
                    }
                    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. 3
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.Nr;
                    }
                    else
                    {
                        ap.ReportError("Commander not found");
                    }

                    cmdname = sp.NextWord();
                }

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

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

                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);
        }
Esempio n. 4
0
 public EDSMLogFetcher(int cmdrid, Action <string> logline)
 {
     Commander = EDCommander.GetCommander(cmdrid);
     LogLine   = logline;
 }
        // helpers for above

        private bool UpdateOutputFolderWithSubFolder()
        {
            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) && OutputFileExtension.ToString().Equals(InputFileExtension.ToString())));
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        protected JournalReaderEntry 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);
            }

            JObject      jo = null;
            JournalEntry je = null;

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

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

            if (je == null)
            {
                System.Diagnostics.Trace.WriteLine($"Bad journal line:\n{line}");
                return(null);
            }

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

                if (header.Beta && !disable_beta_commander_check)
                {
                    TravelLogUnit.type |= 0x8000;
                }

                if (header.Part > 1)
                {
                    JournalEvents.JournalContinued contd = JournalEntry.GetLast <JournalEvents.JournalContinued>(je.EventTimeUTC.AddSeconds(1), e => e.Part == header.Part);

                    // Carry commander over from previous log if it ends with a Continued event.
                    if (contd != null && Math.Abs(header.EventTimeUTC.Subtract(contd.EventTimeUTC).TotalSeconds) < 5 && contd.CommanderId >= 0)
                    {
                        TravelLogUnit.CommanderId = contd.CommanderId;
                    }
                }
            }
            else if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                string newname = (je as JournalEvents.JournalLoadGame).LoadGameCommander;

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

                EDCommander _commander = EDCommander.GetCommander(newname);

                if (_commander == null)
                {
                    EDCommander onlyc = EDCommander.GetAll().FirstOrDefault();
                    if (EDCommander.NumberOfCommanders == 1 && onlyc != null && onlyc.Name == "Jameson (Default)")
                    {
                        onlyc.Name     = newname;
                        onlyc.EdsmName = newname;
                        EDCommander.Update(new List <EDCommander> {
                            onlyc
                        }, false);
                    }
                    else
                    {
                        _commander = EDCommander.Create(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(new JournalReaderEntry {
                JournalEntry = je, Json = jo
            });
        }
Esempio n. 8
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. 9
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);
                }
            }
        }