/// <summary>
        /// Fill the pattern wit the supplied details
        /// </summary>
        /// <param name="pattern">Pattern</param>
        /// <param name="captureDetails">CaptureDetails</param>
        /// <param name="filenameSafeMode">Should the result be made "filename" safe?</param>
        /// <returns>Filled pattern</returns>
        public static string FillPattern(string pattern, ICaptureDetails captureDetails, bool filenameSafeMode)
        {
            IDictionary processVars = null;
            IDictionary userVars = null;
            IDictionary machineVars = null;
            try {
                processVars = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Process);
            } catch (Exception e) {
                LOG.Error("Error retrieving EnvironmentVariableTarget.Process", e);
            }

            try {
                userVars = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User);
            } catch (Exception e) {
                LOG.Error("Error retrieving EnvironmentVariableTarget.User", e);
            }

            try {
                machineVars = Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine);
            } catch (Exception e) {
                LOG.Error("Error retrieving EnvironmentVariableTarget.Machine", e);
            }

            try {
                return VAR_REGEXP.Replace(pattern,
                    new MatchEvaluator(delegate(Match m) { return MatchVarEvaluator(m, captureDetails, processVars, userVars, machineVars, filenameSafeMode); })
              		);
            } catch (Exception e) {
                // adding additional data for bug tracking
                e.Data.Add("title", captureDetails.Title);
                e.Data.Add("pattern", pattern);
                throw e;
            }
        }
		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) {
				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, presetCommand, fullPath, out output, out error);
						ProcessExport(exportInformation, surface);
					});
					commandThread.Name = "Running " + presetCommand;
					commandThread.IsBackground = true;
					commandThread.SetApartmentState(ApartmentState.STA);
					commandThread.Start();
					exportInformation.ExportMade = true;
				} else {
					CallExternalCommand(exportInformation, presetCommand, fullPath, out output, out error);
					ProcessExport(exportInformation, surface);
				}
			}
			return exportInformation;
		}
예제 #3
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            _log.Debug("Start capture export to oo.vg");

            try
            {
                string uploadUrl;

                var exportInformation = new ExportInformation(this.Designation, this.Description)
                {
                    ExportMade = UploadImage(captureDetails, surface, out uploadUrl),
                    Uri = uploadUrl
                };

                ProcessExport(exportInformation, surface);

                if (exportInformation.ExportMade)
                {
                    Clipboard.SetText(uploadUrl);
                }

                return exportInformation;
            }
            finally
            {
                _log.Debug("Export to oo.vg complete");
            }
        }
예제 #4
0
 public PrintHelper(Image image, ICaptureDetails captureDetails)
 {
     this.image = image;
     printDialog.UseEXDialog = true;
     printDocument.DocumentName = FilenameHelper.GetFilenameWithoutExtensionFromPattern(conf.OutputFileFilenamePattern, captureDetails);
     printDocument.PrintPage += DrawImageForPrint;
     printDialog.Document = printDocument;
 }
예제 #5
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
			string uploadURL = null;
			exportInformation.ExportMade = plugin.Upload(captureDetails, surface, out uploadURL);
			exportInformation.Uri = uploadURL;
			ProcessExport(exportInformation, surface);
			return exportInformation;
		}
예제 #6
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(Designation, Description);
			string uploadUrl = _plugin.Upload(captureDetails, surface);
			if (uploadUrl != null) {
				exportInformation.ExportMade = true;
				exportInformation.Uri = uploadUrl;
			}
			ProcessExport(exportInformation, surface);
			return exportInformation;
		}
예제 #7
0
        private bool UploadImage(ICaptureDetails captureDetails, ISurface surface, out string url)
        {
            string path = null;

            try
            {
                _log.Debug("Exporting file to oo.vg");

                var uploadUrl = "http://oo.vg/a/upload";

                var config = IniConfig.GetIniSection<OovgConfiguration>();

                if (!string.IsNullOrEmpty(config.UploadKey))
                {
                    uploadUrl += $"?key={HttpUtility.UrlEncode(config.UploadKey)}";
                }

                // Temporarily store the file somewhere
                path = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings(OutputFormat.png));

                ServicePointManager.Expect100Continue = false;
                var webClient = new WebClient();
                var response = webClient.UploadFile(uploadUrl, "POST", path);

                url = Encoding.ASCII.GetString(response);

                _log.InfoFormat("Upload of {0} to {1} complete", captureDetails.Filename, url);

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while uploading file:" + Environment.NewLine + ex.Message, "oo.vg Screenshot Share");

                _log.Fatal("Uploading failed", ex);

                url = null;
                return false;
            }
            finally
            {
                // clean up after ourselves
                if (!string.IsNullOrEmpty(path))
                {
                    try
                    {
                        File.Delete(path);
                    }
                    catch (Exception e)
                    {
                        _log.Warn("Could not delete temporary file", e);
                    }
                }
            }
        }
 public override bool ExportCapture(ISurface surface, ICaptureDetails captureDetails)
 {
     using (Image image = surface.GetImageForExport()) {
         bool uploaded = plugin.Upload(captureDetails, image);
         if (uploaded) {
             surface.SendMessageEvent(this, SurfaceMessageTyp.Info, "Exported to Dropbox");
             surface.Modified = false;
         }
         return uploaded;
     }
 }
예제 #9
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;
		}
 /// <summary>
 /// A simple helper method which will call ExportCapture for the destination with the specified designation
 /// </summary>
 /// <param name="designation"></param>
 /// <param name="surface"></param>
 /// <param name="captureDetails"></param>
 public static void ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails)
 {
     if (RegisteredDestinations.ContainsKey(designation)) {
         IDestination destination = RegisteredDestinations[designation];
         if (destination.isActive) {
             if (destination.ExportCapture(manuallyInitiated, surface, captureDetails)) {
                 // Export worked, set the modified flag
                 surface.Modified = false;
             }
         }
     }
 }
