private bool SaveScreenshot(Bitmap bitmap, Region region)
        {
            if (bitmap == null)
            {
                return(false);
            }

            Screenshot screenshot = new Screenshot(_screenCapture.ActiveWindowTitle, _screenCapture.DateTimeScreenshotsTaken)
            {
                ViewId      = region.ViewId,
                Path        = FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(config: false, region.Folder, _formMacroTag.MacroTagCollection)) + MacroParser.ParseTags(preview: false, config: false, region.Name, region.Macro, -1, region.Format, _screenCapture.ActiveWindowTitle, _formMacroTag.MacroTagCollection),
                Bitmap      = bitmap,
                Format      = region.Format,
                ProcessName = _screenCapture.ActiveWindowProcessName + ".exe",
                Label       = checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty
            };

            if (_screenCapture.SaveScreenshot(region.JpegQuality, screenshot, _screenshotCollection))
            {
                ScreenshotTakenWithSuccess();

                return(true);
            }
            else
            {
                ScreenshotTakenWithFailure();

                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Saves the screenshots.
        /// </summary>
        public static void Save()
        {
            try
            {
                if (_screenshotList != null && Directory.Exists(FileSystem.ApplicationFolder))
                {
                    XmlWriterSettings xSettings = new XmlWriterSettings
                    {
                        Indent           = true,
                        CloseOutput      = true,
                        CheckCharacters  = true,
                        Encoding         = Encoding.UTF8,
                        NewLineChars     = Environment.NewLine,
                        IndentChars      = XML_FILE_INDENT_CHARS,
                        NewLineHandling  = NewLineHandling.Entitize,
                        ConformanceLevel = ConformanceLevel.Document
                    };

                    using (XmlWriter xWriter =
                               XmlWriter.Create(FileSystem.ApplicationFolder + MacroParser.ParseTags(FileSystem.ScreenshotsFile), xSettings))
                    {
                        xWriter.WriteStartDocument();
                        xWriter.WriteStartElement(XML_FILE_ROOT_NODE);
                        xWriter.WriteAttributeString("app", "version", XML_FILE_ROOT_NODE, Settings.ApplicationVersion);
                        xWriter.WriteAttributeString("app", "codename", XML_FILE_ROOT_NODE, Settings.ApplicationCodename);
                        xWriter.WriteStartElement(XML_FILE_SCREENSHOTS_NODE);

                        foreach (object obj in _screenshotList)
                        {
                            Screenshot screenshot = (Screenshot)obj;

                            xWriter.WriteStartElement(XML_FILE_SCREENSHOT_NODE);
                            xWriter.WriteElementString(SCREENSHOT_VIEWID, screenshot.ViewId.ToString());
                            xWriter.WriteElementString(SCREENSHOT_DATE, screenshot.Date);
                            xWriter.WriteElementString(SCREENSHOT_TIME, screenshot.Time);
                            xWriter.WriteElementString(SCREENSHOT_PATH, screenshot.Path);
                            xWriter.WriteElementString(SCREENSHOT_FORMAT, screenshot.Format.Name);
                            xWriter.WriteElementString(SCREENSHOT_COMPONENT, screenshot.Component.ToString());
                            xWriter.WriteElementString(SCREENSHOT_SLIDENAME, screenshot.Slide.Name);
                            xWriter.WriteElementString(SCREENSHOT_SLIDEVALUE, screenshot.Slide.Value);
                            xWriter.WriteElementString(SCREENSHOT_WINDOW_TITLE, screenshot.WindowTitle);
                            xWriter.WriteElementString(SCREENSHOT_LABEL, screenshot.Label);

                            xWriter.WriteEndElement();
                        }

                        xWriter.WriteEndElement();
                        xWriter.WriteEndElement();
                        xWriter.WriteEndDocument();

                        xWriter.Flush();
                        xWriter.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write("ScreenshotCollection::Save", ex);
            }
        }
Пример #3
0
        private void AddDefaultScreens(ScreenCapture screenCapture, MacroParser macroParser, FileSystem fileSystem, Log log)
        {
            int component = 1;

            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
            {
                ScreenCapture.DeviceOptions deviceResolution = screenCapture.GetDevice(screen);

                Add(new Screen()
                {
                    ViewId      = Guid.NewGuid(),
                    Name        = "Screen " + component,
                    Folder      = fileSystem.ScreenshotsFolder,
                    Macro       = macroParser.DefaultMacro,
                    Component   = component,
                    Format      = _imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat),
                    JpegQuality = 100,
                    Mouse       = true,
                    Active      = true,
                    X           = screen.Bounds.X,
                    Y           = screen.Bounds.Y,
                    Width       = deviceResolution.width,
                    Height      = deviceResolution.height,
                    Source      = 0,
                    DeviceName  = deviceResolution.screen.DeviceName
                });

                log.WriteDebugMessage($"Screen {component} created using \"{fileSystem.ScreenshotsFolder}\" for folder path and \"{macroParser.DefaultMacro}\" for macro.");

                component++;
            }
        }
        /// <summary>
        /// Empty constructor for the Macro Tags tool window.
        /// </summary>
        public FormMacroTagsToolWindow(MacroTagCollection tagCollection, MacroParser macroParser, Log log)
        {
            InitializeComponent();

            _log                = log;
            _macroParser        = macroParser;
            _macroTagCollection = tagCollection;
        }
Пример #5
0
        private void UpdatePreviewMacro()
        {
            textBoxMacroPreview.ForeColor = System.Drawing.Color.Black;
            textBoxMacroPreview.BackColor = System.Drawing.Color.LightYellow;

            textBoxMacroPreview.Text = MacroParser.ParseTags(textBoxFolder.Text, TagCollection) +
                                       MacroParser.ParseTags(preview: true, textBoxName.Text, textBoxMacro.Text, 1,
                                                             ImageFormatCollection.GetByName(comboBoxFormat.Text), Text, TagCollection);
        }
Пример #6
0
        /// <summary>
        /// A class for logging messages to text files.
        /// </summary>
        public Log(Settings settings, FileSystem fileSystem, MacroParser macroParser)
        {
            _settings    = settings;
            _fileSystem  = fileSystem;
            _macroParser = macroParser;

            DebugMode      = Convert.ToBoolean(settings.Application.GetByKey("DebugMode", settings.DefaultSettings.DebugMode).Value);
            LoggingEnabled = Convert.ToBoolean(settings.Application.GetByKey("Logging", settings.DefaultSettings.Logging).Value);
        }
Пример #7
0
        /// <summary>
        /// A class for handling screen capture methods.
        /// </summary>
        public ScreenCapture(Config config, MacroParser macroParser, FileSystem fileSystem, Log log)
        {
            _log         = log;
            _config      = config;
            _macroParser = macroParser;
            _fileSystem  = fileSystem;

            _dm     = new DEVMODE();
            _device = new DeviceOptions();
        }
Пример #8
0
        /// <summary>
        /// Creates a tag given its name, tag type, and its status (whether it be active or inactive).
        /// </summary>
        /// <param name="macroParser"></param>
        /// <param name="name">The name of the tag.</param>
        /// <param name="description">The description of the tag.</param>
        /// <param name="macroTagType">The type of tag.</param>
        /// <param name="enable">The status of the tag.</param>
        public MacroTag(MacroParser macroParser, string name, string description, MacroTagType macroTagType, bool enable)
        {
            _macroParser = macroParser;

            SetDefaultValues();

            Name        = name;
            Description = description;
            Type        = macroTagType;
            Enable      = enable;
        }
Пример #9
0
        /// <summary>
        /// Creates a tag given its name, tag type, and its status (whether it be active or inactive).
        /// </summary>
        /// <param name="macroParser"></param>
        /// <param name="name">The name of the tag.</param>
        /// <param name="description">The description of the tag.</param>
        /// <param name="macroTagType">The type of tag.</param>
        /// <param name="active">The status of the tag.</param>
        public MacroTag(MacroParser macroParser, string name, string description, MacroTagType macroTagType, bool active)
        {
            _macroParser = macroParser;

            SetDefaultValues();

            Name        = name;
            Description = description;
            Type        = macroTagType;
            Active      = active;
        }
Пример #10
0
        /// <summary>
        /// Constructor for FormRegion.
        /// </summary>
        public FormRegion(ScreenCapture screenCapture, MacroParser macroParser, FileSystem fileSystem, Config config, Log log)
        {
            InitializeComponent();

            _log           = log;
            _config        = config;
            _macroParser   = macroParser;
            _screenCapture = screenCapture;
            _fileSystem    = fileSystem;

            ScreenDictionary = new Dictionary <int, System.Windows.Forms.Screen>();
        }
Пример #11
0
        /// <summary>
        /// Creates a tag given its name, tag type, date/time format value, and its status.
        /// </summary>
        /// <param name="macroParser"></param>
        /// <param name="name">The name of the tag.</param>
        /// <param name="description">The description of the tag.</param>
        /// <param name="MacroTagType">The type of tag.</param>
        /// <param name="dateTimeFormatValue">The date/time format value.</param>
        /// <param name="active">The status of the tag.</param>
        public MacroTag(MacroParser macroParser, string name, string description, MacroTagType MacroTagType, string dateTimeFormatValue, bool active)
        {
            _macroParser = macroParser;

            SetDefaultValues();

            Name                = name;
            Description         = description;
            Type                = MacroTagType;
            DateTimeFormatValue = dateTimeFormatValue;
            Enable              = active;
        }
Пример #12
0
        /// <summary>
        /// Constructor for FormScreen.
        /// </summary>
        public FormScreen(ScreenCapture screenCapture, MacroParser macroParser, FileSystem fileSystem, Log log)
        {
            InitializeComponent();

            _log           = log;
            _macroParser   = macroParser;
            _screenCapture = screenCapture;
            _fileSystem    = fileSystem;

            ScreenCollection = new ScreenCollection();
            RegionCollection = new RegionCollection();
            ScreenDictionary = new Dictionary <int, ScreenCapture.DeviceOptions>();
        }
Пример #13
0
        /// <summary>
        /// Constructor for FormScreen.
        /// </summary>
        public FormScreen(ScreenCapture screenCapture, MacroParser macroParser, FileSystem fileSystem, Config config, Log log)
        {
            InitializeComponent();

            _log           = log;
            _config        = config;
            _macroParser   = macroParser;
            _screenCapture = screenCapture;
            _fileSystem    = fileSystem;

            ScreenCollection = new ScreenCollection();
            RegionCollection = new RegionCollection();
        }
Пример #14
0
        /// <summary>
        /// Creates a tag given its name, tag type, and "Time of Day" properties.
        /// </summary>
        /// <param name="macroParser"></param>
        /// <param name="name">The name of the tag.</param>
        /// <param name="description">The description of the tag.</param>
        /// <param name="macroTagType">The type of tag.</param>
        /// <param name="dateTimeFormatValue">The date/time format value.</param>
        /// <param name="timeRangeMacro1Start">The start time for Macro 1.</param>
        /// <param name="timeRangeMacro1End">The end time for Macro 1.</param>
        /// <param name="timeRangeMacro1Macro">The macro for Macro1.</param>
        /// <param name="timeRangeMacro2Start">The start time for Macro 2.</param>
        /// <param name="timeRangeMacro2End">The end time for Macro 2.</param>
        /// <param name="timeRangeMacro2Macro">The macro for Macro 2.</param>
        /// <param name="timeRangeMacro3Start">The start time for Macro 3.</param>
        /// <param name="timeRangeMacro3End">The end time for Macro 3.</param>
        /// <param name="timeRangeMacro3Macro">The macro for Macro 3.</param>
        /// <param name="timeRangeMacro4Start">The start time for Macro 4.</param>
        /// <param name="timeRangeMacro4End">The end time for Macro 4.</param>
        /// <param name="timeRangeMacro4Macro">The macro for Macro 4</param>
        /// <param name="active">Determines the status of the tag (whether it be active or inactive).</param>
        /// <param name="notes">Notes.</param>
        public MacroTag(MacroParser macroParser, string name, string description, MacroTagType macroTagType,
                        string dateTimeFormatValue,
                        DateTime timeRangeMacro1Start,
                        DateTime timeRangeMacro1End,
                        string timeRangeMacro1Macro,
                        DateTime timeRangeMacro2Start,
                        DateTime timeRangeMacro2End,
                        string timeRangeMacro2Macro,
                        DateTime timeRangeMacro3Start,
                        DateTime timeRangeMacro3End,
                        string timeRangeMacro3Macro,
                        DateTime timeRangeMacro4Start,
                        DateTime timeRangeMacro4End,
                        string timeRangeMacro4Macro,
                        bool active, string notes)
        {
            _macroParser = macroParser;

            Name        = name;
            Description = description;
            Type        = macroTagType;

            DateTimeFormatValue = dateTimeFormatValue;

            TimeRangeMacro1Start = timeRangeMacro1Start;
            TimeRangeMacro1End   = timeRangeMacro1End;

            TimeRangeMacro2Start = timeRangeMacro2Start;
            TimeRangeMacro2End   = timeRangeMacro2End;

            TimeRangeMacro3Start = timeRangeMacro3Start;
            TimeRangeMacro3End   = timeRangeMacro3End;

            TimeRangeMacro4Start = timeRangeMacro4Start;
            TimeRangeMacro4End   = timeRangeMacro4End;

            TimeRangeMacro1Macro = timeRangeMacro1Macro;
            TimeRangeMacro2Macro = timeRangeMacro2Macro;
            TimeRangeMacro3Macro = timeRangeMacro3Macro;
            TimeRangeMacro4Macro = timeRangeMacro4Macro;

            Active = active;

            Notes = notes;
        }
Пример #15
0
        /// <summary>
        /// Gets the path from the configuration file based on what line is being processed and a regex pattern.
        /// </summary>
        /// <param name="line">The line to read from the file.</param>
        /// <param name="regex">The regex pattern to use against the line.</param>
        /// <param name="path">The output of the path being returned.</param>
        /// <returns>A boolean to indicate if getting a path was successful or not.</returns>
        private static bool GetPath(string line, string regex, out string path)
        {
            if (line.StartsWith("#") || !Regex.IsMatch(line, regex))
            {
                path = null;
                return(false);
            }

            path = Regex.Match(line, regex).Groups["Path"].Value;

            TagCollection tagCollection = new TagCollection();

            tagCollection.Add(new Tag("user", "The user using this computer (%user%)", TagType.User, active: true));
            tagCollection.Add(new Tag("machine", "The name of the computer (%machine%)", TagType.Machine, active: true));

            path = MacroParser.ParseTags(path, tagCollection);

            if (FileSystem.HasExtension(path))
            {
                string dir = FileSystem.GetDirectoryName(path);

                if (!string.IsNullOrEmpty(dir) && !FileSystem.DirectoryExists(dir))
                {
                    FileSystem.CreateDirectory(dir);
                }
            }
            else
            {
                if (!path.EndsWith(FileSystem.DirectorySeparatorChar().ToString()))
                {
                    path += FileSystem.DirectorySeparatorChar();
                }

                if (!string.IsNullOrEmpty(path) && !FileSystem.DirectoryExists(path))
                {
                    FileSystem.CreateDirectory(path);
                }
            }

            return(true);
        }
Пример #16
0
        /// <summary>
        /// The event method used by "Region Select / Auto Save".
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _formRegionSelectWithMouse_RegionSelectAutoSaveMouseSelectionCompleted(object sender, EventArgs e)
        {
            int x      = _formRegionSelectWithMouse.outputX + 1;
            int y      = _formRegionSelectWithMouse.outputY + 1;
            int width  = _formRegionSelectWithMouse.outputWidth - 2;
            int height = _formRegionSelectWithMouse.outputHeight - 2;

            string autoSaveFolder = textBoxAutoSaveFolder.Text;
            string autoSaveMacro  = textBoxAutoSaveMacro.Text;

            ImageFormat imageFormat = new ImageFormat(ImageFormatSpec.NAME_JPEG, ImageFormatSpec.EXTENSION_JPEG);

            if (_screenCapture.GetScreenImages(-1, x, y, width, height, mouse: false, resolutionRatio: 100, out Bitmap bitmap))
            {
                DateTime dtNow = DateTime.Now;

                _screenCapture.DateTimeScreenshotsTaken = dtNow;
                _screenCapture.ActiveWindowTitle        = "*** Auto Screen Capture - Region Select / Auto Save ***";

                if (_screenCapture.SaveScreenshot(
                        path: FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(config: false, autoSaveFolder, _formTag.TagCollection)) + MacroParser.ParseTags(preview: false, config: false, DateTime.Now.ToString(MacroParser.DateFormat), autoSaveMacro, -1, imageFormat, _screenCapture.ActiveWindowTitle, _formTag.TagCollection),
                        format: imageFormat,
                        component: -1,
                        screenshotType: ScreenshotType.Region,
                        jpegQuality: 100,
                        viewId: new Guid(),
                        bitmap: bitmap,
                        label: checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty,
                        windowTitle: _screenCapture.ActiveWindowTitle,
                        processName: _screenCapture.ActiveWindowProcessName,
                        screenshotCollection: _screenshotCollection
                        ))
                {
                    ScreenshotTakenWithSuccess();
                }
                else
                {
                    ScreenshotTakenWithFailure();
                }
            }
        }
Пример #17
0
        /// <summary>
        /// The constructor for creating a screenshot.
        /// </summary>
        /// <param name="windowTitle">The title of the active window when the screenshot was taken.</param>
        /// <param name="dateTime">The date/time the screenshot was taken.</param>
        /// <param name="macroParser"></param>
        /// <param name="config"></param>
        public Screenshot(string windowTitle, DateTime dateTime, MacroParser macroParser, Config config)
        {
            if (string.IsNullOrEmpty(windowTitle))
            {
                return;
            }

            WindowTitle = windowTitle;

            Date    = dateTime.ToString(macroParser.DateFormat);
            Time    = dateTime.ToString(macroParser.TimeFormat);
            Saved   = false;
            Version = config.Settings.ApplicationVersion;

            Slide = new Slide()
            {
                Name  = "{date=" + Date + "}{time=" + Time + "}",
                Date  = Date,
                Value = Time + " [" + windowTitle + "]"
            };
        }
Пример #18
0
        private static bool GetPath(string line, string regex, out string path)
        {
            if (line.StartsWith("#") || !Regex.IsMatch(line, regex))
            {
                path = null;
                return(false);
            }

            path = Regex.Match(line, regex).Groups["Path"].Value;

            path = MacroParser.ParseTagsForUserAndMachine(path);

            if (Path.HasExtension(path))
            {
                string dir = Path.GetDirectoryName(path);

                if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            else
            {
                if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    path += Path.DirectorySeparatorChar;
                }

                if (!string.IsNullOrEmpty(path) && !Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }

            return(true);
        }
Пример #19
0
        /// <summary>
        /// The constructor for creating a screenshot.
        /// </summary>
        /// <param name="windowTitle">The title of the active window when the screenshot was taken.</param>
        /// <param name="dateTime">The date/time the screenshot was taken.</param>
        /// <param name="macroParser"></param>
        /// <param name="config"></param>
        public Screenshot(string windowTitle, DateTime dateTime, MacroParser macroParser, Config config)
        {
            if (string.IsNullOrEmpty(windowTitle))
            {
                return;
            }

            // Each screenshot has a unique identifier (since version 2.4) just in case we need a reference to it.
            Id = Guid.NewGuid();

            WindowTitle = windowTitle;

            Date           = dateTime.ToString(macroParser.DateFormat);
            Time           = dateTime.ToString(macroParser.TimeFormat);
            ReferenceSaved = false;
            Version        = config.Settings.ApplicationVersion;

            Slide = new Slide()
            {
                Name  = "{date=" + Date + "}{time=" + Time + "}",
                Date  = Date,
                Value = Time + " [" + windowTitle + "]"
            };
        }
Пример #20
0
        private void listBoxMacroTags_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            Tag tag = _tagCollection.GetByName((string)listBoxMacroTags.SelectedItem);

            labelHelp.Text = MacroParser.ParseTags(tag.Description, _tagCollection);
        }
Пример #21
0
        /// <summary>
        /// The empty constructor for creating a tag.
        /// </summary>
        public MacroTag(MacroParser macroParser)
        {
            _macroParser = macroParser;

            SetDefaultValues();
        }
Пример #22
0
        /// <summary>
        /// Loads the macro tags.
        /// </summary>
        public bool LoadXmlFileAndAddTags(Config config, MacroParser macroParser, FileSystem fileSystem, Log log)
        {
            try
            {
                if (fileSystem.FileExists(fileSystem.MacroTagsFile))
                {
                    log.WriteDebugMessage("Macro Tags file \"" + fileSystem.MacroTagsFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(fileSystem.MacroTagsFile);

                    log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xTags = xDoc.SelectNodes(MACRO_TAG_XPATH);

                    // This is to maintain backwards compatibility with versions that are older than 2.4
                    if (xTags.Count == 0)
                    {
                        xTags = xDoc.SelectNodes(@"/autoscreen/tags/tag");
                    }

                    bool eveningExtendsToNextMorning = false;

                    foreach (XmlNode xTag in xTags)
                    {
                        MacroTag      tag     = new MacroTag(macroParser);
                        XmlNodeReader xReader = new XmlNodeReader(xTag);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case MACRO_TAG_NAME:
                                    xReader.Read();
                                    tag.Name = xReader.Value;

                                    if (!tag.Name.StartsWith("%"))
                                    {
                                        tag.Name = "%" + tag.Name;
                                    }

                                    if (!tag.Name.EndsWith("%"))
                                    {
                                        tag.Name += "%";
                                    }

                                    break;

                                case MACRO_TAG_DESCRIPTION:
                                    xReader.Read();
                                    tag.Description = xReader.Value;
                                    break;

                                case MACRO_TAG_NOTES:
                                    xReader.Read();
                                    tag.Notes = xReader.Value;
                                    break;

                                case MACRO_TAG_TYPE:
                                    xReader.Read();

                                    string value = xReader.Value;

                                    // Change the data for each Macro Tag that's being loaded if we've detected that
                                    // the XML document is from an older version of the application.
                                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                                    {
                                        log.WriteDebugMessage("An old version of the macrotags.xml file was detected. Attempting upgrade to new schema.");

                                        Version v2300 = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                                        Version v2326 = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.2.6");
                                        Version v2424 = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BLADE, "2.4.2.4");

                                        Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                                        if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                                        {
                                            log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                            // Starting with 2.3.0.0 the DateTimeFormatFunction type became the DateTimeFormatExpression type.
                                            value = value.Replace("DateTimeFormatFunction", "DateTimeFormatExpression");
                                        }

                                        if (v2326 != null && configVersion != null && configVersion.VersionNumber < v2326.VersionNumber)
                                        {
                                            log.WriteDebugMessage("Boombayah 2.3.2.5 or older detected");

                                            // Starting with 2.3.2.6 the TimeOfDay type became the TimeRange type.
                                            value = value.Replace("TimeOfDay", "TimeRange");
                                        }

                                        if (v2424 != null && configVersion != null && configVersion.VersionNumber < v2424.VersionNumber)
                                        {
                                            log.WriteDebugMessage("Blade 2.4.2.3 or older detected");

                                            // Starting with 2.4.2.4 the CountNow type became the CaptureNowCount type.
                                            value = value.Replace("CountNow", "CaptureNowCount");
                                        }
                                    }

                                    tag.Type = (MacroTagType)Enum.Parse(typeof(MacroTagType), value);
                                    break;

                                case MACRO_TAG_DATETIME_FORMAT_VALUE:
                                    xReader.Read();
                                    tag.DateTimeFormatValue = xReader.Value;
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO1_START:
                                case MACRO_TAG_TIME_OF_DAY_MORNING_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro1Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO1_END:
                                case MACRO_TAG_TIME_OF_DAY_MORNING_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro1End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO2_START:
                                case MACRO_TAG_TIME_OF_DAY_AFTERNOON_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro2Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO2_END:
                                case MACRO_TAG_TIME_OF_DAY_AFTERNOON_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro2End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO3_START:
                                case MACRO_TAG_TIME_OF_DAY_EVENING_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro3Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO3_END:
                                case MACRO_TAG_TIME_OF_DAY_EVENING_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro3End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO4_START:
                                    xReader.Read();
                                    tag.TimeRangeMacro4Start = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO4_END:
                                    xReader.Read();
                                    tag.TimeRangeMacro4End = Convert.ToDateTime(xReader.Value);
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO1_MACRO:
                                case MACRO_TAG_TIME_OF_DAY_MORNING_VALUE:
                                    xReader.Read();
                                    tag.TimeRangeMacro1Macro = xReader.Value;
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO2_MACRO:
                                case MACRO_TAG_TIME_OF_DAY_AFTERNOON_VALUE:
                                    xReader.Read();
                                    tag.TimeRangeMacro2Macro = xReader.Value;
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO3_MACRO:
                                case MACRO_TAG_TIME_OF_DAY_EVENING_VALUE:
                                    xReader.Read();
                                    tag.TimeRangeMacro3Macro = xReader.Value;
                                    break;

                                case MACRO_TAG_TIMERANGE_MACRO4_MACRO:
                                    xReader.Read();
                                    tag.TimeRangeMacro4Macro = xReader.Value;
                                    break;

                                case MACRO_TAG_TIME_OF_DAY_EVENING_EXTENDS_TO_NEXT_MORNING:
                                    xReader.Read();
                                    eveningExtendsToNextMorning = Convert.ToBoolean(xReader.Value);
                                    break;

                                case MACRO_TAG_ENABLE:
                                case "active":     // Any version older than 2.4.0.0 used "active" instead of "enable".
                                    xReader.Read();
                                    tag.Enable = Convert.ToBoolean(xReader.Value);
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Macro Tag that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                        {
                            log.WriteDebugMessage("An old version of the macrotags.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2326         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.2.6");
                            Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Macro Tag that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                tag.Enable = true;

                                // "Description" is a new property for Macro Tag that was introduced in 2.3.0.0
                                switch (tag.Type)
                                {
                                case MacroTagType.ActiveWindowTitle:
                                    tag.Description = "The title of the active window";
                                    break;

                                case MacroTagType.DateTimeFormat:
                                    tag.Description = "A value representing either a date, a time, or a combination of the date and time";
                                    break;

                                case MacroTagType.ImageFormat:
                                    tag.Description = "The image format of the screenshot (such as jpeg or png)";
                                    break;

                                case MacroTagType.ScreenCaptureCycleCount:
                                    tag.Description = "The number of capture cycles during a screen capture session";
                                    break;

                                case MacroTagType.ScreenName:
                                    tag.Description = "The name of the screen or region";
                                    break;

                                case MacroTagType.ScreenNumber:
                                    tag.Description = "The screen number. For example, the first display is screen number 1";
                                    break;

                                case MacroTagType.User:
                                    tag.Description = "The name of the user";
                                    break;

                                case MacroTagType.Machine:
                                    tag.Description = "The name of the computer";
                                    break;

                                case MacroTagType.TimeRange:
                                    tag.Description = "The macro to use for a specific time range";
                                    break;

                                case MacroTagType.DateTimeFormatExpression:
                                    tag.Description = "An expression which represents a time that is either ahead or behind the current time";
                                    break;
                                }
                            }

                            if (v2326 != null && configVersion != null && configVersion.VersionNumber < v2326.VersionNumber)
                            {
                                tag.TimeRangeMacro4Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                                tag.TimeRangeMacro4End   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                                tag.TimeRangeMacro4Macro = string.Empty;

                                // This is an old property from before 2.3.2.6 when TimeOfDay macro tags were used.
                                // Since 2.3.2.6 we now use TimeRange tags so we need to split up the "evening" start and end times
                                // into their own "Macro 4" start and end times when this property is set to true.
                                if (eveningExtendsToNextMorning)
                                {
                                    tag.TimeRangeMacro4Start = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                                    tag.TimeRangeMacro4End   = tag.TimeRangeMacro3End;

                                    tag.TimeRangeMacro3End = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59);

                                    tag.TimeRangeMacro4Macro = tag.TimeRangeMacro3Macro;
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(tag.Name))
                        {
                            Add(tag);
                        }
                    }

                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                    {
                        log.WriteDebugMessage("Macro Tags file detected as an old version");

                        // Go through the macro tags we want to add. If we can't find them then add them to the collection.

                        if (GetByName("%timerange%") == null)
                        {
                            Add(new MacroTag(macroParser, "timerange", "The macro to use during a specific time range. At the moment it is %timerange%", MacroTagType.TimeRange, enable: true));
                        }

                        if (GetByName("%quarteryear%") == null)
                        {
                            Add(new MacroTag(macroParser, "quarteryear", "A number representing the current quarter of the current year (%quarteryear%)", MacroTagType.QuarterYear, enable: true));
                        }

                        if (GetByName("%x%") == null)
                        {
                            Add(new MacroTag(macroParser, "x", "The X value of the screen or region", MacroTagType.X, enable: true));
                        }

                        if (GetByName("%y%") == null)
                        {
                            Add(new MacroTag(macroParser, "y", "The Y value of the screen or region", MacroTagType.Y, enable: true));
                        }

                        if (GetByName("%width%") == null)
                        {
                            Add(new MacroTag(macroParser, "width", "The Width value of the screen or region", MacroTagType.Width, enable: true));
                        }

                        if (GetByName("%height%") == null)
                        {
                            Add(new MacroTag(macroParser, "height", "The Height value of the screen or region", MacroTagType.Height, enable: true));
                        }

                        if (GetByName("%process%") == null)
                        {
                            Add(new MacroTag(macroParser, "process", "The name of the active process", MacroTagType.Process, enable: true));
                        }

                        if (GetByName("%label%") == null)
                        {
                            Add(new MacroTag(macroParser, "label", "The label being applied to the saved screenshot", MacroTagType.Label, enable: true));
                        }

                        if (GetByName("%capturenowcount%") == null)
                        {
                            Add(new MacroTag(macroParser, "capturenowcount", "The number of times Capture Now has been used", MacroTagType.CaptureNowCount, enable: true));
                        }

                        SaveToXmlFile(config, fileSystem, log);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (fileSystem.FileExists(fileSystem.MacroTagsFile))
                {
                    fileSystem.DeleteFile(fileSystem.MacroTagsFile);

                    log.WriteErrorMessage("The file \"" + fileSystem.MacroTagsFile + "\" had to be deleted because an error was encountered. You may need to force quit the application and run it again.");
                }

                log.WriteExceptionMessage("MacroTagCollection::LoadXmlFileAndAddTags", ex);

                return(false);
            }
        }
Пример #23
0
        /// <summary>
        /// Loads the screens.
        /// </summary>
        /// <param name="imageFormatCollection">The image format collection to use.</param>
        /// <param name="config">The configuration to use.</param>
        /// <param name="macroParser">The macro parser to use.</param>
        /// <param name="fileSystem">The file system to use.</param>
        /// <param name="log">The logging class to use.</param>
        /// <returns>Returns true if we were able to load the screens.xml file and add all the available screens otherwise returns false.</returns>
        public bool LoadXmlFileAndAddScreens(ImageFormatCollection imageFormatCollection, Config config, MacroParser macroParser, FileSystem fileSystem, Log log)
        {
            try
            {
                if (fileSystem.FileExists(fileSystem.ScreensFile))
                {
                    log.WriteDebugMessage("Screens file \"" + fileSystem.ScreensFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(fileSystem.ScreensFile);

                    log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xScreens = xDoc.SelectNodes(SCREEN_XPATH);

                    foreach (XmlNode xScreen in xScreens)
                    {
                        Screen        screen  = new Screen();
                        XmlNodeReader xReader = new XmlNodeReader(xScreen);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case SCREEN_VIEWID:
                                    xReader.Read();
                                    screen.ViewId = Guid.Parse(xReader.Value);
                                    break;

                                case SCREEN_NAME:
                                    xReader.Read();
                                    screen.Name = xReader.Value;
                                    break;

                                case SCREEN_FOLDER:
                                    xReader.Read();
                                    screen.Folder = xReader.Value;
                                    break;

                                case SCREEN_MACRO:
                                    xReader.Read();
                                    screen.Macro = xReader.Value;
                                    break;

                                case SCREEN_COMPONENT:
                                    xReader.Read();
                                    screen.Component = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_FORMAT:
                                    xReader.Read();
                                    screen.Format = imageFormatCollection.GetByName(xReader.Value);
                                    break;

                                case SCREEN_JPEG_QUALITY:
                                    xReader.Read();
                                    screen.JpegQuality = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_MOUSE:
                                    xReader.Read();
                                    screen.Mouse = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_ENABLE:
                                case "active":     // Any version older than 2.4.0.0 used "active" instead of "enable".
                                    xReader.Read();
                                    screen.Enable = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_X:
                                    xReader.Read();
                                    screen.X = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_Y:
                                    xReader.Read();
                                    screen.Y = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_WIDTH:
                                    xReader.Read();
                                    screen.Width = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_HEIGHT:
                                    xReader.Read();
                                    screen.Height = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_SOURCE:
                                    xReader.Read();
                                    screen.Source = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_DEVICE_NAME:
                                    xReader.Read();
                                    screen.DeviceName = xReader.Value;
                                    break;

                                case SCREEN_AUTO_ADAPT:
                                    xReader.Read();
                                    screen.AutoAdapt = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_CAPTURE_METHOD:
                                    xReader.Read();
                                    screen.CaptureMethod = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_ENCRYPT:
                                    xReader.Read();
                                    screen.Encrypt = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_RESOLUTION_RATIO:
                                    xReader.Read();
                                    screen.ResolutionRatio = Convert.ToInt32(xReader.Value);
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Screen that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                        {
                            log.WriteDebugMessage("An old version of the screens.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2338         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.3.8");
                            Version v2406         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BLADE, "2.3.0.6");
                            Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Screen that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                screen.Enable = true;
                            }

                            if (v2338 != null && configVersion != null && configVersion.VersionNumber < v2338.VersionNumber)
                            {
                                log.WriteDebugMessage("Boombayah 2.3.3.7 or older detected");

                                int screenIndex = 0;

                                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                                {
                                    if (screen.Component.Equals(screenIndex + 1))
                                    {
                                        screen.X               = 0;
                                        screen.Y               = 0;
                                        screen.Width           = 0;
                                        screen.Height          = 0;
                                        screen.Source          = 0;
                                        screen.DeviceName      = string.Empty;
                                        screen.CaptureMethod   = 1;
                                        screen.AutoAdapt       = true; // 2.4.0.0 has a new "Auto Adapt" feature which will automatically figure out the position and resolution for each screen.
                                        screen.Encrypt         = false;
                                        screen.ResolutionRatio = 100;  // 2.4.0.7
                                    }

                                    screenIndex++;
                                }
                            }

                            if (v2406 != null && configVersion != null && configVersion.VersionNumber <= v2406.VersionNumber)
                            {
                                log.WriteDebugMessage("Blade 2.4.0.6 or older detected");

                                screen.ResolutionRatio = 100;
                            }
                        }

                        if (!string.IsNullOrEmpty(screen.Name))
                        {
                            Add(screen);
                        }
                    }

                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                    {
                        log.WriteDebugMessage("Screens file detected as an old version");
                        SaveToXmlFile(config.Settings, fileSystem, log);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (fileSystem.FileExists(fileSystem.ScreensFile))
                {
                    fileSystem.DeleteFile(fileSystem.ScreensFile);

                    log.WriteErrorMessage("The file \"" + fileSystem.ScreensFile + "\" had to be deleted because an error was encountered. You may need to force quit the application and run it again.");
                }

                log.WriteExceptionMessage("ScreenCollection::LoadXmlFileAndAddScreens", ex);

                return(false);
            }
        }
Пример #24
0
        private void RunRegionCaptures()
        {
            try
            {
                Log.WriteDebugMessage(":: RunRegionCaptures Start ::");

                foreach (Region region in formRegion.RegionCollection)
                {
                    if (region.Active)
                    {
                        MacroParser.screenCapture = _screenCapture;

                        if (!string.IsNullOrEmpty(_screenCapture.ActiveWindowTitle))
                        {
                            // Do not contiune if the active window title needs to be checked and the active window title
                            // does not contain the text defined in "Active Window Title Capture Text".
                            if (region.ActiveWindowTitleCaptureCheck && !string.IsNullOrEmpty(region.ActiveWindowTitleCaptureText) &&
                                !_screenCapture.ActiveWindowTitle.ToLower().Contains(region.ActiveWindowTitleCaptureText.ToLower()))
                            {
                                return;
                            }

                            if (_screenCapture.GetScreenImages(-1, region.X, region.Y, region.Width, region.Height, region.Mouse, region.ResolutionRatio, out Bitmap bitmap))
                            {
                                if (_screenCapture.SaveScreenshot(
                                        path: FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(region.Folder, formTag.TagCollection)) + MacroParser.ParseTags(preview: false, region.Name, region.Macro, -1, region.Format, _screenCapture.ActiveWindowTitle, formTag.TagCollection),
                                        format: region.Format,
                                        component: -1,
                                        screenshotType: ScreenshotType.Region,
                                        jpegQuality: region.JpegQuality,
                                        viewId: region.ViewId,
                                        bitmap: bitmap,
                                        label: checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty,
                                        windowTitle: _screenCapture.ActiveWindowTitle,
                                        processName: _screenCapture.ActiveWindowProcessName,
                                        screenshotCollection: _screenshotCollection
                                        ))
                                {
                                    ScreenshotTakenWithSuccess();
                                }
                                else
                                {
                                    ScreenshotTakenWithFailure();
                                }
                            }
                        }
                    }
                }

                Log.WriteDebugMessage(":: RunRegionCaptures End ::");
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("FormMain-Regions::RunRegionCaptures", ex);
            }
        }
Пример #25
0
        /// <summary>
        /// Loads the screens.
        /// </summary>
        public bool LoadXmlFileAndAddScreens(ImageFormatCollection imageFormatCollection, Config config, MacroParser macroParser, ScreenCapture screenCapture, FileSystem fileSystem, Log log)
        {
            try
            {
                if (fileSystem.FileExists(fileSystem.ScreensFile))
                {
                    log.WriteDebugMessage("Screens file \"" + fileSystem.ScreensFile + "\" found. Attempting to load XML document");

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.Load(fileSystem.ScreensFile);

                    log.WriteDebugMessage("XML document loaded");

                    AppVersion  = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value;
                    AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value;

                    XmlNodeList xScreens = xDoc.SelectNodes(SCREEN_XPATH);

                    foreach (XmlNode xScreen in xScreens)
                    {
                        Screen        screen  = new Screen();
                        XmlNodeReader xReader = new XmlNodeReader(xScreen);

                        while (xReader.Read())
                        {
                            if (xReader.IsStartElement() && !xReader.IsEmptyElement)
                            {
                                switch (xReader.Name)
                                {
                                case SCREEN_VIEWID:
                                    xReader.Read();
                                    screen.ViewId = Guid.Parse(xReader.Value);
                                    break;

                                case SCREEN_NAME:
                                    xReader.Read();
                                    screen.Name = xReader.Value;
                                    break;

                                case SCREEN_FOLDER:
                                    xReader.Read();
                                    screen.Folder = xReader.Value;
                                    break;

                                case SCREEN_MACRO:
                                    xReader.Read();
                                    screen.Macro = xReader.Value;
                                    break;

                                case SCREEN_COMPONENT:
                                    xReader.Read();
                                    screen.Component = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_FORMAT:
                                    xReader.Read();
                                    screen.Format = imageFormatCollection.GetByName(xReader.Value);
                                    break;

                                case SCREEN_JPEG_QUALITY:
                                    xReader.Read();
                                    screen.JpegQuality = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_MOUSE:
                                    xReader.Read();
                                    screen.Mouse = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_ACTIVE:
                                    xReader.Read();
                                    screen.Active = Convert.ToBoolean(xReader.Value);
                                    break;

                                case SCREEN_X:
                                    xReader.Read();
                                    screen.X = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_Y:
                                    xReader.Read();
                                    screen.Y = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_WIDTH:
                                    xReader.Read();
                                    screen.Width = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_HEIGHT:
                                    xReader.Read();
                                    screen.Height = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_SOURCE:
                                    xReader.Read();
                                    screen.Source = Convert.ToInt32(xReader.Value);
                                    break;

                                case SCREEN_DEVICE_NAME:
                                    xReader.Read();
                                    screen.DeviceName = xReader.Value;
                                    break;
                                }
                            }
                        }

                        xReader.Close();

                        // Change the data for each Screen that's being loaded if we've detected that
                        // the XML document is from an older version of the application.
                        if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                        {
                            log.WriteDebugMessage("An old version of the screens.xml file was detected. Attempting upgrade to new schema.");

                            Version v2300         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2338         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.3.8");
                            Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                            if (v2300 != null && configVersion != null && configVersion.VersionNumber < v2300.VersionNumber)
                            {
                                log.WriteDebugMessage("Dalek 2.2.4.6 or older detected");

                                // This is a new property for Screen that was introduced in 2.3.0.0
                                // so any version before 2.3.0.0 needs to have it during an upgrade.
                                screen.Active = true;
                            }

                            if (v2338 != null && configVersion != null && configVersion.VersionNumber < v2338.VersionNumber)
                            {
                                log.WriteDebugMessage("Boombayah 2.3.3.7 or older detected");

                                int component = 1;

                                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                                {
                                    ScreenCapture.DeviceOptions deviceOptions = screenCapture.GetDevice(screenFromWindows);

                                    if (screen.Component.Equals(component))
                                    {
                                        screen.X          = screenFromWindows.Bounds.X;
                                        screen.Y          = screenFromWindows.Bounds.Y;
                                        screen.Width      = deviceOptions.width;
                                        screen.Height     = deviceOptions.height;
                                        screen.Source     = 1;
                                        screen.DeviceName = deviceOptions.screen.DeviceName;
                                    }

                                    component++;
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(screen.Name))
                        {
                            Add(screen);
                        }
                    }

                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                    {
                        log.WriteDebugMessage("Screens file detected as an old version");
                        SaveToXmlFile(config, fileSystem, log);
                    }
                }
                else
                {
                    log.WriteDebugMessage("WARNING: Unable to load screens");

                    if (config.Settings.VersionManager.IsOldAppVersion(config.Settings, AppCodename, AppVersion))
                    {
                        Version v2182         = config.Settings.VersionManager.Versions.Get(Settings.CODENAME_CLARA, Settings.CODEVERSION_CLARA);
                        Version configVersion = config.Settings.VersionManager.Versions.Get(AppCodename, AppVersion);

                        if (v2182 != null && configVersion != null && v2182.VersionNumber == configVersion.VersionNumber)
                        {
                            Add(new Screen()
                            {
                                ViewId      = Guid.NewGuid(),
                                Name        = "Active Window",
                                Folder      = fileSystem.ScreenshotsFolder,
                                Macro       = macroParser.DefaultMacro,
                                Component   = 0,
                                Format      = _imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat),
                                JpegQuality = 100,
                                Mouse       = true,
                                Active      = true,
                                X           = 0,
                                Y           = 0,
                                Width       = 0,
                                Height      = 0,
                                Source      = 0,
                                DeviceName  = string.Empty
                            });
                        }
                    }

                    AddDefaultScreens(screenCapture, macroParser, fileSystem, log);

                    SaveToXmlFile(config, fileSystem, log);
                }

                return(true);
            }
            catch (Exception ex)
            {
                log.WriteExceptionMessage("ScreenCollection::LoadXmlFileAndAddScreens", ex);

                return(false);
            }
        }
Пример #26
0
        /// <summary>
        /// Empty constructor.
        /// </summary>
        public FormMacroTag(MacroParser macroParser)
        {
            InitializeComponent();

            _macroParser = macroParser;
        }
Пример #27
0
        private void RunRegionCaptures()
        {
            try
            {
                foreach (Region region in _formRegion.RegionCollection)
                {
                    if (region.Active)
                    {
                        MacroParser.screenCapture = _screenCapture;

                        if (!string.IsNullOrEmpty(_screenCapture.ActiveWindowTitle))
                        {
                            // Do not contiune if the active window title needs to be checked and the active window title
                            // does not contain the text defined in "Active Window Title Capture Text" and CaptureNow is false.
                            // CaptureNow could be set to "true" during a "Capture Now / Archive" or "Capture Now / Edit" option
                            // so, in that case, we want to capture the screen and save the screenshot regardless of the title text.
                            if (checkBoxActiveWindowTitle.Checked && !string.IsNullOrEmpty(textBoxActiveWindowTitle.Text) &&
                                !_screenCapture.ActiveWindowTitle.ToLower().Contains(textBoxActiveWindowTitle.Text.ToLower()) &&
                                !_screenCapture.CaptureNow)
                            {
                                return;
                            }

                            _screenCapture.CaptureNow = false;

                            if (_screenCapture.GetScreenImages(-1, region.X, region.Y, region.Width, region.Height, region.Mouse, region.ResolutionRatio, out Bitmap bitmap))
                            {
                                if (_screenCapture.SaveScreenshot(
                                        path: FileSystem.CorrectScreenshotsFolderPath(MacroParser.ParseTags(config: false, region.Folder, _formTag.TagCollection)) + MacroParser.ParseTags(preview: false, config: false, region.Name, region.Macro, -1, region.Format, _screenCapture.ActiveWindowTitle, _formTag.TagCollection),
                                        format: region.Format,
                                        component: -1,
                                        screenshotType: ScreenshotType.Region,
                                        jpegQuality: region.JpegQuality,
                                        viewId: region.ViewId,
                                        bitmap: bitmap,
                                        label: checkBoxScreenshotLabel.Checked ? comboBoxScreenshotLabel.Text : string.Empty,
                                        windowTitle: _screenCapture.ActiveWindowTitle,
                                        processName: _screenCapture.ActiveWindowProcessName,
                                        screenshotCollection: _screenshotCollection
                                        ))
                                {
                                    ScreenshotTakenWithSuccess();
                                }
                                else
                                {
                                    ScreenshotTakenWithFailure();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _screenCapture.ApplicationError = true;
                Log.WriteExceptionMessage("FormMain-Regions::RunRegionCaptures", ex);
            }
        }
Пример #28
0
        /// <summary>
        /// Loads the configuration file.
        /// </summary>
        public void Load(FileSystem fileSystem)
        {
            try
            {
                FileSystem = fileSystem;

                Settings    = new Settings();
                MacroParser = new MacroParser(Settings);

                string configDirectory = FileSystem.GetDirectoryName(FileSystem.ConfigFile);

                if (!string.IsNullOrEmpty(configDirectory) && !FileSystem.DirectoryExists(configDirectory))
                {
                    FileSystem.CreateDirectory(configDirectory);
                }

                if (!FileSystem.FileExists(FileSystem.ConfigFile))
                {
                    string[] linesToWrite =
                    {
                        "# Auto Screen Capture Configuration File",
                        "# Use this file to tell the application what folders and files it should utilize.",
                        "# Each key-value pair can be the name of a folder or file or a path to a folder or file.",
                        "# If only the folder name is given then it will be parsed as the sub-folder of the folder",
                        "# where the executed autoscreen.exe binary is located.",                                                   "",
                        "# This is the folder where screenshots will be stored by default.",
                        "ScreenshotsFolder=" + FileSystem.DefaultScreenshotsFolder,                                                 "",
                        "# If any errors are encountered then you will find them in this folder when DebugMode is enabled.",
                        "DebugFolder=" + FileSystem.DefaultDebugFolder,                                                             "",
                        "# Logs are stored in this folder when either Logging or DebugMode is enabled.",
                        "LogsFolder=" + FileSystem.DefaultLogsFolder,                                                               "",
                        "# This file is monitored by the application for commands issued from the command line while it's running.",
                        "CommandFile=" + FileSystem.DefaultCommandFile,                                                             "",
                        "# The application settings (such as DebugMode).",
                        "ApplicationSettingsFile=" + FileSystem.DefaultApplicationSettingsFile,                                     "",
                        "# Your personal settings.",
                        "UserSettingsFile=" + FileSystem.DefaultUserSettingsFile,                                                   "",
                        "# SMTP settings for emailing screenshots using an email server.",
                        "SMTPSettingsFile=" + FileSystem.DefaultSmtpSettingsFile,                                                   "",
                        "# SFTP settings for uploading screenshots to a file server.",
                        "SFTPSettingsFile=" + FileSystem.DefaultSftpSettingsFile,                                                   "",
                        "# References to image editors.",
                        "EditorsFile=" + FileSystem.DefaultEditorsFile,                                                             "",
                        "# References to regions.",
                        "RegionsFile=" + FileSystem.DefaultRegionsFile,                                                             "",
                        "# References to screens.",
                        "ScreensFile=" + FileSystem.DefaultScreensFile,                                                             "",
                        "# References to triggers.",
                        "TriggersFile=" + FileSystem.DefaultTriggersFile,                                                           "",
                        "# References to screenshots.",
                        "ScreenshotsFile=" + FileSystem.DefaultScreenshotsFile,                                                     "",
                        "# References to tags.",
                        "TagsFile=" + FileSystem.DefaultTagsFile,                                                                   "",
                        "# References to schedules.",
                        "SchedulesFile=" + FileSystem.DefaultSchedulesFile,                                                         ""
                    };

                    FileSystem.WriteToFile(FileSystem.ConfigFile, linesToWrite);
                }

                foreach (string line in FileSystem.ReadFromFile(FileSystem.ConfigFile))
                {
                    if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
                    {
                        continue;
                    }

                    string path;

                    if (GetPathAndCreateIfNotFound(line, REGEX_SCREENSHOTS_FOLDER, out path))
                    {
                        FileSystem.ScreenshotsFolder = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_DEBUG_FOLDER, out path))
                    {
                        FileSystem.DebugFolder = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_LOGS_FOLDER, out path))
                    {
                        FileSystem.LogsFolder = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_COMMAND_FILE, out path))
                    {
                        FileSystem.CommandFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_APPLICATION_SETTINGS_FILE, out path))
                    {
                        FileSystem.ApplicationSettingsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_SMTP_SETTINGS_FILE, out path))
                    {
                        FileSystem.SmtpSettingsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_SFTP_SETTINGS_FILE, out path))
                    {
                        FileSystem.SftpSettingsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_USER_SETTINGS_FILE, out path))
                    {
                        FileSystem.UserSettingsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_EDITORS_FILE, out path))
                    {
                        FileSystem.EditorsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_REGIONS_FILE, out path))
                    {
                        FileSystem.RegionsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_SCREENS_FILE, out path))
                    {
                        FileSystem.ScreensFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_TRIGGERS_FILE, out path))
                    {
                        FileSystem.TriggersFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_SCREENSHOTS_FILE, out path))
                    {
                        FileSystem.ScreenshotsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_TAGS_FILE, out path))
                    {
                        FileSystem.TagsFile = path;
                    }

                    if (GetPathAndCreateIfNotFound(line, REGEX_SCHEDULES_FILE, out path))
                    {
                        FileSystem.SchedulesFile = path;
                    }
                }

                CheckAndCreateFolders();

                Settings.Load(FileSystem);
                Log           = new Log(Settings, FileSystem, MacroParser);
                ScreenCapture = new ScreenCapture(this, MacroParser, FileSystem, Log);

                Security security = new Security();
                CheckAndCreateFiles(security, ScreenCapture, Log);
            }
            catch (Exception ex)
            {
                Log.WriteExceptionMessage("Config::Load", ex);
            }
        }
