diff --git a/Greenshot/Configuration/AppConfig.cs b/Greenshot/Configuration/AppConfig.cs
deleted file mode 100644
index de704ee91..000000000
--- a/Greenshot/Configuration/AppConfig.cs
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Greenshot - a free and open source screenshot tool
- * Copyright (C) 2007-2014 Thomas Braun, Jens Klingen, Robin Krom
- *
- * For more information see: http://getgreenshot.org/
- * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-using System;
-using System.Drawing;
-using System.Drawing.Imaging;
-using System.IO;
-using System.Runtime.Serialization.Formatters.Binary;
-using System.Text.RegularExpressions;
-using System.Windows.Forms;
-
-using GreenshotPlugin.UnmanagedHelpers;
-using GreenshotPlugin.Core;
-using Greenshot.IniFile;
-using log4net;
-
-namespace Greenshot.Configuration {
- public enum ScreenshotDestinations {Editor=1, FileDefault=2, FileWithDialog=4, Clipboard=8, Printer=16, EMail=32}
-
- ///
- /// AppConfig is used for loading and saving the configuration. All public fields
- /// in this class are serialized with the BinaryFormatter and then saved to the
- /// config file. After loading the values from file, SetDefaults iterates over
- /// all public fields an sets fields set to null to the default value.
- ///
- [Serializable]
- public class AppConfig {
- private static ILog LOG = LogManager.GetLogger(typeof(AppConfig));
- private static readonly Regex FIXOLD_REGEXP = new Regex(@"%(?[\w]+)%", RegexOptions.Compiled);
- private const string VAR_PREFIX = "${";
- private const string VAR_POSTFIX = "}";
-
- //private static string loc = Assembly.GetExecutingAssembly().Location;
- //private static string oldFilename = Path.Combine(loc.Substring(0,loc.LastIndexOf(@"\")),"config.dat");
- private const string CONFIG_FILE_NAME = "config.dat";
- private static string configfilepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),@"Greenshot\");
-
- // the configuration part - all public vars are stored in the config file
- // don't use "null" and "0" as default value!
-
- #region general application config
- public bool? General_IsFirstLaunch = true;
- #endregion
-
- #region capture config
- public bool? Capture_Mousepointer = true;
- public bool? Capture_Windows_Interactive = false;
- public int Capture_Wait_Time = 101;
- public bool? fixedWaitTime = false;
- #endregion
-
- #region user interface config
- public string Ui_Language = "";
- public bool? Ui_Effects_CameraSound = true;
- #endregion
-
- #region output config
- public ScreenshotDestinations Output_Destinations = ScreenshotDestinations.Editor;
-
-
- public string Output_File_Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- public string Output_File_FilenamePattern = "${capturetime}_${title}";
- public string Output_File_Format = ImageFormat.Png.ToString();
- public bool? Output_File_CopyPathToClipboard = false;
- public int Output_File_JpegQuality = 80;
- public bool? Output_File_PromptJpegQuality = false;
- public int Output_File_IncrementingNumber = 1;
-
- public string Output_FileAs_Fullpath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png");
-
- public bool? Output_Print_PromptOptions = true;
- public bool? Output_Print_AllowRotate = true;
- public bool? Output_Print_AllowEnlarge = true;
- public bool? Output_Print_AllowShrink = true;
- public bool? Output_Print_Center = true;
- public bool? Output_Print_Timestamp = true;
- #endregion
-
- #region editor config
- public WindowPlacement Editor_Placement;
- public Color[] Editor_RecentColors = new Color[12];
- public Font Editor_Font = null;
-
- #endregion
-
- ///
- /// a private constructor because this is a singleton
- ///
- private AppConfig() {
- }
-
- ///
- /// Remove the old %VAR% syntax
- ///
- /// String with old syntax %VAR%
- /// The fixed pattern
- private static string FixFallback(string oldPattern) {
- return FIXOLD_REGEXP.Replace(oldPattern, delegate(Match m) { return VAR_PREFIX + m.Groups["variable"].Value + VAR_POSTFIX;});
- }
-
- ///
- /// loads the configuration from the config file
- ///
- /// an instance of AppConfig with all values set from the config file
- private static AppConfig Load() {
- AppConfig conf = null;
- if (File.Exists(Path.Combine(Application.StartupPath, CONFIG_FILE_NAME))) {
- configfilepath = Application.StartupPath;
- }
- string configfilename = Path.Combine(configfilepath, CONFIG_FILE_NAME);
- try {
- LOG.DebugFormat("Loading configuration from: {0}", configfilename);
- using (FileStream fileStream = File.Open(configfilename, FileMode.Open, FileAccess.Read)) {
- BinaryFormatter binaryFormatter = new BinaryFormatter();
- conf = (AppConfig) binaryFormatter.Deserialize(fileStream);
- }
- conf.Output_File_FilenamePattern = FixFallback(conf.Output_File_FilenamePattern);
- conf.Output_File_Path = FixFallback(conf.Output_File_Path);
- } catch (Exception e) {
- LOG.Warn("(ignoring) Problem loading configuration from: " + configfilename, e);
- }
- return conf;
- }
-
- public static void UpgradeToIni() {
- bool normalIni = File.Exists(Path.Combine(configfilepath, CONFIG_FILE_NAME));
- bool startupIni = File.Exists(Path.Combine(Application.StartupPath, CONFIG_FILE_NAME));
- if (startupIni || normalIni) {
- AppConfig appConfig = Load();
-
- if (appConfig != null) {
- LOG.Info("Migrating old configuration");
- CoreConfiguration coreConfiguration = IniConfig.GetIniSection();
- EditorConfiguration editorConfiguration = IniConfig.GetIniSection();
- // copy values
- try {
- coreConfiguration.OutputFileFilenamePattern = appConfig.Output_File_FilenamePattern;
- if (appConfig.Output_File_Format != null) {
- coreConfiguration.OutputFileFormat = (OutputFormat)Enum.Parse(typeof(OutputFormat), appConfig.Output_File_Format.ToLower());
- }
- coreConfiguration.OutputFileIncrementingNumber = unchecked((uint)appConfig.Output_File_IncrementingNumber);
- coreConfiguration.OutputFileJpegQuality = appConfig.Output_File_JpegQuality;
- coreConfiguration.OutputFilePath = appConfig.Output_File_Path;
- coreConfiguration.OutputFilePromptQuality = (bool)appConfig.Output_File_PromptJpegQuality;
- coreConfiguration.Language = appConfig.Ui_Language;
- coreConfiguration.PlayCameraSound = (bool)appConfig.Ui_Effects_CameraSound;
- coreConfiguration.CaptureMousepointer = (bool)appConfig.Capture_Mousepointer;
- coreConfiguration.OutputFileCopyPathToClipboard = (bool)appConfig.Output_File_CopyPathToClipboard;
- coreConfiguration.OutputPrintAllowEnlarge = (bool)appConfig.Output_Print_AllowEnlarge;
- coreConfiguration.OutputPrintAllowRotate = (bool)appConfig.Output_Print_AllowRotate;
- coreConfiguration.OutputPrintAllowShrink = (bool)appConfig.Output_Print_AllowShrink;
- coreConfiguration.OutputPrintCenter = (bool)appConfig.Output_Print_Center;
- coreConfiguration.OutputPrintPromptOptions = (bool)appConfig.Output_Print_PromptOptions;
- coreConfiguration.OutputPrintFooter = (bool)appConfig.Output_Print_Timestamp;
- int delay = appConfig.Capture_Wait_Time-1;
- if (delay < 0) {
- delay = 0;
- }
- coreConfiguration.CaptureDelay = delay;
- if ((appConfig.Output_Destinations & ScreenshotDestinations.Clipboard) == ScreenshotDestinations.Clipboard) {
- coreConfiguration.OutputDestinations.Add("Clipboard");
- }
- if ((appConfig.Output_Destinations & ScreenshotDestinations.Editor) == ScreenshotDestinations.Editor) {
- coreConfiguration.OutputDestinations.Add("Editor");
- }
- if ((appConfig.Output_Destinations & ScreenshotDestinations.EMail) == ScreenshotDestinations.EMail) {
- coreConfiguration.OutputDestinations.Add("EMail");
- }
- if ((appConfig.Output_Destinations & ScreenshotDestinations.Printer) == ScreenshotDestinations.Printer) {
- coreConfiguration.OutputDestinations.Add("Printer");
- }
- if ((appConfig.Output_Destinations & ScreenshotDestinations.FileDefault) == ScreenshotDestinations.FileDefault) {
- coreConfiguration.OutputDestinations.Add("File");
- }
- if ((appConfig.Output_Destinations & ScreenshotDestinations.FileWithDialog) == ScreenshotDestinations.FileWithDialog) {
- coreConfiguration.OutputDestinations.Add("FileWithDialog");
- }
- IniConfig.Save();
- } catch (Exception e) {
- LOG.Error(e);
- }
- }
- try {
- LOG.Info("Deleting old configuration");
- File.Delete(Path.Combine(configfilepath, CONFIG_FILE_NAME));
- } catch (Exception e) {
- LOG.Error(e);
- }
- }
- }
-
- ///
- /// Checks for the existence of a configuration file.
- /// First in greenshot's Applicationdata folder (where it is stored since 0.6),
- /// then (if it cannot be found there) in greenshot's program directory (where older
- /// versions might have stored it).
- /// If the latter is the case, the file is moved to the new location, so that a user does not lose
- /// their configuration after upgrading.
- /// If there is no file in both locations, a virgin config file is created.
- ///
- private static void CheckConfigFile() {
- // check if file is in the same location as started from, if this is the case
- // we will use this file instead of the ApplicationDate folder
- // Done for Feature Request #2741508
- if (File.Exists(Path.Combine(Application.StartupPath, CONFIG_FILE_NAME))) {
- configfilepath = Application.StartupPath;
- }
- }
- }
-}
diff --git a/Greenshot/Drawing/DrawableContainer.cs b/Greenshot/Drawing/DrawableContainer.cs
index 56698ec2d..2e4b27884 100644
--- a/Greenshot/Drawing/DrawableContainer.cs
+++ b/Greenshot/Drawing/DrawableContainer.cs
@@ -60,6 +60,10 @@ namespace Greenshot.Drawing {
}
}
+ ///
+ /// The public accessible Dispose
+ /// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
+ ///
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
diff --git a/Greenshot/Drawing/StepLabelContainer.cs b/Greenshot/Drawing/StepLabelContainer.cs
index acf3f93a6..5405c8cf2 100644
--- a/Greenshot/Drawing/StepLabelContainer.cs
+++ b/Greenshot/Drawing/StepLabelContainer.cs
@@ -21,10 +21,8 @@
using Greenshot.Drawing.Fields;
using Greenshot.Helpers;
-using Greenshot.Plugin;
using Greenshot.Plugin.Drawing;
using System;
-using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
@@ -133,9 +131,16 @@ namespace Greenshot.Drawing {
///
/// Make sure this element is no longer referenced from the surface
///
- public new void Dispose() {
+ protected override void Dispose(bool disposing) {
+ base.Dispose(disposing);
+ if (!disposing) {
+ return;
+ }
((Surface)Parent).RemoveStepLabel(this);
- base.Dispose();
+ if (_stringFormat != null) {
+ _stringFormat.Dispose();
+ _stringFormat = null;
+ }
}
public override bool HandleMouseMove(int x, int y) {
diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs
index 3a4e208bd..5118b3fa0 100644
--- a/Greenshot/Forms/MainForm.cs
+++ b/Greenshot/Forms/MainForm.cs
@@ -76,13 +76,6 @@ namespace Greenshot {
// Log the startup
LOG.Info("Starting: " + EnvironmentInfo.EnvironmentToString(false));
- // Upgrade if needed
- try {
- AppConfig.UpgradeToIni();
- } catch {
- LOG.Warn("Couldn't upgrade the config.dat to geenshot.ini.");
- }
-
// Read configuration
_conf = IniConfig.GetIniSection();
try {
diff --git a/Greenshot/GlobalSuppressions.cs b/Greenshot/GlobalSuppressions.cs
new file mode 100644
index 000000000..c3a0d1715
Binary files /dev/null and b/Greenshot/GlobalSuppressions.cs differ
diff --git a/Greenshot/Greenshot.csproj b/Greenshot/Greenshot.csproj
index 21b8faef2..61f4cb890 100644
--- a/Greenshot/Greenshot.csproj
+++ b/Greenshot/Greenshot.csproj
@@ -30,7 +30,6 @@
-
@@ -204,6 +203,7 @@
+
diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs
index 30c25f962..2e9be5c8b 100644
--- a/Greenshot/Helpers/CaptureHelper.cs
+++ b/Greenshot/Helpers/CaptureHelper.cs
@@ -40,7 +40,7 @@ namespace Greenshot.Helpers {
///
/// CaptureHelper contains all the capture logic
///
- public class CaptureHelper {
+ public class CaptureHelper : IDisposable {
private static readonly ILog LOG = LogManager.GetLogger(typeof(CaptureHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection();
// TODO: when we get the screen capture code working correctly, this needs to be enabled
@@ -73,36 +73,48 @@ namespace Greenshot.Helpers {
if (disposing) {
// Cleanup
}
+ // Unfortunately we can't dispose the capture, this might still be used somewhere else.
_windows = null;
_selectedCaptureWindow = null;
_capture = null;
}
public static void CaptureClipboard() {
- new CaptureHelper(CaptureMode.Clipboard).MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard)) {
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureRegion(bool captureMouse) {
- new CaptureHelper(CaptureMode.Region, captureMouse).MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region, captureMouse)) {
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureRegion(bool captureMouse, IDestination destination) {
- CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region, captureMouse, destination);
- captureHelper.MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region, captureMouse, destination)) {
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureRegion(bool captureMouse, Rectangle region) {
- new CaptureHelper(CaptureMode.Region, captureMouse).MakeCapture(region);
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region, captureMouse)) {
+ captureHelper.MakeCapture(region);
+ }
}
public static void CaptureFullscreen(bool captureMouse, ScreenCaptureMode screenCaptureMode) {
- CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen, captureMouse);
- captureHelper._screenCaptureMode = screenCaptureMode;
- captureHelper.MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen, captureMouse)) {
+ captureHelper._screenCaptureMode = screenCaptureMode;
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureLastRegion(bool captureMouse) {
- new CaptureHelper(CaptureMode.LastRegion, captureMouse).MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.LastRegion, captureMouse)) {
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureIE(bool captureMouse, WindowDetails windowToCapture) {
- CaptureHelper captureHelper = new CaptureHelper(CaptureMode.IE, captureMouse);
- captureHelper.SelectedCaptureWindow = windowToCapture;
- captureHelper.MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.IE, captureMouse)) {
+ captureHelper.SelectedCaptureWindow = windowToCapture;
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureWindow(bool captureMouse) {
@@ -110,27 +122,35 @@ namespace Greenshot.Helpers {
}
public static void CaptureWindow(WindowDetails windowToCapture) {
- CaptureHelper captureHelper = new CaptureHelper(CaptureMode.ActiveWindow);
- captureHelper.SelectedCaptureWindow = windowToCapture;
- captureHelper.MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.ActiveWindow)) {
+ captureHelper.SelectedCaptureWindow = windowToCapture;
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureWindowInteractive(bool captureMouse) {
- new CaptureHelper(CaptureMode.Window, captureMouse).MakeCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Window)) {
+ captureHelper.MakeCapture();
+ }
}
public static void CaptureFile(string filename) {
- new CaptureHelper(CaptureMode.File).MakeCapture(filename);
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File)) {
+ captureHelper.MakeCapture(filename);
+ }
}
public static void CaptureFile(string filename, IDestination destination) {
- new CaptureHelper(CaptureMode.File).AddDestination(destination).MakeCapture(filename);
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File)) {
+ captureHelper.AddDestination(destination).MakeCapture(filename);
+ }
}
public static void ImportCapture(ICapture captureToImport) {
- CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File);
- captureHelper._capture = captureToImport;
- captureHelper.HandleCapture();
+ using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File)) {
+ captureHelper._capture = captureToImport;
+ captureHelper.HandleCapture();
+ }
}
public CaptureHelper AddDestination(IDestination destination) {
diff --git a/Greenshot/Helpers/MailHelper.cs b/Greenshot/Helpers/MailHelper.cs
index 4c7317545..44ee22a54 100644
--- a/Greenshot/Helpers/MailHelper.cs
+++ b/Greenshot/Helpers/MailHelper.cs
@@ -18,6 +18,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+
+using Greenshot.IniFile;
+using Greenshot.Plugin;
+using GreenshotPlugin.Core;
+using log4net;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -26,44 +31,40 @@ using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
-using Greenshot.Plugin;
-using GreenshotPlugin.Core;
-using Greenshot.IniFile;
-///
-/// Author: Andrew Baker
-/// Datum: 10.03.2006
-/// Available from: http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71&PostID=1
-///
-using log4net;
-
namespace Greenshot.Helpers {
+ ///
+ /// Author: Andrew Baker
+ /// Datum: 10.03.2006
+ /// Available from: http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71&PostID=1
+ ///
#region Public MapiMailMessage Class
///
/// Represents an email message to be sent through MAPI.
///
- public class MapiMailMessage {
+ public class MapiMailMessage : IDisposable {
private static readonly ILog LOG = LogManager.GetLogger(typeof(MapiMailMessage));
- private static CoreConfiguration conf = IniConfig.GetIniSection();
+ private static readonly CoreConfiguration conf = IniConfig.GetIniSection();
///
/// Helper Method for creating an Email with Attachment
///
- /// Path to file
- ///
+ /// Path to file
+ ///
public static void SendImage(string fullPath, string title) {
- MapiMailMessage message = new MapiMailMessage(title, null);
- message.Files.Add(fullPath);
- if (!string.IsNullOrEmpty(conf.MailApiTo)) {
- message._recipientCollection.Add(new Recipient(conf.MailApiTo, RecipientType.To));
+ using (MapiMailMessage message = new MapiMailMessage(title, null)) {
+ message.Files.Add(fullPath);
+ if (!string.IsNullOrEmpty(conf.MailApiTo)) {
+ message._recipientCollection.Add(new Recipient(conf.MailApiTo, RecipientType.To));
+ }
+ if (!string.IsNullOrEmpty(conf.MailApiCC)) {
+ message._recipientCollection.Add(new Recipient(conf.MailApiCC, RecipientType.CC));
+ }
+ if (!string.IsNullOrEmpty(conf.MailApiBCC)) {
+ message._recipientCollection.Add(new Recipient(conf.MailApiBCC, RecipientType.BCC));
+ }
+ message.ShowDialog();
}
- if (!string.IsNullOrEmpty(conf.MailApiCC)) {
- message._recipientCollection.Add(new Recipient(conf.MailApiCC, RecipientType.CC));
- }
- if (!string.IsNullOrEmpty(conf.MailApiBCC)) {
- message._recipientCollection.Add(new Recipient(conf.MailApiBCC, RecipientType.BCC));
- }
- message.ShowDialog();
}
@@ -133,8 +134,8 @@ namespace Greenshot.Helpers {
private string _subject;
private string _body;
private RecipientCollection _recipientCollection;
- private List _files;
- private ManualResetEvent _manualResetEvent;
+ private readonly List _files;
+ private readonly ManualResetEvent _manualResetEvent;
#endregion Member Variables
@@ -230,10 +231,25 @@ namespace Greenshot.Helpers {
_manualResetEvent.Reset();
}
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
#endregion Public Methods
#region Private Methods
+ protected virtual void Dispose(bool disposing) {
+ if (!disposing) {
+ return;
+ }
+ if (_manualResetEvent != null) {
+ _manualResetEvent.Close();
+ }
+
+ }
+
///
/// Sends the mail message.
///
@@ -504,7 +520,7 @@ namespace Greenshot.Helpers {
public IntPtr EntryID = IntPtr.Zero;
}
- [DllImport("MAPI32.DLL", SetLastError = true, CharSet=CharSet.Unicode)]
+ [DllImport("MAPI32.DLL", SetLastError = true, CharSet=CharSet.Ansi)]
public static extern int MAPISendMail(IntPtr session, IntPtr hwnd, MapiMessage message, int flg, int rsv);
#endregion Structs
diff --git a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
index b8ae93598..773fbee38 100644
--- a/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
+++ b/GreenshotExternalCommandPlugin/ExternalCommandDestination.cs
@@ -114,7 +114,7 @@ namespace ExternalCommand {
} catch {
w32ex.Data.Add("commandline", config.commandlines[presetCommand]);
w32ex.Data.Add("arguments", config.arguments[presetCommand]);
- throw w32ex;
+ throw;
}
} catch (Exception ex) {
ex.Data.Add("commandline", config.commandlines[presetCommand]);
@@ -127,7 +127,7 @@ namespace ExternalCommand {
string commandline = config.commandlines[commando];
string arguments = config.arguments[commando];
output = null;
- if (commandline != null && commandline.Length > 0) {
+ if (!string.IsNullOrEmpty(commandline)) {
using (Process p = new Process()) {
p.StartInfo.FileName = commandline;
p.StartInfo.Arguments = String.Format(arguments, fullPath);
diff --git a/GreenshotOfficePlugin/GlobalSuppressions.cs b/GreenshotOfficePlugin/GlobalSuppressions.cs
new file mode 100644
index 000000000..882507f6b
Binary files /dev/null and b/GreenshotOfficePlugin/GlobalSuppressions.cs differ
diff --git a/GreenshotOfficePlugin/GreenshotOfficePlugin.csproj b/GreenshotOfficePlugin/GreenshotOfficePlugin.csproj
index 6297f5d4e..7709d4fb3 100644
--- a/GreenshotOfficePlugin/GreenshotOfficePlugin.csproj
+++ b/GreenshotOfficePlugin/GreenshotOfficePlugin.csproj
@@ -54,6 +54,7 @@
+
@@ -76,9 +77,7 @@
GreenshotPlugin
-
-
-
+
mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
diff --git a/GreenshotOfficePlugin/OfficeInterop/OutlookUtils.cs b/GreenshotOfficePlugin/OfficeInterop/OutlookUtils.cs
index 9a38daa9b..eeab0638b 100644
--- a/GreenshotOfficePlugin/OfficeInterop/OutlookUtils.cs
+++ b/GreenshotOfficePlugin/OfficeInterop/OutlookUtils.cs
@@ -434,6 +434,8 @@ namespace Greenshot.Interop.Office {
PR_REPORTING_MTA_CERTIFICATE = PT.PT_BINARY | 0x1004 << 16,
};
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Interoperability", "CA1401:PInvokesShouldNotBeVisible")]
+ [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1060:MovePInvokesToNativeMethodsClass")]
public class OutlookUtils {
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OutlookUtils));
private const uint KEEP_OPEN_READONLY = 0x00000001;
@@ -783,20 +785,13 @@ namespace Greenshot.Interop.Office {
}
#region MAPI DLL Imports
-
- [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrGetOneProp@12")]
- private static extern void HrGetOneProp(IntPtr pmp, uint ulPropTag, out IntPtr ppProp);
-
- [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi, EntryPoint = "HrSetOneProp@8")]
+ [DllImport("MAPI32.DLL", EntryPoint = "HrSetOneProp@8")]
private static extern void HrSetOneProp(IntPtr pmp, IntPtr pprop);
- [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi, EntryPoint = "MAPIFreeBuffer@4")]
- private static extern void MAPIFreeBuffer(IntPtr lpBuffer);
-
- [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
+ [DllImport("MAPI32.DLL")]
private static extern int MAPIInitialize(IntPtr lpMapiInit);
- [DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
+ [DllImport("MAPI32.DLL")]
private static extern void MAPIUninitialize();
#endregion
}
diff --git a/GreenshotPlugin/Controls/HotkeyControl.cs b/GreenshotPlugin/Controls/HotkeyControl.cs
index 2086e9360..00731f9e0 100644
--- a/GreenshotPlugin/Controls/HotkeyControl.cs
+++ b/GreenshotPlugin/Controls/HotkeyControl.cs
@@ -79,7 +79,7 @@ namespace GreenshotPlugin.Controls {
[DllImport("user32.dll", SetLastError = true)]
private static extern uint MapVirtualKey(uint uCode, uint uMapType);
- [DllImport("user32.dll", EntryPoint = "GetKeyNameTextA", SetLastError = true)]
+ [DllImport("user32.dll", EntryPoint = "GetKeyNameTextW", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern int GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize);
// These variables store the current hotkey and modifier(s)
diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs
index 305131c4b..a63a0dc8f 100644
--- a/GreenshotPlugin/Core/WindowsHelper.cs
+++ b/GreenshotPlugin/Core/WindowsHelper.cs
@@ -1366,7 +1366,7 @@ namespace GreenshotPlugin.Core {
}
returnImage = new Bitmap(windowRect.Width, windowRect.Height, pixelFormat);
using (Graphics graphics = Graphics.FromImage(returnImage)) {
- using (SafeDeviceContextHandle graphicsDC = graphics.getSafeDeviceContext()) {
+ using (SafeDeviceContextHandle graphicsDC = graphics.GetSafeDeviceContext()) {
bool printSucceeded = User32.PrintWindow(Handle, graphicsDC.DangerousGetHandle(), 0x0);
if (!printSucceeded) {
// something went wrong, most likely a "0x80004005" (Acess Denied) when using UAC
diff --git a/GreenshotPlugin/GlobalSuppressions.cs b/GreenshotPlugin/GlobalSuppressions.cs
new file mode 100644
index 000000000..691d5bdec
Binary files /dev/null and b/GreenshotPlugin/GlobalSuppressions.cs differ
diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj
index b5274de11..c1bb819dc 100644
--- a/GreenshotPlugin/GreenshotPlugin.csproj
+++ b/GreenshotPlugin/GreenshotPlugin.csproj
@@ -35,6 +35,7 @@
Component
+
diff --git a/GreenshotPlugin/UnmanagedHelpers/GDI32.cs b/GreenshotPlugin/UnmanagedHelpers/GDI32.cs
index cfd7eda62..e6d7c9ba0 100644
--- a/GreenshotPlugin/UnmanagedHelpers/GDI32.cs
+++ b/GreenshotPlugin/UnmanagedHelpers/GDI32.cs
@@ -18,6 +18,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
+
using System;
using System.Drawing;
using System.Runtime.InteropServices;
@@ -51,7 +52,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
///
///
/// SafeDeviceContextHandle
- public static SafeDeviceContextHandle getSafeDeviceContext(this Graphics graphics) {
+ public static SafeDeviceContextHandle GetSafeDeviceContext(this Graphics graphics) {
return SafeDeviceContextHandle.fromGraphics(graphics);
}
}
@@ -75,10 +76,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
/// A hbitmap SafeHandle implementation
///
public class SafeHBitmapHandle : SafeObjectHandle {
- [SecurityCritical]
- private SafeHBitmapHandle() : base(true) {
- }
-
[SecurityCritical]
public SafeHBitmapHandle(IntPtr preexistingHandle) : base(true) {
SetHandle(preexistingHandle);
@@ -89,10 +86,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
/// A hRegion SafeHandle implementation
///
public class SafeRegionHandle : SafeObjectHandle {
- [SecurityCritical]
- private SafeRegionHandle() : base(true) {
- }
-
[SecurityCritical]
public SafeRegionHandle(IntPtr preexistingHandle) : base(true) {
SetHandle(preexistingHandle);
@@ -103,10 +96,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
/// A dibsection SafeHandle implementation
///
public class SafeDibSectionHandle : SafeObjectHandle {
- [SecurityCritical]
- private SafeDibSectionHandle() : base(true) {
- }
-
[SecurityCritical]
public SafeDibSectionHandle(IntPtr preexistingHandle) : base(true) {
SetHandle(preexistingHandle);
@@ -123,10 +112,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
private SafeHandle hdc;
- [SecurityCritical]
- private SafeSelectObjectHandle() : base(true) {
- }
-
[SecurityCritical]
public SafeSelectObjectHandle(SafeDCHandle hdc, SafeHandle newHandle) : base(true) {
this.hdc = hdc;
@@ -150,10 +135,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
[DllImport("gdi32", SetLastError = true)]
private static extern bool DeleteDC(IntPtr hDC);
- [SecurityCritical]
- private SafeCompatibleDCHandle() : base(true) {
- }
-
[SecurityCritical]
public SafeCompatibleDCHandle(IntPtr preexistingHandle) : base(true) {
SetHandle(preexistingHandle);
@@ -173,9 +154,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
///
public class SafeDeviceContextHandle : SafeDCHandle {
private Graphics graphics = null;
- [SecurityCritical]
- private SafeDeviceContextHandle() : base(true) {
- }
[SecurityCritical]
public SafeDeviceContextHandle(Graphics graphics, IntPtr preexistingHandle) : base(true) {
@@ -225,10 +203,10 @@ namespace GreenshotPlugin.UnmanagedHelpers {
///
///
public static void StretchBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Rectangle destination) {
- using (SafeDeviceContextHandle targetDC = target.getSafeDeviceContext()) {
+ using (SafeDeviceContextHandle targetDC = target.GetSafeDeviceContext()) {
using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
- using (SafeSelectObjectHandle selectObject = safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
+ using (safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
StretchBlt(targetDC, destination.X, destination.Y, destination.Width, destination.Height, safeCompatibleDCHandle, source.Left, source.Top, source.Width, source.Height, CopyPixelOperation.SourceCopy);
}
}
@@ -242,10 +220,10 @@ namespace GreenshotPlugin.UnmanagedHelpers {
///
///
public static void BitBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Point destination, CopyPixelOperation rop) {
- using (SafeDeviceContextHandle targetDC = target.getSafeDeviceContext()) {
+ using (SafeDeviceContextHandle targetDC = target.GetSafeDeviceContext()) {
using (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
- using (SafeSelectObjectHandle selectObject = safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
+ using (safeCompatibleDCHandle.SelectObject(hBitmapHandle)) {
BitBlt(targetDC, destination.X, destination.Y, source.Width, source.Height, safeCompatibleDCHandle, source.Left, source.Top, rop);
}
}
diff --git a/GreenshotPlugin/UnmanagedHelpers/User32.cs b/GreenshotPlugin/UnmanagedHelpers/User32.cs
index ac4447ed3..5730b9db9 100644
--- a/GreenshotPlugin/UnmanagedHelpers/User32.cs
+++ b/GreenshotPlugin/UnmanagedHelpers/User32.cs
@@ -116,7 +116,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
public extern static IntPtr GetWindowLongPtr(IntPtr hwnd, int nIndex);
[DllImport("user32", SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int index, int styleFlags);
- [DllImport("user32", SetLastError = true)]
+ [DllImport("user32", SetLastError = true, EntryPoint = "SetWindowLongPtr")]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int index, IntPtr styleFlags);
[DllImport("user32", SetLastError = true)]
public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);