private void NewJournalEntry(JournalEntry je)       // will be in UI thread
        {
            if (je is JournalLocOrJump)
            {
                LastJournalCmdr = je.CommanderId;
                LastJournalLoc  = je as JournalLocOrJump;
            }
            else
            {
                if (je.CommanderId != LastJournalCmdr)
                {
                    LastJournalLoc  = null;
                    LastJournalCmdr = je.CommanderId;
                }
            }

            if (je.EventTypeID == JournalTypeEnum.Screenshot)
            {
                JournalScreenshot ss     = je as JournalScreenshot;
                string            ssname = ss.Filename;
                if (ssname.StartsWith("\\ED_Pictures\\"))
                {
                    ssname = ssname.Substring(13);
                }
                JournalScreenshotsByName[ssname] = ss;
                System.Diagnostics.Trace.WriteLine("Journal Screenshot logged " + ss.Filename);
                this.paramscallback?.Invoke(cp => ProcessScreenshot(ss.Filename, ss.System, ss, ss.CommanderId, cp));
                JournalScreenshotsByName[ssname] = null;
            }
        }
Exemple #2
0
        private void NewJournalEntry(JournalEntry je)
        {
            if (je is JournalLocOrJump)
            {
                LastJournalCmdr = je.CommanderId;
                LastJournalLoc  = je as JournalLocOrJump;
            }
            else
            {
                if (je.CommanderId != LastJournalCmdr)
                {
                    LastJournalLoc  = null;
                    LastJournalCmdr = je.CommanderId;
                }
            }

            if (je.EventTypeID == JournalTypeEnum.Screenshot)
            {
                JournalScreenshot ss       = je as JournalScreenshot;
                string            filename = GetScreenshotPath(ss);

                if (File.Exists(filename))
                {
                    this.paramscallback?.Invoke(cp => ProcessScreenshot(filename, ss.System, ss, ss.CommanderId, cp));
                }
            }
        }
        private void Display(HistoryEntry he, HistoryList hl)
        {
            if (he != null)
            {
                if (he.EntryType == EliteDangerousCore.JournalTypeEnum.Screenshot)
                {
                    JournalScreenshot ss = (JournalScreenshot)he.journalEntry;

                    JObject jo = ss.GetJson();
                    if (jo["EDDOutputFile"] != null && File.Exists(jo["EDDOutputFile"].Str()))
                    {
                        string store_name = jo["EDDOutputFile"].Str();
                        Point  size       = new Point(jo["EDDOutputWidth"].Int(), jo["EDDOutputHeight"].Int());

                        ScreenShot(store_name, size);
                    }
                    else if (jo["EDDInputFile"] != null && File.Exists(jo["EDDInputFile"].Str()))
                    {
                        string filename = jo["EDDInputFile"].Str();
                        ScreenShot(filename, new Point(ss.Width, ss.Height));
                    }
                    else
                    {
                        string filename = discoveryform.screenshotconverter.GetScreenshotPath(ss);

                        if (File.Exists(filename))
                        {
                            ScreenShot(filename, new Point(ss.Width, ss.Height));
                        }
                    }
                }
            }
        }
Exemple #4
0
        public override void Display(HistoryEntry he, HistoryList hl)
        {
            if (he != null)
            {
                if (he.EntryType == EliteDangerous.JournalTypeEnum.Screenshot)
                {
                    JournalScreenshot ss = (JournalScreenshot)he.journalEntry;

                    JObject jo = ss.GetJson();
                    if (jo["EDDOutputFile"] != null && File.Exists(JSONHelper.GetStringDef(jo["EDDOutputFile"])))
                    {
                        string store_name = JSONHelper.GetStringDef(jo["EDDOutputFile"]);
                        Point  size       = new Point(JSONHelper.GetInt(jo["EDDOutputWidth"]), JSONHelper.GetInt(jo["EDDOutputHeight"]));

                        ScreenShot(store_name, size);
                    }
                    else if (jo["EDDInputFile"] != null && File.Exists(JSONHelper.GetStringDef(jo["EDDInputFile"])))
                    {
                        string filename = JSONHelper.GetStringDef(jo["EDDInputFile"]);
                        ScreenShot(filename, new Point(ss.Width, ss.Height));
                    }
                    else
                    {
                        string filename = discoveryform.ImageHandler.GetScreenshotPath(ss);

                        if (File.Exists(filename))
                        {
                            ScreenShot(filename, new Point(ss.Width, ss.Height));
                        }
                    }
                }
            }
        }
