/// <summary> /// A collection of screenshots. /// </summary> public ScreenshotCollection(ImageFormatCollection imageFormatCollection, ScreenCollection screenCollection) { StringBuilder sbScreenshots = new StringBuilder(); sbScreenshots.Append("/"); sbScreenshots.Append(XML_FILE_ROOT_NODE); sbScreenshots.Append("/"); sbScreenshots.Append(XML_FILE_SCREENSHOTS_NODE); StringBuilder sbScreenshot = new StringBuilder(); sbScreenshot.Append("/"); sbScreenshot.Append(XML_FILE_ROOT_NODE); sbScreenshot.Append("/"); sbScreenshot.Append(XML_FILE_SCREENSHOTS_NODE); sbScreenshot.Append("/"); sbScreenshot.Append(XML_FILE_SCREENSHOT_NODE); SCREENSHOTS_XPATH = sbScreenshots.ToString(); SCREENSHOT_XPATH = sbScreenshot.ToString(); _screenshotList = new List <Screenshot>(); Log.WriteDebugMessage("Initialized screenshot list"); _slideList = new List <Slide>(); Log.WriteDebugMessage("Initialized slide list"); _slideNameList = new List <string>(); Log.WriteDebugMessage("Initialized slide name list"); _imageFormatCollection = imageFormatCollection; _screenCollection = screenCollection; }
private static void SaveToFile(Bitmap bitmap, long jpegQualityLevel, string imageFormat, string imagePath, ScreenshotType screenshotType) { try { if (bitmap != null && !string.IsNullOrEmpty(imageFormat) && !string.IsNullOrEmpty(imagePath)) { if (!Directory.Exists(Path.GetDirectoryName(imagePath))) { Directory.CreateDirectory(Path.GetDirectoryName(imagePath)); } if (screenshotType == ScreenshotType.User) { Log.Write("Screenshot saved: " + imagePath); } if (imageFormat.Equals(ImageFormatSpec.NAME_JPEG)) { var encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, jpegQualityLevel); var encoderInfo = GetEncoderInfo("image/jpeg"); bitmap.Save(imagePath, encoderInfo, encoderParams); } else { bitmap.Save(imagePath, ImageFormatCollection.GetByName(imageFormat).Format); } } } catch (Exception ex) { Log.Write("ScreenCapture::SaveToFile", ex); } }
private void AddNewScreen() { if (InputValid()) { TrimInput(); if (ScreenCollection.GetByName(textBoxName.Text) == null) { ScreenCollection.Add(new Screen( textBoxName.Text, FileSystem.CorrectDirectoryPath(textBoxFolder.Text), textBoxMacro.Text, comboBoxScreenComponent.SelectedIndex, ImageFormatCollection.GetByName(comboBoxFormat.Text), (int)numericUpDownJpegQuality.Value, (int)numericUpDownResolutionRatio.Value, checkBoxMouse.Checked)); Okay(); } else { MessageBox.Show("A screen with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddNewRegion() { if (InputValid()) { TrimInput(); if (RegionCollection.GetByName(textBoxName.Text) == null) { RegionCollection.Add(new Region( textBoxName.Text, FileSystem.CorrectScreenshotsFolderPath(textBoxFolder.Text), textBoxMacro.Text, ImageFormatCollection.GetByName(comboBoxFormat.Text), (int)numericUpDownJpegQuality.Value, (int)numericUpDownResolutionRatio.Value, checkBoxMouse.Checked, (int)numericUpDownX.Value, (int)numericUpDownY.Value, (int)numericUpDownWidth.Value, (int)numericUpDownHeight.Value)); Okay(); } else { MessageBox.Show("A region with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// The form to manage Region Select options. /// </summary> /// <param name="config">The configuration set to use.</param> /// <param name="fileSystem">The file system to use.</param> /// <param name="imageFormatCollection">A collection of image formats.</param> public FormRegionSelectOptions(Config config, FileSystem fileSystem, ImageFormatCollection imageFormatCollection) { _config = config; _fileSystem = fileSystem; _imageFormatCollection = imageFormatCollection; InitializeComponent(); }
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); }
private void UpdatePreviewMacro() { textBoxMacroPreview.ForeColor = System.Drawing.Color.Black; textBoxMacroPreview.BackColor = System.Drawing.Color.LightYellow; textBoxMacroPreview.Text = _macroParser.ParseTags(config: false, textBoxFolder.Text, TagCollection, _log) + _macroParser.ParseTags(preview: true, config: false, textBoxScreenName.Text, textBoxMacro.Text, 1, ImageFormatCollection.GetByName(comboBoxFormat.Text), Text, TagCollection, _log); }
/// <summary> /// The empty constructor for the screen collection. /// </summary> public ScreenCollection() { _imageFormatCollection = new ImageFormatCollection(); StringBuilder sb = new StringBuilder(); sb.Append("/"); sb.Append(XML_FILE_ROOT_NODE); sb.Append("/"); sb.Append(XML_FILE_SCREENS_NODE); sb.Append("/"); sb.Append(XML_FILE_SCREEN_NODE); SCREEN_XPATH = sb.ToString(); }
private void ChangeRegion() { if (InputValid()) { //if (Directory.Exists(textBoxRegionFolder.Text)) //{ if (NameChanged() || InputChanged()) { TrimInput(); if (RegionCollection.GetByName(textBoxName.Text) != null && NameChanged()) { MessageBox.Show("A region with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { RegionCollection.Get(RegionObject).Name = textBoxName.Text; RegionCollection.Get(RegionObject).Folder = FileSystem.CorrectDirectoryPath(textBoxFolder.Text); RegionCollection.Get(RegionObject).Macro = textBoxMacro.Text; RegionCollection.Get(RegionObject).Format = ImageFormatCollection.GetByName(comboBoxFormat.Text); RegionCollection.Get(RegionObject).JpegQuality = (int)numericUpDownJpegQuality.Value; RegionCollection.Get(RegionObject).ResolutionRatio = (int)numericUpDownResolutionRatio.Value; RegionCollection.Get(RegionObject).Mouse = checkBoxMouse.Checked; RegionCollection.Get(RegionObject).X = (int)numericUpDownX.Value; RegionCollection.Get(RegionObject).Y = (int)numericUpDownY.Value; RegionCollection.Get(RegionObject).Width = (int)numericUpDownWidth.Value; RegionCollection.Get(RegionObject).Height = (int)numericUpDownHeight.Value; Okay(); } } else { Close(); } //} //else //{ // MessageBox.Show("The specified folder does not exist.", "Folder Does Not Exist", MessageBoxButtons.OK, MessageBoxIcon.Error); //} } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ChangeScreen() { if (InputValid()) { if (NameChanged() || InputChanged()) { TrimInput(); if (ScreenCollection.GetByName(textBoxScreenName.Text) != null && NameChanged()) { MessageBox.Show("A screen with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { ScreenCollection.Get(ScreenObject).Name = textBoxScreenName.Text; ScreenCollection.Get(ScreenObject).Folder = _fileSystem.CorrectScreenshotsFolderPath(textBoxFolder.Text); ScreenCollection.Get(ScreenObject).Macro = textBoxMacro.Text; ScreenCollection.Get(ScreenObject).Component = comboBoxScreenComponent.SelectedIndex; ScreenCollection.Get(ScreenObject).Format = ImageFormatCollection.GetByName(comboBoxFormat.Text); ScreenCollection.Get(ScreenObject).JpegQuality = (int)numericUpDownJpegQuality.Value; ScreenCollection.Get(ScreenObject).Mouse = checkBoxMouse.Checked; ScreenCollection.Get(ScreenObject).Enable = checkBoxEnable.Checked; ScreenCollection.Get(ScreenObject).X = (int)numericUpDownX.Value; ScreenCollection.Get(ScreenObject).Y = (int)numericUpDownY.Value; ScreenCollection.Get(ScreenObject).Width = (int)numericUpDownWidth.Value; ScreenCollection.Get(ScreenObject).Height = (int)numericUpDownHeight.Value; ScreenCollection.Get(ScreenObject).Source = comboBoxScreenSource.SelectedIndex; ScreenCollection.Get(ScreenObject).AutoAdapt = checkBoxAutoAdapt.Checked; ScreenCollection.Get(ScreenObject).CaptureMethod = comboBoxScreenCaptureMethod.SelectedIndex; ScreenCollection.Get(ScreenObject).Encrypt = checkBoxEncrypt.Checked; ScreenCollection.Get(ScreenObject).ResolutionRatio = (int)numericUpDownResolutionRatio.Value; Okay(); } } else { Close(); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddScreen() { if (InputValid()) { TrimInput(); if (ScreenCollection.GetByName(textBoxScreenName.Text) == null) { ScreenCollection.Add(new Screen() { ViewId = Guid.NewGuid(), Name = textBoxScreenName.Text, Folder = _fileSystem.CorrectScreenshotsFolderPath(textBoxFolder.Text), Macro = textBoxMacro.Text, Component = comboBoxScreenComponent.SelectedIndex, Format = ImageFormatCollection.GetByName(comboBoxFormat.Text), JpegQuality = (int)numericUpDownJpegQuality.Value, Mouse = checkBoxMouse.Checked, Enable = checkBoxEnable.Checked, X = (int)numericUpDownX.Value, Y = (int)numericUpDownY.Value, Width = (int)numericUpDownWidth.Value, Height = (int)numericUpDownHeight.Value, Source = comboBoxScreenSource.SelectedIndex, AutoAdapt = checkBoxAutoAdapt.Checked, CaptureMethod = comboBoxScreenCaptureMethod.SelectedIndex, Encrypt = checkBoxEncrypt.Checked, ResolutionRatio = (int)numericUpDownResolutionRatio.Value }); Okay(); } else { MessageBox.Show("A screen with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ChangeScreen() { if (InputValid()) { //if (Directory.Exists(textBoxScreenFolder.Text)) //{ if (NameChanged() || InputChanged()) { TrimInput(); if (ScreenCollection.GetByName(textBoxName.Text) != null && NameChanged()) { MessageBox.Show("A screen with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { ScreenCollection.Get(ScreenObject).Name = textBoxName.Text; ScreenCollection.Get(ScreenObject).Folder = FileSystem.CorrectDirectoryPath(textBoxFolder.Text); ScreenCollection.Get(ScreenObject).Macro = textBoxMacro.Text; ScreenCollection.Get(ScreenObject).Component = comboBoxScreenComponent.SelectedIndex; ScreenCollection.Get(ScreenObject).Format = ImageFormatCollection.GetByName(comboBoxFormat.Text); ScreenCollection.Get(ScreenObject).JpegQuality = (int)numericUpDownJpegQuality.Value; ScreenCollection.Get(ScreenObject).ResolutionRatio = (int)numericUpDownResolutionRatio.Value; ScreenCollection.Get(ScreenObject).Mouse = checkBoxMouse.Checked; Okay(); } } else { Close(); } //} //else //{ //} } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ChangeRegion() { if (InputValid()) { if (NameChanged() || InputChanged()) { TrimInput(); if (RegionCollection.GetByName(textBoxName.Text) != null && NameChanged()) { MessageBox.Show("A region with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { RegionCollection.Get(RegionObject).Name = textBoxName.Text; RegionCollection.Get(RegionObject).Folder = FileSystem.CorrectScreenshotsFolderPath(textBoxFolder.Text); RegionCollection.Get(RegionObject).Macro = textBoxMacro.Text; RegionCollection.Get(RegionObject).Format = ImageFormatCollection.GetByName(comboBoxFormat.Text); RegionCollection.Get(RegionObject).JpegQuality = (int)numericUpDownJpegQuality.Value; RegionCollection.Get(RegionObject).ResolutionRatio = (int)numericUpDownResolutionRatio.Value; RegionCollection.Get(RegionObject).Mouse = checkBoxMouse.Checked; RegionCollection.Get(RegionObject).X = (int)numericUpDownX.Value; RegionCollection.Get(RegionObject).Y = (int)numericUpDownY.Value; RegionCollection.Get(RegionObject).Width = (int)numericUpDownWidth.Value; RegionCollection.Get(RegionObject).Height = (int)numericUpDownHeight.Value; RegionCollection.Get(RegionObject).Active = checkBoxActive.Checked; RegionCollection.Get(RegionObject).ActiveWindowTitleCaptureCheck = checkBoxActiveWindowTitle.Checked; RegionCollection.Get(RegionObject).ActiveWindowTitleCaptureText = textBoxActiveWindowTitle.Text; Okay(); } } else { Close(); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void UpdatePreviewMacro() { textBoxMacroPreview.ForeColor = System.Drawing.Color.Black; textBoxMacroPreview.BackColor = System.Drawing.Color.LightYellow; Screen screen = new Screen { Name = textBoxScreenName.Text, X = (int)numericUpDownX.Value, Y = (int)numericUpDownY.Value, Width = (int)numericUpDownWidth.Value, Height = (int)numericUpDownHeight.Value, Format = ImageFormatCollection.GetByName(comboBoxFormat.Text) }; string label = _config.Settings.User.GetByKey("ScreenshotLabel", string.Empty).Value.ToString(); textBoxMacroPreview.Text = _macroParser.ParseTags(preview: true, textBoxFolder.Text, screen, Text, Assembly.GetExecutingAssembly().GetName().Name, label, TagCollection, _log) + _macroParser.ParseTags(preview: true, textBoxMacro.Text, screen, Text, Assembly.GetExecutingAssembly().GetName().Name, label, TagCollection, _log); }
public static string ParseTags(string path, string imageFormat, string screenName, DateTime dateTimeScreenshotTaken) { if (!string.IsNullOrEmpty(imageFormat)) { path = path.Replace("%format%", ImageFormatCollection.GetByName(imageFormat).Extension.TrimStart('.')); } if (!string.IsNullOrEmpty(screenName)) { path = path.Replace("%screen%", screenName); } path = path.Replace("%year%", dateTimeScreenshotTaken.ToString("yyyy")); path = path.Replace("%month%", dateTimeScreenshotTaken.ToString("MM")); path = path.Replace("%day%", dateTimeScreenshotTaken.ToString("dd")); path = path.Replace("%hour%", dateTimeScreenshotTaken.ToString("HH")); path = path.Replace("%minute%", dateTimeScreenshotTaken.ToString("mm")); path = path.Replace("%second%", dateTimeScreenshotTaken.ToString("ss")); path = path.Replace("%millisecond%", dateTimeScreenshotTaken.ToString("fff")); return(path); }
private void AddRegion() { if (InputValid()) { TrimInput(); if (RegionCollection.GetByName(textBoxRegionName.Text) == null) { RegionCollection.Add(new Region() { ViewId = Guid.NewGuid(), Name = textBoxRegionName.Text, Folder = _fileSystem.CorrectScreenshotsFolderPath(textBoxFolder.Text), Macro = textBoxMacro.Text, Format = ImageFormatCollection.GetByName(comboBoxFormat.Text), JpegQuality = (int)numericUpDownJpegQuality.Value, Mouse = checkBoxMouse.Checked, X = (int)numericUpDownX.Value, Y = (int)numericUpDownY.Value, Width = (int)numericUpDownWidth.Value, Height = (int)numericUpDownHeight.Value, Enable = checkBoxEnable.Checked, Encrypt = checkBoxEncrypt.Checked }); Okay(); } else { MessageBox.Show("A region with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void AddNewScreen() { if (InputValid()) { TrimInput(); if (ScreenCollection.GetByName(textBoxName.Text) == null) { ScreenCollection.Add(new Screen() { Name = textBoxName.Text, Folder = FileSystem.CorrectScreenshotsFolderPath(textBoxFolder.Text), Macro = textBoxMacro.Text, Component = comboBoxScreenComponent.SelectedIndex, Format = ImageFormatCollection.GetByName(comboBoxFormat.Text), JpegQuality = (int)numericUpDownJpegQuality.Value, ResolutionRatio = (int)numericUpDownResolutionRatio.Value, Mouse = checkBoxMouse.Checked, Active = checkBoxActive.Checked, ActiveWindowTitleCaptureCheck = checkBoxActiveWindowTitle.Checked, ActiveWindowTitleCaptureText = textBoxActiveWindowTitle.Text }); Okay(); } else { MessageBox.Show("A screen with this name already exists.", "Duplicate Name Conflict", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show("Please enter valid input for each field.", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Loads the regions. /// </summary> public void LoadXmlFileAndAddRegions(ImageFormatCollection imageFormatCollection) { try { Log.WriteDebugMessage(":: LoadXmlFileAndAddRegions Start ::"); if (FileSystem.FileExists(FileSystem.RegionsFile)) { Log.WriteDebugMessage("Regions file \"" + FileSystem.RegionsFile + "\" found. Attempting to load XML document"); XmlDocument xDoc = new XmlDocument(); xDoc.Load(FileSystem.RegionsFile); Log.WriteDebugMessage("XML document loaded"); AppVersion = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value; AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value; XmlNodeList xRegions = xDoc.SelectNodes(REGION_XPATH); foreach (XmlNode xRegion in xRegions) { Region region = new Region(); XmlNodeReader xReader = new XmlNodeReader(xRegion); while (xReader.Read()) { if (xReader.IsStartElement() && !xReader.IsEmptyElement) { switch (xReader.Name) { case REGION_VIEWID: xReader.Read(); region.ViewId = Guid.Parse(xReader.Value); break; case REGION_NAME: xReader.Read(); region.Name = xReader.Value; break; case REGION_FOLDER: xReader.Read(); region.Folder = xReader.Value; break; case REGION_MACRO: xReader.Read(); region.Macro = xReader.Value; break; case REGION_FORMAT: xReader.Read(); region.Format = imageFormatCollection.GetByName(xReader.Value); break; case REGION_JPEG_QUALITY: xReader.Read(); region.JpegQuality = Convert.ToInt32(xReader.Value); break; case REGION_RESOLUTION_RATIO: xReader.Read(); region.ResolutionRatio = Convert.ToInt32(xReader.Value); break; case REGION_MOUSE: xReader.Read(); region.Mouse = Convert.ToBoolean(xReader.Value); break; case REGION_X: xReader.Read(); region.X = Convert.ToInt32(xReader.Value); break; case REGION_Y: xReader.Read(); region.Y = Convert.ToInt32(xReader.Value); break; case REGION_WIDTH: xReader.Read(); region.Width = Convert.ToInt32(xReader.Value); break; case REGION_HEIGHT: xReader.Read(); region.Height = Convert.ToInt32(xReader.Value); break; case REGION_ACTIVE: xReader.Read(); region.Active = Convert.ToBoolean(xReader.Value); break; case REGION_ACTIVE_WINDOW_TITLE_CAPTURE_CHECK: xReader.Read(); region.ActiveWindowTitleCaptureCheck = Convert.ToBoolean(xReader.Value); break; case REGION_ACTIVE_WINDOW_TITLE_CAPTURE_TEXT: xReader.Read(); region.ActiveWindowTitleCaptureText = xReader.Value; break; } } } xReader.Close(); // Change the data for each region that's being loaded if we've detected that // the XML document is from an older version of the application. if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { Log.WriteDebugMessage("An old version of the regions file was detected. Attempting upgrade to new region schema"); Version v2182 = Settings.VersionManager.Versions.Get("Clara", "2.1.8.2"); Version v2300 = Settings.VersionManager.Versions.Get("Boombayah", "2.3.0.0"); Version configVersion = Settings.VersionManager.Versions.Get(AppCodename, AppVersion); if (v2182 != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion)) { Log.WriteDebugMessage("Clara 2.1.8.2 or older detected"); region.ViewId = Guid.NewGuid(); // Get the screenshots folder path from the old user settings to be used for the region's folder property. region.Folder = Settings.VersionManager.OldUserSettings.GetByKey("ScreenshotsDirectory", FileSystem.ScreenshotsFolder).Value.ToString(); region.Folder = FileSystem.CorrectScreenshotsFolderPath(region.Folder); // 2.1 used "%region%", but 2.2 uses "%name%" for a region's Macro value. region.Macro = region.Macro.Replace("%region%", "%name%"); region.Format = imageFormatCollection.GetByName(ImageFormatSpec.NAME_JPEG); region.JpegQuality = 100; region.ResolutionRatio = 100; region.Mouse = true; region.Active = true; } 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. region.Active = true; } } if (!string.IsNullOrEmpty(region.Name)) { Add(region); } } // Write out the regions to the XML document now that we've updated the region objects // with their appropriate property values if it was an old version of the application. if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { Log.WriteDebugMessage("Regions file detected as an old version"); SaveToXmlFile(); } } else { Log.WriteDebugMessage($"WARNING: {FileSystem.RegionsFile} not found. Unable to load regions"); SaveToXmlFile(); } Log.WriteDebugMessage(":: LoadXmlFileAndAddRegions End ::"); } catch (Exception ex) { Log.WriteExceptionMessage("RegionCollection::Load", ex); } }
/// <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); } }
/// <summary> /// Loads the screens. /// </summary> public bool LoadXmlFileAndAddScreens(ImageFormatCollection imageFormatCollection) { 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_RESOLUTION_RATIO: xReader.Read(); screen.ResolutionRatio = 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; } } } 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 (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { Log.WriteDebugMessage("An old version of the screens.xml file was detected. Attempting upgrade to new schema."); Version v2300 = Settings.VersionManager.Versions.Get("Boombayah", "2.3.0.0"); Version configVersion = 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 (!string.IsNullOrEmpty(screen.Name)) { Add(screen); } } if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { Log.WriteDebugMessage("Screens file detected as an old version"); SaveToXmlFile(); } } else { Log.WriteDebugMessage("WARNING: Unable to load screens"); // Setup some screens based on what we can find. for (int screenNumber = 1; screenNumber <= System.Windows.Forms.Screen.AllScreens.Length; screenNumber++) { Screen screen = new Screen() { Name = $"Screen {screenNumber}", Folder = FileSystem.ScreenshotsFolder, Macro = MacroParser.DefaultMacro, Component = screenNumber, Format = imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat), JpegQuality = 100, ResolutionRatio = 100, Mouse = true, Active = true }; Add(screen); Log.WriteDebugMessage($"Screen {screenNumber} created using \"{FileSystem.ScreenshotsFolder}\" for folder path and \"{MacroParser.DefaultMacro}\" for macro."); } SaveToXmlFile(); } return(true); } catch (Exception ex) { Log.WriteExceptionMessage("ScreenCollection::LoadXmlFileAndAddScreens", ex); return(false); } }
/// <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); } }
/// <summary> /// Loads the screenshots. /// </summary> public static void Load(ImageFormatCollection imageFormatCollection, ScreenCollection screenCollection, RegionCollection regionCollection) { if (Directory.Exists(FileSystem.ApplicationFolder) && File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile)) { xDoc = new XmlDocument(); xDoc.Load(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile); AppVersion = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value; AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value; XmlNodeList xScreeshots = xDoc.SelectNodes(SCREENSHOT_XPATH); foreach (XmlNode xScreenshot in xScreeshots) { Screenshot screenshot = new Screenshot(); screenshot.Slide = new Slide(); XmlNodeReader xReader = new XmlNodeReader(xScreenshot); while (xReader.Read()) { if (xReader.IsStartElement()) { switch (xReader.Name) { case SCREENSHOT_VIEWID: xReader.Read(); screenshot.ViewId = Guid.Parse(xReader.Value); break; case SCREENSHOT_DATE: xReader.Read(); screenshot.Date = xReader.Value; break; case SCREENSHOT_TIME: xReader.Read(); screenshot.Time = xReader.Value; break; case SCREENSHOT_PATH: xReader.Read(); screenshot.Path = xReader.Value; break; case SCREENSHOT_FORMAT: xReader.Read(); screenshot.Format = imageFormatCollection.GetByName(xReader.Value); break; // 2.1 used "screen" for its definition of each display/monitor whereas 2.2 uses "component". // Active Window is now represented by 0 rather than 5. case SCREENSHOT_SCREEN: if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename) && Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null) { xReader.Read(); screenshot.Screen = Convert.ToInt32(xReader.Value); screenshot.Component = screenshot.Screen == 5 ? 0 : screenshot.Screen; } break; // We still want to support "component" since this was introduced in version 2.2 as the new representation for "screen". case SCREENSHOT_COMPONENT: xReader.Read(); screenshot.Component = Convert.ToInt32(xReader.Value); if (screenshot.Component == -1) { screenshot.ScreenshotType = ScreenshotType.Region; } else if (screenshot.Component == 0) { screenshot.ScreenshotType = ScreenshotType.ActiveWindow; } else { screenshot.ScreenshotType = ScreenshotType.Screen; } break; case SCREENSHOT_SLIDENAME: xReader.Read(); screenshot.Slide.Name = xReader.Value; break; case SCREENSHOT_SLIDEVALUE: xReader.Read(); screenshot.Slide.Value = xReader.Value; break; case SCREENSHOT_WINDOW_TITLE: xReader.Read(); screenshot.WindowTitle = xReader.Value; break; case SCREENSHOT_LABEL: xReader.Read(); screenshot.Label = xReader.Value; break; } } } xReader.Close(); if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename)) { if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null) { // We need to associate the screenshot's view ID with the component's view ID // because this special ID value is used for figuring out what screenshot image to display. screenshot.ViewId = screenCollection.GetByComponent(screenshot.Component).ViewId; string windowTitle = "*Screenshot imported from an old version of Auto Screen Capture*"; Regex rgxOldSlidename = new Regex( @"^(?<Date>\d{4}-\d{2}-\d{2}) (?<Time>(?<Hour>\d{2})-(?<Minute>\d{2})-(?<Second>\d{2})-(?<Millisecond>\d{3}))"); string hour = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Hour"].Value; string minute = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Minute"].Value; string second = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Second"].Value; string millisecond = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Millisecond"] .Value; screenshot.Date = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Date"].Value; screenshot.Time = hour + ":" + minute + ":" + second + "." + millisecond; screenshot.Slide.Name = "{date=" + screenshot.Date + "}{time=" + screenshot.Time + "}"; screenshot.Slide.Value = screenshot.Time + " [" + windowTitle + "]"; screenshot.WindowTitle = windowTitle; } } if (!string.IsNullOrEmpty(screenshot.Date) && !string.IsNullOrEmpty(screenshot.Time) && !string.IsNullOrEmpty(screenshot.Path) && screenshot.Format != null && !string.IsNullOrEmpty(screenshot.Slide.Name) && !string.IsNullOrEmpty(screenshot.Slide.Value)) { Add(screenshot, screenCollection, regionCollection); } } // Write out the upgraded screenshots (if any were found). if (Settings.VersionManager.IsOldAppVersion(AppVersion, AppCodename)) { Save(); } } }
/// <summary> /// Loads the screens. /// </summary> public void Load(ImageFormatCollection imageFormatCollection) { try { if (Directory.Exists(FileSystem.ApplicationFolder) && File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreensFile)) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(FileSystem.ApplicationFolder + FileSystem.ScreensFile); 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()) { 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_RESOLUTION_RATIO: xReader.Read(); screen.ResolutionRatio = Convert.ToInt32(xReader.Value); break; case SCREEN_MOUSE: xReader.Read(); screen.Mouse = Convert.ToBoolean(xReader.Value); break; } } } xReader.Close(); if (!string.IsNullOrEmpty(screen.Name)) { Add(screen); } } if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { Save(); } } else { Log.Write($"WARNING: {FileSystem.ScreensFile} not found. Detecting available screens and creating them"); Add(new Screen($"Active Window", FileSystem.ScreenshotsFolder, MacroParser.DefaultMacro, 0, imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat), 100, 100, true)); Log.Write($"Active Window created using \"{FileSystem.ScreenshotsFolder}\" for folder path and \"{MacroParser.DefaultMacro}\" for macro"); // Setup some screens based on what we can find. for (int screenNumber = 1; screenNumber <= System.Windows.Forms.Screen.AllScreens.Length; screenNumber++) { Add(new Screen($"Screen {screenNumber}", FileSystem.ScreenshotsFolder, MacroParser.DefaultMacro, screenNumber, imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat), 100, 100, true)); Log.Write($"Screen {screenNumber} created using \"{FileSystem.ScreenshotsFolder}\" for folder path and \"{MacroParser.DefaultMacro}\" for macro."); } Save(); } } catch (Exception ex) { Log.Write("ScreenCollection::Load", ex); } }
private void CheckAndCreateFiles(Security security, ScreenCapture screenCapture, Log log) { if (string.IsNullOrEmpty(FileSystem.CommandFile)) { FileSystem.CommandFile = FileSystem.DefaultCommandFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nCommandFile=" + FileSystem.DefaultCommandFile); if (!FileSystem.FileExists(FileSystem.DefaultCommandFile)) { FileSystem.CreateFile(FileSystem.DefaultCommandFile); } } if (string.IsNullOrEmpty(FileSystem.ApplicationSettingsFile)) { FileSystem.ApplicationSettingsFile = FileSystem.DefaultApplicationSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nApplicationSettingsFile=" + FileSystem.DefaultApplicationSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.SmtpSettingsFile)) { FileSystem.SmtpSettingsFile = FileSystem.DefaultSmtpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSMTPSettingsFile=" + FileSystem.DefaultSmtpSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.SftpSettingsFile)) { FileSystem.SftpSettingsFile = FileSystem.DefaultSftpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSFTPSettingsFile=" + FileSystem.DefaultSftpSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.UserSettingsFile)) { FileSystem.UserSettingsFile = FileSystem.DefaultUserSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nUserSettingsFile=" + FileSystem.DefaultUserSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } Settings.User.Load(Settings, FileSystem); Settings.SMTP.Load(Settings, FileSystem); Settings.SFTP.Load(Settings, FileSystem); Settings.VersionManager.OldApplicationSettings = Settings.Application.Clone(); Settings.VersionManager.OldUserSettings = Settings.User.Clone(); Settings.UpgradeApplicationSettings(Settings.Application, FileSystem); Settings.UpgradeUserSettings(Settings.User, screenCapture, security, FileSystem); Settings.UpgradeSmtpSettings(Settings.SMTP, FileSystem); Settings.UpgradeSftpSettings(Settings.SFTP, FileSystem); if (string.IsNullOrEmpty(FileSystem.ScreenshotsFile)) { ImageFormatCollection imageFormatCollection = new ImageFormatCollection(); ScreenCollection screenCollection = new ScreenCollection(); ScreenshotCollection screenshotCollection = new ScreenshotCollection(imageFormatCollection, screenCollection, screenCapture, this, FileSystem, log); screenshotCollection.SaveToXmlFile(this); } if (string.IsNullOrEmpty(FileSystem.EditorsFile)) { // Loading the editor collection will automatically create the default editors and add them to the collection. EditorCollection editorCollection = new EditorCollection(); editorCollection.LoadXmlFileAndAddEditors(this, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.RegionsFile)) { RegionCollection regionCollection = new RegionCollection(); regionCollection.SaveToXmlFile(Settings, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.ScreensFile)) { // Loading the screen collection will automatically create the available screens and add them to the collection. ScreenCollection screenCollection = new ScreenCollection(); screenCollection.LoadXmlFileAndAddScreens(new ImageFormatCollection(), this, MacroParser, screenCapture, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.TriggersFile)) { // Loading triggers will automatically create the default triggers and add them to the collection. TriggerCollection triggerCollection = new TriggerCollection(); triggerCollection.LoadXmlFileAndAddTriggers(this, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.TagsFile)) { // Loading tags will automatically create the default tags and add them to the collection. MacroTagCollection tagCollection = new MacroTagCollection(); tagCollection.LoadXmlFileAndAddTags(this, MacroParser, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.SchedulesFile)) { // Loading schedules will automatically create the default schedules and add them to the collection. ScheduleCollection scheduleCollection = new ScheduleCollection(); scheduleCollection.LoadXmlFileAndAddSchedules(this, FileSystem, log); } }
/// <summary> /// Loads the screens. /// </summary> public void Load(ImageFormatCollection imageFormatCollection) { if (File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreensFile)) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(FileSystem.ApplicationFolder + FileSystem.ScreensFile); 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()) { switch (xReader.Name) { 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_RESOLUTION_RATIO: xReader.Read(); screen.ResolutionRatio = Convert.ToInt32(xReader.Value); break; case SCREEN_MOUSE: xReader.Read(); screen.Mouse = Convert.ToBoolean(xReader.Value); break; } } } xReader.Close(); if (!string.IsNullOrEmpty(screen.Name)) { Add(screen); } } } else { // Setup some screens based on what we can find. for (int screenNumber = 1; screenNumber <= System.Windows.Forms.Screen.AllScreens.Length; screenNumber++) { Add(new Screen($"Screen {screenNumber}", FileSystem.ScreenshotsFolder, MacroParser.DefaultMacro, screenNumber, imageFormatCollection.GetByName(ScreenCapture.DefaultImageFormat), 100, 100, true)); } Save(); } }
/// <summary> /// Loads the regions. /// </summary> public void Load(ImageFormatCollection imageFormatCollection) { try { if (Directory.Exists(FileSystem.ApplicationFolder) && File.Exists(FileSystem.ApplicationFolder + FileSystem.RegionsFile)) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(FileSystem.ApplicationFolder + FileSystem.RegionsFile); AppVersion = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value; AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value; XmlNodeList xRegions = xDoc.SelectNodes(REGION_XPATH); foreach (XmlNode xRegion in xRegions) { Region region = new Region(); XmlNodeReader xReader = new XmlNodeReader(xRegion); while (xReader.Read()) { if (xReader.IsStartElement()) { switch (xReader.Name) { case REGION_VIEWID: xReader.Read(); region.ViewId = Guid.Parse(xReader.Value); break; case REGION_NAME: xReader.Read(); region.Name = xReader.Value; break; case REGION_FOLDER: xReader.Read(); region.Folder = xReader.Value; break; case REGION_MACRO: xReader.Read(); region.Macro = xReader.Value; break; case REGION_FORMAT: xReader.Read(); region.Format = imageFormatCollection.GetByName(xReader.Value); break; case REGION_JPEG_QUALITY: xReader.Read(); region.JpegQuality = Convert.ToInt32(xReader.Value); break; case REGION_RESOLUTION_RATIO: xReader.Read(); region.ResolutionRatio = Convert.ToInt32(xReader.Value); break; case REGION_MOUSE: xReader.Read(); region.Mouse = Convert.ToBoolean(xReader.Value); break; case REGION_X: xReader.Read(); region.X = Convert.ToInt32(xReader.Value); break; case REGION_Y: xReader.Read(); region.Y = Convert.ToInt32(xReader.Value); break; case REGION_WIDTH: xReader.Read(); region.Width = Convert.ToInt32(xReader.Value); break; case REGION_HEIGHT: xReader.Read(); region.Height = Convert.ToInt32(xReader.Value); break; } } } xReader.Close(); // Change the data for each region that's being loaded if we've detected that // the XML file is from an older version of the application. if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion)) { Log.Write("An old version of the regions file was detected. Attempting upgrade to new region format"); region.ViewId = Guid.NewGuid(); // Get the screenshots folder path from the old user settings to be used for the region's folder property. region.Folder = Settings.VersionManager.OldUserSettings.GetByKey("ScreenshotsDirectory", FileSystem.ScreenshotsFolder).Value.ToString(); region.Folder = FileSystem.CorrectDirectoryPath(region.Folder); // 2.1 used "%region%", but 2.2 uses "%name%" for a region's Macro value. region.Macro = region.Macro.Replace("%region%", "%name%"); region.Format = imageFormatCollection.GetByName(ImageFormatSpec.NAME_JPEG); region.JpegQuality = 100; region.ResolutionRatio = 100; region.Mouse = false; } } if (!string.IsNullOrEmpty(region.Name)) { Add(region); } } // Write out the regions to the XML file now that we've updated the region objects // with their appropriate property values if it was an old version of the application. if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { Save(); } } else { Log.Write($"WARNING: {FileSystem.RegionsFile} not found. Unable to load regions"); } } catch (Exception ex) { Log.Write("RegionCollection::Load", ex); } }
/// <summary> /// Loads the regions. /// </summary> public void Load(ImageFormatCollection imageFormatCollection) { if (File.Exists(FileSystem.ApplicationFolder + FileSystem.RegionsFile)) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(FileSystem.ApplicationFolder + FileSystem.RegionsFile); XmlNodeList xRegions = xDoc.SelectNodes(REGION_XPATH); foreach (XmlNode xRegion in xRegions) { Region region = new Region(); XmlNodeReader xReader = new XmlNodeReader(xRegion); while (xReader.Read()) { if (xReader.IsStartElement()) { switch (xReader.Name) { case REGION_NAME: xReader.Read(); region.Name = xReader.Value; break; case REGION_FOLDER: xReader.Read(); region.Folder = xReader.Value; break; case REGION_MACRO: xReader.Read(); region.Macro = xReader.Value; break; case REGION_FORMAT: xReader.Read(); region.Format = imageFormatCollection.GetByName(xReader.Value); break; case REGION_JPEG_QUALITY: xReader.Read(); region.JpegQuality = Convert.ToInt32(xReader.Value); break; case REGION_RESOLUTION_RATIO: xReader.Read(); region.ResolutionRatio = Convert.ToInt32(xReader.Value); break; case REGION_MOUSE: xReader.Read(); region.Mouse = Convert.ToBoolean(xReader.Value); break; case REGION_X: xReader.Read(); region.X = Convert.ToInt32(xReader.Value); break; case REGION_Y: xReader.Read(); region.Y = Convert.ToInt32(xReader.Value); break; case REGION_WIDTH: xReader.Read(); region.Width = Convert.ToInt32(xReader.Value); break; case REGION_HEIGHT: xReader.Read(); region.Height = Convert.ToInt32(xReader.Value); break; } } } xReader.Close(); if (!string.IsNullOrEmpty(region.Name)) { Add(region); } } } }
private static void CheckAndCreateFiles() { if (string.IsNullOrEmpty(FileSystem.CommandFile)) { FileSystem.CommandFile = FileSystem.DefaultCommandFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nCommandFile=" + FileSystem.DefaultCommandFile); if (!FileSystem.FileExists(FileSystem.DefaultCommandFile)) { FileSystem.CreateFile(FileSystem.DefaultCommandFile); } } if (string.IsNullOrEmpty(FileSystem.ApplicationSettingsFile)) { FileSystem.ApplicationSettingsFile = FileSystem.DefaultApplicationSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nApplicationSettingsFile=" + FileSystem.DefaultApplicationSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } SettingCollection applicationSettingsCollection = new SettingCollection { Filepath = FileSystem.ApplicationSettingsFile }; applicationSettingsCollection.Save(); } if (string.IsNullOrEmpty(FileSystem.UserSettingsFile)) { FileSystem.UserSettingsFile = FileSystem.DefaultUserSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nUserSettingsFile=" + FileSystem.DefaultUserSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } SettingCollection userSettingsCollection = new SettingCollection { Filepath = FileSystem.ApplicationSettingsFile }; userSettingsCollection.Save(); } if (string.IsNullOrEmpty(FileSystem.ScreenshotsFile)) { ImageFormatCollection imageFormatCollection = new ImageFormatCollection(); ScreenCollection screenCollection = new ScreenCollection(); ScreenshotCollection screenshotCollection = new ScreenshotCollection(imageFormatCollection, screenCollection); screenshotCollection.SaveToXmlFile(0); } if (string.IsNullOrEmpty(FileSystem.EditorsFile)) { // Loading the editor collection will automatically create the default editors and add them to the collection. EditorCollection editorCollection = new EditorCollection(); editorCollection.LoadXmlFileAndAddEditors(); } if (string.IsNullOrEmpty(FileSystem.RegionsFile)) { RegionCollection regionCollection = new RegionCollection(); regionCollection.SaveToXmlFile(); } if (string.IsNullOrEmpty(FileSystem.ScreensFile)) { // Loading the screen collection will automatically create the available screens and add them to the collection. ScreenCollection screenCollection = new ScreenCollection(); screenCollection.LoadXmlFileAndAddScreens(new ImageFormatCollection()); } if (string.IsNullOrEmpty(FileSystem.TriggersFile)) { // Loading triggers will automatically create the default triggers and add them to the collection. TriggerCollection triggerCollection = new TriggerCollection(); triggerCollection.LoadXmlFileAndAddTriggers(); } if (string.IsNullOrEmpty(FileSystem.TagsFile)) { // Loading tags will automatically create the default tags and add them to the collection. TagCollection tagCollection = new TagCollection(); tagCollection.LoadXmlFileAndAddTags(); } if (string.IsNullOrEmpty(FileSystem.SchedulesFile)) { // Loading schedules will automatically create the default schedules and add them to the collection. ScheduleCollection scheduleCollection = new ScheduleCollection(); scheduleCollection.LoadXmlFileAndAddSchedules(); } }
/// <summary> /// Loads the user's saved settings. /// </summary> private void LoadSettings() { try { Log.WriteMessage("*** Welcome to " + Settings.ApplicationName + " " + Settings.ApplicationVersion + " (\"" + Settings.ApplicationCodename + "\") ***"); Log.WriteMessage("Starting application"); Log.WriteDebugMessage("At this point the application should be able to run normally"); Log.WriteDebugMessage("but it would be a good idea to check what we found in your autoscreen.conf file"); Log.WriteDebugMessage("Your autoscreen.conf file is \"" + FileSystem.ConfigFile + "\""); Log.WriteDebugMessage("The name and location of it can be changed with the -config command line argument:"); Log.WriteDebugMessage("autoscreen.exe -config=C:\\MyAutoScreenCapture.conf"); Log.WriteDebugMessage("Checking what we loaded from your autoscreen.conf file ..."); Log.WriteDebugMessage("ApplicationSettingsFile=" + FileSystem.ApplicationSettingsFile); Log.WriteDebugMessage("UserSettingsFile=" + FileSystem.UserSettingsFile); Log.WriteDebugMessage("DebugFolder=" + FileSystem.DebugFolder); Log.WriteDebugMessage("LogsFolder=" + FileSystem.LogsFolder); Log.WriteDebugMessage("CommandFile=" + FileSystem.CommandFile); Log.WriteDebugMessage("ScreenshotsFolder=" + FileSystem.ScreenshotsFolder); Log.WriteDebugMessage("ScreenshotsFile=" + FileSystem.ScreenshotsFile); Log.WriteDebugMessage("TriggersFile=" + FileSystem.TriggersFile); Log.WriteDebugMessage("ScreensFile=" + FileSystem.ScreensFile); Log.WriteDebugMessage("RegionsFile=" + FileSystem.RegionsFile); Log.WriteDebugMessage("EditorsFile=" + FileSystem.EditorsFile); Log.WriteDebugMessage("TagsFile = " + FileSystem.TagsFile); Log.WriteDebugMessage("It looks like I successfully parsed your \"" + FileSystem.ConfigFile + "\" file."); Log.WriteDebugMessage("I'm now going to attempt to load your personal settings and any screenshots you have taken."); Log.WriteMessage("Initializing screen capture"); _screenCapture = new ScreenCapture(); Log.WriteMessage("Initializing image format collection"); _imageFormatCollection = new ImageFormatCollection(); Log.WriteMessage("Initializing editor collection"); if (!_formEditor.EditorCollection.LoadXmlFileAndAddEditors()) { _screenCapture.ApplicationError = true; } Log.WriteDebugMessage("Number of editors loaded = " + _formEditor.EditorCollection.Count); Log.WriteMessage("Initializing trigger collection"); if (!_formTrigger.TriggerCollection.LoadXmlFileAndAddTriggers()) { _screenCapture.ApplicationError = true; } Log.WriteDebugMessage("Number of triggers loaded = " + _formTrigger.TriggerCollection.Count); Log.WriteMessage("Initializing region collection"); if (!_formRegion.RegionCollection.LoadXmlFileAndAddRegions(_imageFormatCollection)) { _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.WriteMessage("Initializing screen collection"); if (!_formScreen.ScreenCollection.LoadXmlFileAndAddScreens(_imageFormatCollection)) { _screenCapture.ApplicationError = true; } Log.WriteDebugMessage("Number of screens loaded = " + _formScreen.ScreenCollection.Count); Log.WriteMessage("Initializing tag collection"); if (!_formMacroTag.MacroTagCollection.LoadXmlFileAndAddTags()) { _screenCapture.ApplicationError = true; } Log.WriteDebugMessage("Number of tags loaded = " + _formMacroTag.MacroTagCollection.Count); Log.WriteMessage("Initializing schedule collection"); if (!_formSchedule.ScheduleCollection.LoadXmlFileAndAddSchedules()) { _screenCapture.ApplicationError = true; } Log.WriteDebugMessage("Number of schedules loaded = " + _formSchedule.ScheduleCollection.Count); Log.WriteMessage("Building screens module"); BuildScreensModule(); Log.WriteMessage("Building editors module"); BuildEditorsModule(); Log.WriteMessage("Building triggers module"); BuildTriggersModule(); Log.WriteMessage("Building regions module"); BuildRegionsModule(); Log.WriteMessage("Building tags module"); BuildMacroTagsModule(); Log.WriteMessage("Building schedules module"); BuildSchedulesModule(); Log.WriteMessage("Building screenshot preview context menu"); BuildScreenshotPreviewContextualMenu(); Log.WriteMessage("Building view tab pages"); BuildViewTabPages(); Log.WriteMessage("Initializing screenshot collection"); _screenshotCollection = new ScreenshotCollection(_imageFormatCollection, _formScreen.ScreenCollection); _screenshotCollection.LoadXmlFile(); int screenCaptureInterval = Convert.ToInt32(Settings.User.GetByKey("ScreenCaptureInterval", DefaultSettings.ScreenCaptureInterval).Value); Log.WriteDebugMessage("ScreenCaptureInterval = " + screenCaptureInterval); if (screenCaptureInterval == 0) { screenCaptureInterval = 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(Settings.User.GetByKey("CaptureLimit", DefaultSettings.CaptureLimit).Value); Log.WriteDebugMessage("CaptureLimit = " + numericUpDownCaptureLimit.Value); checkBoxCaptureLimit.Checked = Convert.ToBoolean(Settings.User.GetByKey("CaptureLimitCheck", DefaultSettings.CaptureLimitCheck).Value); Log.WriteDebugMessage("CaptureLimitCheck = " + checkBoxCaptureLimit.Checked); checkBoxInitialScreenshot.Checked = Convert.ToBoolean(Settings.User.GetByKey("TakeInitialScreenshot", DefaultSettings.TakeInitialScreenshot).Value); Log.WriteDebugMessage("TakeInitialScreenshot = " + checkBoxInitialScreenshot.Checked); notifyIcon.Visible = Convert.ToBoolean(Settings.User.GetByKey("ShowSystemTrayIcon", DefaultSettings.ShowSystemTrayIcon).Value); Log.WriteDebugMessage("ShowSystemTrayIcon = " + notifyIcon.Visible); comboBoxScreenshotLabel.Text = Settings.User.GetByKey("ScreenshotLabel", DefaultSettings.ScreenshotLabel).Value.ToString(); Log.WriteDebugMessage("ScreenshotLabel = " + comboBoxScreenshotLabel.Text); checkBoxScreenshotLabel.Checked = Convert.ToBoolean(Settings.User.GetByKey("ApplyScreenshotLabel", DefaultSettings.ApplyScreenshotLabel).Value); // Active Window Title checkBoxActiveWindowTitle.Checked = Convert.ToBoolean(Settings.User.GetByKey("ActiveWindowTitleCaptureCheck", DefaultSettings.ActiveWindowTitleCaptureCheck).Value); textBoxActiveWindowTitle.Text = Settings.User.GetByKey("ActiveWindowTitleCaptureText", 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(Settings.User.GetByKey("ActiveWindowTitleMatchType", 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(); // Region Select / Auto Save textBoxAutoSaveFolder.Text = Settings.User.GetByKey("AutoSaveFolder", DefaultSettings.AutoSaveFolder).Value.ToString(); textBoxAutoSaveMacro.Text = Settings.User.GetByKey("AutoSaveMacro", DefaultSettings.AutoSaveMacro).Value.ToString(); EnableStartCapture(); CaptureLimitCheck(); Log.WriteDebugMessage("Settings loaded"); } catch (Exception ex) { _screenCapture.ApplicationError = true; Log.WriteExceptionMessage("FormMain-Settings::LoadSettings", ex); } }
/// <summary> /// Loads the screenshots. /// </summary> public void Load(ImageFormatCollection imageFormatCollection, ScreenCollection screenCollection, RegionCollection regionCollection) { try { _mutexWriteFile.WaitOne(); Log.Write("Loading screenshots from screenshots.xml"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); if (_screenshotList == null) { _screenshotList = new List <Screenshot>(); Log.Write("Initialized screenshot list"); } if (_slideList == null) { _slideList = new List <Slide>(); Log.Write("Initialized slide list"); } if (_slideNameList == null) { _slideNameList = new List <string>(); Log.Write("Initialized slide name list"); } if (_screenshotList != null && Directory.Exists(FileSystem.ApplicationFolder) && !File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile)) { Log.Write("Could not find \"" + FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile + "\" so creating it"); 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 + 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); xWriter.WriteEndElement(); xWriter.WriteEndElement(); xWriter.WriteEndDocument(); xWriter.Flush(); xWriter.Close(); } Log.Write("Created \"" + FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile + "\""); } if (_screenshotList != null && Directory.Exists(FileSystem.ApplicationFolder) && File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile)) { xDoc = new XmlDocument(); lock (xDoc) { xDoc.Load(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile); AppVersion = xDoc.SelectSingleNode("/autoscreen").Attributes["app:version"]?.Value; AppCodename = xDoc.SelectSingleNode("/autoscreen").Attributes["app:codename"]?.Value; Log.Write("Getting screenshots from screenshots.xml using XPath query \"" + SCREENSHOT_XPATH + "\""); XmlNodeList xScreeshots = xDoc.SelectNodes(SCREENSHOT_XPATH); if (xScreeshots != null) { Log.Write("Loading each screenshot from screenshots.xml"); foreach (XmlNode xScreenshot in xScreeshots) { Screenshot screenshot = new Screenshot(); screenshot.Slide = new Slide(); XmlNodeReader xReader = new XmlNodeReader(xScreenshot); while (xReader.Read()) { if (xReader.IsStartElement()) { switch (xReader.Name) { case SCREENSHOT_VIEWID: xReader.Read(); screenshot.ViewId = Guid.Parse(xReader.Value); break; case SCREENSHOT_DATE: xReader.Read(); screenshot.Date = xReader.Value; screenshot.Slide.Date = xReader.Value; break; case SCREENSHOT_TIME: xReader.Read(); screenshot.Time = xReader.Value; break; case SCREENSHOT_PATH: xReader.Read(); screenshot.Path = xReader.Value; break; case SCREENSHOT_FORMAT: xReader.Read(); screenshot.Format = imageFormatCollection.GetByName(xReader.Value); break; // 2.1 used "screen" for its definition of each display/monitor whereas 2.2 uses "component". // Active Window is now represented by 0 rather than 5. case SCREENSHOT_SCREEN: if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion) && Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion)) { xReader.Read(); screenshot.Screen = Convert.ToInt32(xReader.Value); screenshot.Component = screenshot.Screen == 5 ? 0 : screenshot.Screen; } break; // We still want to support "component" since this was introduced in version 2.2 as the new representation for "screen". case SCREENSHOT_COMPONENT: xReader.Read(); screenshot.Component = Convert.ToInt32(xReader.Value); if (screenshot.Component == -1) { screenshot.ScreenshotType = ScreenshotType.Region; } else if (screenshot.Component == 0) { screenshot.ScreenshotType = ScreenshotType.ActiveWindow; } else { screenshot.ScreenshotType = ScreenshotType.Screen; } break; case SCREENSHOT_SLIDENAME: xReader.Read(); screenshot.Slide.Name = xReader.Value; break; case SCREENSHOT_SLIDEVALUE: xReader.Read(); screenshot.Slide.Value = xReader.Value; break; case SCREENSHOT_WINDOW_TITLE: xReader.Read(); screenshot.WindowTitle = xReader.Value; break; case SCREENSHOT_PROCESS_NAME: xReader.Read(); screenshot.ProcessName = xReader.Value; break; case SCREENSHOT_LABEL: xReader.Read(); screenshot.Label = xReader.Value; break; } } } xReader.Close(); if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion)) { // We need to associate the screenshot's view ID with the component's view ID // because this special ID value is used for figuring out what screenshot image to display. screenshot.ViewId = screenCollection.GetByComponent(screenshot.Component).ViewId; string windowTitle = "*Screenshot imported from an old version of Auto Screen Capture*"; Regex rgxOldSlidename = new Regex(@"^(?<Date>\d{4}-\d{2}-\d{2}) (?<Time>(?<Hour>\d{2})-(?<Minute>\d{2})-(?<Second>\d{2})-(?<Millisecond>\d{3}))"); string hour = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Hour"].Value; string minute = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Minute"].Value; string second = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Second"].Value; string millisecond = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Millisecond"].Value; screenshot.Date = rgxOldSlidename.Match(screenshot.Slide.Name).Groups["Date"].Value; screenshot.Time = hour + ":" + minute + ":" + second + "." + millisecond; screenshot.Slide.Name = "{date=" + screenshot.Date + "}{time=" + screenshot.Time + "}"; screenshot.Slide.Value = screenshot.Time + " [" + windowTitle + "]"; screenshot.WindowTitle = windowTitle; } // Remove all the existing XML child nodes from the old XML screenshot. xScreenshot.RemoveAll(); // Prepare the new XML child nodes for the old XML screenshot ... XmlElement xViewId = xDoc.CreateElement(SCREENSHOT_VIEWID); xViewId.InnerText = screenshot.ViewId.ToString(); XmlElement xDate = xDoc.CreateElement(SCREENSHOT_DATE); xDate.InnerText = screenshot.Date; XmlElement xTime = xDoc.CreateElement(SCREENSHOT_TIME); xTime.InnerText = screenshot.Time; XmlElement xPath = xDoc.CreateElement(SCREENSHOT_PATH); xPath.InnerText = screenshot.Path; XmlElement xFormat = xDoc.CreateElement(SCREENSHOT_FORMAT); xFormat.InnerText = screenshot.Format.Name; XmlElement xComponent = xDoc.CreateElement(SCREENSHOT_COMPONENT); xComponent.InnerText = screenshot.Component.ToString(); XmlElement xSlidename = xDoc.CreateElement(SCREENSHOT_SLIDENAME); xSlidename.InnerText = screenshot.Slide.Name; XmlElement xSlidevalue = xDoc.CreateElement(SCREENSHOT_SLIDEVALUE); xSlidevalue.InnerText = screenshot.Slide.Value; XmlElement xWindowTitle = xDoc.CreateElement(SCREENSHOT_WINDOW_TITLE); xWindowTitle.InnerText = screenshot.WindowTitle; XmlElement xProcessName = xDoc.CreateElement(SCREENSHOT_PROCESS_NAME); xProcessName.InnerText = screenshot.ProcessName; XmlElement xLabel = xDoc.CreateElement(SCREENSHOT_LABEL); xLabel.InnerText = screenshot.Label; // Create the new XML child nodes for the old XML screenshot so that it's now in the format of the new XML screenshot. xScreenshot.AppendChild(xViewId); xScreenshot.AppendChild(xDate); xScreenshot.AppendChild(xTime); xScreenshot.AppendChild(xPath); xScreenshot.AppendChild(xFormat); xScreenshot.AppendChild(xComponent); xScreenshot.AppendChild(xSlidename); xScreenshot.AppendChild(xSlidevalue); xScreenshot.AppendChild(xWindowTitle); xScreenshot.AppendChild(xProcessName); xScreenshot.AppendChild(xLabel); } if (!string.IsNullOrEmpty(screenshot.Date) && !string.IsNullOrEmpty(screenshot.Time) && !string.IsNullOrEmpty(screenshot.Path) && screenshot.Format != null && !string.IsNullOrEmpty(screenshot.Slide.Name) && !string.IsNullOrEmpty(screenshot.Slide.Value) && !string.IsNullOrEmpty(screenshot.WindowTitle)) { screenshot.Saved = true; Add(screenshot); } } } else { Log.Write("WARNING: Unable to load screenshots from screenshots.xml"); } if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion)) { Log.Write("Old application version discovered when loading screenshots.xml"); // We'll have to create the app:version and app:codename attributes for screenshots.xml if we're upgrading from "Clara". if (Settings.VersionManager.Versions.Get("Clara", "2.1.8.2") != null && string.IsNullOrEmpty(AppCodename) && string.IsNullOrEmpty(AppVersion)) { XmlAttribute attributeVersion = xDoc.CreateAttribute("app", "version", "autoscreen"); XmlAttribute attributeCodename = xDoc.CreateAttribute("app", "codename", "autoscreen"); attributeVersion.Value = Settings.ApplicationVersion; attributeCodename.Value = Settings.ApplicationCodename; xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes.Append(attributeVersion); xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes.Append(attributeCodename); } // Apply the latest version and codename if the version of Auto Screen Capture is older than this version. xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes["app:version"].Value = Settings.ApplicationVersion; xDoc.SelectSingleNode("/" + XML_FILE_ROOT_NODE).Attributes["app:codename"].Value = Settings.ApplicationCodename; xDoc.Save(FileSystem.ApplicationFolder + FileSystem.ScreenshotsFile); Log.Write("Upgraded screenshots.xml"); } } } stopwatch.Stop(); Log.Write("It took " + stopwatch.ElapsedMilliseconds + " milliseconds to load " + _screenshotList.Count + " screenshots"); } catch (Exception ex) { Log.Write("ScreenshotCollection::Load", ex); } finally { _mutexWriteFile.ReleaseMutex(); } }