예제 #11
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(Designation, Description);
			try {
				ClipboardHelper.SetClipboardData(surface);
				exportInformation.ExportMade = true;
			} catch (Exception) {
				// TODO: Change to general logic in ProcessExport
				surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString(LangKey.editor_clipboardfailed));
			}
			ProcessExport(exportInformation, surface);
			return exportInformation;
		}
예제 #12
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(Designation, Description);
			string savedTo = null;
			// Bug #2918756 don't overwrite path if SaveWithDialog returns null!
			savedTo = ImageOutput.SaveWithDialog(surface, captureDetails);
			if (savedTo != null) {
				exportInformation.ExportMade = true;
				exportInformation.Filepath = savedTo;
				captureDetails.Filename = savedTo;
				conf.OutputFileAsFullpath = savedTo;
			}
			ProcessExport(exportInformation, surface);
			return exportInformation;
		}
예제 #13
0
		public override ExportInformation ExportCapture(bool manually, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
			string uploadURL = null;
			bool uploaded = plugin.Upload(captureDetails, surface, out uploadURL);
			if (uploaded) {
				exportInformation.Uri = uploadURL;
				exportInformation.ExportMade = true;
				if (config.AfterUploadLinkToClipBoard) {
					ClipboardHelper.SetClipboardData(uploadURL);
				}
			}
			ProcessExport(exportInformation, surface);
			return exportInformation;
		}
예제 #14
0
		/// <summary>
		/// Export the capture with the destination picker
		/// </summary>
		/// <param name="manuallyInitiated">Did the user select this destination?</param>
		/// <param name="surface">Surface to export</param>
		/// <param name="captureDetails">Details of the capture</param>
		/// <returns>true if export was made</returns>
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			List<IDestination> destinations = new List<IDestination>();
			foreach(IDestination destination in DestinationHelper.GetAllDestinations()) {
				if ("Picker".Equals(destination.Designation)) {
					continue;
				}
				if (!destination.isActive) {
					continue;
				}
				destinations.Add(destination);
			}

			// No Processing, this is done in the selected destination (if anything was selected)
			return ShowPickerMenu(true, surface, captureDetails, destinations);
		}
예제 #15
0
		public override bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails) {
			LOG.DebugFormat("Changing surface to grayscale!");
			using (BitmapBuffer bbb = new BitmapBuffer(surface.Image as Bitmap, false)) {
				bbb.Lock();
				for(int y=0;y<bbb.Height; y++) {
					for(int x=0;x<bbb.Width; x++) {
						Color color = bbb.GetColorAt(x, y);
						int luma  = (int)((0.3*color.R) + (0.59*color.G) + (0.11*color.B));
						color = Color.FromArgb(luma, luma, luma);
						bbb.SetColorAt(x, y, color);
					}
				}
			}

			return true;
		}
예제 #16
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
			CoreConfiguration config = IniConfig.GetIniSection<CoreConfiguration>();
			OutputSettings outputSettings = new OutputSettings();

			string file = FilenameHelper.GetFilename(OutputFormat.png, null);
			string filePath = Path.Combine(config.OutputFilePath, file);
			using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
				using (Image image = surface.GetImageForExport()) {
					ImageOutput.SaveToStream(image, stream, outputSettings);
				}
			}
			exportInformation.Filepath = filePath;
			exportInformation.ExportMade = true;
			ProcessExport(exportInformation, surface);
			return exportInformation;
		}