Exemple #5
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);
                }
            }
        }
        private void OnNewEntry(HistoryEntry he, HistoryList hl)
        {
            last_he = he;
            if (last_he != null)
            {
                // hmm. not checking EDSM for scan data.. do we want to ? prob not.

                JournalScan sd = discoveryform.history.GetScans(he.System.Name).Where(sc => sc.BodyName == he.WhereAmI).FirstOrDefault();
                bodyRadius = sd?.nRadius;

                switch (he.journalEntry.EventTypeID)
                {
                case JournalTypeEnum.Screenshot:
                    JournalScreenshot js = he.journalEntry as JournalScreenshot;
                    latitude  = js.nLatitude;
                    longitude = js.nLongitude;
                    break;

                case JournalTypeEnum.Touchdown:
                    JournalTouchdown jt = he.journalEntry as JournalTouchdown;
                    if (jt.PlayerControlled.HasValue && jt.PlayerControlled.Value)
                    {
                        latitude  = jt.Latitude;
                        longitude = jt.Longitude;
                    }
                    break;

                case JournalTypeEnum.Location:
                    JournalLocation jl = he.journalEntry as JournalLocation;
                    latitude  = jl.Latitude;
                    longitude = jl.Longitude;
                    break;

                case JournalTypeEnum.Liftoff:
                    JournalLiftoff jlo = he.journalEntry as JournalLiftoff;
                    if (jlo.PlayerControlled.HasValue && jlo.PlayerControlled.Value)
                    {
                        latitude  = jlo.Latitude;
                        longitude = jlo.Longitude;
                    }
                    break;

                case JournalTypeEnum.LeaveBody:
                    latitude  = null;
                    longitude = null;
                    break;

                case JournalTypeEnum.FSDJump:           // to allow us to do PopulateBookmark..
                    break;

                default:
                    return;
                }

                PopulateBookmarkCombo();
                DisplayCompass();
            }
        }
        private void TimerTickedOut(string filename, int cmdrid)   // timer is executed on a background thread, go back to UI
        {
            string            basename = Path.GetFileName(filename);
            JournalScreenshot ss       = null;

            JournalScreenshotsByName.TryGetValue(basename, out ss);

            this.paramscallback?.Invoke(cp => ProcessScreenshot(filename, ss?.System, ss, cmdrid, cp)); //process on UI thread
        }
Exemple #8
0
        private void Display(HistoryEntry he, HistoryList hl)
        {
            last_he = he;
            if (last_he != null)
            {
                JournalScan sd = discoveryform.history.GetScans(he.System.Name).Where(sc => sc.BodyName == he.WhereAmI).FirstOrDefault();
                bodyRadius = sd?.nRadius;

                switch (he.journalEntry.EventTypeID)
                {
                case JournalTypeEnum.Screenshot:
                    JournalScreenshot js = he.journalEntry as JournalScreenshot;
                    latitude  = js.nLatitude;
                    longitude = js.nLongitude;
                    break;

                case JournalTypeEnum.Touchdown:
                    JournalTouchdown jt = he.journalEntry as JournalTouchdown;
                    if (jt.PlayerControlled.HasValue && jt.PlayerControlled.Value)
                    {
                        latitude  = jt.Latitude;
                        longitude = jt.Longitude;
                    }
                    break;

                case JournalTypeEnum.Location:
                    JournalLocation jl = he.journalEntry as JournalLocation;
                    latitude  = jl.Latitude;
                    longitude = jl.Longitude;
                    break;

                case JournalTypeEnum.Liftoff:
                    JournalLiftoff jlo = he.journalEntry as JournalLiftoff;
                    if (jlo.PlayerControlled.HasValue && jlo.PlayerControlled.Value)
                    {
                        latitude  = jlo.Latitude;
                        longitude = jlo.Longitude;
                    }
                    break;

                case JournalTypeEnum.LeaveBody:
                    latitude  = null;
                    longitude = null;
                    break;

                default:
                    return;
                }
                Display();
            }
        }
