From 15253ef295c29544da97edd7c01e1cc69ea25e7f Mon Sep 17 00:00:00 2001 From: RKrom Date: Sun, 15 Jun 2014 11:45:01 +0200 Subject: [PATCH] Code cleanup, removed a lot of FxCop messages and added some more disposing. --- Greenshot/Configuration/AppConfig.cs | 227 ------------------ Greenshot/Drawing/DrawableContainer.cs | 4 + Greenshot/Drawing/StepLabelContainer.cs | 13 +- Greenshot/Forms/MainForm.cs | 7 - Greenshot/GlobalSuppressions.cs | Bin 0 -> 12860 bytes Greenshot/Greenshot.csproj | 2 +- Greenshot/Helpers/CaptureHelper.cs | 64 +++-- Greenshot/Helpers/MailHelper.cs | 72 +++--- .../ExternalCommandDestination.cs | 4 +- GreenshotOfficePlugin/GlobalSuppressions.cs | Bin 0 -> 3260 bytes .../GreenshotOfficePlugin.csproj | 5 +- .../OfficeInterop/OutlookUtils.cs | 15 +- GreenshotPlugin/Controls/HotkeyControl.cs | 2 +- GreenshotPlugin/Core/WindowsHelper.cs | 2 +- GreenshotPlugin/GlobalSuppressions.cs | Bin 0 -> 112942 bytes GreenshotPlugin/GreenshotPlugin.csproj | 1 + GreenshotPlugin/UnmanagedHelpers/GDI32.cs | 34 +-- GreenshotPlugin/UnmanagedHelpers/User32.cs | 2 +- 18 files changed, 119 insertions(+), 335 deletions(-) delete mode 100644 Greenshot/Configuration/AppConfig.cs create mode 100644 Greenshot/GlobalSuppressions.cs create mode 100644 GreenshotOfficePlugin/GlobalSuppressions.cs create mode 100644 GreenshotPlugin/GlobalSuppressions.cs 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 0000000000000000000000000000000000000000..c3a0d1715caf7e045730146ab01298ad181b8228 GIT binary patch literal 12860 zcmeHNSx*~54EA%S{)bg6RUjY~kothshj2Cz6vPHpR8`eB2_Yqy*bORwzU}wfjP}Sv zK@g5;gu?F5csw2-V|zS*|18V01k#W*=}L^ZQ#^ap#+!YQ(b|?4zJJOU{%^_?aOBiLVDZqs?X}oKeELhVl!&O^mKeI>SM(XGzz33Ai4x#sxaNz%ft?+Q3Wf zZHx|-8jcCj%N28_7rK@NUqgj)ly)$Zumkj@R7CiSu>#W9Rh~B|@I)9xzQ=$WDlETj zr5sQ0_kn?UBEYm|QTwkHmhbHCgOjA1-))R;X1I~k)6jK9n2&Q9b$OW?FWmeor=7kK zKjqc|cM@5`Jd{pT&e3k1GkPe0CwFQ|+M7~yn~s?dje$J@CeAtn?WS*zy2^yc1qGd} z=t#%mEUhUO6{#zIMeTK**uku{luCx9ft-MvF{o-ON2wpwi2>lUn(8=xv&I!Q+VR=! zYk)aud$c~&Zqoe?ZRD>>oqg+=J5&p$E%gDr1**w^QWk?Y$|y#=<9X4ls}sD;Tkjm! zzo%GeaWQ_Uz{+{3nbd~?ASkB_=BUYve2|a$tz*e2K4f9YbCG0vbshEr;__ zgShX+z|p&2rC|+0zgb5hpLCY2)*DO%BU1Y`s9m&BCbVzjCe5Gm-BatiK&$a&1nzAq zH4*0KJ~Y4|;i~dZcJY>o?I|OfEAX27!(Q%ai-o>WTdB7lnFnv?<-6_=UWU|^r<7s% zC^9U{H!FKD-{-W^L&&!e3+G< z#7B@HpUlJZK4AghHSE6iTug6!JSESJfjfhPNodq%Ij>9oeAa8;-`n4u1-KaDF45%e-oa;( zjOm`|hJjd?~Y%2c5nBD{9OTBb3VWECq4eI Pz-zn5>rZ;7aaZ6U9^}=n literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..882507f6b2bc153394105cf0e4819544426c8df0 GIT binary patch literal 3260 zcmeH}OK;Oa6ou~^iT_|33AGY!c}OfOu_&Mx7J*1f76`F0shgT6PEvBZXUZG~05UGbb+&RbY7+0E^e^>w<=?HT2Dtk_J;%F3; zVAY9r(px`E&1&vG5$S|T`IcB36d9|E69`}7oR7EiWWx8#E8~Sm>c8*=sVX>H_Sc-y*tntK*VR&!rw28E#{3P^9+J@pZd5 zGI35-O-kBgG_fzBS%T`)8C8F%CrbR-w+k<(91-_tXyI^3cBdeX`eFo%O#oAN-@{ZC&@O?!qMZ zxTAC + @@ -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 0000000000000000000000000000000000000000..691d5bdece11f0918b96cf2f03101a372ba9fb84 GIT binary patch literal 112942 zcmeHQZEqXL5x&m_`X2-b2wXH(o3`kO0R146k}O2BSy67<1c4!&l*C#T1(J%R{`j`f zv!l(;?cFU!@z`6+1H+cZz1v&fJo7#~```ckKKp&PlbvN(**Kfye;4?9osIB6`TY)` zj=Qp<2qTJJek+YO8Bg4_AiWn zz}>r9{)B#Ep64Z;~dZ9Gh}r|n#sHH&(Ghq#|!5t-7fKV7TNFc z98%{)_7R`Uo0IjB{+{kcNj{pdCWbM=&>d!9U?x8G7Hb#0`PIEBA#NwY+zWT7f5UpM z`6^yyM{a!~di|R?z*EU7FVq{|$^MDe++kHi_eO~iV&VqZX{7o$U5~gB(f&OPf8F32 zfxAZQH-1`#W z|HREgj+^7}1!m=Qh)m+)23L?yFYt`L?Cb0g*TF_Y{qKx#kRa~e?Raa3d-x5%!`gPUFYv!lxb`i^hPaw<`V4d4Io{*_#EHlq za{SDFGrpad0d0sku7eWrtE{ONzQbx>VRa{22k&(cZ~HiVho_uoZ}9IvexBj8eXQln z>^Gp&Z?Yeqq)G`*@@Dw%gw`{>)%WhbQZC;I2>Ube^)(O{B5U9%P1!NTn;^|QpvT`a z50UyFpOc%3)pStxH{gih`@RBG1AK=&j8XOv@D2WrpPRxVx~c zKR7##{+G8U=^Ipi{sy+Dk4+rl{wX|#?{F9W{V9Bjn1&9ez+2}%EwVple}v^)lmdsa z4#$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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);