예제 #17
0
		public override bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails) {
			surface.SelectElement(surface.AddCursorContainer(Cursors.Hand, 100, 100));
			// Do something with the screenshot
			string title = captureDetails.Title;
			if (title != null) {
				LOG.Debug("Added title to surface: " + title);
				surface.SelectElement(surface.AddTextContainer(title, HorizontalAlignment.Center, VerticalAlignment.CENTER,
                       FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
			}
			surface.SelectElement(surface.AddTextContainer(Environment.UserName, HorizontalAlignment.Right, VerticalAlignment.TOP,
                       FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
			surface.SelectElement(surface.AddTextContainer(Environment.MachineName, HorizontalAlignment.Right, VerticalAlignment.BOTTOM,
                       FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
			surface.SelectElement(surface.AddTextContainer(captureDetails.DateTime.ToLongDateString(), HorizontalAlignment.Left, VerticalAlignment.BOTTOM,
                       FontFamily.GenericSansSerif, 12f, false, false, false, 2, Color.Red, Color.White));
			return true;
		}
예제 #18
0
		/// <summary>
		/// Helper Method for creating an Email with Image Attachment
		/// </summary>
		/// <param name="image">The image to send</param>
		/// <param name="captureDetails">ICaptureDetails</param>
		public static void SendImage(ISurface surface, ICaptureDetails captureDetails) {
			string tmpFile = ImageOutput.SaveNamedTmpFile(surface, captureDetails, new SurfaceOutputSettings());

			if (tmpFile != null) {
				// Store the list of currently active windows, so we can make sure we show the email window later!
				List<WindowDetails> windowsBefore = WindowDetails.GetVisibleWindows();
				bool isEmailSend = false;
				//if (EmailConfigHelper.HasOutlook() && (conf.OutputEMailFormat == EmailFormat.OUTLOOK_HTML || conf.OutputEMailFormat == EmailFormat.OUTLOOK_TXT)) {
				//	isEmailSend = OutlookExporter.ExportToOutlook(tmpFile, captureDetails);
				//}
				if (!isEmailSend && EmailConfigHelper.HasMAPI()) {
					// Fallback to MAPI
					// Send the email
					SendImage(tmpFile, captureDetails.Title);
				}
				WindowDetails.ActiveNewerWindows(windowsBefore);
			}
		}
예제 #19
0
		public override bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails) {
			bool changed = false;
			string title = captureDetails.Title;
			if (!string.IsNullOrEmpty(title)) {
				title = title.Trim();
				foreach(string titleIdentifier in config.ActiveTitleFixes) {
					string regexpString = config.TitleFixMatcher[titleIdentifier];
					string replaceString = config.TitleFixReplacer[titleIdentifier];
					if (replaceString == null) {
						replaceString = "";
					}
					if (!string.IsNullOrEmpty(regexpString)) {
						Regex regex = new Regex(regexpString);
						title = regex.Replace(title, replaceString);
						changed = true;
					}
				}
			}
			captureDetails.Title = title;
			return changed;
		}
예제 #20
0
 public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat, ICaptureDetails captureDetails)
 {
     return FillPattern(pattern, captureDetails, true) + "." + imageFormat.ToString().ToLower();
 }
예제 #21
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var    exportInformation = new ExportInformation(this.Designation, this.Description);
            string filename          = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
            var    outputSettings    = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);

            try
            {
                // Run upload in the background
                new PleaseWaitForm().ShowAndWait(Description, "Uploading",
                                                 delegate()
                {
                    demoPlugin.DemoConnector.AddAttachment(filename, new SurfaceContainer(surface, outputSettings, filename));
                }
                                                 );
                LOG.Debug("Uploaded to Jira.");
                exportInformation.ExportMade = true;
            }
            catch (Exception e)
            {
                MessageBox.Show("Upload failure");
            }
            return(exportInformation);
        }
예제 #22
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);

            try
            {
                using (var clipboardAccessToken = ClipboardNative.Access())
                {
                    clipboardAccessToken.ClearContents();
                    // TODO: Test if this works
                    if (!string.IsNullOrEmpty(surface.LastSaveFullPath))
                    {
                        clipboardAccessToken.SetAsUnicodeString(surface.LastSaveFullPath);
                    }

                    foreach (var clipboardFormat in CoreConfiguration.ClipboardFormats)
                    {
                        switch (clipboardFormat)
                        {
                        case ClipboardFormats.DIB:
                            clipboardAccessToken.SetAsDeviceIndependendBitmap(surface);
                            break;

                        case ClipboardFormats.DIBV5:
                            clipboardAccessToken.SetAsFormat17(surface);
                            break;

                        case ClipboardFormats.PNG:
                            clipboardAccessToken.SetAsBitmap(surface, new SurfaceOutputSettings(OutputFormats.png));
                            break;

                        case ClipboardFormats.BITMAP:
                            clipboardAccessToken.SetAsBitmap(surface, new SurfaceOutputSettings(OutputFormats.bmp));
                            break;

                        case ClipboardFormats.HTML:
                            clipboardAccessToken.SetAsHtml(surface);
                            break;

                        case ClipboardFormats.HTMLDATAURL:
                            clipboardAccessToken.SetAsEmbeddedHtml(surface);
                            break;
                        }
                    }
                }
                exportInformation.ExportMade = true;
            }
            catch (Exception)
            {
                // TODO: Change to general logic in ProcessExport
                surface.SendMessageEvent(this, SurfaceMessageTyp.Error, "Error");                 //GreenshotLanguage.editorclipboardfailed);
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surfaceToUpload, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            string                filename          = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);

            if (jira != null)
            {
                try {
                    // Run upload in the background
                    new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                     delegate() {
                        jiraPlugin.JiraConnector.addAttachment(jira.Key, filename, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
                    }
                                                     );
                    LOG.Debug("Uploaded to Jira.");
                    exportInformation.ExportMade = true;
                    // TODO: This can't work:
                    exportInformation.Uri = surfaceToUpload.UploadURL;
                } catch (Exception e) {
                    MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                }
            }
            else
            {
                JiraForm jiraForm = new JiraForm(jiraPlugin.JiraConnector);
                if (jiraPlugin.JiraConnector.isLoggedIn)
                {
                    jiraForm.setFilename(filename);
                    DialogResult result = jiraForm.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        try {
                            // Run upload in the background
                            new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
                                                             delegate() {
                                jiraForm.upload(new SurfaceContainer(surfaceToUpload, outputSettings, filename));
                            }
                                                             );
                            LOG.Debug("Uploaded to Jira.");
                            exportInformation.ExportMade = true;
                            // TODO: This can't work:
                            exportInformation.Uri = surfaceToUpload.UploadURL;
                        } catch (Exception e) {
                            MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
                        }
                    }
                }
            }
            ProcessExport(exportInformation, surfaceToUpload);
            return(exportInformation);
        }
예제 #24
0
        /// <summary>
        /// This will be called when the menu item in the Editor is clicked
        /// </summary>
        public bool Upload(ICaptureDetails captureDetails, Image image)
        {
            if (config.DropboxAccessToken == null)
            {
                MessageBox.Show(lang.GetString(LangKey.TokenNotSet), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            else
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, lang.GetString(LangKey.communication_wait));

                    host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality);
                    byte[] buffer = stream.GetBuffer();
                    try
                    {
                        string      filename    = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
                        DropboxInfo DropboxInfo = DropboxUtils.UploadToDropbox(buffer, captureDetails.Title, filename);

                        if (config.DropboxUploadHistory == null)
                        {
                            config.DropboxUploadHistory = new Dictionary <string, string>();
                        }

                        if (DropboxInfo.ID != null)
                        {
                            LOG.InfoFormat("Storing Dropbox upload for id {0}", DropboxInfo.ID);

                            config.DropboxUploadHistory.Add(DropboxInfo.ID, DropboxInfo.ID);
                            config.runtimeDropboxHistory.Add(DropboxInfo.ID, DropboxInfo);
                        }

                        DropboxInfo.Image = DropboxUtils.CreateThumbnail(image, 90, 90);
                        // Make sure the configuration is save, so we don't lose the deleteHash
                        IniConfig.Save();
                        // Make sure the history is loaded, will be done only once
                        DropboxUtils.LoadHistory();

                        // Show
                        if (config.AfterUploadOpenHistory)
                        {
                            DropboxHistory.ShowHistory();
                        }

                        if (config.AfterUploadLinkToClipBoard)
                        {
                            Clipboard.SetText(DropboxInfo.WebUrl);
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.ToString());
                        return(false);
                    }
                    finally
                    {
                        backgroundForm.CloseDialog();
                    }
                }
            }
        }
