private void CallWithConverter(Action <ScreenShotImageConverter> cb) // called by Watcher with a function to run in the UI main thread.. { if (discoveryform.InvokeRequired) // on discovery form UI thread, action.. { discoveryform.Invoke(new Action(() => CallWithConverter(cb))); } else { if (AutoConvert) { ScreenShotImageConverter p = new ScreenShotImageConverter(); p.InputFolder = ScreenshotsDir; p.OutputFolder = OutputDir; p.FolderFormatIndex = FolderNameFormat; p.FilenameFormatIndex = FileNameFormat; p.HighRes = MarkHiRes; p.CropImage = CropImage; p.CropArea = CropArea; p.RemoveInputFile = RemoveOriginal; p.OutputFileExtension = OutputFileExtension; p.InputFileExtension = InputFileExtension; p.CopyToClipboard = CopyToClipboard; System.Diagnostics.Debug.Assert(Application.MessageLoop); cb(p); // call the processor the system wants. Function needs an image converter. Back to processScreenshot } } }
public void Init(ScreenShotConverter cf, bool hires) { this.hires = hires; comboBoxOutputAs.Items.AddRange(Enum.GetNames(typeof(ScreenShotImageConverter.OutputTypes))); comboBoxOutputAs.SelectedIndex = (int)cf.OutputFileExtension; comboBoxScanFor.Items.AddRange(Enum.GetNames(typeof(ScreenShotImageConverter.InputTypes))); comboBoxScanFor.SelectedIndex = (int)cf.InputFileExtension; initialssfolder = textBoxScreenshotsDir.Text = cf.ScreenshotsDir; textBoxOutputDir.Text = cf.OutputDir; comboBoxSubFolder.Items.AddRange(ScreenShotImageConverter.SubFolderSelections); comboBoxSubFolder.SelectedIndex = cf.FolderNameFormat; comboBoxFileNameFormat.Items.AddRange(ScreenShotImageConverter.FileNameFormats); comboBoxFileNameFormat.SelectedIndex = cf.FileNameFormat; checkBoxCropImage.Checked = cf.CropImage; numericUpDownTop.Value = cf.CropArea.Top; numericUpDownLeft.Value = cf.CropArea.Left; numericUpDownWidth.Value = cf.CropArea.Width; numericUpDownHeight.Value = cf.CropArea.Height; SetNumEnabled(); textBoxFileNameExample.Text = ScreenShotImageConverter.CreateFileName("Sol", "Earth", "HighResScreenshot_0000.bmp", comboBoxFileNameFormat.SelectedIndex, hires, DateTime.Now); BaseUtils.Translator.Instance.Translate(this); label_index.Text = this.Text; }
public void Init(ScreenShotConverter cf, bool hires) { this.hires = hires; comboBoxOutputAs.Items.AddRange(Enum.GetNames(typeof(ScreenShotImageConverter.OutputTypes))); comboBoxOutputAs.SelectedIndex = (int)cf.OutputFileExtension; comboBoxScanFor.Items.AddRange(Enum.GetNames(typeof(ScreenShotImageConverter.InputTypes))); comboBoxScanFor.SelectedIndex = (int)cf.InputFileExtension; initialssfolder = textBoxScreenshotsDir.Text = cf.ScreenshotsDir; textBoxOutputDir.Text = cf.OutputDir; comboBoxSubFolder.Items.AddRange(ScreenShotImageConverter.SubFolderSelections); comboBoxSubFolder.SelectedIndex = cf.FolderNameFormat; comboBoxFileNameFormat.Items.AddRange(ScreenShotImageConverter.FileNameFormats); comboBoxFileNameFormat.SelectedIndex = cf.FileNameFormat; string[] opt = new string[] { "Off", "Crop", "Resize" }; extComboBoxConvert1.Items.AddRange(opt); extComboBoxConvert2.Items.AddRange(opt); extComboBoxConvert1.SelectedIndex = (int)cf.CropResize1; extComboBoxConvert2.SelectedIndex = (int)cf.CropResize2; extCheckBoxRemoveOriginal.Checked = cf.RemoveOriginal; extCheckBoxKeepMasterConvertedImage.Checked = cf.KeepMasterConvertedImage; numericUpDownTop1.Value = cf.CropResizeArea1.Top; numericUpDownLeft1.Value = cf.CropResizeArea1.Left; numericUpDownWidth1.Value = cf.CropResizeArea1.Width; numericUpDownHeight1.Value = cf.CropResizeArea1.Height; extNumericUpDownTop2.Value = cf.CropResizeArea2.Top; extNumericUpDownLeft2.Value = cf.CropResizeArea2.Left; extNumericUpDownWidth2.Value = cf.CropResizeArea2.Width; extNumericUpDownHeight2.Value = cf.CropResizeArea2.Height; SetNumEnabled(); extComboBoxConvert1.SelectedIndexChanged += (s, e) => { SetNumEnabled(); }; extComboBoxConvert2.SelectedIndexChanged += (s, e) => { SetNumEnabled(); }; textBoxFileNameExample.Text = ScreenShotImageConverter.CreateFileName("Sol", "Earth", "HighResScreenshot_0000.bmp", comboBoxFileNameFormat.SelectedIndex, hires, DateTime.Now); BaseUtils.Translator.Instance.Translate(this); label_index.Text = this.Text; }
private void ConvertCompleted(ScreenShotImageConverter cp) // Called by the watcher when a convert had completed, in UI thread { System.Diagnostics.Debug.Assert(Application.MessageLoop); if (cp.Converted && cp.CopyToClipboard) { using (Image bmp = Bitmap.FromFile(cp.OutputFilename)) { try { Clipboard.SetImage(bmp); } catch { discoveryform.LogLineHighlight("Copying image to clipboard failed"); } } } OnScreenShot?.Invoke(cp.OutputFilename, cp.FinalSize); }
private void comboBoxFileNameFormat_SelectedIndexChanged(object sender, EventArgs e) { textBoxFileNameExample.Text = ScreenShotImageConverter.CreateFileName("Sol", "Earth", "HighResScreenshot_0000.bmp", comboBoxFileNameFormat.SelectedIndex, hires, DateTime.Now); }
// 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 void ProcessFilesystemEvent(object sender, System.IO.FileSystemEventArgs e, ScreenShotImageConverter cp) // on UI thread { System.Diagnostics.Debug.Assert(System.Windows.Forms.Application.MessageLoop); int cmdrid = LastJournalCmdr; if (e.FullPath.ToLowerInvariant().EndsWith(".bmp")) { if (!ScreenshotTimers.ContainsKey(e.FullPath)) { System.Threading.Timer timer = new System.Threading.Timer(s => TimerTickedOut(e.FullPath, cmdrid), null, 5000, System.Threading.Timeout.Infinite); // Destroy the timer if OnScreenshot was run between the above check and adding the timer to the dictionary if (!ScreenshotTimers.TryAdd(e.FullPath, timer)) { timer.Dispose(); } } } else { ProcessScreenshot(e.FullPath, null, null, cmdrid, cp); } }