示例#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);
        }