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); } }
/// <summary> /// Saves the regions. /// </summary> public void Save() { if (Directory.Exists(FileSystem.ApplicationFolder)) { XmlWriterSettings xSettings = new XmlWriterSettings(); xSettings.Indent = true; xSettings.CloseOutput = true; xSettings.CheckCharacters = true; xSettings.Encoding = Encoding.UTF8; xSettings.NewLineChars = Environment.NewLine; xSettings.IndentChars = XML_FILE_INDENT_CHARS; xSettings.NewLineHandling = NewLineHandling.Entitize; xSettings.ConformanceLevel = ConformanceLevel.Document; if (File.Exists(FileSystem.ApplicationFolder + FileSystem.RegionsFile)) { File.Delete(FileSystem.ApplicationFolder + FileSystem.RegionsFile); } using (XmlWriter xWriter = XmlWriter.Create(FileSystem.ApplicationFolder + FileSystem.RegionsFile, 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_REGIONS_NODE); foreach (object obj in _regionList) { Region region = (Region)obj; xWriter.WriteStartElement(XML_FILE_REGION_NODE); xWriter.WriteElementString(REGION_VIEWID, region.ViewId.ToString()); xWriter.WriteElementString(REGION_NAME, region.Name); xWriter.WriteElementString(REGION_FOLDER, FileSystem.CorrectDirectoryPath(region.Folder)); xWriter.WriteElementString(REGION_MACRO, region.Macro); xWriter.WriteElementString(REGION_FORMAT, region.Format.Name); xWriter.WriteElementString(REGION_JPEG_QUALITY, region.JpegQuality.ToString()); xWriter.WriteElementString(REGION_RESOLUTION_RATIO, region.ResolutionRatio.ToString()); xWriter.WriteElementString(REGION_MOUSE, region.Mouse.ToString()); xWriter.WriteElementString(REGION_X, region.X.ToString()); xWriter.WriteElementString(REGION_Y, region.Y.ToString()); xWriter.WriteElementString(REGION_WIDTH, region.Width.ToString()); xWriter.WriteElementString(REGION_HEIGHT, region.Height.ToString()); xWriter.WriteEndElement(); } xWriter.WriteEndElement(); xWriter.WriteEndElement(); xWriter.WriteEndDocument(); xWriter.Flush(); xWriter.Close(); } } }
public Screen(string name, string folder, string macro, int component, ImageFormat format, int jpegQuality, int resolutionRatio, bool mouse) { ViewId = Guid.NewGuid(); Name = name; Folder = FileSystem.CorrectDirectoryPath(folder); Macro = macro; Component = component; Format = format; JpegQuality = jpegQuality; ResolutionRatio = resolutionRatio; Mouse = mouse; }
public Region(string name, string folder, string macro, ImageFormat format, int jpegQuality, int resolutionRatio, bool mouse, int x, int y, int width, int height) { ViewId = Guid.NewGuid(); Name = name; Folder = FileSystem.CorrectDirectoryPath(folder); Macro = macro; Format = format; JpegQuality = jpegQuality; ResolutionRatio = resolutionRatio; Mouse = mouse; X = x; Y = y; Width = width; Height = height; }
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 (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 FormScreen_Load(object sender, EventArgs e) { comboBoxFormat.Items.Clear(); comboBoxScreenComponent.Items.Clear(); comboBoxTags.DataSource = null; pictureBoxPreview.Image = null; // *** Macro Tags *** comboBoxTags.DisplayMember = "Description"; comboBoxTags.ValueMember = "Name"; comboBoxTags.DataSource = MacroTagCollection.GetList(); // ****************** foreach (ImageFormat imageFormat in ImageFormatCollection) { comboBoxFormat.Items.Add(imageFormat.Name); } comboBoxScreenComponent.Items.Add("Active Window"); for (int i = 1; i <= ScreenDictionary.Count; i++) { System.Windows.Forms.Screen screen = ScreenDictionary[i]; comboBoxScreenComponent.Items.Add("Screen " + i + " (" + screen.Bounds.Width + " x " + screen.Bounds.Height + ")"); } if (ScreenObject != null) { Text = "Change Screen"; textBoxName.Text = ScreenObject.Name; textBoxFolder.Text = FileSystem.CorrectDirectoryPath(ScreenObject.Folder); textBoxMacro.Text = ScreenObject.Macro; if (ScreenObject.Component < comboBoxScreenComponent.Items.Count) { SetControls(enabled: true); comboBoxScreenComponent.SelectedIndex = ScreenObject.Component; } else { SetControls(enabled: false); } comboBoxFormat.SelectedItem = ScreenObject.Format.Name; numericUpDownJpegQuality.Value = ScreenObject.JpegQuality; numericUpDownResolutionRatio.Value = ScreenObject.ResolutionRatio; checkBoxMouse.Checked = ScreenObject.Mouse; } else { Text = "Add New Screen"; textBoxName.Text = string.Empty; textBoxFolder.Text = FileSystem.ScreenshotsFolder; textBoxMacro.Text = MacroParser.DefaultMacro; comboBoxScreenComponent.SelectedIndex = 0; comboBoxFormat.SelectedItem = ScreenCapture.DefaultImageFormat; numericUpDownJpegQuality.Value = 100; numericUpDownResolutionRatio.Value = 100; checkBoxMouse.Checked = true; } timerScreenPreview.Enabled = true; }
private void FormRegion_Load(object sender, EventArgs e) { ScreenDictionary.Clear(); comboBoxScreenTemplate.Items.Clear(); comboBoxTags.DataSource = null; int component = 1; foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens) { ScreenDictionary.Add(component, screen); component++; } // *** Screen Template *** comboBoxScreenTemplate.Items.Add(string.Empty); for (int i = 1; i <= ScreenDictionary.Count; i++) { System.Windows.Forms.Screen screen = ScreenDictionary[i]; comboBoxScreenTemplate.Items.Add("Screen " + i + " (" + screen.Bounds.Width + " x " + screen.Bounds.Height + ")"); } comboBoxScreenTemplate.SelectedIndex = 0; // *********************** // *** Macro Tags *** comboBoxTags.DisplayMember = "Description"; comboBoxTags.ValueMember = "Name"; comboBoxTags.DataSource = MacroTagCollection.GetList(); // ****************** comboBoxFormat.Items.Clear(); foreach (ImageFormat imageFormat in ImageFormatCollection) { comboBoxFormat.Items.Add(imageFormat.Name); } if (RegionObject != null) { Text = "Change Region"; textBoxName.Text = RegionObject.Name; textBoxFolder.Text = FileSystem.CorrectDirectoryPath(RegionObject.Folder); textBoxMacro.Text = RegionObject.Macro; comboBoxFormat.SelectedItem = RegionObject.Format.Name; numericUpDownJpegQuality.Value = RegionObject.JpegQuality; numericUpDownResolutionRatio.Value = RegionObject.ResolutionRatio; checkBoxMouse.Checked = RegionObject.Mouse; numericUpDownX.Value = RegionObject.X; numericUpDownY.Value = RegionObject.Y; numericUpDownWidth.Value = RegionObject.Width; numericUpDownHeight.Value = RegionObject.Height; } else { Text = "Add New Region"; textBoxName.Text = "Region " + (RegionCollection.Count + 1); textBoxFolder.Text = FileSystem.ScreenshotsFolder; textBoxMacro.Text = MacroParser.DefaultMacro; comboBoxFormat.SelectedItem = ScreenCapture.DefaultImageFormat; numericUpDownJpegQuality.Value = 100; numericUpDownResolutionRatio.Value = 100; checkBoxMouse.Checked = true; numericUpDownX.Value = 0; numericUpDownY.Value = 0; numericUpDownWidth.Value = 800; numericUpDownHeight.Value = 600; } timerPreview.Enabled = true; }
/// <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> /// Saves the screens. /// </summary> public void Save() { try { if (Directory.Exists(FileSystem.ApplicationFolder)) { XmlWriterSettings xSettings = new XmlWriterSettings(); xSettings.Indent = true; xSettings.CloseOutput = true; xSettings.CheckCharacters = true; xSettings.Encoding = Encoding.UTF8; xSettings.NewLineChars = Environment.NewLine; xSettings.IndentChars = XML_FILE_INDENT_CHARS; xSettings.NewLineHandling = NewLineHandling.Entitize; xSettings.ConformanceLevel = ConformanceLevel.Document; if (File.Exists(FileSystem.ApplicationFolder + FileSystem.ScreensFile)) { File.Delete(FileSystem.ApplicationFolder + FileSystem.ScreensFile); } using (XmlWriter xWriter = XmlWriter.Create(FileSystem.ApplicationFolder + FileSystem.ScreensFile, 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_SCREENS_NODE); foreach (object obj in _screenList) { Screen screen = (Screen)obj; xWriter.WriteStartElement(XML_FILE_SCREEN_NODE); xWriter.WriteElementString(SCREEN_VIEWID, screen.ViewId.ToString()); xWriter.WriteElementString(SCREEN_NAME, screen.Name); xWriter.WriteElementString(SCREEN_FOLDER, FileSystem.CorrectDirectoryPath(screen.Folder)); xWriter.WriteElementString(SCREEN_MACRO, screen.Macro); xWriter.WriteElementString(SCREEN_COMPONENT, screen.Component.ToString()); xWriter.WriteElementString(SCREEN_FORMAT, screen.Format.Name); xWriter.WriteElementString(SCREEN_JPEG_QUALITY, screen.JpegQuality.ToString()); xWriter.WriteElementString(SCREEN_RESOLUTION_RATIO, screen.ResolutionRatio.ToString()); xWriter.WriteElementString(SCREEN_MOUSE, screen.Mouse.ToString()); xWriter.WriteEndElement(); } xWriter.WriteEndElement(); xWriter.WriteEndElement(); xWriter.WriteEndDocument(); xWriter.Flush(); xWriter.Close(); } } } catch (Exception ex) { Log.Write("ScreenCollection::Save", ex); } }