Skip to content

Commit

Permalink
2.3.3.7 - Memory leak fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
igloo-gkendall committed Jan 14, 2021
1 parent ab565a1 commit 4d5dde2
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.3.6")]
[assembly: AssemblyFileVersion("2.3.3.6")]
[assembly: AssemblyVersion("2.3.3.7")]
[assembly: AssemblyFileVersion("2.3.3.7")]
[assembly: NeutralResourcesLanguageAttribute("en-CA")]
103 changes: 55 additions & 48 deletions ScreenCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class ScreenCapture
[StructLayout(LayoutKind.Sequential)]
private struct CURSORINFO
{
public Int32 cbSize;
public Int32 flags;
public int cbSize;
public int flags;
public IntPtr hCursor;
public POINTAPI ptScreenPos;
}
Expand Down Expand Up @@ -70,8 +70,8 @@ private struct POINTAPI
[DllImport("user32.dll", SetLastError = true)]
private static extern bool DrawIconEx(IntPtr hdc, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyHeight, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags);

private const Int32 CURSOR_SHOWING = 0x0001;
private const Int32 DI_NORMAL = 0x0003;
private const int CURSOR_SHOWING = 0x0001;
private const int DI_NORMAL = 0x0003;

[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
Expand Down Expand Up @@ -103,56 +103,56 @@ internal struct WINDOWPLACEMENT
public int length;
public int flags;
public ShowWindowCommands showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition;
public Point ptMinPosition;
public Point ptMaxPosition;
public Rectangle rcNormalPosition;
}

[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

public const int ENUM_CURRENT_SETTINGS = -1;
private const int ENUM_CURRENT_SETTINGS = -1;

[DllImport("user32.dll")]
public static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);
private static extern bool EnumDisplaySettings(string lpszDeviceName, int iModeNum, ref DEVMODE lpDevMode);

[StructLayout(LayoutKind.Sequential)]
public struct DEVMODE
private struct DEVMODE
{
private const int CCHDEVICENAME = 0x20;
private const int CCHFORMNAME = 0x20;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
public string dmDeviceName;
public short dmSpecVersion;
public short dmDriverVersion;
public short dmSize;
public short dmDriverExtra;
public int dmFields;
public int dmPositionX;
public int dmPositionY;
public ScreenOrientation dmDisplayOrientation;
public int dmDisplayFixedOutput;
public short dmColor;
public short dmDuplex;
public short dmYResolution;
public short dmTTOption;
public short dmCollate;
private string dmDeviceName;
private short dmSpecVersion;
private short dmDriverVersion;
internal short dmSize;
private short dmDriverExtra;
private int dmFields;
private int dmPositionX;
private int dmPositionY;
private ScreenOrientation dmDisplayOrientation;
private int dmDisplayFixedOutput;
private short dmColor;
private short dmDuplex;
private short dmYResolution;
private short dmTTOption;
private short dmCollate;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
public string dmFormName;
public short dmLogPixels;
public int dmBitsPerPel;
public int dmPelsWidth;
public int dmPelsHeight;
public int dmDisplayFlags;
public int dmDisplayFrequency;
public int dmICMMethod;
public int dmICMIntent;
public int dmMediaType;
public int dmDitherType;
public int dmReserved1;
public int dmReserved2;
public int dmPanningWidth;
public int dmPanningHeight;
private string dmFormName;
private short dmLogPixels;
private int dmBitsPerPel;
internal int dmPelsWidth;
internal int dmPelsHeight;
private int dmDisplayFlags;
private int dmDisplayFrequency;
private int dmICMMethod;
private int dmICMIntent;
private int dmMediaType;
private int dmDitherType;
private int dmReserved1;
private int dmReserved2;
private int dmPanningWidth;
private int dmPanningHeight;
}

/// <summary>
Expand Down Expand Up @@ -356,12 +356,16 @@ private void SaveToFile(string path, ImageFormat format, int jpegQuality, Bitmap
bitmap.Save(path, format.Format);
}

bitmap.Dispose();

