Example #1
0
        private void AddDefaultScreens()
        {
            int component = 1;

            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
            {
                ScreenCapture.DeviceResolution deviceResolution = ScreenCapture.GetDeviceResolution(screen);

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

                Log.WriteDebugMessage($"Screen {component} created using \"{FileSystem.ScreenshotsFolder}\" for folder path and \"{MacroParser.DefaultMacro}\" for macro.");

                component++;
            }
        }
Example #2
0
        private System.Windows.Forms.Screen GetScreenByIndex(int index)
        {
            try
            {
                ScreenCapture.DeviceResolution deviceResolution = ScreenDictionary[index];

                return(deviceResolution.screen);
            }
            catch (KeyNotFoundException)
            {
                return(null);
            }
        }
Example #3
0
        private void comboBoxRegionScreenTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ScreenDictionary.ContainsKey(comboBoxScreenTemplate.SelectedIndex))
            {
                ScreenCapture.DeviceResolution deviceResolution = ScreenDictionary[comboBoxScreenTemplate.SelectedIndex];

                numericUpDownX.Value      = deviceResolution.screen.Bounds.X;
                numericUpDownY.Value      = deviceResolution.screen.Bounds.Y;
                numericUpDownWidth.Value  = deviceResolution.width;
                numericUpDownHeight.Value = deviceResolution.height;

                comboBoxScreenTemplate.SelectedIndex = 0;
            }
        }
Example #4
0
        /// <summary>
        /// Updates the screen dictionary with the available screens.
        /// </summary>
        public void RefreshScreenDictionary()
        {
            ScreenDictionary.Clear();

            int component = 1;

            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
            {
                ScreenCapture.DeviceResolution deviceResolution = ScreenCapture.GetDeviceResolution(screen);

                ScreenDictionary.Add(component, deviceResolution);
                component++;
            }
        }
