mirror of
https://github.com/greenshot/greenshot
synced 2025-07-15 01:23:47 -07:00
Code cleanup, removed a lot of FxCop messages and added some more disposing.
This commit is contained in:
parent
49869a2630
commit
15253ef295
18 changed files with 119 additions and 335 deletions
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
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}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
|
||||||
[Serializable]
|
|
||||||
public class AppConfig {
|
|
||||||
private static ILog LOG = LogManager.GetLogger(typeof(AppConfig));
|
|
||||||
private static readonly Regex FIXOLD_REGEXP = new Regex(@"%(?<variable>[\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
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// a private constructor because this is a singleton
|
|
||||||
/// </summary>
|
|
||||||
private AppConfig() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Remove the old %VAR% syntax
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="oldPattern">String with old syntax %VAR%</param>
|
|
||||||
/// <returns>The fixed pattern</returns>
|
|
||||||
private static string FixFallback(string oldPattern) {
|
|
||||||
return FIXOLD_REGEXP.Replace(oldPattern, delegate(Match m) { return VAR_PREFIX + m.Groups["variable"].Value + VAR_POSTFIX;});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// loads the configuration from the config file
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>an instance of AppConfig with all values set from the config file</returns>
|
|
||||||
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<CoreConfiguration>();
|
|
||||||
EditorConfiguration editorConfiguration = IniConfig.GetIniSection<EditorConfiguration>();
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 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.
|
|
||||||
/// </summary>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -60,6 +60,10 @@ namespace Greenshot.Drawing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The public accessible Dispose
|
||||||
|
/// Will call the GarbageCollector to SuppressFinalize, preventing being cleaned twice
|
||||||
|
/// </summary>
|
||||||
public void Dispose() {
|
public void Dispose() {
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
|
|
@ -21,10 +21,8 @@
|
||||||
|
|
||||||
using Greenshot.Drawing.Fields;
|
using Greenshot.Drawing.Fields;
|
||||||
using Greenshot.Helpers;
|
using Greenshot.Helpers;
|
||||||
using Greenshot.Plugin;
|
|
||||||
using Greenshot.Plugin.Drawing;
|
using Greenshot.Plugin.Drawing;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
using System.Drawing.Text;
|
using System.Drawing.Text;
|
||||||
|
@ -133,9 +131,16 @@ namespace Greenshot.Drawing {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Make sure this element is no longer referenced from the surface
|
/// Make sure this element is no longer referenced from the surface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public new void Dispose() {
|
protected override void Dispose(bool disposing) {
|
||||||
|
base.Dispose(disposing);
|
||||||
|
if (!disposing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
((Surface)Parent).RemoveStepLabel(this);
|
((Surface)Parent).RemoveStepLabel(this);
|
||||||
base.Dispose();
|
if (_stringFormat != null) {
|
||||||
|
_stringFormat.Dispose();
|
||||||
|
_stringFormat = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandleMouseMove(int x, int y) {
|
public override bool HandleMouseMove(int x, int y) {
|
||||||
|
|
|
@ -76,13 +76,6 @@ namespace Greenshot {
|
||||||
// Log the startup
|
// Log the startup
|
||||||
LOG.Info("Starting: " + EnvironmentInfo.EnvironmentToString(false));
|
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
|
// Read configuration
|
||||||
_conf = IniConfig.GetIniSection<CoreConfiguration>();
|
_conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
try {
|
try {
|
||||||
|
|
BIN
Greenshot/GlobalSuppressions.cs
Normal file
BIN
Greenshot/GlobalSuppressions.cs
Normal file
Binary file not shown.
|
@ -30,7 +30,6 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="AssemblyInfo.cs" />
|
<Compile Include="AssemblyInfo.cs" />
|
||||||
<Compile Include="Configuration\AppConfig.cs" />
|
|
||||||
<Compile Include="Configuration\EditorConfiguration.cs" />
|
<Compile Include="Configuration\EditorConfiguration.cs" />
|
||||||
<Compile Include="Configuration\LanguageKeys.cs" />
|
<Compile Include="Configuration\LanguageKeys.cs" />
|
||||||
<Compile Include="Configuration\RuntimeConfig.cs" />
|
<Compile Include="Configuration\RuntimeConfig.cs" />
|
||||||
|
@ -204,6 +203,7 @@
|
||||||
</Compile>
|
</Compile>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
<None Include="Helpers\AviHelper.cs" />
|
<None Include="Helpers\AviHelper.cs" />
|
||||||
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
<Compile Include="Helpers\CaptureHelper.cs" />
|
<Compile Include="Helpers\CaptureHelper.cs" />
|
||||||
<Compile Include="Helpers\Colors.cs" />
|
<Compile Include="Helpers\Colors.cs" />
|
||||||
<Compile Include="Helpers\CopyData.cs" />
|
<Compile Include="Helpers\CopyData.cs" />
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CaptureHelper contains all the capture logic
|
/// CaptureHelper contains all the capture logic
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CaptureHelper {
|
public class CaptureHelper : IDisposable {
|
||||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(CaptureHelper));
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(CaptureHelper));
|
||||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
// TODO: when we get the screen capture code working correctly, this needs to be enabled
|
// TODO: when we get the screen capture code working correctly, this needs to be enabled
|
||||||
|
@ -73,36 +73,48 @@ namespace Greenshot.Helpers {
|
||||||
if (disposing) {
|
if (disposing) {
|
||||||
// Cleanup
|
// Cleanup
|
||||||
}
|
}
|
||||||
|
// Unfortunately we can't dispose the capture, this might still be used somewhere else.
|
||||||
_windows = null;
|
_windows = null;
|
||||||
_selectedCaptureWindow = null;
|
_selectedCaptureWindow = null;
|
||||||
_capture = null;
|
_capture = null;
|
||||||
}
|
}
|
||||||
public static void CaptureClipboard() {
|
public static void CaptureClipboard() {
|
||||||
new CaptureHelper(CaptureMode.Clipboard).MakeCapture();
|
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Clipboard)) {
|
||||||
|
captureHelper.MakeCapture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void CaptureRegion(bool captureMouse) {
|
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) {
|
public static void CaptureRegion(bool captureMouse, IDestination destination) {
|
||||||
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region, captureMouse, destination);
|
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.Region, captureMouse, destination)) {
|
||||||
captureHelper.MakeCapture();
|
captureHelper.MakeCapture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void CaptureRegion(bool captureMouse, Rectangle region) {
|
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) {
|
public static void CaptureFullscreen(bool captureMouse, ScreenCaptureMode screenCaptureMode) {
|
||||||
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen, captureMouse);
|
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.FullScreen, captureMouse)) {
|
||||||
captureHelper._screenCaptureMode = screenCaptureMode;
|
captureHelper._screenCaptureMode = screenCaptureMode;
|
||||||
captureHelper.MakeCapture();
|
captureHelper.MakeCapture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void CaptureLastRegion(bool captureMouse) {
|
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) {
|
public static void CaptureIE(bool captureMouse, WindowDetails windowToCapture) {
|
||||||
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.IE, captureMouse);
|
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.IE, captureMouse)) {
|
||||||
captureHelper.SelectedCaptureWindow = windowToCapture;
|
captureHelper.SelectedCaptureWindow = windowToCapture;
|
||||||
captureHelper.MakeCapture();
|
captureHelper.MakeCapture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CaptureWindow(bool captureMouse) {
|
public static void CaptureWindow(bool captureMouse) {
|
||||||
|
@ -110,27 +122,35 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CaptureWindow(WindowDetails windowToCapture) {
|
public static void CaptureWindow(WindowDetails windowToCapture) {
|
||||||
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.ActiveWindow);
|
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.ActiveWindow)) {
|
||||||
captureHelper.SelectedCaptureWindow = windowToCapture;
|
captureHelper.SelectedCaptureWindow = windowToCapture;
|
||||||
captureHelper.MakeCapture();
|
captureHelper.MakeCapture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CaptureWindowInteractive(bool captureMouse) {
|
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) {
|
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) {
|
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) {
|
public static void ImportCapture(ICapture captureToImport) {
|
||||||
CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File);
|
using (CaptureHelper captureHelper = new CaptureHelper(CaptureMode.File)) {
|
||||||
captureHelper._capture = captureToImport;
|
captureHelper._capture = captureToImport;
|
||||||
captureHelper.HandleCapture();
|
captureHelper.HandleCapture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CaptureHelper AddDestination(IDestination destination) {
|
public CaptureHelper AddDestination(IDestination destination) {
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
using Greenshot.IniFile;
|
||||||
|
using Greenshot.Plugin;
|
||||||
|
using GreenshotPlugin.Core;
|
||||||
|
using log4net;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -26,44 +31,40 @@ using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Greenshot.Plugin;
|
|
||||||
using GreenshotPlugin.Core;
|
|
||||||
using Greenshot.IniFile;
|
|
||||||
/// <summary>
|
|
||||||
/// Author: Andrew Baker
|
|
||||||
/// Datum: 10.03.2006
|
|
||||||
/// Available from: http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71&PostID=1
|
|
||||||
/// </summary>
|
|
||||||
using log4net;
|
|
||||||
|
|
||||||
namespace Greenshot.Helpers {
|
namespace Greenshot.Helpers {
|
||||||
|
/// <summary>
|
||||||
|
/// Author: Andrew Baker
|
||||||
|
/// Datum: 10.03.2006
|
||||||
|
/// Available from: http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71&PostID=1
|
||||||
|
/// </summary>
|
||||||
#region Public MapiMailMessage Class
|
#region Public MapiMailMessage Class
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an email message to be sent through MAPI.
|
/// Represents an email message to be sent through MAPI.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MapiMailMessage {
|
public class MapiMailMessage : IDisposable {
|
||||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(MapiMailMessage));
|
private static readonly ILog LOG = LogManager.GetLogger(typeof(MapiMailMessage));
|
||||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
private static readonly CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Helper Method for creating an Email with Attachment
|
/// Helper Method for creating an Email with Attachment
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fullpath">Path to file</param>
|
/// <param name="fullPath">Path to file</param>
|
||||||
/// <param name="captureDetails"></param>
|
/// <param name="title"></param>
|
||||||
public static void SendImage(string fullPath, string title) {
|
public static void SendImage(string fullPath, string title) {
|
||||||
MapiMailMessage message = new MapiMailMessage(title, null);
|
using (MapiMailMessage message = new MapiMailMessage(title, null)) {
|
||||||
message.Files.Add(fullPath);
|
message.Files.Add(fullPath);
|
||||||
if (!string.IsNullOrEmpty(conf.MailApiTo)) {
|
if (!string.IsNullOrEmpty(conf.MailApiTo)) {
|
||||||
message._recipientCollection.Add(new Recipient(conf.MailApiTo, RecipientType.To));
|
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 _subject;
|
||||||
private string _body;
|
private string _body;
|
||||||
private RecipientCollection _recipientCollection;
|
private RecipientCollection _recipientCollection;
|
||||||
private List<string> _files;
|
private readonly List<string> _files;
|
||||||
private ManualResetEvent _manualResetEvent;
|
private readonly ManualResetEvent _manualResetEvent;
|
||||||
|
|
||||||
#endregion Member Variables
|
#endregion Member Variables
|
||||||
|
|
||||||
|
@ -230,10 +231,25 @@ namespace Greenshot.Helpers {
|
||||||
_manualResetEvent.Reset();
|
_manualResetEvent.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion Public Methods
|
#endregion Public Methods
|
||||||
|
|
||||||
#region Private Methods
|
#region Private Methods
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing) {
|
||||||
|
if (!disposing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_manualResetEvent != null) {
|
||||||
|
_manualResetEvent.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends the mail message.
|
/// Sends the mail message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -504,7 +520,7 @@ namespace Greenshot.Helpers {
|
||||||
public IntPtr EntryID = IntPtr.Zero;
|
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);
|
public static extern int MAPISendMail(IntPtr session, IntPtr hwnd, MapiMessage message, int flg, int rsv);
|
||||||
|
|
||||||
#endregion Structs
|
#endregion Structs
|
||||||
|
|
|
@ -114,7 +114,7 @@ namespace ExternalCommand {
|
||||||
} catch {
|
} catch {
|
||||||
w32ex.Data.Add("commandline", config.commandlines[presetCommand]);
|
w32ex.Data.Add("commandline", config.commandlines[presetCommand]);
|
||||||
w32ex.Data.Add("arguments", config.arguments[presetCommand]);
|
w32ex.Data.Add("arguments", config.arguments[presetCommand]);
|
||||||
throw w32ex;
|
throw;
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.Data.Add("commandline", config.commandlines[presetCommand]);
|
ex.Data.Add("commandline", config.commandlines[presetCommand]);
|
||||||
|
@ -127,7 +127,7 @@ namespace ExternalCommand {
|
||||||
string commandline = config.commandlines[commando];
|
string commandline = config.commandlines[commando];
|
||||||
string arguments = config.arguments[commando];
|
string arguments = config.arguments[commando];
|
||||||
output = null;
|
output = null;
|
||||||
if (commandline != null && commandline.Length > 0) {
|
if (!string.IsNullOrEmpty(commandline)) {
|
||||||
using (Process p = new Process()) {
|
using (Process p = new Process()) {
|
||||||
p.StartInfo.FileName = commandline;
|
p.StartInfo.FileName = commandline;
|
||||||
p.StartInfo.Arguments = String.Format(arguments, fullPath);
|
p.StartInfo.Arguments = String.Format(arguments, fullPath);
|
||||||
|
|
BIN
GreenshotOfficePlugin/GlobalSuppressions.cs
Normal file
BIN
GreenshotOfficePlugin/GlobalSuppressions.cs
Normal file
Binary file not shown.
|
@ -54,6 +54,7 @@
|
||||||
<Compile Include="Destinations\OneNoteDestination.cs" />
|
<Compile Include="Destinations\OneNoteDestination.cs" />
|
||||||
<Compile Include="Destinations\PowerpointDestination.cs" />
|
<Compile Include="Destinations\PowerpointDestination.cs" />
|
||||||
<Compile Include="Destinations\WordDestination.cs" />
|
<Compile Include="Destinations\WordDestination.cs" />
|
||||||
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
<Compile Include="OfficeConfiguration.cs" />
|
<Compile Include="OfficeConfiguration.cs" />
|
||||||
<Compile Include="OfficePlugin.cs" />
|
<Compile Include="OfficePlugin.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
@ -76,9 +77,7 @@
|
||||||
<Name>GreenshotPlugin</Name>
|
<Name>GreenshotPlugin</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup />
|
||||||
<Folder Include="Destinations" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
|
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
|
||||||
|
|
|
@ -434,6 +434,8 @@ namespace Greenshot.Interop.Office {
|
||||||
PR_REPORTING_MTA_CERTIFICATE = PT.PT_BINARY | 0x1004 << 16,
|
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 {
|
public class OutlookUtils {
|
||||||
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OutlookUtils));
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OutlookUtils));
|
||||||
private const uint KEEP_OPEN_READONLY = 0x00000001;
|
private const uint KEEP_OPEN_READONLY = 0x00000001;
|
||||||
|
@ -783,20 +785,13 @@ namespace Greenshot.Interop.Office {
|
||||||
}
|
}
|
||||||
|
|
||||||
#region MAPI DLL Imports
|
#region MAPI DLL Imports
|
||||||
|
[DllImport("MAPI32.DLL", EntryPoint = "HrSetOneProp@8")]
|
||||||
[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")]
|
|
||||||
private static extern void HrSetOneProp(IntPtr pmp, IntPtr pprop);
|
private static extern void HrSetOneProp(IntPtr pmp, IntPtr pprop);
|
||||||
|
|
||||||
[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi, EntryPoint = "MAPIFreeBuffer@4")]
|
[DllImport("MAPI32.DLL")]
|
||||||
private static extern void MAPIFreeBuffer(IntPtr lpBuffer);
|
|
||||||
|
|
||||||
[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
|
|
||||||
private static extern int MAPIInitialize(IntPtr lpMapiInit);
|
private static extern int MAPIInitialize(IntPtr lpMapiInit);
|
||||||
|
|
||||||
[DllImport("MAPI32.DLL", CharSet = CharSet.Ansi)]
|
[DllImport("MAPI32.DLL")]
|
||||||
private static extern void MAPIUninitialize();
|
private static extern void MAPIUninitialize();
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace GreenshotPlugin.Controls {
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
private static extern uint MapVirtualKey(uint uCode, uint uMapType);
|
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);
|
private static extern int GetKeyNameText(uint lParam, [Out] StringBuilder lpString, int nSize);
|
||||||
|
|
||||||
// These variables store the current hotkey and modifier(s)
|
// These variables store the current hotkey and modifier(s)
|
||||||
|
|
|
@ -1366,7 +1366,7 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
returnImage = new Bitmap(windowRect.Width, windowRect.Height, pixelFormat);
|
returnImage = new Bitmap(windowRect.Width, windowRect.Height, pixelFormat);
|
||||||
using (Graphics graphics = Graphics.FromImage(returnImage)) {
|
using (Graphics graphics = Graphics.FromImage(returnImage)) {
|
||||||
using (SafeDeviceContextHandle graphicsDC = graphics.getSafeDeviceContext()) {
|
using (SafeDeviceContextHandle graphicsDC = graphics.GetSafeDeviceContext()) {
|
||||||
bool printSucceeded = User32.PrintWindow(Handle, graphicsDC.DangerousGetHandle(), 0x0);
|
bool printSucceeded = User32.PrintWindow(Handle, graphicsDC.DangerousGetHandle(), 0x0);
|
||||||
if (!printSucceeded) {
|
if (!printSucceeded) {
|
||||||
// something went wrong, most likely a "0x80004005" (Acess Denied) when using UAC
|
// something went wrong, most likely a "0x80004005" (Acess Denied) when using UAC
|
||||||
|
|
BIN
GreenshotPlugin/GlobalSuppressions.cs
Normal file
BIN
GreenshotPlugin/GlobalSuppressions.cs
Normal file
Binary file not shown.
|
@ -35,6 +35,7 @@
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Core\FastBitmap.cs" />
|
<Compile Include="Core\FastBitmap.cs" />
|
||||||
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
<Compile Include="IEInterop\IHTMLBodyElement.cs" />
|
<Compile Include="IEInterop\IHTMLBodyElement.cs" />
|
||||||
<Compile Include="IEInterop\IHTMLCurrentStyle.cs" />
|
<Compile Include="IEInterop\IHTMLCurrentStyle.cs" />
|
||||||
<Compile Include="IEInterop\IHTMLDocument.cs" />
|
<Compile Include="IEInterop\IHTMLDocument.cs" />
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
@ -51,7 +52,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="graphics"></param>
|
/// <param name="graphics"></param>
|
||||||
/// <returns>SafeDeviceContextHandle</returns>
|
/// <returns>SafeDeviceContextHandle</returns>
|
||||||
public static SafeDeviceContextHandle getSafeDeviceContext(this Graphics graphics) {
|
public static SafeDeviceContextHandle GetSafeDeviceContext(this Graphics graphics) {
|
||||||
return SafeDeviceContextHandle.fromGraphics(graphics);
|
return SafeDeviceContextHandle.fromGraphics(graphics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,10 +76,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
/// A hbitmap SafeHandle implementation
|
/// A hbitmap SafeHandle implementation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SafeHBitmapHandle : SafeObjectHandle {
|
public class SafeHBitmapHandle : SafeObjectHandle {
|
||||||
[SecurityCritical]
|
|
||||||
private SafeHBitmapHandle() : base(true) {
|
|
||||||
}
|
|
||||||
|
|
||||||
[SecurityCritical]
|
[SecurityCritical]
|
||||||
public SafeHBitmapHandle(IntPtr preexistingHandle) : base(true) {
|
public SafeHBitmapHandle(IntPtr preexistingHandle) : base(true) {
|
||||||
SetHandle(preexistingHandle);
|
SetHandle(preexistingHandle);
|
||||||
|
@ -89,10 +86,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
/// A hRegion SafeHandle implementation
|
/// A hRegion SafeHandle implementation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SafeRegionHandle : SafeObjectHandle {
|
public class SafeRegionHandle : SafeObjectHandle {
|
||||||
[SecurityCritical]
|
|
||||||
private SafeRegionHandle() : base(true) {
|
|
||||||
}
|
|
||||||
|
|
||||||
[SecurityCritical]
|
[SecurityCritical]
|
||||||
public SafeRegionHandle(IntPtr preexistingHandle) : base(true) {
|
public SafeRegionHandle(IntPtr preexistingHandle) : base(true) {
|
||||||
SetHandle(preexistingHandle);
|
SetHandle(preexistingHandle);
|
||||||
|
@ -103,10 +96,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
/// A dibsection SafeHandle implementation
|
/// A dibsection SafeHandle implementation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SafeDibSectionHandle : SafeObjectHandle {
|
public class SafeDibSectionHandle : SafeObjectHandle {
|
||||||
[SecurityCritical]
|
|
||||||
private SafeDibSectionHandle() : base(true) {
|
|
||||||
}
|
|
||||||
|
|
||||||
[SecurityCritical]
|
[SecurityCritical]
|
||||||
public SafeDibSectionHandle(IntPtr preexistingHandle) : base(true) {
|
public SafeDibSectionHandle(IntPtr preexistingHandle) : base(true) {
|
||||||
SetHandle(preexistingHandle);
|
SetHandle(preexistingHandle);
|
||||||
|
@ -123,10 +112,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
|
|
||||||
private SafeHandle hdc;
|
private SafeHandle hdc;
|
||||||
|
|
||||||
[SecurityCritical]
|
|
||||||
private SafeSelectObjectHandle() : base(true) {
|
|
||||||
}
|
|
||||||
|
|
||||||
[SecurityCritical]
|
[SecurityCritical]
|
||||||
public SafeSelectObjectHandle(SafeDCHandle hdc, SafeHandle newHandle) : base(true) {
|
public SafeSelectObjectHandle(SafeDCHandle hdc, SafeHandle newHandle) : base(true) {
|
||||||
this.hdc = hdc;
|
this.hdc = hdc;
|
||||||
|
@ -150,10 +135,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
[DllImport("gdi32", SetLastError = true)]
|
[DllImport("gdi32", SetLastError = true)]
|
||||||
private static extern bool DeleteDC(IntPtr hDC);
|
private static extern bool DeleteDC(IntPtr hDC);
|
||||||
|
|
||||||
[SecurityCritical]
|
|
||||||
private SafeCompatibleDCHandle() : base(true) {
|
|
||||||
}
|
|
||||||
|
|
||||||
[SecurityCritical]
|
[SecurityCritical]
|
||||||
public SafeCompatibleDCHandle(IntPtr preexistingHandle) : base(true) {
|
public SafeCompatibleDCHandle(IntPtr preexistingHandle) : base(true) {
|
||||||
SetHandle(preexistingHandle);
|
SetHandle(preexistingHandle);
|
||||||
|
@ -173,9 +154,6 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SafeDeviceContextHandle : SafeDCHandle {
|
public class SafeDeviceContextHandle : SafeDCHandle {
|
||||||
private Graphics graphics = null;
|
private Graphics graphics = null;
|
||||||
[SecurityCritical]
|
|
||||||
private SafeDeviceContextHandle() : base(true) {
|
|
||||||
}
|
|
||||||
|
|
||||||
[SecurityCritical]
|
[SecurityCritical]
|
||||||
public SafeDeviceContextHandle(Graphics graphics, IntPtr preexistingHandle) : base(true) {
|
public SafeDeviceContextHandle(Graphics graphics, IntPtr preexistingHandle) : base(true) {
|
||||||
|
@ -225,10 +203,10 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
/// <param name="target"></param>
|
/// <param name="target"></param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
public static void StretchBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Rectangle destination) {
|
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 (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
|
||||||
using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
|
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);
|
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 {
|
||||||
/// <param name="target"></param>
|
/// <param name="target"></param>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
public static void BitBlt(this Graphics target, Bitmap sourceBitmap, Rectangle source, Point destination, CopyPixelOperation rop) {
|
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 (SafeCompatibleDCHandle safeCompatibleDCHandle = CreateCompatibleDC(targetDC)) {
|
||||||
using (SafeHBitmapHandle hBitmapHandle = new SafeHBitmapHandle(sourceBitmap.GetHbitmap())) {
|
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);
|
BitBlt(targetDC, destination.X, destination.Y, source.Width, source.Height, safeCompatibleDCHandle, source.Left, source.Top, rop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
public extern static IntPtr GetWindowLongPtr(IntPtr hwnd, int nIndex);
|
public extern static IntPtr GetWindowLongPtr(IntPtr hwnd, int nIndex);
|
||||||
[DllImport("user32", SetLastError = true)]
|
[DllImport("user32", SetLastError = true)]
|
||||||
public static extern int SetWindowLong(IntPtr hWnd, int index, int styleFlags);
|
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);
|
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int index, IntPtr styleFlags);
|
||||||
[DllImport("user32", SetLastError = true)]
|
[DllImport("user32", SetLastError = true)]
|
||||||
public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
|
public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue