public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            string            tmpFile           = captureDetails.Filename;

            if (tmpFile == null || surface.Modified || !Regex.IsMatch(tmpFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
            }
            if (documentCaption != null)
            {
                try {
                    WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
                    exportInformation.ExportMade = true;
                } catch (Exception) {
                    try {
                        WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
                        exportInformation.ExportMade = true;
                    } catch (Exception ex) {
                        LOG.Error(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description));
                    }
                }
            }
            else
            {
                if (!manuallyInitiated)
                {
                    List <string> documents = WordExporter.GetWordDocuments();
                    if (documents != null && documents.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new WordDestination());
                        foreach (string document in documents)
                        {
                            destinations.Add(new WordDestination(document));
                        }
                        // Return the ExportInformation from the picker without processing, as this indirectly comes from us self
                        return(ShowPickerMenu(false, surface, captureDetails, destinations));
                    }
                }
                try {
                    WordExporter.InsertIntoNewDocument(tmpFile, null, null);
                    exportInformation.ExportMade = true;
                } catch (Exception) {
                    // Retry once, just in case
                    try {
                        WordExporter.InsertIntoNewDocument(tmpFile, null, null);
                        exportInformation.ExportMade = true;
                    } catch (Exception ex) {
                        LOG.Error(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetFormattedString("destination_exportfailed", Description));
                    }
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Export the capture to outlook
        /// </summary>
        /// <param name="manuallyInitiated"></param>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        /// <returns></returns>
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            // Outlook logic
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified || !Regex.IsMatch(tmpFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
            }
            else
            {
                LOG.InfoFormat("Using already available file: {0}", tmpFile);
            }

            // Create a attachment name for the image
            string attachmentName = captureDetails.Title;

            if (!string.IsNullOrEmpty(attachmentName))
            {
                attachmentName = attachmentName.Trim();
            }
            // Set default if non is set
            if (string.IsNullOrEmpty(attachmentName))
            {
                attachmentName = "Greenshot Capture";
            }
            // Make sure it's "clean" so it doesn't corrupt the header
            attachmentName = Regex.Replace(attachmentName, @"[^\x20\d\w]", "");

            if (outlookInspectorCaption != null)
            {
                OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName);
                exportInformation.ExportMade = true;
            }
            else
            {
                if (!manuallyInitiated)
                {
                    IDictionary <string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets();
                    if (inspectorCaptions != null && inspectorCaptions.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new OutlookDestination());
                        foreach (string inspectorCaption in inspectorCaptions.Keys)
                        {
                            destinations.Add(new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
                        }
                        // Return the ExportInformation from the picker without processing, as this indirectly comes from us self
                        return(ShowPickerMenu(false, surface, captureDetails, destinations));
                    }
                }
                else
                {
                    exportInformation.ExportMade = OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC, null);
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Ejemplo n.º 3
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            base.SetDefaults(surface);
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            bool   createdFile = false;
            string imageFile   = captureDetails.Filename;

            if (imageFile == null || surface.Modified || !Regex.IsMatch(imageFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                imageFile   = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
                createdFile = true;
            }
            if (_workbookName != null)
            {
                ExcelExporter.InsertIntoExistingWorkbook(_workbookName, imageFile, surface.Image.Size);
            }
            else
            {
                ExcelExporter.InsertIntoNewWorkbook(imageFile, surface.Image.Size);
            }
            exportInformation.ExportMade = true;
            ProcessExport(exportInformation, surface);
            // Cleanup imageFile if we created it here, so less tmp-files are generated and left
            if (createdFile)
            {
                ImageOutput.DeleteNamedTmpFile(imageFile);
            }
            return(exportInformation);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Place the bitmap as HTML on the clipboard
        /// </summary>
        /// <param name="clipboardAccessToken">IClipboardAccessToken</param>
        /// <param name="surface">ISurface</param>
        public static void SetAsHtml(this IClipboardAccessToken clipboardAccessToken, ISurface surface)
        {
            var pngOutputSettings = new SurfaceOutputSettings(OutputFormats.png, 100, false);
            // This file is automatically deleted when Greenshot exits.
            var filename = ImageOutput.SaveNamedTmpFile(surface, surface.CaptureDetails, pngOutputSettings);
            // Set the PNG stream
            var htmlText = GenerateHtmlString(new NativeSize(surface.Width, surface.Height), filename);

            clipboardAccessToken.SetAsHtml(htmlText);
        }
Ejemplo n.º 5
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();


            if (presetCommand != null)
            {
                bool   runInBackground = presetCommand.RunInBackground;
                string fullPath        = captureDetails.Filename;
                if (fullPath == null)
                {
                    fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings);
                }

                string output = null;
                if (runInBackground)
                {
                    Thread commandThread = new Thread(delegate() {
                        CallExternalCommand(presetCommand, fullPath, out output);
                    });
                    commandThread.Name         = "Running " + presetCommand;
                    commandThread.IsBackground = true;
                    commandThread.Start();
                    exportInformation.ExportMade = true;
                }
                else
                {
                    try {
                        if (CallExternalCommand(presetCommand, fullPath, out output) == 0)
                        {
                            exportInformation.ExportMade = true;
                        }
                        else
                        {
                            exportInformation.ErrorMessage = output;
                        }
                    } catch (Exception ex) {
                        exportInformation.ErrorMessage = ex.Message;
                    }
                }

                //exportInformation.Uri = "file://" + fullPath;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
Ejemplo n.º 6
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(Designation, Description);
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();

            outputSettings.PreventGreenshotFormat();

            if (_presetCommand != null)
            {
                if (!config.RunInbackground.ContainsKey(_presetCommand))
                {
                    config.RunInbackground.Add(_presetCommand, true);
                }
                bool   runInBackground = config.RunInbackground[_presetCommand];
                string fullPath        = captureDetails.Filename;
                if (fullPath == null)
                {
                    fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings);
                }

                string output;
                string error;
                if (runInBackground)
                {
                    Thread commandThread = new Thread(delegate()
                    {
                        CallExternalCommand(exportInformation, fullPath, out output, out error);
                        ProcessExport(exportInformation, surface);
                    })
                    {
                        Name         = "Running " + _presetCommand,
                        IsBackground = true
                    };
                    commandThread.SetApartmentState(ApartmentState.STA);
                    commandThread.Start();
                    exportInformation.ExportMade = true;
                }
                else
                {
                    CallExternalCommand(exportInformation, fullPath, out output, out error);
                    ProcessExport(exportInformation, surface);
                }
            }
            return(exportInformation);
        }
