Skip to content

Commit

Permalink
2.3.1.7 - OptimizeScreenCapture implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinkendall committed Aug 4, 2020
1 parent 5816c1c commit a6c74fd
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 31 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.1.6")]
[assembly: AssemblyFileVersion("2.3.1.6")]
[assembly: AssemblyVersion("2.3.1.7")]
[assembly: AssemblyFileVersion("2.3.1.7")]
[assembly: NeutralResourcesLanguageAttribute("en-CA")]
93 changes: 87 additions & 6 deletions ScreenCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace AutoScreenCapture
{
Expand Down Expand Up @@ -278,7 +280,7 @@ public Bitmap GetScreenBitmap(int x, int y, int width, int height, int resolutio
graphicsDestination.Flush();

CaptureError = false;

return bitmapDestination;
}

Expand Down Expand Up @@ -478,6 +480,7 @@ public bool SaveScreenshot(string path, ImageFormat format, int component, Scree
try
{
int filepathLengthLimit = Convert.ToInt32(Settings.Application.GetByKey("FilepathLengthLimit", DefaultSettings.FilepathLengthLimit).Value);
bool optimizeScreenCapture = Convert.ToBoolean(Settings.Application.GetByKey("OptimizeScreenCapture", DefaultSettings.OptimizeScreenCapture).Value);

if (!string.IsNullOrEmpty(path))
{
Expand Down Expand Up @@ -512,11 +515,37 @@ public bool SaveScreenshot(string path, ImageFormat format, int component, Scree
Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created");
}

Screenshot screenshot = new Screenshot(DateTimeScreenshotsTaken, path, format, component, screenshotType, windowTitle, processName, viewId, label);
Screenshot lastScreenshotOfThisView = screenshotCollection.GetLastScreenshotOfView(viewId);

screenshotCollection.Add(screenshot);
Screenshot newScreenshotOfThisView = new Screenshot(windowTitle, DateTimeScreenshotsTaken)
{
ViewId = viewId,
Path = path,
Format = format,
Component = component,
ScreenshotType = screenshotType,
ProcessName = processName + ".exe",
Label = label
};

if (optimizeScreenCapture)
{
newScreenshotOfThisView.Hash = GetMD5Hash(bitmap, format);

SaveToFile(path, format, jpegQuality, bitmap);
if (lastScreenshotOfThisView == null || string.IsNullOrEmpty(lastScreenshotOfThisView.Hash) ||
!lastScreenshotOfThisView.Hash.Equals(newScreenshotOfThisView.Hash))
{
screenshotCollection.Add(newScreenshotOfThisView);

SaveToFile(path, format, jpegQuality, bitmap);
}
}
else
{
screenshotCollection.Add(newScreenshotOfThisView);

SaveToFile(path, format, jpegQuality, bitmap);
}
}
}
else
Expand Down Expand Up @@ -560,9 +589,37 @@ public bool SaveScreenshot(string path, ImageFormat format, int component, Scree
Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created");
}

screenshotCollection.Add(new Screenshot(DateTimeScreenshotsTaken, path, format, component, screenshotType, windowTitle, processName, viewId, label));
Screenshot lastScreenshotOfThisView = screenshotCollection.GetLastScreenshotOfView(viewId);

SaveToFile(path, format, jpegQuality, bitmap);
Screenshot newScreenshotOfThisView = new Screenshot(windowTitle, DateTimeScreenshotsTaken)
{
ViewId = viewId,
Path = path,
Format = format,
Component = component,
ScreenshotType = screenshotType,
ProcessName = processName + ".exe",
Label = label
};

if (optimizeScreenCapture)
{
newScreenshotOfThisView.Hash = GetMD5Hash(bitmap, format);

if (lastScreenshotOfThisView == null || string.IsNullOrEmpty(lastScreenshotOfThisView.Hash) ||
!lastScreenshotOfThisView.Hash.Equals(newScreenshotOfThisView.Hash))
{
screenshotCollection.Add(newScreenshotOfThisView);

SaveToFile(path, format, jpegQuality, bitmap);
}
}
else
{
screenshotCollection.Add(newScreenshotOfThisView);

SaveToFile(path, format, jpegQuality, bitmap);
}
}
catch (Exception)
{
Expand Down Expand Up @@ -626,5 +683,29 @@ private ImageCodecInfo GetEncoderInfo(string mimeType)
var encoders = ImageCodecInfo.GetImageEncoders();
return encoders.FirstOrDefault(t => t.MimeType == mimeType);
}

private static string GetMD5Hash(Bitmap bitmap, ImageFormat format)
{
byte[] bytes = null;

using (MemoryStream ms = new MemoryStream())
{
bitmap.Save(ms, format.Format);
bytes = ms.ToArray();
}

MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

byte[] hash = md5.ComputeHash(bytes);

StringBuilder sb = new StringBuilder();

foreach (byte b in hash)
{
sb.Append(b.ToString("x2").ToLower());
}

return sb.ToString();
}
}
}
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.1.6"/>
version="2.3.1.7"/>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>True/PM</dpiAware>
Expand Down
2 changes: 1 addition & 1 deletion interface/FormAbout.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<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.1.6 ("Boombayah")
<value>Auto Screen Capture 2.3.1.7 ("Boombayah")
Developed by Gavin Kendall (2008 - 2020)

https://autoscreen.sourceforge.io/
Expand Down
26 changes: 9 additions & 17 deletions modules/screenshots/Screenshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public class Screenshot
/// </summary>
public bool Saved { get; set; }

/// <summary>
/// The hash of the bitmap image associated with the screenshot.
/// </summary>
public string Hash { get; set; }

