/// <summary> /// Check and eventually fix the command settings /// </summary> /// <param name="command"></param> /// <returns>false if the command is not correctly configured</returns> private bool IsCommandValid(string command) { if (!_externalCommandConfig.RunInbackground.ContainsKey(command)) { Log.Warn().WriteLine("Found missing runInbackground for {0}", command); // Fix it _externalCommandConfig.RunInbackground.Add(command, true); } if (!_externalCommandConfig.Argument.ContainsKey(command)) { Log.Warn().WriteLine("Found missing argument for {0}", command); // Fix it _externalCommandConfig.Argument.Add(command, "{0}"); } if (!_externalCommandConfig.Commandline.ContainsKey(command)) { Log.Warn().WriteLine("Found missing commandline for {0}", command); return(false); } var commandline = FilenameHelper.FillVariables(_externalCommandConfig.Commandline[command], true); commandline = FilenameHelper.FillCmdVariables(commandline, true); if (File.Exists(commandline)) { return(true); } Log.Warn().WriteLine("Found 'invalid' commandline {0} for command {1}", _externalCommandConfig.Commandline[command], command); return(false); }
private void DisplaySettings() { colorButton_window_background.SelectedColor = coreConfiguration.DWMBackgroundColor; if (Language.CurrentLanguage != null) { combobox_language.SelectedValue = Language.CurrentLanguage; } // Disable editing when the value is fixed combobox_language.Enabled = !coreConfiguration.Values["Language"].IsFixed; textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false); // Disable editing when the value is fixed textbox_storagelocation.Enabled = !coreConfiguration.Values["OutputFilePath"].IsFixed; SetWindowCaptureMode(coreConfiguration.WindowCaptureMode); // Disable editing when the value is fixed combobox_window_capture_mode.Enabled = !coreConfiguration.CaptureWindowsInteractive && !coreConfiguration.Values["WindowCaptureMode"].IsFixed; radiobuttonWindowCapture.Checked = !coreConfiguration.CaptureWindowsInteractive; trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality; trackBarJpegQuality.Enabled = !coreConfiguration.Values["OutputFileJpegQuality"].IsFixed; textBoxJpegQuality.Text = coreConfiguration.OutputFileJpegQuality + "%"; DisplayDestinations(); numericUpDownWaitTime.Value = coreConfiguration.CaptureDelay >= 0?coreConfiguration.CaptureDelay:0; numericUpDownWaitTime.Enabled = !coreConfiguration.Values["CaptureDelay"].IsFixed; if (IniConfig.IsPortable) { checkbox_autostartshortcut.Visible = false; checkbox_autostartshortcut.Checked = false; } else { // Autostart checkbox logic. if (StartupHelper.hasRunAll()) { // Remove runUser if we already have a run under all StartupHelper.deleteRunUser(); checkbox_autostartshortcut.Enabled = StartupHelper.canWriteRunAll(); checkbox_autostartshortcut.Checked = true; // We already checked this } else if (StartupHelper.IsInStartupFolder()) { checkbox_autostartshortcut.Enabled = false; checkbox_autostartshortcut.Checked = true; // We already checked this } else { // No run for all, enable the checkbox and set it to true if the current user has a key checkbox_autostartshortcut.Enabled = StartupHelper.canWriteRunUser(); checkbox_autostartshortcut.Checked = StartupHelper.hasRunUser(); } } numericUpDown_daysbetweencheck.Value = coreConfiguration.UpdateCheckInterval; numericUpDown_daysbetweencheck.Enabled = !coreConfiguration.Values["UpdateCheckInterval"].IsFixed; CheckDestinationSettings(); }
private bool CheckStorageLocationPath() { bool settingsOk = Directory.Exists(FilenameHelper.FillVariables(textbox_storagelocation.Text, false)); DisplayTextBoxValidity(textbox_storagelocation, settingsOk); return(settingsOk); }
/// <summary> /// The Contextmenu_OpenRecent currently opens the last know save location /// </summary> private void Contextmenu_OpenRecent(object sender, EventArgs eventArgs) { string path; string configPath = FilenameHelper.FillVariables(conf.OutputFilePath, false); string lastFilePath = Path.GetDirectoryName(conf.OutputFileAsFullpath); if (Directory.Exists(lastFilePath)) { path = lastFilePath; } else if (Directory.Exists(configPath)) { path = configPath; } else { // What do I open when nothing can be found? Right, nothing... return; } LOG.Debug("DoubleClick was called! Starting: " + path); try { System.Diagnostics.Process.Start(path); } catch (Exception e) { // Make sure we show what we tried to open in the exception e.Data.Add("path", path); throw e; } }
private string GetRootDirFromConfig() { string rootDir = conf.OutputFilePath; rootDir = FilenameHelper.FillVariables(rootDir, false); return(rootDir); }
private string CreateNewFilename(ICaptureDetails captureDetails) { string fullPath = null; Log.Info().WriteLine("Creating new filename"); CoreConfiguration.ValidateAndCorrect(); var filename = FilenameHelper.GetFilenameFromPattern(CoreConfiguration.OutputFileFilenamePattern, CoreConfiguration.OutputFileFormat, captureDetails); var filepath = FilenameHelper.FillVariables(CoreConfiguration.OutputFilePath, false); try { fullPath = Path.Combine(filepath, filename); } catch (ArgumentException) { // configured filename or path not valid, show error message... Log.Info().WriteLine("Generated path or filename not valid: {0}, {1}", filepath, filename); MessageBox.Show(GreenshotLanguage.ErrorSaveInvalidChars, GreenshotLanguage.Error); // TODO: offer settings? // ... lets get the pattern fixed.... // fullPath = CreateNewFilename(captureDetails); // ... cancelled. // fullPath = null; } return(fullPath); }
private void DisplaySettings() { colorButton_window_background.SelectedColor = coreConfiguration.DWMBackgroundColor; if (Language.CurrentLanguage != null) { combobox_language.SelectedValue = Language.CurrentLanguage; } textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false); SetWindowCaptureMode(coreConfiguration.WindowCaptureMode); trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality; textBoxJpegQuality.Text = coreConfiguration.OutputFileJpegQuality + "%"; DisplayDestinations(); numericUpDownWaitTime.Value = coreConfiguration.CaptureDelay >= 0 ? coreConfiguration.CaptureDelay : 0; // If the run for all is set we disable and set the checkbox if (StartupHelper.checkRunAll()) { checkbox_autostartshortcut.Enabled = false; checkbox_autostartshortcut.Checked = true; } else { // No run for all, enable the checkbox and set it to true if the current user has a key checkbox_autostartshortcut.Enabled = true; checkbox_autostartshortcut.Checked = StartupHelper.checkRunUser(); } numericUpDown_daysbetweencheck.Value = coreConfiguration.UpdateCheckInterval; CheckDestinationSettings(); }
/// <summary> /// The actual executing code for the external command /// </summary> /// <param name="commando"></param> /// <param name="fullPath"></param> /// <param name="verb"></param> /// <param name="output"></param> /// <param name="error"></param> /// <returns></returns> private static int CallExternalCommand(string commando, string fullPath, string verb, out string output, out string error) { var commandline = Config.Commandline[commando]; var arguments = Config.Argument[commando]; output = null; error = null; if (!string.IsNullOrEmpty(commandline)) { using (var process = new Process()) { // Fix variables commandline = FilenameHelper.FillVariables(commandline, true); commandline = FilenameHelper.FillCmdVariables(commandline); arguments = FilenameHelper.FillVariables(arguments, false); arguments = FilenameHelper.FillCmdVariables(arguments, false); process.StartInfo.FileName = FilenameHelper.FillCmdVariables(commandline); process.StartInfo.Arguments = FormatArguments(arguments, fullPath); process.StartInfo.UseShellExecute = false; if (Config.RedirectStandardOutput) { process.StartInfo.RedirectStandardOutput = true; } if (Config.RedirectStandardError) { process.StartInfo.RedirectStandardError = true; } if (verb != null) { process.StartInfo.Verb = verb; } Log.Info().WriteLine("Starting : {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); process.Start(); process.WaitForExit(); if (Config.RedirectStandardOutput) { output = process.StandardOutput.ReadToEnd(); if (Config.ShowStandardOutputInLog && output.Trim().Length > 0) { Log.Info().WriteLine("Output:\n{0}", output); } } if (Config.RedirectStandardError) { error = process.StandardError.ReadToEnd(); if (error.Trim().Length > 0) { Log.Warn().WriteLine("Error:\n{0}", error); } } Log.Info().WriteLine("Finished : {0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); return(process.ExitCode); } } return(-1); }
private void BrowseClick(object sender, EventArgs e) { // Get the storage location and replace the environment variables folderBrowserDialog1.SelectedPath = FilenameHelper.FillVariables(textbox_storagelocation.Text, false); if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { // Only change if there is a change, otherwise we might overwrite the environment variables if (folderBrowserDialog1.SelectedPath != null && !folderBrowserDialog1.SelectedPath.Equals(FilenameHelper.FillVariables(textbox_storagelocation.Text, false))) { textbox_storagelocation.Text = folderBrowserDialog1.SelectedPath; } } }
private void OkButtonState() { // Assume OK buttonOk.Enabled = true; textBox_name.BackColor = Color.White; textBox_commandline.BackColor = Color.White; textBox_arguments.BackColor = Color.White; // Is there a text in the name field if (string.IsNullOrEmpty(textBox_name.Text)) { buttonOk.Enabled = false; } // Check if commandname is unique if (_commando == null && !string.IsNullOrEmpty(textBox_name.Text) && ExternalCommandConfig.Commands.Contains(textBox_name.Text)) { buttonOk.Enabled = false; textBox_name.BackColor = Color.Red; } // Is there a text in the commandline field if (string.IsNullOrEmpty(textBox_commandline.Text)) { buttonOk.Enabled = false; } if (!string.IsNullOrEmpty(textBox_commandline.Text)) { // Added this to be more flexible, using the Greenshot var format var cmdPath = FilenameHelper.FillVariables(textBox_commandline.Text, true); // And also replace the "DOS" Variables cmdPath = FilenameHelper.FillCmdVariables(cmdPath, true); // Is the command available? if (!File.Exists(cmdPath)) { buttonOk.Enabled = false; textBox_commandline.BackColor = Color.Red; } } // Are the arguments in a valid format? try { var arguments = FilenameHelper.FillVariables(textBox_arguments.Text, false); arguments = FilenameHelper.FillCmdVariables(arguments, false); ExternalCommandDestination.FormatArguments(arguments, string.Empty); } catch { buttonOk.Enabled = false; textBox_arguments.BackColor = Color.Red; } }
// Check the settings and somehow visibly mark when something is incorrect private bool CheckSettings() { bool settingsOk = true; if (!Directory.Exists(FilenameHelper.FillVariables(textbox_storagelocation.Text, false))) { textbox_storagelocation.BackColor = Color.Red; settingsOk = false; } else { textbox_storagelocation.BackColor = Control.DefaultBackColor; } return(settingsOk); }
public override bool ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { bool outputMade = false; string pattern = "${title}"; if (string.IsNullOrEmpty(pattern)) { pattern = "greenshot ${capturetime}"; } string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails); string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false); string fullPath = Path.Combine(filepath, filename); // Catching any exception to prevent that the user can't write in the directory. // This is done for e.g. bugs #2974608, #2963943, #2816163, #2795317, #2789218, #3004642 using (Image image = surface.GetImageForExport()) { try { // TODO: For now we overwrite, but this should be fixed some time ImageOutput.Save(image, fullPath, true); outputMade = true; } catch (Exception e) { LOG.Error("Error saving screenshot!", e); // Show the problem MessageBox.Show(Language.GetString(LangKey.error_save), Language.GetString(LangKey.error)); // when save failed we present a SaveWithDialog fullPath = ImageOutput.SaveWithDialog(image, captureDetails); outputMade = (fullPath != null); } } // Don't overwite filename if no output is made if (outputMade) { surface.LastSaveFullPath = fullPath; surface.Modified = false; captureDetails.Filename = fullPath; surface.SendMessageEvent(this, SurfaceMessageTyp.FileSaved, Language.GetFormattedString(LangKey.editor_imagesaved, surface.LastSaveFullPath)); } else { surface.SendMessageEvent(this, SurfaceMessageTyp.Info, ""); } return(outputMade); }
/// <summary> /// The Contextmenu_OpenRecent currently opens the last know save location /// </summary> private void Contextmenu_OpenRecent(object sender, EventArgs eventArgs) { _coreConfiguration.ValidateAndCorrectOutputFilePath(); _coreConfiguration.ValidateAndCorrectOutputFileAsFullpath(); var path = _coreConfiguration.OutputFileAsFullpath; if (!File.Exists(path)) { path = FilenameHelper.FillVariables(_coreConfiguration.OutputFilePath, false); // Fix for #1470, problems with a drive which is no longer available try { var lastFilePath = Path.GetDirectoryName(_coreConfiguration.OutputFileAsFullpath); if (lastFilePath != null && Directory.Exists(lastFilePath)) { path = lastFilePath; } else if (!Directory.Exists(path)) { // What do I open when nothing can be found? Right, nothing... return; } } catch (Exception ex) { Log.Warn().WriteLine(ex, "Couldn't open the path to the last exported file, taking default."); } } try { ExplorerHelper.OpenInExplorer(path); } catch (Exception ex) { // Make sure we show what we tried to open in the exception ex.Data.Add("path", path); Log.Warn().WriteLine(ex, "Couldn't open the path to the last exported file"); // No reason to create a bug-form, we just display the error. MessageBox.Show(this, ex.Message, $"Opening {path}", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string CreateNewFilename(ICaptureDetails captureDetails) { string fullPath; Log.Info().WriteLine("Creating new filename"); var pattern = _coreConfiguration.OutputFileFilenamePattern; if (string.IsNullOrEmpty(pattern)) { pattern = "greenshot ${capturetime}"; } var filename = FilenameHelper.GetFilenameFromPattern(pattern, _coreConfiguration.OutputFileFormat, captureDetails); _coreConfiguration.ValidateAndCorrectOutputFilePath(); var filepath = FilenameHelper.FillVariables(_coreConfiguration.OutputFilePath, false); try { fullPath = Path.Combine(filepath, filename); } catch (ArgumentException) { // configured filename or path not valid, show error message... Log.Info().WriteLine("Generated path or filename not valid: {0}, {1}", filepath, filename); MessageBox.Show(Language.GetString(LangKey.error_save_invalid_chars), Language.GetString(LangKey.error)); // ... lets get the pattern fixed.... var dialogResult = _settingsForm.ShowDialog(); if (dialogResult == DialogResult.OK) { // ... OK -> then try again: fullPath = CreateNewFilename(captureDetails); } else { // ... cancelled. fullPath = null; } } return(fullPath); }
// Check the settings and somehow visibly mark when something is incorrect private bool CheckSettings() { bool settingsOk = true; if (!Directory.Exists(FilenameHelper.FillVariables(textbox_storagelocation.Text, false))) { textbox_storagelocation.BackColor = Color.Red; settingsOk = false; } else { // "Added" feature #3547158 if (Environment.OSVersion.Version.Major >= 6) { this.textbox_storagelocation.BackColor = System.Drawing.SystemColors.Window; } else { this.textbox_storagelocation.BackColor = System.Drawing.SystemColors.Control; } } return(settingsOk); }
private void SaveSettings() { if (combobox_language.SelectedItem != null) { string newLang = combobox_language.SelectedValue.ToString(); if (!string.IsNullOrEmpty(newLang)) { coreConfiguration.Language = combobox_language.SelectedValue.ToString(); } } coreConfiguration.WindowCaptureMode = GetSelected <WindowCaptureMode>(combobox_window_capture_mode); if (!FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false).Equals(textbox_storagelocation.Text)) { coreConfiguration.OutputFilePath = textbox_storagelocation.Text; } coreConfiguration.OutputFileJpegQuality = trackBarJpegQuality.Value; List <string> destinations = new List <string>(); if (checkbox_picker.Checked) { destinations.Add(PickerDestination.DESIGNATION); } foreach (int index in destinationsListView.CheckedIndices) { ListViewItem item = destinationsListView.Items[index]; IDestination destination = item.Tag as IDestination; if (item.Checked) { destinations.Add(destination.Designation); } } coreConfiguration.OutputDestinations = destinations; coreConfiguration.CaptureDelay = (int)numericUpDownWaitTime.Value; coreConfiguration.DWMBackgroundColor = colorButton_window_background.SelectedColor; coreConfiguration.UpdateCheckInterval = (int)numericUpDown_daysbetweencheck.Value; IniConfig.Save(); // Make sure the current language & settings are reflected in the Main-context menu MainForm.instance.UpdateUI(); try { // Check if the Run for all is set if (!StartupHelper.checkRunAll()) { // If not set the registry according to the settings if (checkbox_autostartshortcut.Checked) { StartupHelper.setRunUser(); } else { StartupHelper.deleteRunUser(); } } else { // The run key for Greenshot is set for all users, delete the local version! StartupHelper.deleteRunUser(); } } catch (Exception e) { LOG.Warn("Problem checking registry, ignoring for now: ", e); } }
private void SaveSettings() { if (combobox_language.SelectedItem != null) { string newLang = combobox_language.SelectedValue.ToString(); if (!string.IsNullOrEmpty(newLang)) { coreConfiguration.Language = combobox_language.SelectedValue.ToString(); } } // retrieve the set clipboard formats List <ClipboardFormat> clipboardFormats = new List <ClipboardFormat>(); foreach (int index in listview_clipboardformats.CheckedIndices) { ListViewItem item = listview_clipboardformats.Items[index]; if (item.Checked) { clipboardFormats.Add((ClipboardFormat)item.Tag); } } coreConfiguration.ClipboardFormats = clipboardFormats; coreConfiguration.WindowCaptureMode = GetSelected <WindowCaptureMode>(combobox_window_capture_mode); if (!FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false).Equals(textbox_storagelocation.Text)) { coreConfiguration.OutputFilePath = textbox_storagelocation.Text; } coreConfiguration.OutputFileJpegQuality = trackBarJpegQuality.Value; List <string> destinations = new List <string>(); if (checkbox_picker.Checked) { destinations.Add(PickerDestination.DESIGNATION); } foreach (int index in listview_destinations.CheckedIndices) { ListViewItem item = listview_destinations.Items[index]; IDestination destinationFromTag = item.Tag as IDestination; if (item.Checked && destinationFromTag != null) { destinations.Add(destinationFromTag.Designation); } } coreConfiguration.OutputDestinations = destinations; coreConfiguration.CaptureDelay = (int)numericUpDownWaitTime.Value; coreConfiguration.DWMBackgroundColor = colorButton_window_background.SelectedColor; coreConfiguration.UpdateCheckInterval = (int)numericUpDown_daysbetweencheck.Value; coreConfiguration.IconSize = new Size((int)numericUpdownIconSize.Value, (int)numericUpdownIconSize.Value); try { if (checkbox_autostartshortcut.Checked) { // It's checked, so we set the RunUser if the RunAll isn't set. // Do this every time, so the executable is correct. if (!StartupHelper.HasRunAll()) { StartupHelper.SetRunUser(); } } else { // Delete both settings if it's unchecked if (StartupHelper.HasRunAll()) { StartupHelper.DeleteRunAll(); } if (StartupHelper.HasRunUser()) { StartupHelper.DeleteRunUser(); } } } catch (Exception e) { Log.Warn("Problem checking registry, ignoring for now: ", e); } }
private void DisplaySettings() { colorButton_window_background.SelectedColor = coreConfiguration.DWMBackgroundColor; // Expert mode, the clipboard formats foreach (ClipboardFormats clipboardFormat in Enum.GetValues(typeof(ClipboardFormats))) { var item = listview_clipboardformats.Items.Add(Language.Translate(clipboardFormat)); item.Tag = clipboardFormat; item.Checked = coreConfiguration.ClipboardFormats.Contains(clipboardFormat); } if (Language.CurrentLanguage != null) { combobox_language.SelectedValue = Language.CurrentLanguage; } // Disable editing when the value is fixed combobox_language.Enabled = !coreConfiguration.IsWriteProtected("Language"); textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false); // Disable editing when the value is fixed textbox_storagelocation.Enabled = !coreConfiguration.IsWriteProtected("OutputFilePath"); SetWindowCaptureMode(coreConfiguration.WindowCaptureMode); // Disable editing when the value is fixed combobox_window_capture_mode.Enabled = !coreConfiguration.CaptureWindowsInteractive && !coreConfiguration.IsWriteProtected("WindowCaptureMode"); radiobuttonWindowCapture.Checked = !coreConfiguration.CaptureWindowsInteractive; trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality; trackBarJpegQuality.Enabled = !coreConfiguration.IsWriteProtected("OutputFileJpegQuality"); textBoxJpegQuality.Text = $"{coreConfiguration.OutputFileJpegQuality}%"; DisplayDestinations(); numericUpDownWaitTime.Value = coreConfiguration.CaptureDelay >= 0 ? coreConfiguration.CaptureDelay : 0; numericUpDownWaitTime.Enabled = !coreConfiguration.IsWriteProtected("CaptureDelay"); if (coreConfiguration.IsPortable) { checkbox_autostartshortcut.Visible = false; checkbox_autostartshortcut.Checked = false; } else { // Autostart checkbox logic. if (StartupHelper.HasRunAll()) { // Remove runUser if we already have a run under all StartupHelper.DeleteRunUser(); checkbox_autostartshortcut.Enabled = StartupHelper.CanWriteRunAll(); checkbox_autostartshortcut.Checked = true; // We already checked this } else if (StartupHelper.IsInStartupFolder()) { checkbox_autostartshortcut.Enabled = false; checkbox_autostartshortcut.Checked = true; // We already checked this } else { // No run for all, enable the checkbox and set it to true if the current user has a key checkbox_autostartshortcut.Enabled = StartupHelper.CanWriteRunUser(); checkbox_autostartshortcut.Checked = StartupHelper.HasRunUser(); } } numericUpDown_daysbetweencheck.Value = coreConfiguration.UpdateCheckInterval; numericUpDown_daysbetweencheck.Enabled = !coreConfiguration.IsWriteProtected("UpdateCheckInterval"); numericUpdownIconSize.Value = coreConfiguration.IconSize.Width / 16 * 16; CheckDestinationSettings(); }
private void DisplaySettings() { region_hotkeyControl.SetHotkey(coreConfiguration.RegionHotkey); fullscreen_hotkeyControl.SetHotkey(coreConfiguration.FullscreenHotkey); window_hotkeyControl.SetHotkey(coreConfiguration.WindowHotkey); lastregion_hotkeyControl.SetHotkey(coreConfiguration.LastregionHotkey); ie_hotkeyControl.SetHotkey(coreConfiguration.IEHotkey); colorButton_window_background.SelectedColor = coreConfiguration.DWMBackgroundColor; checkbox_ie_capture.Checked = coreConfiguration.IECapture; if (lang.CurrentLanguage != null) { combobox_language.SelectedValue = lang.CurrentLanguage; } textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false); textbox_screenshotname.Text = coreConfiguration.OutputFileFilenamePattern; combobox_primaryimageformat.SelectedItem = coreConfiguration.OutputFileFormat; SetEmailFormat(coreConfiguration.OutputEMailFormat); SetWindowCaptureMode(coreConfiguration.WindowCaptureMode); checkbox_copypathtoclipboard.Checked = coreConfiguration.OutputFileCopyPathToClipboard; trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality; textBoxJpegQuality.Text = coreConfiguration.OutputFileJpegQuality + "%"; checkbox_alwaysshowjpegqualitydialog.Checked = coreConfiguration.OutputFilePromptJpegQuality; checkbox_playsound.Checked = coreConfiguration.PlayCameraSound; checkbox_clipboard.Checked = coreConfiguration.OutputDestinations.Contains(Destination.Clipboard); checkbox_file.Checked = coreConfiguration.OutputDestinations.Contains(Destination.FileDefault); checkbox_fileas.Checked = coreConfiguration.OutputDestinations.Contains(Destination.FileWithDialog); checkbox_printer.Checked = coreConfiguration.OutputDestinations.Contains(Destination.Printer); checkbox_editor.Checked = coreConfiguration.OutputDestinations.Contains(Destination.Editor); checkbox_email.Checked = coreConfiguration.OutputDestinations.Contains(Destination.EMail); checkboxPrintInverted.Checked = coreConfiguration.OutputPrintInverted; checkboxAllowCenter.Checked = coreConfiguration.OutputPrintCenter; checkboxAllowEnlarge.Checked = coreConfiguration.OutputPrintAllowEnlarge; checkboxAllowRotate.Checked = coreConfiguration.OutputPrintAllowRotate; checkboxAllowShrink.Checked = coreConfiguration.OutputPrintAllowShrink; checkboxTimestamp.Checked = coreConfiguration.OutputPrintTimestamp; checkbox_alwaysshowprintoptionsdialog.Checked = coreConfiguration.OutputPrintPromptOptions; checkbox_capture_mousepointer.Checked = coreConfiguration.CaptureMousepointer; checkbox_capture_windows_interactive.Checked = coreConfiguration.CaptureWindowsInteractive; checkbox_editor_match_capture_size.Checked = editorConfiguration.MatchSizeToCapture; numericUpDownWaitTime.Value = coreConfiguration.CaptureDelay >= 0 ? coreConfiguration.CaptureDelay : 0; // If the run for all is set we disable and set the checkbox if (StartupHelper.checkRunAll()) { checkbox_autostartshortcut.Enabled = false; checkbox_autostartshortcut.Checked = true; } else { // No run for all, enable the checkbox and set it to true if the current user has a key checkbox_autostartshortcut.Enabled = true; checkbox_autostartshortcut.Checked = StartupHelper.checkRunUser(); } checkbox_usedefaultproxy.Checked = coreConfiguration.UseProxy; numericUpDown_daysbetweencheck.Value = coreConfiguration.UpdateCheckInterval; CheckClipboardSettings(); }
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); }
private void SaveSettings() { if (combobox_language.SelectedItem != null) { coreConfiguration.Language = combobox_language.SelectedValue.ToString(); } coreConfiguration.WindowCaptureMode = GetSelected <WindowCaptureMode>(combobox_window_capture_mode); coreConfiguration.OutputFileFilenamePattern = textbox_screenshotname.Text; if (!FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false).Equals(textbox_storagelocation.Text)) { coreConfiguration.OutputFilePath = textbox_storagelocation.Text; } if (combobox_primaryimageformat.SelectedItem != null) { coreConfiguration.OutputFileFormat = (OutputFormat)combobox_primaryimageformat.SelectedItem; } else { coreConfiguration.OutputFileFormat = OutputFormat.png; } coreConfiguration.OutputEMailFormat = GetSelected <EmailFormat>(combobox_emailformat); coreConfiguration.OutputFileCopyPathToClipboard = checkbox_copypathtoclipboard.Checked; coreConfiguration.OutputFileJpegQuality = trackBarJpegQuality.Value; coreConfiguration.OutputFilePromptJpegQuality = checkbox_alwaysshowjpegqualitydialog.Checked; coreConfiguration.PlayCameraSound = checkbox_playsound.Checked; List <Destination> destinations = new List <Destination>(); if (checkbox_clipboard.Checked) { destinations.Add(Destination.Clipboard); } if (checkbox_file.Checked) { destinations.Add(Destination.FileDefault); } if (checkbox_fileas.Checked) { destinations.Add(Destination.FileWithDialog); } if (checkbox_printer.Checked) { destinations.Add(Destination.Printer); } if (checkbox_editor.Checked) { destinations.Add(Destination.Editor); } if (checkbox_email.Checked) { destinations.Add(Destination.EMail); } coreConfiguration.OutputDestinations = destinations; coreConfiguration.OutputPrintInverted = checkboxPrintInverted.Checked; coreConfiguration.OutputPrintCenter = checkboxAllowCenter.Checked; coreConfiguration.OutputPrintAllowEnlarge = checkboxAllowEnlarge.Checked; coreConfiguration.OutputPrintAllowRotate = checkboxAllowRotate.Checked; coreConfiguration.OutputPrintAllowShrink = checkboxAllowShrink.Checked; coreConfiguration.OutputPrintTimestamp = checkboxTimestamp.Checked; coreConfiguration.OutputPrintPromptOptions = checkbox_alwaysshowprintoptionsdialog.Checked; coreConfiguration.CaptureMousepointer = checkbox_capture_mousepointer.Checked; coreConfiguration.CaptureWindowsInteractive = checkbox_capture_windows_interactive.Checked; coreConfiguration.CaptureDelay = (int)numericUpDownWaitTime.Value; coreConfiguration.DWMBackgroundColor = colorButton_window_background.SelectedColor; coreConfiguration.RegionHotkey = region_hotkeyControl.ToString(); coreConfiguration.FullscreenHotkey = fullscreen_hotkeyControl.ToString(); coreConfiguration.WindowHotkey = window_hotkeyControl.ToString(); coreConfiguration.LastregionHotkey = lastregion_hotkeyControl.ToString(); coreConfiguration.IEHotkey = ie_hotkeyControl.ToString(); coreConfiguration.IECapture = checkbox_ie_capture.Checked; coreConfiguration.UpdateCheckInterval = (int)numericUpDown_daysbetweencheck.Value; coreConfiguration.UseProxy = checkbox_usedefaultproxy.Checked; editorConfiguration.MatchSizeToCapture = checkbox_editor_match_capture_size.Checked; IniConfig.Save(); // Make sure the current language & settings are reflected in the Main-context menu MainForm.instance.UpdateUI(); try { // Check if the Run for all is set if (!StartupHelper.checkRunAll()) { // If not set the registry according to the settings if (checkbox_autostartshortcut.Checked) { StartupHelper.setRunUser(); } else { StartupHelper.deleteRunUser(); } } else { // The run key for Greenshot is set for all users, delete the local version! StartupHelper.deleteRunUser(); } } catch (Exception e) { LOG.Warn("Problem checking registry, ignoring for now: ", e); } }
private void DisplaySettings() { colorButton_window_background.SelectedColor = coreConfiguration.DWMBackgroundColor; // Expert mode, the clipboard formats foreach (ClipboardFormat clipboardFormat in Enum.GetValues(typeof(ClipboardFormat))) { ListViewItem item = listview_clipboardformats.Items.Add(Language.Translate(clipboardFormat)); item.Tag = clipboardFormat; item.Checked = coreConfiguration.ClipboardFormats.Contains(clipboardFormat); } if (Language.CurrentLanguage != null) { combobox_language.SelectedValue = Language.CurrentLanguage; } // Disable editing when the value is fixed combobox_language.Enabled = !coreConfiguration.Values["Language"].IsFixed; textbox_storagelocation.Text = FilenameHelper.FillVariables(coreConfiguration.OutputFilePath, false); // Disable editing when the value is fixed textbox_storagelocation.Enabled = !coreConfiguration.Values["OutputFilePath"].IsFixed; SetWindowCaptureMode(coreConfiguration.WindowCaptureMode); // Disable editing when the value is fixed combobox_window_capture_mode.Enabled = !coreConfiguration.CaptureWindowsInteractive && !coreConfiguration.Values["WindowCaptureMode"].IsFixed; radiobuttonWindowCapture.Checked = !coreConfiguration.CaptureWindowsInteractive; trackBarJpegQuality.Value = coreConfiguration.OutputFileJpegQuality; trackBarJpegQuality.Enabled = !coreConfiguration.Values["OutputFileJpegQuality"].IsFixed; textBoxJpegQuality.Text = coreConfiguration.OutputFileJpegQuality + "%"; DisplayDestinations(); numericUpDownWaitTime.Value = coreConfiguration.CaptureDelay >= 0?coreConfiguration.CaptureDelay:0; numericUpDownWaitTime.Enabled = !coreConfiguration.Values["CaptureDelay"].IsFixed; if (IniConfig.IsPortable) { checkbox_autostartshortcut.Visible = false; checkbox_autostartshortcut.Checked = false; } else { // Autostart checkbox logic. if (StartupHelper.HasRunAll()) { // Remove runUser if we already have a run under all StartupHelper.DeleteRunUser(); checkbox_autostartshortcut.Enabled = StartupHelper.CanWriteRunAll(); checkbox_autostartshortcut.Checked = true; // We already checked this } else if (StartupHelper.IsInStartupFolder()) { checkbox_autostartshortcut.Enabled = false; checkbox_autostartshortcut.Checked = true; // We already checked this } else { // No run for all, enable the checkbox and set it to true if the current user has a key checkbox_autostartshortcut.Enabled = StartupHelper.CanWriteRunUser(); checkbox_autostartshortcut.Checked = StartupHelper.HasRunUser(); } } numericUpDown_daysbetweencheck.Value = coreConfiguration.UpdateCheckInterval; numericUpDown_daysbetweencheck.Enabled = !coreConfiguration.Values["UpdateCheckInterval"].IsFixed; numericUpdownIconSize.Value = coreConfiguration.IconSize.Width / 16 * 16; if (!string.IsNullOrEmpty(coreConfiguration.DestinationDefaultBorderEffect?.Trim())) { var defaultBorderEffect = Newtonsoft.Json.JsonConvert.DeserializeObject <DefaultBorderEffect>(coreConfiguration.DestinationDefaultBorderEffect); if (null != defaultBorderEffect) { this.txtEffectBorderWidth.Value = defaultBorderEffect.Width; this.btnEffectBorderColor.SelectedColor = defaultBorderEffect.Color; this.btnEffectBorderColor.BackColor = this.btnEffectBorderColor.SelectedColor; } } CheckDestinationSettings(); }