Ejemplo n.º 7
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);
            var outputSettings    = new SurfaceOutputSettings();

            outputSettings.PreventGreenshotFormat();

            if (_presetCommand != null)
            {
                if (!Config.RunInbackground.ContainsKey(_presetCommand))
                {
                    Config.RunInbackground.Add(_presetCommand, true);
                }
                var runInBackground = Config.RunInbackground[_presetCommand];
                var fullPath        = captureDetails.Filename;
                if (fullPath == null)
                {
                    fullPath = ImageOutput.SaveNamedTmpFile(surface, captureDetails, outputSettings);
                }

                if (runInBackground)
                {
                    var commandThread = new Thread(() =>
                    {
                        CallExternalCommand(exportInformation, fullPath, out _, out _);
                        ProcessExport(exportInformation, surface);
                    })
                    {
                        Name         = "Running " + _presetCommand,
                        IsBackground = true
                    };
                    commandThread.SetApartmentState(ApartmentState.STA);
                    commandThread.Start();
                    exportInformation.ExportMade = true;
                }
                else
                {
                    CallExternalCommand(exportInformation, fullPath, out _, out _);
                    ProcessExport(exportInformation, surface);
                }
            }
            return(exportInformation);
        }
Ejemplo n.º 8
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            base.SetDefaults(surface);
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            string            tmpFile           = captureDetails.Filename;
            Size imageSize = Size.Empty;

            if (tmpFile == null || surface.Modified || !Regex.IsMatch(tmpFile, @".*(\.png|\.gif|\.jpg|\.jpeg|\.tiff|\.bmp)$"))
            {
                tmpFile   = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings().PreventGreenshotFormat());
                imageSize = surface.Image.Size;
            }
            if (_presentationName != null)
            {
                exportInformation.ExportMade = PowerpointExporter.ExportToPresentation(_presentationName, tmpFile, imageSize, captureDetails.Title);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    var presentations = PowerpointExporter.GetPowerpointPresentations();
                    if (presentations != null && presentations.Count > 0)
                    {
                        var destinations = new List <IDestination> {
                            new PowerpointDestination()
                        };
                        foreach (string presentation in presentations)
                        {
                            destinations.Add(new PowerpointDestination(presentation));
                        }
                        // Return the ExportInformation from the picker without processing, as this indirectly comes from us self
                        return(ShowPickerMenu(false, surface, captureDetails, destinations));
                    }
                }
                else if (!exportInformation.ExportMade)
                {
                    exportInformation.ExportMade = PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile   = captureDetails.Filename;
            Size   imageSize = Size.Empty;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile   = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                    imageSize = image.Size;
                }
            }
            if (presentationName != null)
            {
                PowerpointExporter.ExportToPresentation(presentationName, tmpFile, imageSize, captureDetails.Title);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    List <string> presentations = PowerpointExporter.GetPowerpointPresentations();
                    if (presentations != null && presentations.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new PowerpointDestination());
                        foreach (string presentation in presentations)
                        {
                            destinations.Add(new PowerpointDestination(presentation));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return(false);
                    }
                }
                PowerpointExporter.InsertIntoNewPresentation(tmpFile, imageSize, captureDetails.Title);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;
            return(true);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            if (documentCaption != null)
            {
                WordExporter.InsertIntoExistingDocument(documentCaption, tmpFile);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    List <string> documents = WordExporter.GetWordDocuments();
                    if (documents != null && documents.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new WordDestination());
                        foreach (string document in documents)
                        {
                            destinations.Add(new WordDestination(document));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return(false);
                    }
                }
                WordExporter.InsertIntoNewDocument(tmpFile);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;

            return(true);
        }
