diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index abc092a43..ab6f3353c 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -121,7 +121,7 @@ namespace Greenshot { for(int argumentNr = 0; argumentNr < args.Length; argumentNr++) { string argument = args[argumentNr]; // Help - if (argument.ToLower().Equals("/help")) { + if (argument.ToLower().Equals("/help") || argument.ToLower().Equals("/h") || argument.ToLower().Equals("/?")) { // Try to attach to the console bool attachedToConsole = Kernel32.AttachConsole(Kernel32.ATTACHCONSOLE_ATTACHPARENTPROCESS); // If attach didn't work, open a console diff --git a/Greenshot/Forms/SettingsForm.Designer.cs b/Greenshot/Forms/SettingsForm.Designer.cs index 42e078685..7e693debb 100644 --- a/Greenshot/Forms/SettingsForm.Designer.cs +++ b/Greenshot/Forms/SettingsForm.Designer.cs @@ -1019,31 +1019,31 @@ namespace Greenshot { // checkbox_reuseeditor // this.checkbox_reuseeditor.LanguageKey = "expertsettings_reuseeditorifpossible"; - this.checkbox_reuseeditor.Location = new System.Drawing.Point(10, 231); + this.checkbox_reuseeditor.Location = new System.Drawing.Point(10, 225); this.checkbox_reuseeditor.Name = "checkbox_reuseeditor"; this.checkbox_reuseeditor.PropertyName = "ReuseEditor"; this.checkbox_reuseeditor.SectionName = "Editor"; - this.checkbox_reuseeditor.Size = new System.Drawing.Size(394, 19); + this.checkbox_reuseeditor.Size = new System.Drawing.Size(394, 24); this.checkbox_reuseeditor.TabIndex = 31; this.checkbox_reuseeditor.UseVisualStyleBackColor = true; // // checkbox_minimizememoryfootprint // this.checkbox_minimizememoryfootprint.LanguageKey = "expertsettings_minimizememoryfootprint"; - this.checkbox_minimizememoryfootprint.Location = new System.Drawing.Point(10, 211); + this.checkbox_minimizememoryfootprint.Location = new System.Drawing.Point(10, 206); this.checkbox_minimizememoryfootprint.Name = "checkbox_minimizememoryfootprint"; this.checkbox_minimizememoryfootprint.PropertyName = "MinimizeWorkingSetSize"; - this.checkbox_minimizememoryfootprint.Size = new System.Drawing.Size(394, 19); + this.checkbox_minimizememoryfootprint.Size = new System.Drawing.Size(394, 24); this.checkbox_minimizememoryfootprint.TabIndex = 30; this.checkbox_minimizememoryfootprint.UseVisualStyleBackColor = true; // // checkbox_checkunstableupdates // this.checkbox_checkunstableupdates.LanguageKey = "expertsettings_checkunstableupdates"; - this.checkbox_checkunstableupdates.Location = new System.Drawing.Point(10, 191); + this.checkbox_checkunstableupdates.Location = new System.Drawing.Point(10, 187); this.checkbox_checkunstableupdates.Name = "checkbox_checkunstableupdates"; this.checkbox_checkunstableupdates.PropertyName = "CheckUnstable"; - this.checkbox_checkunstableupdates.Size = new System.Drawing.Size(394, 19); + this.checkbox_checkunstableupdates.Size = new System.Drawing.Size(394, 24); this.checkbox_checkunstableupdates.TabIndex = 29; this.checkbox_checkunstableupdates.UseVisualStyleBackColor = true; // @@ -1064,7 +1064,7 @@ namespace Greenshot { this.label_counter.LanguageKey = "expertsettings_counter"; this.label_counter.Location = new System.Drawing.Point(7, 285); this.label_counter.Name = "label_counter"; - this.label_counter.Size = new System.Drawing.Size(0, 13); + this.label_counter.Size = new System.Drawing.Size(246, 13); this.label_counter.TabIndex = 27; // // textbox_counter @@ -1081,7 +1081,7 @@ namespace Greenshot { this.label_footerpattern.LanguageKey = "expertsettings_footerpattern"; this.label_footerpattern.Location = new System.Drawing.Point(7, 259); this.label_footerpattern.Name = "label_footerpattern"; - this.label_footerpattern.Size = new System.Drawing.Size(0, 13); + this.label_footerpattern.Size = new System.Drawing.Size(103, 13); this.label_footerpattern.TabIndex = 25; // // textbox_footerpattern @@ -1128,7 +1128,7 @@ namespace Greenshot { this.label_clipboardformats.LanguageKey = "expertsettings_clipboardformats"; this.label_clipboardformats.Location = new System.Drawing.Point(7, 39); this.label_clipboardformats.Name = "label_clipboardformats"; - this.label_clipboardformats.Size = new System.Drawing.Size(0, 13); + this.label_clipboardformats.Size = new System.Drawing.Size(88, 13); this.label_clipboardformats.TabIndex = 20; // // checkbox_enableexpert diff --git a/GreenshotPlugin/Core/BinaryStructHelper.cs b/GreenshotPlugin/Core/BinaryStructHelper.cs index af3c96398..6652ee935 100644 --- a/GreenshotPlugin/Core/BinaryStructHelper.cs +++ b/GreenshotPlugin/Core/BinaryStructHelper.cs @@ -38,8 +38,7 @@ namespace GreenshotPlugin.Core { int size = Marshal.SizeOf(typeof(T)); ptr = Marshal.AllocHGlobal(size); Marshal.Copy(bytes, 0, ptr, size); - object obj = Marshal.PtrToStructure(ptr, typeof(T)); - return (T)obj; + return FromIntPtr(ptr); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); @@ -47,6 +46,17 @@ namespace GreenshotPlugin.Core { } } + /// + /// Get a struct from a byte array + /// + /// typeof struct + /// byte[] + /// struct + public static T FromIntPtr(IntPtr intPtr) where T : struct { + object obj = Marshal.PtrToStructure(intPtr, typeof(T)); + return (T)obj; + } + /// /// copy a struct to a byte array /// @@ -59,14 +69,25 @@ namespace GreenshotPlugin.Core { int size = Marshal.SizeOf(typeof(T)); ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(obj, ptr, true); - byte[] bytes = new byte[size]; - Marshal.Copy(ptr, bytes, 0, size); - return bytes; + return FromPtrToByteArray(ptr); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } } + + /// + /// copy a struct from a pointer to a byte array + /// + /// typeof struct + /// IntPtr to struct + /// byte[] + public static byte[] FromPtrToByteArray(IntPtr ptr) where T : struct { + int size = Marshal.SizeOf(typeof(T)); + byte[] bytes = new byte[size]; + Marshal.Copy(ptr, bytes, 0, size); + return bytes; + } } } diff --git a/GreenshotPlugin/Core/ClipboardHelper.cs b/GreenshotPlugin/Core/ClipboardHelper.cs index c1eab0366..9d34ed4c4 100644 --- a/GreenshotPlugin/Core/ClipboardHelper.cs +++ b/GreenshotPlugin/Core/ClipboardHelper.cs @@ -241,31 +241,33 @@ EndSelection:<<<<<<<4 // If the EnableSpecialDIBClipboardReader flag in the config is set, use the code from: // http://www.thomaslevesque.com/2009/02/05/wpf-paste-an-image-from-the-clipboard/ // to read the DeviceIndependentBitmap from the clipboard, this might fix bug 3576125 - if (config.EnableSpecialDIBClipboardReader) { - MemoryStream ms = Clipboard.GetData("DeviceIndependentBitmap") as MemoryStream; + if (config.EnableSpecialDIBClipboardReader && formats.Contains("DeviceIndependentBitmap")) { + MemoryStream ms = GetClipboardData("DeviceIndependentBitmap") as MemoryStream; if (ms != null) { byte[] dibBuffer = new byte[ms.Length]; ms.Read(dibBuffer, 0, dibBuffer.Length); BitmapInfoHeader infoHeader = BinaryStructHelper.FromByteArray(dibBuffer); + // Only use this code, when the biCommpression != 0 (BI_RGB) + if (infoHeader.biCompression != 0) { + int fileHeaderSize = Marshal.SizeOf(typeof(BitmapFileHeader)); + uint infoHeaderSize = infoHeader.biSize; + int fileSize = (int)(fileHeaderSize + infoHeader.biSize + infoHeader.biSizeImage); - int fileHeaderSize = Marshal.SizeOf(typeof(BitmapFileHeader)); - uint infoHeaderSize = infoHeader.biSize; - int fileSize = (int)(fileHeaderSize + infoHeader.biSize + infoHeader.biSizeImage); + BitmapFileHeader fileHeader = new BitmapFileHeader(); + fileHeader.bfType = BitmapFileHeader.BM; + fileHeader.bfSize = fileSize; + fileHeader.bfReserved1 = 0; + fileHeader.bfReserved2 = 0; + fileHeader.bfOffBits = (int)(fileHeaderSize + infoHeaderSize + infoHeader.biClrUsed * 4); - BitmapFileHeader fileHeader = new BitmapFileHeader(); - fileHeader.bfType = BitmapFileHeader.BM; - fileHeader.bfSize = fileSize; - fileHeader.bfReserved1 = 0; - fileHeader.bfReserved2 = 0; - fileHeader.bfOffBits = (int)(fileHeaderSize + infoHeaderSize + infoHeader.biClrUsed * 4); + byte[] fileHeaderBytes = BinaryStructHelper.ToByteArray(fileHeader); - byte[] fileHeaderBytes = BinaryStructHelper.ToByteArray(fileHeader); - - using (MemoryStream msBitmap = new MemoryStream()) { - msBitmap.Write(fileHeaderBytes, 0, fileHeaderSize); - msBitmap.Write(dibBuffer, 0, dibBuffer.Length); - msBitmap.Seek(0, SeekOrigin.Begin); - return Image.FromStream(msBitmap); + using (MemoryStream msBitmap = new MemoryStream()) { + msBitmap.Write(fileHeaderBytes, 0, fileHeaderSize); + msBitmap.Write(dibBuffer, 0, dibBuffer.Length); + msBitmap.Seek(0, SeekOrigin.Begin); + return Image.FromStream(msBitmap); + } } } } diff --git a/GreenshotPlugin/Core/CoreConfiguration.cs b/GreenshotPlugin/Core/CoreConfiguration.cs index 1ec077e94..fee77bfaa 100644 --- a/GreenshotPlugin/Core/CoreConfiguration.cs +++ b/GreenshotPlugin/Core/CoreConfiguration.cs @@ -191,7 +191,7 @@ namespace GreenshotPlugin.Core { [IniProperty("ExperimentalFeatures", Description="A list of experimental features, this allows us to test certain features before releasing them.", ExcludeIfNull=true)] public List ExperimentalFeatures; - [IniProperty("EnableSpecialDIBClipboardReader", Description = "Enable a special DIB clipboard reader", DefaultValue="False")] + [IniProperty("EnableSpecialDIBClipboardReader", Description = "Enable a special DIB clipboard reader", DefaultValue="True")] public bool EnableSpecialDIBClipboardReader; // Specify what THIS build is