Пример #29
0
        /// <summary>
        /// Parses macro tag expressions for date/time format.
        /// </summary>
        /// <param name="dateTime">The date/time object to parse.</param>
        /// <param name="tagExpression">The tag expression to use on the date/time object.</param>
        /// <param name="macroParser"></param>
        /// <returns>A parsed macro string value.</returns>
        public string ParseTagExpressionForDateTimeFormat(DateTime dateTime, string tagExpression, MacroParser macroParser)
        {
            string result = tagExpression;

            if (Regex.IsMatch(tagExpression, DateTimeFormatTagExpressionRegex))
            {
                string dateTimePart   = Regex.Match(tagExpression, DateTimeFormatTagExpressionRegex).Groups["DateTimePart"].Value;
                string @operator      = Regex.Match(tagExpression, DateTimeFormatTagExpressionRegex).Groups["Operator"].Value;
                int    @value         = Convert.ToInt32(Regex.Match(tagExpression, DateTimeFormatTagExpressionRegex).Groups["Value"].Value);
                string dateTimeFormat = Regex.Match(tagExpression, DateTimeFormatTagExpressionRegex).Groups["DateTimeFormat"].Value.TrimStart('[').TrimEnd(']');

                if (@operator.Equals("-"))
                {
                    if (dateTimePart.Equals("year"))
                    {
                        dateTime = dateTime.AddYears(-@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.YearFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("month"))
                    {
                        dateTime = dateTime.AddMonths(-@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.MonthFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("day"))
                    {
                        dateTime = dateTime.AddDays(-@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.DayFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("hour"))
                    {
                        dateTime = dateTime.AddHours(-@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.HourFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("minute"))
                    {
                        dateTime = dateTime.AddMinutes(-@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.MinuteFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("second"))
                    {
                        dateTime = dateTime.AddSeconds(-@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.SecondFormat) : dateTime.ToString(dateTimeFormat);
                    }
                }

                if (@operator.Equals("+"))
                {
                    if (dateTimePart.Equals("year"))
                    {
                        dateTime = dateTime.AddYears(+@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.YearFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("month"))
                    {
                        dateTime = dateTime.AddMonths(+@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.MonthFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("day"))
                    {
                        dateTime = dateTime.AddDays(+@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.DayFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("hour"))
                    {
                        dateTime = dateTime.AddHours(+@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.HourFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("minute"))
                    {
                        dateTime = dateTime.AddMinutes(+@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.MinuteFormat) : dateTime.ToString(dateTimeFormat);
                    }

                    if (dateTimePart.Equals("second"))
                    {
                        dateTime = dateTime.AddSeconds(+@value);
                        result   = string.IsNullOrEmpty(dateTimeFormat) ? dateTime.ToString(macroParser.SecondFormat) : dateTime.ToString(dateTimeFormat);
                    }
                }
            }

            return(result);
        }
Пример #30
0
        /// <summary>
        /// Loads the user's saved settings.
        /// </summary>
        private void LoadSettings()
        {
            try
            {
                _macroParser = new MacroParser(_config.Settings);

                _log.WriteMessage("*** Welcome to " + _config.Settings.ApplicationName + " " + _config.Settings.ApplicationVersion + " (\"" + _config.Settings.ApplicationCodename + "\") ***");
                _log.WriteMessage("Starting application");
                _log.WriteMessage("At this point the application should be able to run normally");
                _log.WriteMessage("but it would be a good idea to check what we found in your autoscreen.conf file");
                _log.WriteMessage("Your autoscreen.conf file is \"" + _fileSystem.ConfigFile + "\"");
                _log.WriteMessage("The name and location of it can be changed with the -config command line argument:");
                _log.WriteMessage("autoscreen.exe -config=C:\\MyAutoScreenCapture.conf");
                _log.WriteMessage("Checking what we loaded from your autoscreen.conf file ...");
                _log.WriteMessage("ApplicationSettingsFile=" + _fileSystem.ApplicationSettingsFile);
                _log.WriteMessage("UserSettingsFile=" + _fileSystem.UserSettingsFile);
                _log.WriteMessage("DebugFolder=" + _fileSystem.DebugFolder);
                _log.WriteMessage("LogsFolder=" + _fileSystem.LogsFolder);
                _log.WriteMessage("CommandFile=" + _fileSystem.CommandFile);
                _log.WriteMessage("ScreenshotsFolder=" + _fileSystem.ScreenshotsFolder);
                _log.WriteMessage("ScreenshotsFile=" + _fileSystem.ScreenshotsFile);
                _log.WriteMessage("TriggersFile=" + _fileSystem.TriggersFile);
                _log.WriteMessage("ScreensFile=" + _fileSystem.ScreensFile);
                _log.WriteMessage("RegionsFile=" + _fileSystem.RegionsFile);
                _log.WriteMessage("EditorsFile=" + _fileSystem.EditorsFile);
                _log.WriteMessage("TagsFile = " + _fileSystem.TagsFile);

                _log.WriteMessage("It looks like I successfully parsed your \"" + _fileSystem.ConfigFile + "\" file.");

                _log.WriteDebugMessage("Initializing screen capture");
                _screenCapture = new ScreenCapture(_config, _macroParser, _fileSystem, _log);

                _log.WriteDebugMessage("Initializing image format collection");
                _imageFormatCollection = new ImageFormatCollection();

                _log.WriteDebugMessage("Initializing forms");
                _formAbout                = new FormAbout();
                _formHelp                 = new FormHelp();
                _formMacroTag             = new FormMacroTag(_macroParser);
                _formRegion               = new FormRegion(_screenCapture, _macroParser, _fileSystem, _log);
                _formScreen               = new FormScreen(_screenCapture, _macroParser, _fileSystem, _log);
                _formEditor               = new FormEditor(_config, _fileSystem, _log);
                _formEmailSettings        = new FormEmailSettings(_config, _fileSystem, _log);
                _formFileTransferSettings = new FormFileTransferSettings(_config, _fileSystem, _log);
                _formRegionSelectOptions  = new FormRegionSelectOptions(_config, _fileSystem, _imageFormatCollection);
                _formSchedule             = new FormSchedule();
                _formTrigger              = new FormTrigger(_fileSystem);
                _formEnterPassphrase      = new FormEnterPassphrase(_screenCapture, _config, _log);
                _formScreenCaptureStatus  = new FormScreenCaptureStatus();

                _log.WriteDebugMessage("Initializing editor collection");

                if (!_formEditor.EditorCollection.LoadXmlFileAndAddEditors(_config, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }

                _log.WriteDebugMessage("Number of editors loaded = " + _formEditor.EditorCollection.Count);

                _log.WriteDebugMessage("Initializing trigger collection");

                if (!_formTrigger.TriggerCollection.LoadXmlFileAndAddTriggers(_config, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }

                _log.WriteDebugMessage("Number of triggers loaded = " + _formTrigger.TriggerCollection.Count);

                _log.WriteDebugMessage("Initializing region collection");

                if (!_formRegion.RegionCollection.LoadXmlFileAndAddRegions(_imageFormatCollection, _config, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }

                // Add regions to the Screen form so we can select them as a source.
                _formScreen.RegionCollection = _formRegion.RegionCollection;
                _log.WriteDebugMessage("Number of regions loaded = " + _formRegion.RegionCollection.Count);

                _log.WriteDebugMessage("Initializing screen collection");

                if (!_formScreen.ScreenCollection.LoadXmlFileAndAddScreens(_imageFormatCollection, _config, _macroParser, _screenCapture, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }

                _log.WriteDebugMessage("Number of screens loaded = " + _formScreen.ScreenCollection.Count);

                _log.WriteDebugMessage("Initializing tag collection");

                if (!_formMacroTag.MacroTagCollection.LoadXmlFileAndAddTags(_config, _macroParser, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }

                _log.WriteDebugMessage("Number of tags loaded = " + _formMacroTag.MacroTagCollection.Count);

                _log.WriteDebugMessage("Initializing schedule collection");

                if (!_formSchedule.ScheduleCollection.LoadXmlFileAndAddSchedules(_config, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }

                _log.WriteDebugMessage("Number of schedules loaded = " + _formSchedule.ScheduleCollection.Count);

                _log.WriteDebugMessage("Building screens module");
                BuildScreensModule();

                _log.WriteDebugMessage("Building editors module");
                BuildEditorsModule();

                _log.WriteDebugMessage("Building triggers module");
                BuildTriggersModule();

                _log.WriteDebugMessage("Building regions module");
                BuildRegionsModule();

                _log.WriteDebugMessage("Building tags module");
                BuildMacroTagsModule();

                _log.WriteDebugMessage("Building schedules module");
                BuildSchedulesModule();

                _log.WriteDebugMessage("Building screenshot preview context menu");
                BuildScreenshotPreviewContextualMenu();

                _log.WriteDebugMessage("Building view tab pages");
                BuildViewTabPages();

                _log.WriteDebugMessage("Initializing screenshot collection");
                _screenshotCollection = new ScreenshotCollection(_imageFormatCollection, _formScreen.ScreenCollection, _screenCapture, _config, _fileSystem, _log);

                _screenshotCollection.LoadXmlFile(_config);

                int screenCaptureInterval = Convert.ToInt32(_config.Settings.User.GetByKey("ScreenCaptureInterval", _config.Settings.DefaultSettings.ScreenCaptureInterval).Value);
                _log.WriteDebugMessage("ScreenCaptureInterval = " + screenCaptureInterval);

                if (screenCaptureInterval == 0)
                {
                    screenCaptureInterval = _config.Settings.DefaultSettings.ScreenCaptureInterval;
                    _log.WriteDebugMessage("WARNING: Screen capture interval was found to be 0 so 60,000 milliseconds (or 1 minute) is being used as the default value");
                }

                _log.WriteDebugMessage("Assigning screen capture interval value to its appropriate hour, minute, second, and millisecond variables");

                decimal screenCaptureIntervalHours = Convert.ToDecimal(TimeSpan.FromMilliseconds(Convert.ToDouble(screenCaptureInterval)).Hours);
                _log.WriteDebugMessage("Hours = " + screenCaptureIntervalHours);

                decimal screenCaptureIntervalMinutes = Convert.ToDecimal(TimeSpan.FromMilliseconds(Convert.ToDouble(screenCaptureInterval)).Minutes);
                _log.WriteDebugMessage("Minutes = " + screenCaptureIntervalMinutes);

                decimal screenCaptureIntervalSeconds = Convert.ToDecimal(TimeSpan.FromMilliseconds(Convert.ToDouble(screenCaptureInterval)).Seconds);
                _log.WriteDebugMessage("Seconds = " + screenCaptureIntervalSeconds);

                decimal screenCaptureIntervalMilliseconds = Convert.ToDecimal(TimeSpan.FromMilliseconds(Convert.ToDouble(screenCaptureInterval)).Milliseconds);
                _log.WriteDebugMessage("Milliseconds = " + screenCaptureIntervalMilliseconds);

                numericUpDownHoursInterval.Value        = screenCaptureIntervalHours;
                numericUpDownMinutesInterval.Value      = screenCaptureIntervalMinutes;
                numericUpDownSecondsInterval.Value      = screenCaptureIntervalSeconds;
                numericUpDownMillisecondsInterval.Value = screenCaptureIntervalMilliseconds;

                numericUpDownCaptureLimit.Value = Convert.ToInt32(_config.Settings.User.GetByKey("CaptureLimit", _config.Settings.DefaultSettings.CaptureLimit).Value);
                _log.WriteDebugMessage("CaptureLimit = " + numericUpDownCaptureLimit.Value);

                checkBoxCaptureLimit.Checked = Convert.ToBoolean(_config.Settings.User.GetByKey("CaptureLimitCheck", _config.Settings.DefaultSettings.CaptureLimitCheck).Value);
                _log.WriteDebugMessage("CaptureLimitCheck = " + checkBoxCaptureLimit.Checked);

                checkBoxInitialScreenshot.Checked = Convert.ToBoolean(_config.Settings.User.GetByKey("TakeInitialScreenshot", _config.Settings.DefaultSettings.TakeInitialScreenshot).Value);
                _log.WriteDebugMessage("TakeInitialScreenshot = " + checkBoxInitialScreenshot.Checked);

                notifyIcon.Visible = Convert.ToBoolean(_config.Settings.User.GetByKey("ShowSystemTrayIcon", _config.Settings.DefaultSettings.ShowSystemTrayIcon).Value);
                _log.WriteDebugMessage("ShowSystemTrayIcon = " + notifyIcon.Visible);

                comboBoxScreenshotLabel.Text = _config.Settings.User.GetByKey("ScreenshotLabel", _config.Settings.DefaultSettings.ScreenshotLabel).Value.ToString();
                _log.WriteDebugMessage("ScreenshotLabel = " + comboBoxScreenshotLabel.Text);

                checkBoxScreenshotLabel.Checked = Convert.ToBoolean(_config.Settings.User.GetByKey("ApplyScreenshotLabel", _config.Settings.DefaultSettings.ApplyScreenshotLabel).Value);

                // Active Window Title
                checkBoxActiveWindowTitle.Checked = Convert.ToBoolean(_config.Settings.User.GetByKey("ActiveWindowTitleCaptureCheck", _config.Settings.DefaultSettings.ActiveWindowTitleCaptureCheck).Value);
                textBoxActiveWindowTitle.Text     = _config.Settings.User.GetByKey("ActiveWindowTitleCaptureText", _config.Settings.DefaultSettings.ActiveWindowTitleCaptureText).Value.ToString();

                if (checkBoxActiveWindowTitle.Checked)
                {
                    textBoxActiveWindowTitle.Enabled          = true;
                    radioButtonCaseSensitiveMatch.Enabled     = true;
                    radioButtonCaseInsensitiveMatch.Enabled   = true;
                    radioButtonRegularExpressionMatch.Enabled = true;
                }
                else
                {
                    textBoxActiveWindowTitle.Enabled          = false;
                    radioButtonCaseSensitiveMatch.Enabled     = false;
                    radioButtonCaseInsensitiveMatch.Enabled   = false;
                    radioButtonRegularExpressionMatch.Enabled = false;
                }

                radioButtonCaseSensitiveMatch.Checked     = false;
                radioButtonCaseInsensitiveMatch.Checked   = false;
                radioButtonRegularExpressionMatch.Checked = false;

                int activeWindowTitleMatchType = Convert.ToInt32(_config.Settings.User.GetByKey("ActiveWindowTitleMatchType", _config.Settings.DefaultSettings.ActiveWindowTitleMatchType).Value);

                switch (activeWindowTitleMatchType)
                {
                case 1:
                    radioButtonCaseSensitiveMatch.Checked = true;
                    break;

                case 2:
                    radioButtonCaseInsensitiveMatch.Checked = true;
                    break;

                case 3:
                    radioButtonRegularExpressionMatch.Checked = true;
                    break;
                }

                // Application Focus
                RefreshApplicationFocusList();

                EnableStartCapture();

                CaptureLimitCheck();

                _log.WriteDebugMessage("Settings loaded");
            }
            catch (Exception ex)
            {
                _screenCapture.ApplicationError = true;
                _log.WriteExceptionMessage("FormMain-Settings::LoadSettings", ex);
            }
        }