Ejemplo n.º 11
0
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            if (workbookName != null)
            {
                ExcelExporter.InsertIntoExistingWorkbook(workbookName, tmpFile);
            }
            else
            {
                ExcelExporter.InsertIntoNewWorkbook(tmpFile);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;
            return(true);
        }
        public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            if (!isOutlookUsed)
            {
                using (Image image = surface.GetImageForExport()) {
                    MapiMailMessage.SendImage(image, captureDetails);
                    surface.Modified = false;
                    surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to " + mapiClient);
                }
                return(true);
            }

            // Outlook logic
            string tmpFile = captureDetails.Filename;

            if (tmpFile == null || surface.Modified)
            {
                using (Image image = surface.GetImageForExport()) {
                    tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, conf.OutputFileFormat, conf.OutputFileJpegQuality, conf.OutputFileReduceColors);
                }
            }
            else
            {
                LOG.InfoFormat("Using already available file: {0}", tmpFile);
            }

            // Create a attachment name for the image
            string attachmentName = captureDetails.Title;

            if (!string.IsNullOrEmpty(attachmentName))
            {
                attachmentName = attachmentName.Trim();
            }
            // Set default if non is set
            if (string.IsNullOrEmpty(attachmentName))
            {
                attachmentName = "Greenshot Capture";
            }
            // Make sure it's "clean" so it doesn't corrupt the header
            attachmentName = Regex.Replace(attachmentName, @"[^\x20\d\w]", "");

            if (outlookInspectorCaption != null)
            {
                OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName);
            }
            else
            {
                if (!manuallyInitiated)
                {
                    Dictionary <string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings);
                    if (inspectorCaptions != null && inspectorCaptions.Count > 0)
                    {
                        List <IDestination> destinations = new List <IDestination>();
                        destinations.Add(new EmailDestination());
                        foreach (string inspectorCaption in inspectorCaptions.Keys)
                        {
                            destinations.Add(new EmailDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
                        }
                        ContextMenuStrip menu = PickerDestination.CreatePickerMenu(false, surface, captureDetails, destinations);
                        PickerDestination.ShowMenuAtCursor(menu);
                        return(false);
                    }
                }
                OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, captureDetails.Title, attachmentName);
            }
            surface.SendMessageEvent(this, SurfaceMessageTyp.Info, Language.GetFormattedString(LangKey.exported_to, Description));
            surface.Modified = false;

            // Don't know how to handle a cancel in the email

            return(true);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Write the ISurface to the specified stream by using the supplied IFileConfiguration
        /// </summary>
        /// <param name="surface">ISurface</param>
        /// <param name="fileConfiguration">IFileConfiguration</param>
        /// <param name="destinationFileConfiguration">IDestinationFileConfiguration</param>
        public static string SaveNamedTmpFile(this ISurface surface, IFileConfiguration fileConfiguration, IDestinationFileConfiguration destinationFileConfiguration = null)
        {
            var outputSettings = surface.GenerateOutputSettings(fileConfiguration.Choose(destinationFileConfiguration));

            return(ImageOutput.SaveNamedTmpFile(surface, surface.CaptureDetails, outputSettings));
        }