Example #5
0
        private void FormRegion_Load(object sender, EventArgs e)
        {
            textBoxRegionName.Focus();

            HelpMessage("This is where to configure a region capture. Change the X, Y, Width, and Height properties while watching Preview");

            _toolTip.SetToolTip(checkBoxMouse, "You can include the mouse pointer in your screenshots if the \"Include mouse pointer\" option is checked");
            _toolTip.SetToolTip(comboBoxFormat, "Change the image format for the screenshots taken by this region capture. JPEG is the recommended image format");
            _toolTip.SetToolTip(comboBoxScreenTemplate, "Acquire the width and height from an available screen to import as the width and height for your region capture");
            _toolTip.SetToolTip(checkBoxActive, "You can capture this region if Active is checked (turned on)");
            _toolTip.SetToolTip(buttonBrowseFolder, "Browse for a folder where screenshots of this region capture will be saved to");
            _toolTip.SetToolTip(buttonMacroTags, "Open a list of available macro tags. You can keep the Macro Tags window open while you modify your macro");

            ScreenDictionary.Clear();
            comboBoxScreenTemplate.Items.Clear();

            int component = 1;

            foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
            {
                ScreenCapture.DeviceResolution deviceResolution = ScreenCapture.GetDeviceResolution(screen);

                ScreenDictionary.Add(component, deviceResolution);
                component++;
            }

            // *** Screen Template ***
            comboBoxScreenTemplate.Items.Add(string.Empty);

            for (int i = 1; i <= ScreenDictionary.Count; i++)
            {
                ScreenCapture.DeviceResolution deviceResolution = ScreenDictionary[i];

                comboBoxScreenTemplate.Items.Add("\"" + deviceResolution.screen.DeviceName + "\" X:" + deviceResolution.screen.Bounds.X + " Y:" + deviceResolution.screen.Bounds.Y + " (" + deviceResolution.width + "x" + deviceResolution.height + ")");
            }

            comboBoxScreenTemplate.SelectedIndex = 0;
            // ***********************

            comboBoxFormat.Items.Clear();

            foreach (ImageFormat imageFormat in ImageFormatCollection)
            {
                comboBoxFormat.Items.Add(imageFormat.Name);
            }

            if (RegionObject != null)
            {
                Text = "Change Region";

                textBoxRegionName.Text             = RegionObject.Name;
                textBoxFolder.Text                 = FileSystem.CorrectScreenshotsFolderPath(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;
                checkBoxActive.Checked             = RegionObject.Active;
            }
            else
            {
                Text = "Add Region";

                textBoxRegionName.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;
                checkBoxActive.Checked             = true;
            }

            UpdatePreviewMacro();
            UpdatePreviewImage(ScreenCapture);
        }
Example #6
0
        private void FormScreen_Load(object sender, EventArgs e)
        {
            textBoxScreenName.Focus();

            HelpMessage("This is where to configure a screen capture. Select an available screen from the Component drop-down menu and keep an eye on Preview");

            comboBoxFormat.Items.Clear();
            comboBoxScreenComponent.Items.Clear();

            pictureBoxPreview.Image = null;

            foreach (ImageFormat imageFormat in ImageFormatCollection)
            {
                comboBoxFormat.Items.Add(imageFormat.Name);
            }

            comboBoxScreenComponent.Items.Add("Active Window");

            for (int i = 1; i <= ScreenDictionary.Count; i++)
            {
                ScreenCapture.DeviceResolution deviceResolution = ScreenDictionary[i];
                comboBoxScreenComponent.Items.Add("Screen " + i + " (" + deviceResolution.width + " x " + deviceResolution.height + ")");
            }

            if (ScreenObject != null)
            {
                Text = "Change Screen";

                textBoxScreenName.Text = ScreenObject.Name;
                textBoxFolder.Text     = FileSystem.CorrectScreenshotsFolderPath(ScreenObject.Folder);
                textBoxMacro.Text      = ScreenObject.Macro;

                if (ScreenObject.Component < comboBoxScreenComponent.Items.Count)
                {
                    comboBoxScreenComponent.SelectedIndex = ScreenObject.Component;
                }
                else
                {
                    comboBoxScreenComponent.SelectedIndex = 0;
                    MessageBox.Show("The configured screen component has an invalid index since it is not available on this system. The component has therefore been set to Active Window.", "Invalid Screen Index", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                comboBoxFormat.SelectedItem        = ScreenObject.Format.Name;
                numericUpDownJpegQuality.Value     = ScreenObject.JpegQuality;
                numericUpDownResolutionRatio.Value = ScreenObject.ResolutionRatio;
                checkBoxMouse.Checked  = ScreenObject.Mouse;
                checkBoxActive.Checked = ScreenObject.Active;
            }
            else
            {
                Text = "Add New Screen";

                textBoxScreenName.Text = "Screen " + (ScreenCollection.Count + 1);
                textBoxFolder.Text     = FileSystem.ScreenshotsFolder;
                textBoxMacro.Text      = MacroParser.DefaultMacro;
                comboBoxScreenComponent.SelectedIndex = 0;
                comboBoxFormat.SelectedItem           = ScreenCapture.DefaultImageFormat;
                numericUpDownJpegQuality.Value        = 100;
                numericUpDownResolutionRatio.Value    = 100;
                checkBoxMouse.Checked  = true;
                checkBoxActive.Checked = true;
            }

            UpdatePreviewMacro();
            UpdatePreviewImage(ScreenCapture);
        }
Example #7
0
        private void comboBoxScreenSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBoxScreenComponent.Items.Clear();

            // Auto Screen Capture
            if (comboBoxScreenSource.SelectedIndex == 0)
            {
                comboBoxScreenComponent.Items.Add("Active Window");

                // Add screens from screens.xml file.
                foreach (Screen screen in ScreenCollection)
                {
                    // We don't want a Screen object that's null.
                    if (screen == null)
                    {
                        continue;
                    }

                    // We don't care if it's a Screen using Active Window as its Component because that's already available in the list.
                    if (screen.Component == 0 && screen.Source == 0)
                    {
                        continue;
                    }

                    comboBoxScreenComponent.Items.Add("\"" + screen.Name + "\" X:" + screen.X + " Y:" + screen.Y + " (" + screen.Width + "x" + screen.Height + ")");
                }

                // Add regions from regions.xml file.
                foreach (Region region in RegionCollection)
                {
                    // We don't want a Region object that's null.
                    if (region == null)
                    {
                        continue;
                    }

                    comboBoxScreenComponent.Items.Add("\"" + region.Name + "\" X:" + region.X + " Y:" + region.Y + " (" + region.Width + "x" + region.Height + ")");
                }
            }

            // Graphics Card
            if (comboBoxScreenSource.SelectedIndex == 1)
            {
                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                {
                    ScreenCapture.DeviceResolution deviceResolution = ScreenCapture.GetDeviceResolution(screenFromWindows);

                    comboBoxScreenComponent.Items.Add("\"" + deviceResolution.screen.DeviceName + "\" X:" + deviceResolution.screen.Bounds.X + " Y:" + deviceResolution.screen.Bounds.Y + " (" + deviceResolution.width + "x" + deviceResolution.height + ")");
                }
            }

            // Operating System
            if (comboBoxScreenSource.SelectedIndex == 2)
            {
                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                {
                    comboBoxScreenComponent.Items.Add("\"" + screenFromWindows.DeviceName + "\" X:" + screenFromWindows.Bounds.X + " Y:" + screenFromWindows.Bounds.Y + " (" + screenFromWindows.Bounds.Width + "x" + screenFromWindows.Bounds.Height + ")");
                }
            }

            if (ScreenObject != null && ScreenObject.Component < comboBoxScreenComponent.Items.Count)
            {
                comboBoxScreenComponent.SelectedIndex = ScreenObject.Component;
            }
            else
            {
                comboBoxScreenComponent.SelectedIndex = 0;
            }
        }
Example #8
0
        /// <summary>
        /// Loads the screens.
        /// </summary>
        public bool LoadXmlFileAndAddScreens(ImageFormatCollection imageFormatCollection)
        {
            try
            {
                _imageFormatCollection = imageFormatCollection;

                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;

                                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 (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(Settings.CODENAME_BOOMBAYAH, Settings.CODEVERSION_BOOMBAYAH);
                            Version v2340         = Settings.VersionManager.Versions.Get(Settings.CODENAME_BOOMBAYAH, "2.3.4.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 (v2340 != null && configVersion != null && configVersion.VersionNumber < v2340.VersionNumber)
                            {
                                Log.WriteDebugMessage("Boombayah 2.3.3.2 or older detected");

                                int component = 1;

                                foreach (System.Windows.Forms.Screen screenFromWindows in System.Windows.Forms.Screen.AllScreens)
                                {
                                    ScreenCapture.DeviceResolution deviceResolution = ScreenCapture.GetDeviceResolution(screenFromWindows);

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

                                    component++;
                                }
                            }
                        }

                        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. Initializing screen collection");

                    if (Settings.VersionManager.IsOldAppVersion(AppCodename, AppVersion))
                    {
                        Version v2182         = Settings.VersionManager.Versions.Get(Settings.CODENAME_CLARA, Settings.CODEVERSION_CLARA);
                        Version configVersion = 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,
                                ResolutionRatio = 100,
                                Mouse           = true,
                                Active          = true,
                                X          = 0,
                                Y          = 0,
                                Width      = 0,
                                Height     = 0,
                                Source     = 0,
                                DeviceName = string.Empty
                            });
                        }
                    }

                    AddDefaultScreens();

                    SaveToXmlFile();
                }

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

                return(false);
            }
        }