Exemple #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.StartsWith("\\ED_Pictures\\") ? ss.Filename.Substring(13) : ss.Filename;
                invokeonui?.Invoke(cp =>
                {
                    bool leftinplace = ProcessScreenshot(ss.Filename, ss, cp);
                    if (leftinplace)
                    {
                        journalScreenshotted[ssname] = ss;          // if we leave the file behind, tell the file watcher we have done it
                    }
                });
            }
        }
Exemple #10
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);
        }
Exemple #11
0
        public string GetScreenshotPath(JournalScreenshot ss)
        {
            string filename = ss.Filename;

            if (filename.StartsWith("\\ED_Pictures\\"))
            {
                filename = filename.Substring(13);
                string filepath = Path.Combine(watchedfolder ?? EDPicturesDir, filename);

                if (!File.Exists(filepath))
                {
                    filepath = Path.Combine(EDPicturesDir, filename);
                }

                if (File.Exists(filepath))
                {
                    filename = filepath;
                }
            }

            return(filename);
        }
        public string GetScreenshotPath(JournalScreenshot ss)       // helper to find path for screenshots
        {
            string filename        = ss.Filename;
            string defaultInputDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Frontier Developments", "Elite Dangerous");

            if (filename.StartsWith("\\ED_Pictures\\"))
            {
                filename = filename.Substring(13);
                string filepath = Path.Combine(ScreenshotsDir ?? defaultInputDir, filename);

                if (!File.Exists(filepath))
                {
                    filepath = Path.Combine(defaultInputDir, filename);
                }

                if (File.Exists(filepath))
                {
                    filename = filepath;
                }
            }

            return(filename);
        }
        // called thru CalLWithConverter in UI main class.. that pases a ImageConverter to us
        // sysname and or ss can be null if it was picked up by a watcher not the new journal screenshot entry

        private void ProcessScreenshot(string filename, string sysname, JournalScreenshot ss, int cmdrid, ScreenShotImageConverter cp)
        {
            System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop);  // UI thread

            System.Threading.Timer timer = null;

            if (sysname == null)
            {
                if (LastJournalLoc != null)
                {
                    sysname = LastJournalLoc.StarSystem;
                }
                else if (cmdrid >= 0)
                {
                    LastJournalLoc = JournalEntry.GetLast <JournalLocOrJump>(cmdrid, DateTime.UtcNow);
                    if (LastJournalLoc != null)
                    {
                        sysname = LastJournalLoc.StarSystem;
                    }
                }
            }

            if (sysname == null)
            {
                HistoryEntry he = discoveryform.history.GetLast;
                sysname = (he != null) ? he.System.Name : "Unknown System";
            }

            try
            {
                cp.InputFilename     = filename;
                cp.SystemName        = sysname;
                cp.JournalScreenShot = ss;
                cp.CommanderID       = cmdrid;

                bool converted = false;

                using (Bitmap bmp = cp.GetScreenshot(ref filename, discoveryform.LogLine))
                {
                    // Don't run if OnScreenshot has already run for this image
                    if ((ScreenshotTimers.TryGetValue(filename, out timer) && timer == null) || (!ScreenshotTimers.TryAdd(filename, null) && !ScreenshotTimers.TryUpdate(filename, null, timer)))
                    {
                        return;
                    }

                    if (timer != null)
                    {
                        timer.Dispose();
                    }

                    converted = cp.Convert(bmp, discoveryform.LogLine);
                }

                if (converted && cp.RemoveOriginal)         // if remove, delete original picture
                {
                    ScreenshotTimers.TryRemove(filename, out timer);

                    try
                    {
                        File.Delete(filename);
                    }
                    catch
                    {
                        System.Diagnostics.Trace.WriteLine($"Unable to remove file {filename}");
                    }
                }

                this.OnScreenshot?.Invoke(cp);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception watcher: " + ex.Message);
                System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace);


                discoveryform.LogLineHighlight("Error in executing image conversion, try another screenshot, check output path settings. (Exception ".T(EDTx.ScreenshotDirectoryWatcher_Excp) + ex.Message + ")");
            }
        }
        private bool TryGetScreenshot(string filename, string cur_sysname, ref int cmdrid, ref JournalScreenshot ss, ref string store_name, ref Point finalsize, ref DateTime timestamp, out Bitmap bmp, out string readfilename, Action <string> logit, bool throwOnError = false)
        {
            string defaultInputDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "Frontier Developments", "Elite Dangerous");

            if (filename.StartsWith("\\ED_Pictures\\"))
            {
                filename = filename.Substring(13);
                string filepath = Path.Combine(InputFolder ?? defaultInputDir, filename);

                if (!File.Exists(filepath))
                {
                    filepath = Path.Combine(defaultInputDir, filename);
                }

                if (File.Exists(filepath))
                {
                    filename = filepath;
                }
            }

            bmp = null;

            try
            {
                using (FileStream testfile = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))        // throws if can't open
                {
                    timestamp = new FileInfo(filename).CreationTimeUtc;
                    MemoryStream memstrm = new MemoryStream(); // will be owned by bitmap
                    testfile.CopyTo(memstrm);
                    memstrm.Seek(0, SeekOrigin.Begin);
                    bmp = new Bitmap(memstrm);

                    if (ss == null)
                    {
                        ss = JournalScreenshot.GetScreenshot(filename, bmp.Size.Width, bmp.Size.Height, timestamp, cur_sysname == "Unknown System" ? null : cur_sysname, cmdrid);
                    }

                    if (ss != null)
                    {
                        string ss_infile  = null;
                        string ss_outfile = null;
                        int    ss_width   = 0;
                        int    ss_height  = 0;
                        ss.GetConvertedFilename(out ss_infile, out ss_outfile, out ss_width, out ss_height);
                        JObject jo = ss.GetJson();
                        if (ss_outfile != null && File.Exists(ss_outfile))
                        {
                            store_name = ss_outfile;
                            finalsize  = new Point(ss_width, ss_height);
                        }
                    }

                    readfilename = filename;
                    cmdrid       = ss.CommanderId;
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (bmp != null)
                {
                    bmp.Dispose();
                }

                if (throwOnError)
                {
                    logit(string.Format("Unable to open screenshot '{0}': {1}".Tx(this, "ERRF"), filename, ex.Message));
                    throw;
                }

                readfilename = null;
                return(false);
            }
        }
        private Bitmap GetScreenshot(string inputfile, string cur_sysname, ref int cmdrid, ref JournalScreenshot ss, ref string store_name, ref Point finalsize, ref DateTime timestamp, ref string readfilename, Action <string> logit)
        {
            Bitmap bmp = null;

            for (int tries = 60; tries > 0; tries--)          // wait 30 seconds and then try it anyway.. 32K hires shots take a while to write.
            {
                if (TryGetScreenshot(inputfile, cur_sysname, ref cmdrid, ref ss, ref store_name, ref finalsize, ref timestamp, out bmp, out readfilename, logit, false))
                {
                    break;
                }

                System.Threading.Thread.Sleep(500);     // every 500ms see if we can read the file, if we can, go, else wait..
            }

            if (bmp == null)
            {
                TryGetScreenshot(inputfile, cur_sysname, ref cmdrid, ref ss, ref store_name, ref finalsize, ref timestamp, out bmp, out readfilename, logit, true);
            }

            return(bmp);
        }
