Tested the fixes for bug #3576125, this now should work... although there might be some cases where reading the clipboard doesn't work as supposed. I added a configuration setting, but didn't add it to the expert settings due to a lack of "space". (Did fix the spacing of the checkboxes though)

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2198 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-10-25 07:54:32 +00:00
parent cbf04192b6
commit 3e9b5b91c5
5 changed files with 57 additions and 34 deletions

View file

@ -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

View file

@ -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

View file

@ -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<T>(ptr);
} finally {
if (ptr != IntPtr.Zero) {
Marshal.FreeHGlobal(ptr);
@ -47,6 +46,17 @@ namespace GreenshotPlugin.Core {
}
}
/// <summary>
/// Get a struct from a byte array
/// </summary>
/// <typeparam name="T">typeof struct</typeparam>
/// <param name="bytes">byte[]</param>
/// <returns>struct</returns>
public static T FromIntPtr<T>(IntPtr intPtr) where T : struct {
object obj = Marshal.PtrToStructure(intPtr, typeof(T));
return (T)obj;
}
/// <summary>
/// copy a struct to a byte array
/// </summary>
@ -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<T>(ptr);
} finally {
if (ptr != IntPtr.Zero) {
Marshal.FreeHGlobal(ptr);
}
}
}
/// <summary>
/// copy a struct from a pointer to a byte array
/// </summary>
/// <typeparam name="T">typeof struct</typeparam>
/// <param name="ptr">IntPtr to struct</param>
/// <returns>byte[]</returns>
public static byte[] FromPtrToByteArray<T>(IntPtr ptr) where T : struct {
int size = Marshal.SizeOf(typeof(T));
byte[] bytes = new byte[size];
Marshal.Copy(ptr, bytes, 0, size);
return bytes;
}
}
}

View file

@ -241,13 +241,14 @@ 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<BitmapInfoHeader>(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);
@ -269,6 +270,7 @@ EndSelection:<<<<<<<4
}
}
}
}
return Clipboard.GetImage();
} catch (Exception ee) {
if (retryCount == 0) {

View file

@ -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<string> 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