예제 #25
0
 public static string GetFilenameFromPattern(string pattern, OutputFormat imageFormat, ICaptureDetails captureDetails)
 {
     return(FillPattern(pattern, captureDetails, true) + "." + imageFormat.ToString().ToLower());
 }
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.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)
                {
                    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));
                        }
                        // 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);
        }
예제 #27
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);

            MapiMailMessage.SendImage(surface, captureDetails);
            exportInformation.ExportMade = true;
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
예제 #28
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation     exportInformation = new ExportInformation(this.Designation, this.Description);
            CoreConfiguration     config            = IniConfig.GetIniSection <CoreConfiguration>();
            SurfaceOutputSettings outputSettings    = new SurfaceOutputSettings();

            string file     = FilenameHelper.GetFilename(OutputFormat.png, null);
            string filePath = Path.Combine(config.OutputFilePath, file);

            using (FileStream stream = new FileStream(filePath, FileMode.Create)) {
                ImageOutput.SaveToStream(surface, stream, outputSettings);
            }
            exportInformation.Filepath   = filePath;
            exportInformation.ExportMade = true;
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
예제 #29
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            // Bug #2918756 don't overwrite path if SaveWithDialog returns null!
            var savedTo = ImageOutput.SaveWithDialog(surface, captureDetails);

            if (savedTo != null)
            {
                base.SetDefaults(surface);
                exportInformation.ExportMade = true;
                exportInformation.Filepath   = savedTo;
                captureDetails.Filename      = savedTo;
                conf.OutputFileAsFullpath    = savedTo;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
예제 #30
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);
        }
예제 #31
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);

            exportInformation.ExportMade = plugin.DoOCR(surface) != null;
            return(exportInformation);
        }
예제 #32
0
 /// <summary>
 /// This method will be called by the regexp.replace as a MatchEvaluator delegate!
 /// Will delegate this to the MatchVarEvaluatorInternal and catch any exceptions
 /// <param name="match">What are we matching?</param>
 /// <param name="captureDetails">The detail, can be null</param>
 /// <param name="processVars">Variables from the process</param>
 /// <param name="userVars">Variables from the user</param>
 /// <param name="machineVars">Variables from the machine</param>
 /// <returns>string with the match replacement</returns>
 private static string MatchVarEvaluator(Match match, ICaptureDetails captureDetails, IDictionary processVars, IDictionary userVars, IDictionary machineVars, bool filenameSafeMode)
 {
     try
     {
         return MatchVarEvaluatorInternal(match, captureDetails, processVars, userVars, machineVars, filenameSafeMode);
     }
     catch (Exception e)
     {
         LOG.Error("Error in MatchVarEvaluatorInternal", e);
     }
     return "";
 }
예제 #33
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);
        }
예제 #34
0
 public ImageOutputEventArgs(string fullPath, Image image, ICaptureDetails captureDetails)
 {
     this.image          = image;
     this.fullPath       = fullPath;
     this.captureDetails = captureDetails;
 }
예제 #35
0
 public static string GetFilenameWithoutExtensionFromPattern(string pattern, ICaptureDetails captureDetails)
 {
     return(FillPattern(pattern, captureDetails, true));
 }
예제 #36
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.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
            {
                LOG.InfoFormat("Creating new filename");
                string pattern = conf.OutputFileFilenamePattern;
                if (string.IsNullOrEmpty(pattern))
                {
                    pattern = "greenshot ${capturetime}";
                }
                string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails);
                string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false);
                fullPath = Path.Combine(filepath, filename);
                // 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 overwite 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);
        }
        /// <summary>
        /// Upload the capture to Facebook
        /// </summary>
        /// <param name="captureDetails"></param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <param name="uploadURL">out string for the url</param>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadURL)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(OutputFormat.png);
            try {
                string filename = Path.GetFileName(FilenameHelper.GetFilename(OutputFormat.png, captureDetails));
                FacebookInfo FacebookInfo = null;

                // Run upload in the background
                new PleaseWaitForm().ShowAndWait("Facebook plug-in", Language.GetString("facebook", LangKey.communication_wait),
                    delegate {
                        FacebookInfo = FacebookUtils.UploadToFacebook(surfaceToUpload, outputSettings, config.IncludeTitle ? captureDetails.Title : null, filename);
                    }
                );
                // This causes an exeption if the upload failed :)
                LOG.DebugFormat("Uploaded to Facebook page: " + FacebookInfo.Page);
                uploadURL = null;

                try {
                    uploadURL = FacebookInfo.Page;
                    Clipboard.SetText(FacebookInfo.Page);
                } catch (Exception ex) {
                    LOG.Error("Can't write to clipboard: ", ex);
                }
                return true;
            } catch (Exception e) {
                LOG.Error(e);
                MessageBox.Show(Language.GetString("facebook", LangKey.upload_failure) + " " + e.Message);
            }
            uploadURL = null;
            return false;
        }
 public SaveImageFileDialog(ICaptureDetails captureDetails)
 {
     this.captureDetails = captureDetails;
     init();
 }
 /// <summary>
 /// A simple helper method which will call ProcessCapture for the Processor with the specified designation
 /// </summary>
 /// <param name="designation"></param>
 /// <param name="surface"></param>
 /// <param name="captureDetails"></param>
 public static void ProcessCapture(string designation, ISurface surface, ICaptureDetails captureDetails)
 {
     if (RegisteredProcessors.ContainsKey(designation)) {
         IProcessor Processor = RegisteredProcessors[designation];
         if (Processor.isActive) {
             Processor.ProcessCapture(surface, captureDetails);
         }
     }
 }
        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);
        }