/// <summary>
/// The empty constructor a screenshot object.
/// </summary>
Expand All @@ -109,29 +114,16 @@ public Screenshot()
/// <summary>
/// The constructor for creating a screenshot.
/// </summary>
/// <param name="dateTime">The date/time the screenshot was taken.</param>
/// <param name="path">The path of the filename for the screenshot.</param>
/// <param name="format">The image format of the screenshot.</param>
/// <param name="component">The component used for the screenshot.</param>
/// <param name="screenshotType">The type of screenshot.</param>
/// <param name="windowTitle">The title of the active window when the screenshot was taken.</param>
/// <param name="processName">The process name of the active application when the screenshot was taken.</param>
/// <param name="viewId">The view ID associated with either the screen or the region for the screenshot.</param>
/// <param name="label">The label to be applied to the screenshot.</param>
public Screenshot(DateTime dateTime, string path, ImageFormat format, int component, ScreenshotType screenshotType, string windowTitle, string processName, Guid viewId, string label)
/// <param name="dateTime">The date/time the screenshot was taken.</param>
public Screenshot(string windowTitle, DateTime dateTime)
{
if (string.IsNullOrEmpty(windowTitle)) return;

ViewId = viewId;
WindowTitle = windowTitle;

Date = dateTime.ToString(MacroParser.DateFormat);
Time = dateTime.ToString(MacroParser.TimeFormat);
Path = path;
Format = format;
Component = component;
ScreenshotType = screenshotType;
WindowTitle = windowTitle;
ProcessName = processName + ".exe";
Label = label;
Saved = false;
Version = Settings.ApplicationVersion;

Expand Down
31 changes: 29 additions & 2 deletions modules/screenshots/ScreenshotCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ public Screenshot GetScreenshot(string slideName, Guid viewId)
{
lock (_screenshotList)
{
foreach (Screenshot screenshot in _screenshotList)
foreach (Screenshot screenshot in _screenshotList.Where(x => x.ViewId.Equals(viewId)))
{
if (screenshot.Slide != null && !string.IsNullOrEmpty(screenshot.Slide.Name) && screenshot.Slide.Name.Equals(slideName) && screenshot.ViewId.Equals(viewId))
if (screenshot.Slide != null && !string.IsNullOrEmpty(screenshot.Slide.Name) && screenshot.Slide.Name.Equals(slideName))
{
foundScreenshot = screenshot;
break;
Expand All @@ -314,6 +314,33 @@ public Screenshot GetScreenshot(string slideName, Guid viewId)
return foundScreenshot;
}

/// <summary>
///
/// </summary>
/// <param name="viewId"></param>
/// <returns></returns>
public Screenshot GetLastScreenshotOfView(Guid viewId)
{
try
{
Screenshot foundScreenshot = new Screenshot();

if (_screenshotList != null)
{
lock (_screenshotList)
{
foundScreenshot = _screenshotList.Last(x => x.ViewId.Equals(viewId));
}
}

return foundScreenshot;
}
catch (Exception)
{
return null;
}
}

/// <summary>
/// Gets a list of screenshots based on the date and time.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Auto Screen Capture by Gavin Kendall
Last updated on 2020-08-04 (August 4, 2020)
[The information presented here refers to the latest version of the application (which is currently 2.3.1.6)]
[The information presented here refers to the latest version of the application (which is currently 2.3.1.7)]
=============================================================================================================


Expand Down
1 change: 1 addition & 0 deletions settings/DefaultSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static class DefaultSettings
internal static readonly int FilepathLengthLimit = 2000;
internal static readonly bool StopOnLowDiskError = true;
internal static readonly int ActiveWindowTitleLengthLimit = 2000;
internal static readonly bool OptimizeScreenCapture = true;

// Default user settings.
internal static readonly int IntScreenCaptureInterval = 60000;
Expand Down
9 changes: 8 additions & 1 deletion settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public static void Initialize()
new Version(CODENAME_BOOMBAYAH, "2.3.1.2"), // Snagit Editor introduced as a new default image editor if available.
new Version(CODENAME_BOOMBAYAH, "2.3.1.3"), // Fixed bug with new Editor throwing null reference exception on changing its properties because Notes was null.
new Version(CODENAME_BOOMBAYAH, "2.3.1.4"), // ExitOnError set to True by default.
new Version(CODENAME_BOOMBAYAH, "2.3.1.5") // Region Select / Auto Save implemented.
new Version(CODENAME_BOOMBAYAH, "2.3.1.5"), // Region Select / Auto Save implemented.
new Version(CODENAME_BOOMBAYAH, "2.3.1.6") // Region Select Edit implemented and fixed bug with ViewId for new Screens and Regions.
};

Application = new SettingCollection
Expand Down Expand Up @@ -294,6 +295,11 @@ public static void Initialize()
{
Application.Add(new Setting("ActiveWindowTitleLengthLimit", DefaultSettings.ActiveWindowTitleLengthLimit));
}

if (!Application.KeyExists("OptimizeScreenCapture"))
{
Application.Add(new Setting("OptimizeScreenCapture", DefaultSettings.OptimizeScreenCapture));
}
}
else
{
Expand Down Expand Up @@ -321,6 +327,7 @@ public static void Initialize()
Application.Add(new Setting("FilepathLengthLimit", DefaultSettings.FilepathLengthLimit));
Application.Add(new Setting("StopOnLowDiskError", DefaultSettings.StopOnLowDiskError));
Application.Add(new Setting("ActiveWindowTitleLengthLimit", DefaultSettings.ActiveWindowTitleLengthLimit));
Application.Add(new Setting("OptimizeScreenCapture", DefaultSettings.OptimizeScreenCapture));
}

Application.Save();
Expand Down

0 comments on commit a6c74fd

Please sign in to comment.