Exemplo n.º 1
0
		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;
		}
Exemplo n.º 2
0
 /// <summary>
 /// Save with showing a dialog
 /// </summary>
 /// <param name="surface"></param>
 /// <param name="captureDetails"></param>
 /// <returns>Path to filename</returns>
 public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
 {
     string returnValue = null;
     using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails))
     {
         DialogResult dialogResult = saveImageFileDialog.ShowDialog();
         if (dialogResult.Equals(DialogResult.OK))
         {
             try
             {
                 string fileNameWithExtension = saveImageFileDialog.FileNameWithExtension;
                 SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
                 if (conf.OutputFilePromptQuality)
                 {
                     QualityDialog qualityDialog = new QualityDialog(outputSettings);
                     qualityDialog.ShowDialog();
                 }
                 // TODO: For now we always overwrite, should be changed
                 Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
                 returnValue = fileNameWithExtension;
                 IniConfig.Save();
             }
             catch (ExternalException)
             {
                 MessageBox.Show(Language.GetFormattedString("error_nowriteaccess", saveImageFileDialog.FileName).Replace(@"\\", @"\"), Language.GetString("error"));
             }
         }
     }
     return returnValue;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Save with showing a dialog
 /// </summary>
 /// <param name="surface"></param>
 /// <param name="captureDetails"></param>
 /// <returns>Path to filename</returns>
 public static string SaveWithDialog(ISurface surface, ICaptureDetails captureDetails)
 {
     string returnValue = null;
     using (SaveImageFileDialog saveImageFileDialog = new SaveImageFileDialog(captureDetails))
     {
         DialogResult dialogResult = saveImageFileDialog.ShowDialog();
         if (dialogResult.Equals(DialogResult.OK))
         {
             try
             {
                 string fileNameWithExtension = saveImageFileDialog.FileNameWithExtension;
                 SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(FormatForFilename(fileNameWithExtension));
                 if (conf.OutputFilePromptQuality)
                 {
                     QualityDialog qualityDialog = new QualityDialog(outputSettings);
                     qualityDialog.ShowDialog();
                 }
                 // For now we always overwrite, should be changed
                 Save(surface, fileNameWithExtension, true, outputSettings, conf.OutputFileCopyPathToClipboard);
                 returnValue = fileNameWithExtension;
                 IniConfig.Save();
             }
             catch (ExternalException)
             {
                 MessageBox.Show(string.Format("Cannot save file to {0}.\r\nPlease check write accessibility of the selected storage location.",
                     saveImageFileDialog.FileName).Replace(@"\\", @"\"), "Error");
             }
         }
     }
     return returnValue;
 }