예제 #41
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);

            try {
                ClipboardHelper.SetClipboardData(surface);
                exportInformation.ExportMade = true;
            } catch (Exception) {
                // TODO: Change to general logic in ProcessExport
                surface.SendMessageEvent(this, SurfaceMessageTyp.Error, Language.GetString(LangKey.editor_clipboardfailed));
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
예제 #42
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);

            if (_page == null)
            {
                try
                {
                    exportInformation.ExportMade = OneNoteExporter.ExportToNewPage(surface);
                }
                catch (Exception ex)
                {
                    exportInformation.ErrorMessage = ex.Message;
                    Log.Error().WriteLine(ex);
                }
            }
            else
            {
                try
                {
                    exportInformation.ExportMade = OneNoteExporter.ExportToPage(surface, _page);
                }
                catch (Exception ex)
                {
                    exportInformation.ErrorMessage = ex.Message;
                    Log.Error().WriteLine(ex);
                }
            }
            return(exportInformation);
        }
예제 #43
0
        /// <summary>
        /// A simple helper method which will call ExportCapture for the destination with the specified designation
        /// </summary>
        /// <param name="designation"></param>
        /// <param name="surface"></param>
        /// <param name="captureDetails"></param>
        public static ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails)
        {
            IDestination destination = GetDestination(designation);

            if (destination != null && destination.IsActive)
            {
                return(destination.ExportCapture(manuallyInitiated, surface, captureDetails));
            }
            return(null);
        }
예제 #44
0
 public abstract bool ProcessCapture(ISurface surface, ICaptureDetails captureDetails);
예제 #45
0
 /// <summary>
 /// Return a filename for the current image format (png,jpg etc) with the default file pattern
 /// that is specified in the configuration
 /// </summary>
 /// <param name="format">A string with the format</param>
 /// <returns>The filename which should be used to save the image</returns>
 public static string GetFilename(OutputFormat format, ICaptureDetails captureDetails)
 {
     string pattern = conf.OutputFileFilenamePattern;
     if (pattern == null || string.IsNullOrEmpty(pattern.Trim()))
     {
         pattern = "greenshot ${capturetime}";
     }
     return GetFilenameFromPattern(pattern, format, captureDetails);
 }