Log.WriteMessage("Screenshot saved to file at path \"" + path + "\"");
}
}
catch (Exception ex)
catch (Exception)
{
Log.WriteExceptionMessage("ScreenCapture::SaveToFile", ex);
// We want to write to the error file instead of writing an exception just in case the user
// has ExitOnError set and the exception causes the application to exit.
Log.WriteErrorMessage("There was an error encountered when saving the screenshot image.");
}
}

Expand All @@ -372,8 +376,11 @@ private void SaveToFile(string path, ImageFormat format, int jpegQuality, Bitmap
/// <returns>A struct having the screen, display device width, and display device height.</returns>
public static DeviceResolution GetDeviceResolution(System.Windows.Forms.Screen screen)
{
DEVMODE dm = new DEVMODE();
dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
DEVMODE dm = new DEVMODE
{
dmSize = (short)Marshal.SizeOf(typeof(DEVMODE))
};

EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm);

DeviceResolution deviceResolution = new DeviceResolution()
Expand Down Expand Up @@ -478,7 +485,7 @@ public Bitmap GetScreenBitmap(int x, int y, int width, int height, int resolutio
graphicsDestination.Flush();

CaptureError = false;

return bitmapDestination;
}

Expand Down Expand Up @@ -613,7 +620,7 @@ public string GetActiveWindowProcessName()
/// <summary>
/// Gets the bitmap images for the avaialble screens.
/// </summary>
/// <param name="component">The component to capture. This could be the active window or a screen.</param>
/// <param name="component">The component index.</param>
/// <param name="x">The X value of the bitmap.</param>
/// <param name="y">The Y value of the bitmap.</param>
/// <param name="width">The Width value of the bitmap.</param>
Expand Down Expand Up @@ -669,7 +676,7 @@ public bool SaveScreenshot(int jpegQuality, Screenshot screenshot, ScreenshotCol
try
{
int filepathLengthLimit = Convert.ToInt32(Settings.Application.GetByKey("FilepathLengthLimit", DefaultSettings.FilepathLengthLimit).Value);

if (!string.IsNullOrEmpty(screenshot.Path))
{
if (screenshot.Path.Length > filepathLengthLimit)
Expand Down Expand Up @@ -709,7 +716,7 @@ public bool SaveScreenshot(int jpegQuality, Screenshot screenshot, ScreenshotCol

return false;
}

ApplicationWarning = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<assemblyIdentity
type="win32"
name="GavinKendall.AutoScreenCapture"
version="2.3.3.6"/>
version="2.3.3.7"/>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>True/PM</dpiAware>
Expand Down
5 changes: 3 additions & 2 deletions interface/FormAbout.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="richTextBoxDeveloper.Text" xml:space="preserve">
<value>Auto Screen Capture 2.3.3.6 ("Boombayah")
Developed by Gavin Kendall (2008 - 2020)
<value>Auto Screen Capture 2.3.3.7 ("Boombayah")
Developed by Gavin Kendall (2008 - 2021)

SourceForge Project Site
https://autoscreen.sourceforge.io/
Expand Down Expand Up @@ -322,6 +322,7 @@ END OF TERMS AND CONDITIONS</value>
</data>
<data name="richTextBoxChangelog.Text" xml:space="preserve">
<value>Codename "Boombayah"
2.3.3.7 Memory leak fix.
2.3.3.6 Active Window Title text comparison includes type of match to use during text comparison.
2.3.3.5 Application Focus now has Delay Before and Delay After options.
2.3.3.4 A bug fix for saving of file when adding screenshot to collection.
Expand Down
1 change: 1 addition & 0 deletions settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public static void Initialize()
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.3")); // An internal list of image hash values are stored when emailing screenshots so we do not email duplicate images.
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.4")); // A bug fix for saving of file when adding screenshot to collection.
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.5")); // Application Focus now has Delay Before and Delay After options.
_versionCollection.Add(new Version(CODENAME_BOOMBAYAH, "2.3.3.6")); // Active Window Title text comparison includes type of match to use during text comparison.

Application = new SettingCollection
{
Expand Down

0 comments on commit 4d5dde2

Please sign in to comment.