public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { ExportInformation exportInformation = new ExportInformation(Designation, Description); bool outputMade; bool overwrite; string fullPath; // Get output settings from the configuration SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(); if (captureDetails != null && captureDetails.Filename != null) { // As we save a pre-selected file, allow to overwrite. overwrite = true; LOG.InfoFormat("Using previous filename"); fullPath = captureDetails.Filename; outputSettings.Format = ImageOutput.FormatForFilename(fullPath); } else { fullPath = CreateNewFilename(captureDetails); // As we generate a file, the configuration tells us if we allow to overwrite overwrite = conf.OutputFileAllowOverwrite; } if (conf.OutputFilePromptQuality) { QualityDialog qualityDialog = new QualityDialog(outputSettings); qualityDialog.ShowDialog(); } // Catching any exception to prevent that the user can't write in the directory. // This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642 try { ImageOutput.Save(surface, fullPath, overwrite, outputSettings, conf.OutputFileCopyPathToClipboard); outputMade = true; } catch (ArgumentException ex1) { // Our generated filename exists, display 'save-as' LOG.InfoFormat("Not overwriting: {0}", ex1.Message); // when we don't allow to overwrite present a new SaveWithDialog fullPath = ImageOutput.SaveWithDialog(surface, captureDetails); outputMade = (fullPath != null); } catch (Exception ex2) { LOG.Error("Error saving screenshot!", ex2); // Show the problem MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error)); // when save failed we present a SaveWithDialog fullPath = ImageOutput.SaveWithDialog(surface, captureDetails); outputMade = (fullPath != null); } // Don't overwrite filename if no output is made if (outputMade) { exportInformation.ExportMade = outputMade; exportInformation.Filepath = fullPath; captureDetails.Filename = fullPath; conf.OutputFileAsFullpath = fullPath; } ProcessExport(exportInformation, surface); return(exportInformation); }
void SaveToolStripMenuItemClick(object sender, System.EventArgs e) { try { ImageOutput.Save(surface.GetImageForExport(), lastSaveFullPath); updateStatusLabel(lang.GetString("editor_imagesaved").Replace("%storagelocation%", lastSaveFullPath), fileSavedStatusContextMenu); } catch (System.Runtime.InteropServices.ExternalException) { MessageBox.Show(lang.GetString("error_nowriteaccess").Replace("%path%", lastSaveFullPath).Replace(@"\\", @"\"), lang.GetString("error")); } }
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { bool outputMade = false; string pattern = "${title}"; if (string.IsNullOrEmpty(pattern)) { pattern = "greenshot ${capturetime}"; } string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails); string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false); string fullPath = Path.Combine(filepath, filename); // Catching any exception to prevent that the user can't write in the directory. // This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642 using (Image image = surface.GetImageForExport()) { try { // TODO: For now we overwrite, but this should be fixed some time ImageOutput.Save(image, fullPath, true); outputMade = true; } catch (Exception e) { LOG.Error("Error saving screenshot!", e); // Show the problem MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error)); // when save failed we present a SaveWithDialog fullPath = ImageOutput.SaveWithDialog(image, captureDetails); outputMade = (fullPath != null); } } // Don't overwite filename if no output is made if (outputMade) { surface.LastSaveFullPath = fullPath; surface.Modified = false; captureDetails.Filename = fullPath; surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath)); } else { surface.SendMessageEvent(this, SurfaceMessageTyp.Info, ""); } return(outputMade); }
private void Save() { try { if (lastSaveFullPath != null) { ImageOutput.Save(surface.GetImageForExport(), lastSaveFullPath); updateStatusLabel("Image saved to %storagelocation%.".Replace("%storagelocation%", lastSaveFullPath), fileSavedStatusContextMenu); } else { SaveAs(); } } catch (System.Runtime.InteropServices.ExternalException ex) { MessageBox.Show(ex.Message); } }
void CaptureImage(Image img) { DoCaptureFeedback(); this.Hide(); string fullPath = null; ImageOutput.PrepareClipboardObject(); if ((conf.Output_Destinations & ScreenshotDestinations.FileDefault) == ScreenshotDestinations.FileDefault) { string filename = FilenameHelper.GetFilenameFromPattern(conf.Output_File_FilenamePattern, conf.Output_File_Format); fullPath = Path.Combine(conf.Output_File_Path, filename); ImageOutput.Save(img, fullPath); } if ((conf.Output_Destinations & ScreenshotDestinations.FileWithDialog) == ScreenshotDestinations.FileWithDialog) { fullPath = ImageOutput.SaveWithDialog(img); } if ((conf.Output_Destinations & ScreenshotDestinations.Clipboard) == ScreenshotDestinations.Clipboard) { ImageOutput.CopyToClipboard(img); } if ((conf.Output_Destinations & ScreenshotDestinations.Printer) == ScreenshotDestinations.Printer) { new PrintHelper(img).PrintWithDialog(); } if ((conf.Output_Destinations & ScreenshotDestinations.Editor) == ScreenshotDestinations.Editor) { ImageEditorForm editor = new ImageEditorForm(); editor.SetImage(img); if (fullPath != null) { editor.SetImagePath(fullPath); } editor.Show(); } }