예제 #46
0
        public override async Task <ExportInformation> ExportCaptureAsync(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var uploadUrl = await Upload(surface).ConfigureAwait(true);

            var exportInformation = new ExportInformation(Designation, Description)
            {
                ExportMade = uploadUrl != null,
                Uri        = uploadUrl
            };

            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
예제 #47
0
 public static string GetFilenameWithoutExtensionFromPattern(string pattern, ICaptureDetails captureDetails)
 {
     return FillPattern(pattern, captureDetails, true);
 }
예제 #48
0
 public ExportInformation ExportCapture(bool manuallyInitiated, string designation, ISurface surface, ICaptureDetails captureDetails)
 {
     return(DestinationHelper.ExportCapture(manuallyInitiated, designation, surface, captureDetails));
 }
예제 #49
0
        /// <summary>
        /// This method will be called by the regexp.replace as a MatchEvaluator delegate!
        /// </summary>
        /// <param name="match">What are we matching?</param>
        /// <param name="captureDetails">The detail, can be null</param>
        /// <returns></returns>
        private static string MatchVarEvaluatorInternal(Match match, ICaptureDetails captureDetails, IDictionary processVars, IDictionary userVars, IDictionary machineVars, bool filenameSafeMode)
        {
            // some defaults
            int padWidth = 0;
            int startIndex = 0;
            int endIndex = 0;
            char padChar = ' ';
            string dateFormat = "yyyy-MM-dd HH-mm-ss";
            IDictionary<string, string> replacements = new Dictionary<string, string>();
            string replaceValue = "";
            string variable = match.Groups["variable"].Value;
            string parameters = match.Groups["parameters"].Value;

            if (parameters != null && parameters.Length > 0)
            {
                string[] parms = SPLIT_REGEXP.Split(parameters);
                foreach (string parameter in parms)
                {
                    switch (parameter.Substring(0, 1))
                    {
                        // Padding p<width>[,pad-character]
                        case "p":
                            string[] padParams = parameter.Substring(1).Split(new char[] { ',' });
                            try
                            {
                                padWidth = int.Parse(padParams[0]);
                            }
                            catch
                            {
                            };
                            if (padParams.Length > 1)
                            {
                                padChar = padParams[1][0];
                            }
                            break;
                        // replace
                        // r<old string>,<new string>
                        case "r":
                            string[] replaceParameters = parameter.Substring(1).Split(new char[] { ',' });
                            if (replaceParameters != null && replaceParameters.Length == 2)
                            {
                                replacements.Add(replaceParameters[0], replaceParameters[1]);
                            }
                            break;
                        // Dateformat d<format>
                        // Format can be anything that is used in C# date formatting
                        case "d":
                            dateFormat = parameter.Substring(1);
                            if (dateFormat.StartsWith("\""))
                            {
                                dateFormat = dateFormat.Substring(1);
                            }
                            if (dateFormat.EndsWith("\""))
                            {
                                dateFormat = dateFormat.Substring(0, dateFormat.Length - 1);
                            }
                            break;
                        // Substring:
                        // s<start>[,length]
                        case "s":
                            string range = parameter.Substring(1);
                            string[] rangelist = range.Split(new char[] { ',' });
                            if (rangelist.Length > 0)
                            {
                                try
                                {
                                    startIndex = int.Parse(rangelist[0]);
                                }
                                catch
                                {
                                    // Ignore
                                }
                            }
                            if (rangelist.Length > 1)
                            {
                                try
                                {
                                    endIndex = int.Parse(rangelist[1]);
                                }
                                catch
                                {
                                    // Ignore
                                }
                            }
                            break;
                    }
                }
            }
            if (processVars != null && processVars.Contains(variable))
            {
                replaceValue = (string)processVars[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else if (userVars != null && userVars.Contains(variable))
            {
                replaceValue = (string)userVars[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else if (machineVars != null && machineVars.Contains(variable))
            {
                replaceValue = (string)machineVars[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else if (captureDetails != null && captureDetails.MetaData != null && captureDetails.MetaData.ContainsKey(variable))
            {
                replaceValue = captureDetails.MetaData[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else
            {
                // Handle other variables
                // Default use "now" for the capture take´n
                DateTime capturetime = DateTime.Now;
                // Use default application name for title
                string title = Application.ProductName;

                // Check if we have capture details
                if (captureDetails != null)
                {
                    capturetime = captureDetails.DateTime;
                    if (captureDetails.Title != null)
                    {
                        title = captureDetails.Title;
                        if (title.Length > MAX_TITLE_LENGTH)
                        {
                            title = title.Substring(0, MAX_TITLE_LENGTH);
                        }
                    }
                }
                switch (variable)
                {
                    case "domain":
                        replaceValue = Environment.UserDomainName;
                        break;
                    case "user":
                        replaceValue = Environment.UserName;
                        break;
                    case "hostname":
                        replaceValue = Environment.MachineName;
                        break;
                    case "YYYY":
                        if (padWidth == 0)
                        {
                            padWidth = -4;
                            padChar = '0';
                        }
                        replaceValue = capturetime.Year.ToString();
                        break;
                    case "MM":
                        replaceValue = capturetime.Month.ToString();
                        if (padWidth == 0)
                        {
                            padWidth = -2;
                            padChar = '0';
                        }
                        break;
                    case "DD":
                        replaceValue = capturetime.Day.ToString();
                        if (padWidth == 0)
                        {
                            padWidth = -2;
                            padChar = '0';
                        }
                        break;
                    case "hh":
                        if (padWidth == 0)
                        {
                            padWidth = -2;
                            padChar = '0';
                        }
                        replaceValue = capturetime.Hour.ToString();
                        break;
                    case "mm":
                        if (padWidth == 0)
                        {
                            padWidth = -2;
                            padChar = '0';
                        }
                        replaceValue = capturetime.Minute.ToString();
                        break;
                    case "ss":
                        if (padWidth == 0)
                        {
                            padWidth = -2;
                            padChar = '0';
                        }
                        replaceValue = capturetime.Second.ToString();
                        break;
                    case "now":
                        replaceValue = DateTime.Now.ToString(dateFormat);
                        if (filenameSafeMode)
                        {
                            replaceValue = MakeFilenameSafe(replaceValue);
                        }
                        break;
                    case "capturetime":
                        replaceValue = capturetime.ToString(dateFormat);
                        if (filenameSafeMode)
                        {
                            replaceValue = MakeFilenameSafe(replaceValue);
                        }
                        break;
                    case "NUM":
                        conf.OutputFileIncrementingNumber++;
                        IniConfig.Save();
                        replaceValue = conf.OutputFileIncrementingNumber.ToString();
                        if (padWidth == 0)
                        {
                            padWidth = -6;
                            padChar = '0';
                        }

                        break;
                    case "title":
                        replaceValue = title;
                        if (filenameSafeMode)
                        {
                            replaceValue = MakeFilenameSafe(replaceValue);
                        }
                        break;
                    case "MyPictures":
                        replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                        break;
                    case "MyMusic":
                        replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                        break;
                    case "MyDocuments":
                        replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                        break;
                    case "Personal":
                        replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                        break;
                    case "Desktop":
                        replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                        break;
                    case "ApplicationData":
                        replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                        break;
                    case "LocalApplicationData":
                        replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                        break;
                }
            }
            // do padding
            if (padWidth > 0)
            {
                replaceValue = replaceValue.PadRight(padWidth, padChar);
            }
            else if (padWidth < 0)
            {
                replaceValue = replaceValue.PadLeft(-padWidth, padChar);
            }

            // do substring
            if (startIndex != 0 || endIndex != 0)
            {
                if (startIndex < 0)
                {
                    startIndex = replaceValue.Length + startIndex;
                }
                if (endIndex < 0)
                {
                    endIndex = replaceValue.Length + endIndex;
                }
                if (endIndex != 0)
                {
                    try
                    {
                        replaceValue = replaceValue.Substring(startIndex, endIndex);
                    }
                    catch
                    {
                        // Ignore
                    }
                }
                else
                {
                    try
                    {
                        replaceValue = replaceValue.Substring(startIndex);
                    }
                    catch
                    {
                        // Ignore
                    }
                }
            }

            // new for feature #697
            if (replacements.Count > 0)
            {
                foreach (string oldValue in replacements.Keys)
                {
                    replaceValue = replaceValue.Replace(oldValue, replacements[oldValue]);
                }
            }
            return replaceValue;
        }
예제 #50
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
            string            uploadURL         = null;

            exportInformation.ExportMade = plugin.Upload(captureDetails, surface, out uploadURL);
            exportInformation.Uri        = uploadURL;
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
 public SaveImageFileDialog(ICaptureDetails captureDetails)
 {
     this.captureDetails = captureDetails;
     init();
 }
예제 #52
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);

            if (page != null)
            {
                try {
                    OneNoteExporter.ExportToPage(surface, page);
                    exportInformation.ExportMade = true;
                } catch (Exception ex) {
                    exportInformation.ErrorMessage = ex.Message;
                    LOG.Error(ex);
                }
            }
            return(exportInformation);
        }
예제 #53
0
        /// <summary>
        /// This method will be called by the regexp.replace as a MatchEvaluator delegate!
        /// </summary>
        /// <param name="match">What are we matching?</param>
        /// <param name="captureDetails">The detail, can be null</param>
        /// <returns></returns>
        private static string MatchVarEvaluatorInternal(Match match, ICaptureDetails captureDetails, IDictionary processVars, IDictionary userVars, IDictionary machineVars, bool filenameSafeMode)
        {
            // some defaults
            int    padWidth   = 0;
            int    startIndex = 0;
            int    endIndex   = 0;
            char   padChar    = ' ';
            string dateFormat = "yyyy-MM-dd HH-mm-ss";

            string replaceValue = "";
            string variable     = match.Groups["variable"].Value;
            string parameters   = match.Groups["parameters"].Value;

            if (parameters != null && parameters.Length > 0)
            {
                string[] parms = SPLIT_REGEXP.Split(parameters);
                foreach (string parameter in parms)
                {
                    switch (parameter.Substring(0, 1))
                    {
                    case "p":
                        string[] padParams = parameter.Substring(1).Split(new char[] { ',' });
                        try
                        {
                            padWidth = int.Parse(padParams[0]);
                        }
                        catch
                        {
                        };
                        if (padParams.Length > 1)
                        {
                            padChar = padParams[1][0];
                        }
                        break;

                    case "d":
                        dateFormat = parameter.Substring(1);
                        if (dateFormat.StartsWith("\""))
                        {
                            dateFormat = dateFormat.Substring(1);
                        }
                        if (dateFormat.EndsWith("\""))
                        {
                            dateFormat = dateFormat.Substring(0, dateFormat.Length - 1);
                        }
                        break;

                    case "s":
                        string   range     = parameter.Substring(1);
                        string[] rangelist = range.Split(new char[] { ',' });
                        if (rangelist.Length > 0)
                        {
                            try
                            {
                                startIndex = int.Parse(rangelist[0]);
                            }
                            catch
                            {
                                // Ignore
                            }
                        }
                        if (rangelist.Length > 1)
                        {
                            try
                            {
                                endIndex = int.Parse(rangelist[1]);
                            }
                            catch
                            {
                                // Ignore
                            }
                        }
                        break;
                    }
                }
            }
            if (processVars != null && processVars.Contains(variable))
            {
                replaceValue = (string)processVars[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else if (userVars != null && userVars.Contains(variable))
            {
                replaceValue = (string)userVars[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else if (machineVars != null && machineVars.Contains(variable))
            {
                replaceValue = (string)machineVars[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else if (captureDetails != null && captureDetails.MetaData != null && captureDetails.MetaData.ContainsKey(variable))
            {
                replaceValue = captureDetails.MetaData[variable];
                if (filenameSafeMode)
                {
                    replaceValue = MakePathSafe(replaceValue);
                }
            }
            else
            {
                // Handle other variables
                // Default use "now" for the capture take´n
                DateTime capturetime = DateTime.Now;
                // Use default application name for title
                string title = Application.ProductName;

                // Check if we have capture details
                if (captureDetails != null)
                {
                    capturetime = captureDetails.DateTime;
                    if (captureDetails.Title != null)
                    {
                        title = captureDetails.Title;
                        if (title.Length > MAX_TITLE_LENGTH)
                        {
                            title = title.Substring(0, MAX_TITLE_LENGTH);
                        }
                    }
                }
                switch (variable)
                {
                case "domain":
                    replaceValue = Environment.UserDomainName;
                    break;

                case "user":
                    replaceValue = Environment.UserName;
                    break;

                case "hostname":
                    replaceValue = Environment.MachineName;
                    break;

                case "YYYY":
                    if (padWidth == 0)
                    {
                        padWidth = -4;
                        padChar  = '0';
                    }
                    replaceValue = capturetime.Year.ToString();
                    break;

                case "MM":
                    replaceValue = capturetime.Month.ToString();
                    if (padWidth == 0)
                    {
                        padWidth = -2;
                        padChar  = '0';
                    }
                    break;

                case "DD":
                    replaceValue = capturetime.Day.ToString();
                    if (padWidth == 0)
                    {
                        padWidth = -2;
                        padChar  = '0';
                    }
                    break;

                case "hh":
                    if (padWidth == 0)
                    {
                        padWidth = -2;
                        padChar  = '0';
                    }
                    replaceValue = capturetime.Hour.ToString();
                    break;

                case "mm":
                    if (padWidth == 0)
                    {
                        padWidth = -2;
                        padChar  = '0';
                    }
                    replaceValue = capturetime.Minute.ToString();
                    break;

                case "ss":
                    if (padWidth == 0)
                    {
                        padWidth = -2;
                        padChar  = '0';
                    }
                    replaceValue = capturetime.Second.ToString();
                    break;

                case "now":
                    replaceValue = DateTime.Now.ToString(dateFormat);
                    if (filenameSafeMode)
                    {
                        replaceValue = MakeFilenameSafe(replaceValue);
                    }
                    break;

                case "capturetime":
                    replaceValue = capturetime.ToString(dateFormat);
                    if (filenameSafeMode)
                    {
                        replaceValue = MakeFilenameSafe(replaceValue);
                    }
                    break;

                case "NUM":
                    conf.OutputFileIncrementingNumber++;
                    IniConfig.Save();
                    replaceValue = conf.OutputFileIncrementingNumber.ToString();
                    if (padWidth == 0)
                    {
                        padWidth = -6;
                        padChar  = '0';
                    }

                    break;

                case "title":
                    replaceValue = title;
                    if (filenameSafeMode)
                    {
                        replaceValue = MakeFilenameSafe(replaceValue);
                    }
                    break;

                case "MyPictures":
                    replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                    break;

                case "MyMusic":
                    replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                    break;

                case "MyDocuments":
                    replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    break;

                case "Personal":
                    replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    break;

                case "Desktop":
                    replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                    break;

                case "ApplicationData":
                    replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                    break;

                case "LocalApplicationData":
                    replaceValue = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                    break;
                }
            }
            // do padding
            if (padWidth > 0)
            {
                replaceValue = replaceValue.PadRight(padWidth, padChar);
            }
            else if (padWidth < 0)
            {
                replaceValue = replaceValue.PadLeft(-padWidth, padChar);
            }

            // do substring
            if (startIndex != 0 || endIndex != 0)
            {
                if (startIndex < 0)
                {
                    startIndex = replaceValue.Length + startIndex;
                }
                if (endIndex < 0)
                {
                    endIndex = replaceValue.Length + endIndex;
                }
                if (endIndex != 0)
                {
                    try
                    {
                        replaceValue = replaceValue.Substring(startIndex, endIndex);
                    }
                    catch
                    {
                        // Ignore
                    }
                }
                else
                {
                    try
                    {
                        replaceValue = replaceValue.Substring(startIndex);
                    }
                    catch
                    {
                        // Ignore
                    }
                }
            }

            return(replaceValue);
        }
예제 #54
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(Designation, Description)
            {
                ExportMade = _plugin.DoOcr(surface) != null
            };

            return(exportInformation);
        }
예제 #55
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surfaceToUpload, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
			string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
			SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
			if (jira != null) {
				try {
					// Run upload in the background
					new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
						delegate() {
							jiraPlugin.JiraConnector.addAttachment(jira.Key, filename, new SurfaceContainer(surfaceToUpload, outputSettings, filename));
						}
					);
					LOG.Debug("Uploaded to Jira.");
					exportInformation.ExportMade = true;
					// TODO: This can't work:
					exportInformation.Uri = surfaceToUpload.UploadURL;
				} catch (Exception e) {
					MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
				}
			} else {
				JiraForm jiraForm = new JiraForm(jiraPlugin.JiraConnector);
				if (jiraPlugin.JiraConnector.isLoggedIn) {
					jiraForm.setFilename(filename);
					DialogResult result = jiraForm.ShowDialog();
					if (result == DialogResult.OK) {
						try {
							// Run upload in the background
							new PleaseWaitForm().ShowAndWait(Description, Language.GetString("jira", LangKey.communication_wait),
								delegate() {
									jiraForm.upload(new SurfaceContainer(surfaceToUpload, outputSettings, filename));
								}
							);
							LOG.Debug("Uploaded to Jira.");
							exportInformation.ExportMade = true;
							// TODO: This can't work:
							exportInformation.Uri = surfaceToUpload.UploadURL;
						} catch(Exception e) {
							MessageBox.Show(Language.GetString("jira", LangKey.upload_failure) + " " + e.Message);
						}
					}
				}
			}
			ProcessExport(exportInformation, surfaceToUpload);
			return exportInformation;
		}
 public string SaveNamedTmpFile(Image image, ICaptureDetails captureDetails, OutputFormat outputFormat, int quality, bool reduceColors)
 {
     return ImageOutput.SaveNamedTmpFile(image, captureDetails, outputFormat, quality, reduceColors);
 }
예제 #57
0
		public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
			ExportInformation exportInformation = new ExportInformation(Designation, Description);
			// Make sure we collect the garbage before opening the screenshot
			GC.Collect();
			GC.WaitForPendingFinalizers();

			bool modified = surface.Modified;
			if (editor == null) {
				if (editorConfiguration.ReuseEditor) {
					foreach(IImageEditor openedEditor in ImageEditorForm.Editors) {
						if (!openedEditor.Surface.Modified) {
							openedEditor.Surface = surface;
							exportInformation.ExportMade = true;
							break;
						}
					}
				}
				if (!exportInformation.ExportMade) {
					try {
						ImageEditorForm editorForm = new ImageEditorForm(surface, !surface.Modified); // Output made??

						if (!string.IsNullOrEmpty(captureDetails.Filename)) {
							editorForm.SetImagePath(captureDetails.Filename);
						}
						editorForm.Show();
						editorForm.Activate();
						LOG.Debug("Finished opening Editor");
						exportInformation.ExportMade = true;
					} catch (Exception e) {
						LOG.Error(e);
						exportInformation.ErrorMessage = e.Message;
					}
				}
			} else {
				try {
					using (Image image = surface.GetImageForExport()) {
						editor.Surface.AddImageContainer(image, 10, 10);
					}
					exportInformation.ExportMade = true;
				} catch (Exception e) {
					LOG.Error(e);
					exportInformation.ErrorMessage = e.Message;
				}
			}
			ProcessExport(exportInformation, surface);
			// Workaround for the modified flag when using the editor.
			surface.Modified = modified;
			return exportInformation;
		}
예제 #58
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);
        }
예제 #59
0
        protected override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            var exportInformation = new ExportInformation(Designation, Description);
            var 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().WriteLine(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, string.Format(GreenshotLanguage.DestinationExportFailed, Description));
                    }
                }
            }
            else
            {
                if (!manuallyInitiated)
                {
                    var documents = WordExporter.GetWordDocuments();
                    if (documents != null && documents.Count > 0)
                    {
                        var destinations = new List <IDestination>
                        {
                            new WordDestination(CoreConfiguration, GreenshotLanguage)
                        };
                        foreach (var document in documents)
                        {
                            destinations.Add(new WordDestination(document, CoreConfiguration, GreenshotLanguage));
                        }
                        // 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().WriteLine(ex);
                        // TODO: Change to general logic in ProcessExport
                        surface.SendMessageEvent(this, SurfaceMessageTyp.Error, string.Format(GreenshotLanguage.DestinationExportFailed, Description));
                    }
                }
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }
예제 #60
0
        public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails)
        {
            ExportInformation exportInformation = new ExportInformation(Designation, Description);
            string            uploadUrl;
            bool uploaded = _plugin.Upload(captureDetails, surface, out uploadUrl);

            if (uploaded)
            {
                exportInformation.ExportMade = true;
                exportInformation.Uri        = uploadUrl;
            }
            ProcessExport(exportInformation, surface);
            return(exportInformation);
        }