Exemple #16
0
 public string GetScreenshotPath(JournalScreenshot ss)
 {
     return(Watcher.GetScreenshotPath(ss));
 }
Exemple #17
0
        private async void OnNewEntry(HistoryEntry he, HistoryList hl)
        {
            last_he = he;
            if (last_he != null)
            {
                if (bodyRadius == null || lastradiusbody != he.WhereAmI)                                                  // try and get radius, this is cleared on target selection
                {
                    StarScan.SystemNode last_sn = await discoveryform.history.StarScan.FindSystemAsync(he.System, false); // find scan if we have one

                    JournalScan sd = last_sn?.Find(he.WhereAmI)?.ScanData;                                                // find body scan data if present, null if not
                    bodyRadius = sd?.nRadius;
                    if (bodyRadius.HasValue)
                    {
                        lastradiusbody = he.WhereAmI;
                        System.Diagnostics.Debug.WriteLine("Compass Radius Set " + lastradiusbody + " " + bodyRadius.Value);
                    }
                }

                switch (he.journalEntry.EventTypeID)
                {
                case JournalTypeEnum.Screenshot:
                    JournalScreenshot js = he.journalEntry as JournalScreenshot;
                    latitude  = js.nLatitude;
                    longitude = js.nLongitude;
                    altitude  = js.nAltitude;
                    break;

                case JournalTypeEnum.Touchdown:
                    JournalTouchdown jt = he.journalEntry as JournalTouchdown;
                    if (jt.PlayerControlled.HasValue && jt.PlayerControlled.Value)
                    {
                        latitude  = jt.Latitude;
                        longitude = jt.Longitude;
                        altitude  = 0;
                    }
                    break;

                case JournalTypeEnum.Location:
                    JournalLocation jl = he.journalEntry as JournalLocation;
                    latitude  = jl.Latitude;
                    longitude = jl.Longitude;
                    altitude  = null;
                    break;

                case JournalTypeEnum.Liftoff:
                    JournalLiftoff jlo = he.journalEntry as JournalLiftoff;
                    if (jlo.PlayerControlled.HasValue && jlo.PlayerControlled.Value)
                    {
                        latitude  = jlo.Latitude;
                        longitude = jlo.Longitude;
                        altitude  = 0;
                    }
                    break;

                case JournalTypeEnum.LeaveBody:
                    latitude  = null;
                    longitude = null;
                    altitude  = null;
                    break;

                case JournalTypeEnum.FSDJump:           // to allow us to do PopulateBookmark..
                case JournalTypeEnum.CarrierJump:
                    break;

                default:
                    return;
                }

                PopulateBookmarkCombo();
                DisplayCompass();
            }
        }
