Skip to content

Commit 46b6fec

Browse files
2.2.0.3 - Active window title is retrieved earlier for less chance in having different titles in different screenshot objects despite being in the same screen capture cycle. Some code cleanup. Documentation being added. Fixed a racing condition issue with KeepScreenshotsForDays and Save in ScreenshotCollection
1 parent 3336c46 commit 46b6fec

File tree

13 files changed

+238
-56
lines changed

13 files changed

+238
-56
lines changed

FormMain.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,9 @@ private void TakeScreenshot()
24592459
_screenCapture.DateTimePreviousCycle = DateTime.Now;
24602460
Log.Write("Date and time of screen capture cycle set to " + _screenCapture.DateTimePreviousCycle);
24612461

2462+
_screenCapture.ActiveWindowTitle = _screenCapture.GetActiveWindowTitle();
2463+
Log.Write("Active window title of screen capture set to " + _screenCapture.ActiveWindowTitle);
2464+
24622465
RunRegionCaptures();
24632466

24642467
RunScreenCaptures();
@@ -2706,9 +2709,7 @@ private void RunRegionCaptures()
27062709
{
27072710
MacroParser.screenCapture = _screenCapture;
27082711

2709-
string activeWindowTitle = _screenCapture.GetActiveWindowTitle();
2710-
2711-
if (!string.IsNullOrEmpty(activeWindowTitle))
2712+
if (!string.IsNullOrEmpty(_screenCapture.ActiveWindowTitle))
27122713
{
27132714
if (_screenCapture.GetScreenImages(-1, region.X, region.Y, region.Width, region.Height, region.Mouse, out Bitmap bitmap))
27142715
{
@@ -2722,7 +2723,7 @@ private void RunRegionCaptures()
27222723
viewId: region.ViewId,
27232724
bitmap: bitmap,
27242725
label: textBoxScreenshotLabel.Text,
2725-
windowTitle: activeWindowTitle,
2726+
windowTitle: _screenCapture.ActiveWindowTitle,
27262727
screenCollection: formScreen.ScreenCollection,
27272728
regionCollection: formRegion.RegionCollection,
27282729
screenshotCollection: _screenshotCollection
@@ -2749,10 +2750,8 @@ private void RunScreenCaptures()
27492750
{
27502751
MacroParser.screenCapture = _screenCapture;
27512752

2752-
string activeWindowTitle = _screenCapture.GetActiveWindowTitle();
2753-
27542753
// Active Window
2755-
if (!string.IsNullOrEmpty(activeWindowTitle))
2754+
if (!string.IsNullOrEmpty(_screenCapture.ActiveWindowTitle))
27562755
{
27572756
if (_screenCapture.GetScreenImages(screen.Component, 0, 0, 0, 0, false, out Bitmap bitmap))
27582757
{
@@ -2766,7 +2765,7 @@ private void RunScreenCaptures()
27662765
viewId: screen.ViewId,
27672766
bitmap: bitmap,
27682767
label: textBoxScreenshotLabel.Text,
2769-
windowTitle: activeWindowTitle,
2768+
windowTitle: _screenCapture.ActiveWindowTitle,
27702769
screenCollection: formScreen.ScreenCollection,
27712770
regionCollection: formRegion.RegionCollection,
27722771
screenshotCollection: _screenshotCollection
@@ -2788,9 +2787,7 @@ private void RunScreenCaptures()
27882787
{
27892788
MacroParser.screenCapture = _screenCapture;
27902789

2791-
string activeWindowTitle = _screenCapture.GetActiveWindowTitle();
2792-
2793-
if (!string.IsNullOrEmpty(activeWindowTitle))
2790+
if (!string.IsNullOrEmpty(_screenCapture.ActiveWindowTitle))
27942791
{
27952792
// Screen X
27962793
if (_screenCapture.GetScreenImages(screen.Component,
@@ -2809,7 +2806,7 @@ private void RunScreenCaptures()
28092806
viewId: screen.ViewId,
28102807
bitmap: bitmap,
28112808
label: textBoxScreenshotLabel.Text,
2812-
windowTitle: activeWindowTitle,
2809+
windowTitle: _screenCapture.ActiveWindowTitle,
28132810
screenCollection: formScreen.ScreenCollection,
28142811
regionCollection: formRegion.RegionCollection,
28152812
screenshotCollection: _screenshotCollection

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.2.0.2")]
36-
[assembly: AssemblyFileVersion("2.2.0.2")]
35+
[assembly: AssemblyVersion("2.2.0.3")]
36+
[assembly: AssemblyFileVersion("2.2.0.3")]
3737
[assembly: NeutralResourcesLanguageAttribute("en-CA")]

ScreenCapture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ private struct POINTAPI
9595
/// </summary>
9696
public TimeSpan TimeRemainingForNextScreenshot { get { return DateTimeNextCycle.Subtract(DateTime.Now).Duration(); } }
9797

98+
/// <summary>
99+
/// The title of the active window.
100+
/// </summary>
101+
public string ActiveWindowTitle { get; set; }
102+
98103
public Image GetImageByPath(string path)
99104
{
100105
Image image = null;

app.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<assemblyIdentity
44
type="win32"
55
name="GavinKendall.AutoScreenCapture"
6-
version="2.2.0.2"/>
6+
version="2.2.0.3"/>
77
<asmv3:application>
88
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
99
<dpiAware>True/PM</dpiAware>

image_format/ImageFormat.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,31 @@
77
//-----------------------------------------------------------------------
88
namespace AutoScreenCapture
99
{
10+
/// <summary>
11+
///
12+
/// </summary>
1013
public class ImageFormat
1114
{
15+
/// <summary>
16+
///
17+
/// </summary>
1218
public string Name { get; set; }
19+
20+
/// <summary>
21+
///
22+
/// </summary>
1323
public string Extension { get; set; }
24+
25+
/// <summary>
26+
///
27+
/// </summary>
1428
public System.Drawing.Imaging.ImageFormat Format { get; private set; }
1529

30+
/// <summary>
31+
///
32+
/// </summary>
33+
/// <param name="name"></param>
34+
/// <param name="extension"></param>
1635
public ImageFormat(string name, string extension)
1736
{
1837
Name = name;

image_format/ImageFormatCollection.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ namespace AutoScreenCapture
1010
using System.Collections;
1111
using System.Collections.Generic;
1212

13+
/// <summary>
14+
///
15+
/// </summary>
1316
public class ImageFormatCollection : IEnumerable<ImageFormat>
1417
{
1518
private readonly List<ImageFormat> _imageFormatList = new List<ImageFormat>();
1619

20+
/// <summary>
21+
///
22+
/// </summary>
1723
public ImageFormatCollection()
1824
{
1925
Add(new ImageFormat(ImageFormatSpec.NAME_BMP, ImageFormatSpec.EXTENSION_BMP));
@@ -25,6 +31,10 @@ public ImageFormatCollection()
2531
Add(new ImageFormat(ImageFormatSpec.NAME_WMF, ImageFormatSpec.EXTENSION_WMF));
2632
}
2733

34+
/// <summary>
35+
///
36+
/// </summary>
37+
/// <returns></returns>
2838
public List<ImageFormat>.Enumerator GetEnumerator()
2939
{
3040
return _imageFormatList.GetEnumerator();
@@ -40,13 +50,22 @@ IEnumerator<ImageFormat> IEnumerable<ImageFormat>.GetEnumerator()
4050
return GetEnumerator();
4151
}
4252

53+
/// <summary>
54+
///
55+
/// </summary>
56+
/// <param name="imageFormat"></param>
4357
public void Add(ImageFormat imageFormat)
4458
{
4559
_imageFormatList.Add(imageFormat);
4660

4761
Log.Write("Image format added: " + imageFormat.Name + " (" + imageFormat.Extension + ")");
4862
}
4963

64+
/// <summary>
65+
///
66+
/// </summary>
67+
/// <param name="name"></param>
68+
/// <returns></returns>
5069
public ImageFormat GetByName(string name)
5170
{
5271
foreach (ImageFormat imageFormat in _imageFormatList)

image_format/ImageFormatSpec.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,79 @@
77
//-----------------------------------------------------------------------
88
namespace AutoScreenCapture
99
{
10+
/// <summary>
11+
///
12+
/// </summary>
1013
public static class ImageFormatSpec
1114
{
15+
/// <summary>
16+
///
17+
/// </summary>
1218
public const string NAME_BMP = "BMP";
19+
20+
/// <summary>
21+
///
22+
/// </summary>
1323
public const string NAME_EMF = "EMF";
24+
25+
/// <summary>
26+
///
27+
/// </summary>
1428
public const string NAME_GIF = "GIF";
29+
30+
/// <summary>
31+
///
32+
/// </summary>
1533
public const string NAME_JPEG = "JPEG";
34+
35+
/// <summary>
36+
///
37+
/// </summary>
1638
public const string NAME_PNG = "PNG";
39+
40+
/// <summary>
41+
///
42+
/// </summary>
1743
public const string NAME_TIFF = "TIFF";
44+
45+
/// <summary>
46+
///
47+
/// </summary>
1848
public const string NAME_WMF = "WMF";
1949

50+
/// <summary>
51+
///
52+
/// </summary>
2053
public const string EXTENSION_BMP = ".bmp";
54+
55+
/// <summary>
56+
///
57+
/// </summary>
2158
public const string EXTENSION_EMF = ".emf";
59+
60+
/// <summary>
61+
///
62+
/// </summary>
2263
public const string EXTENSION_GIF = ".gif";
64+
65+
/// <summary>
66+
///
67+
/// </summary>
2368
public const string EXTENSION_JPEG = ".jpeg";
69+
70+
/// <summary>
71+
///
72+
/// </summary>
2473
public const string EXTENSION_PNG = ".png";
74+
75+
/// <summary>
76+
///
77+
/// </summary>
2578
public const string EXTENSION_TIFF = ".tiff";
79+
80+
/// <summary>
81+
///
82+
/// </summary>
2683
public const string EXTENSION_WMF = ".wmf";
2784
}
2885
}

log/Log.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,36 @@ namespace AutoScreenCapture
1111
using System.IO;
1212
using System.Threading;
1313

14+
/// <summary>
15+
///
16+
/// </summary>
1417
public static class Log
1518
{
16-
// Required when multiple threads are writing to the same log file.
1719
private static Mutex _mutexWriteFile = new Mutex();
1820

21+
/// <summary>
22+
///
23+
/// </summary>
1924
public static bool Enabled { get; set; }
2025

2126
private static readonly string extension = ".txt";
2227
private static readonly string logFile = "autoscreen-log";
2328
private static readonly string errorFile = "autoscreen-error";
2429

30+
/// <summary>
31+
///
32+
/// </summary>
33+
/// <param name="message"></param>
2534
public static void Write(string message)
2635
{
2736
Write(message, null);
2837
}
2938

39+
/// <summary>
40+
///
41+
/// </summary>
42+
/// <param name="message"></param>
43+
/// <param name="ex"></param>
3044
public static void Write(string message, Exception ex)
3145
{
3246
try

macro/MacroParser.cs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,70 @@
77
//-----------------------------------------------------------------------
88
namespace AutoScreenCapture
99
{
10+
/// <summary>
11+
///
12+
/// </summary>
1013
public static class MacroParser
1114
{
15+
/// <summary>
16+
///
17+
/// </summary>
1218
public static ScreenCapture screenCapture;
19+
20+
/// <summary>
21+
///
22+
/// </summary>
1323
public static readonly string YearFormat = "yyyy";
24+
25+
/// <summary>
26+
///
27+
/// </summary>
1428
public static readonly string MonthFormat = "MM";
29+
30+
/// <summary>
31+
///
32+
/// </summary>
1533
public static readonly string DayFormat = "dd";
34+
35+
/// <summary>
36+
///
37+
/// </summary>
1638
public static readonly string HourFormat = "HH";
39+
40+
/// <summary>
41+
///
42+
/// </summary>
1743
public static readonly string MinuteFormat = "mm";
44+
45+
/// <summary>
46+
///
47+
/// </summary>
1848
public static readonly string SecondFormat = "ss";
49+
50+
/// <summary>
51+
///
52+
/// </summary>
1953
public static readonly string MillisecondFormat = "fff";
54+
55+
/// <summary>
56+
///
57+
/// </summary>
2058
public static readonly string DateFormat = YearFormat + "-" + MonthFormat + "-" + DayFormat;
59+
60+
/// <summary>
61+
///
62+
/// </summary>
2163
public static readonly string TimeFormat = HourFormat + ":" + MinuteFormat + ":" + SecondFormat + "." + MillisecondFormat;
64+
65+
/// <summary>
66+
///
67+
/// </summary>
2268
public static readonly string TimeFormatForWindows = HourFormat + "-" + MinuteFormat + "-" + SecondFormat + "-" + MillisecondFormat;
23-
public static readonly string DefaultMacro = @"%date%\%name%\%date%_%time%.%format%";
2469

25-
public static string ParseTags(string macro)
26-
{
27-
return ParseTags(string.Empty, macro, null);
28-
}
70+
/// <summary>
71+
///
72+
/// </summary>
73+
public static readonly string DefaultMacro = @"%date%\%name%\%date%_%time%.%format%";
2974

3075
/// <summary>
3176
/// Replaces tags (such as "%year%") with an appropriate value (such as "2019").

0 commit comments

Comments
 (0)