예제 #1
0
        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));
                        }
                    }
                }
            }
        }
예제 #2
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));
                        }
                    }
                }
            }
        }
        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);
            }
        }
예제 #4
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);
        }