Exemple #18
0
        private Bitmap GetScreenshot(string inputfile, string cur_sysname, int cmdrid, ref JournalScreenshot ss, ref string store_name, ref Point finalsize, ref FileInfo fi)
        {
            FileStream   testfile = null;
            MemoryStream memstrm  = new MemoryStream();
            Bitmap       bmp      = null;

            for (int tries = 60; tries-- > 0;)          // wait 30 seconds and then try it anyway.. 32K hires shots take a while to write.
            {
                System.Threading.Thread.Sleep(500);     // every 500ms see if we can read the file, if we can, go, else wait..
                try
                {
                    //Console.WriteLine("Trying " + inputfile);
                    using (testfile = File.Open(inputfile, FileMode.Open, FileAccess.Read, FileShare.Read))        // throws if can't open
                    {
                        memstrm.SetLength(0);
                        testfile.CopyTo(memstrm);
                        memstrm.Seek(0, SeekOrigin.Begin);
                        bmp = new Bitmap(memstrm);
                    }
                    //Console.WriteLine("Worked " + inputfile);
                    break;
                }
                catch
                {
                }
            }

            try
            {
                //Console.WriteLine("Trying " + inputfile);
                using (testfile = File.Open(inputfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))        // throws if can't open
                {
                    memstrm.SetLength(0);
                    testfile.CopyTo(memstrm);
                    memstrm.Seek(0, SeekOrigin.Begin);
                    bmp = new Bitmap(memstrm);
                }
                //Console.WriteLine("Worked " + inputfile);
            }
            catch (Exception ex)
            {
                Controller.LogLineHighlight($"Unable to open screenshot '{inputfile}': {ex.Message}");
                throw;
            }

            try
            {
                fi = new FileInfo(inputfile);
                if (ss == null)
                {
                    ss = JournalScreenshot.GetScreenshot(inputfile, bmp.Size.Width, bmp.Size.Height, fi.CreationTimeUtc, cur_sysname == "Unknown System" ? null : cur_sysname, cmdrid);
                }

                if (ss != null)
                {
                    JObject jo = ss.GetJson();
                    if (jo["EDDOutputFile"] != null && File.Exists(JSONHelper.GetStringDef(jo["EDDOutputFile"])))
                    {
                        store_name = JSONHelper.GetStringDef(jo["EDDOutputFile"]);
                        finalsize  = new Point(JSONHelper.GetInt(jo["EDDOutputWidth"]), JSONHelper.GetInt(jo["EDDOutputHeight"]));
                    }
                }
            }
            catch
            {
                bmp.Dispose();
                throw;
            }

            return(bmp);
        }