Пример #1
0
        /// <summary>
        /// Removes the selected Macro Tags from the Macro Tags tab page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeSelectedMacroTags_Click(object sender, EventArgs e)
        {
            int countBeforeRemoval = _formMacroTag.MacroTagCollection.Count;

            foreach (Control control in tabPageMacroTags.Controls)
            {
                if (control.GetType().Equals(typeof(CheckBox)))
                {
                    CheckBox checkBox = (CheckBox)control;

                    if (checkBox.Checked)
                    {
                        MacroTag trigger = _formMacroTag.MacroTagCollection.Get((MacroTag)checkBox.Tag);
                        _formMacroTag.MacroTagCollection.Remove(trigger);
                    }
                }
            }

            if (countBeforeRemoval > _formMacroTag.MacroTagCollection.Count)
            {
                BuildMacroTagsModule();

                if (!_formMacroTag.MacroTagCollection.SaveToXmlFile())
                {
                    _screenCapture.ApplicationError = true;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Shows the "Change Macro Tag" window to enable the user to edit a chosen Macro Tag.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void changeMacroTag_Click(object sender, EventArgs e)
        {
            ShowInterface();

            MacroTag macroTag = new MacroTag(_macroParser);

            if (sender is Button)
            {
                Button buttonSelected = (Button)sender;
                macroTag = (MacroTag)buttonSelected.Tag;
            }

            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem toolStripMenuItemSelected = (ToolStripMenuItem)sender;
                macroTag = (MacroTag)toolStripMenuItemSelected.Tag;
            }

            _formMacroTag.MacroTagObject = macroTag;

            _formMacroTag.ShowDialog(this);

            if (_formMacroTag.DialogResult == DialogResult.OK)
            {
                BuildMacroTagsModule();

                if (!_formMacroTag.MacroTagCollection.SaveToXmlFile(_config, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }
            }
        }
Пример #3
0
        private void comboBoxTags_SelectedIndexChanged(object sender, EventArgs e)
        {
            MacroTag macroTag = (MacroTag)comboBoxTags.SelectedItem;

            if (macroTag != null && !string.IsNullOrEmpty(macroTag.Name))
            {
                textBoxMacro.Text         += macroTag.Name;
                comboBoxTags.SelectedIndex = 0;
            }
        }
Пример #4
0
        private void FormMacroTag_Load(object sender, EventArgs e)
        {
            textBoxName.Focus();

            HelpMessage("This is where to configure a macro tag which will be used when the filepath of a screenshot is parsed");

            _toolTip.SetToolTip(checkBoxActive, "The filepath containing this macro tag will be parsed if Active is checked (turned on)");
            _toolTip.SetToolTip(comboBoxType, "The type of macro tag depends on what information will be acquired for it");

            comboBoxType.Items.Clear();
            comboBoxType.Items.Add("Screen Name");
            comboBoxType.Items.Add("Screen Number");
            comboBoxType.Items.Add("Image Format");
            comboBoxType.Items.Add("Screen Capture Cycle Count");
            comboBoxType.Items.Add("Active Window Title");
            comboBoxType.Items.Add("Date/Time Format");
            comboBoxType.Items.Add("User");
            comboBoxType.Items.Add("Machine");
            comboBoxType.Items.Add("Time Range");
            comboBoxType.Items.Add("Date/Time Format Expression");
            comboBoxType.Items.Add("Quarter Year");

            if (MacroTagObject != null)
            {
                Text = "Change Macro Tag";

                textBoxName.Text = MacroTagObject.Name;

                textBoxDescription.Text = MacroTagObject.Description;

                comboBoxType.SelectedIndex      = (int)MacroTagObject.Type;
                textBoxDateTimeFormatValue.Text = MacroTagObject.DateTimeFormatValue;

                dateTimePickerMacro1Start.Value = MacroTagObject.TimeRangeMacro1Start;
                dateTimePickerMacro1End.Value   = MacroTagObject.TimeRangeMacro1End;

                dateTimePickerMacro2Start.Value = MacroTagObject.TimeRangeMacro2Start;
                dateTimePickerMacro2End.Value   = MacroTagObject.TimeRangeMacro2End;

                dateTimePickerMacro3Start.Value = MacroTagObject.TimeRangeMacro3Start;
                dateTimePickerMacro3End.Value   = MacroTagObject.TimeRangeMacro3End;

                dateTimePickerMacro4Start.Value = MacroTagObject.TimeRangeMacro4Start;
                dateTimePickerMacro4End.Value   = MacroTagObject.TimeRangeMacro4End;

                textBoxMacro1Macro.Text = MacroTagObject.TimeRangeMacro1Macro;
                textBoxMacro2Macro.Text = MacroTagObject.TimeRangeMacro2Macro;
                textBoxMacro3Macro.Text = MacroTagObject.TimeRangeMacro3Macro;
                textBoxMacro4Macro.Text = MacroTagObject.TimeRangeMacro4Macro;

                checkBoxActive.Checked = MacroTagObject.Active;

                textBoxNotes.Text = MacroTagObject.Notes;
            }
            else
            {
                Text = "Add Macro Tag";

                MacroTag tag = new MacroTag();

                textBoxName.Text = "%macrotag" + (MacroTagCollection.Count + 1) + "%";

                textBoxDescription.Text = "Please provide a brief summary for the purpose of this macro tag";

                comboBoxType.SelectedIndex      = 0;
                textBoxDateTimeFormatValue.Text = tag.DateTimeFormatValue;

                dateTimePickerMacro1Start.Value = tag.TimeRangeMacro1Start;
                dateTimePickerMacro1End.Value   = tag.TimeRangeMacro1End;

                dateTimePickerMacro2Start.Value = tag.TimeRangeMacro2Start;
                dateTimePickerMacro2End.Value   = tag.TimeRangeMacro2End;

                dateTimePickerMacro3Start.Value = tag.TimeRangeMacro3Start;
                dateTimePickerMacro3End.Value   = tag.TimeRangeMacro3End;

                dateTimePickerMacro4Start.Value = tag.TimeRangeMacro4Start;
                dateTimePickerMacro4End.Value   = tag.TimeRangeMacro4End;

                textBoxMacro1Macro.Text = tag.TimeRangeMacro1Macro;
                textBoxMacro2Macro.Text = tag.TimeRangeMacro2Macro;
                textBoxMacro3Macro.Text = tag.TimeRangeMacro3Macro;
                textBoxMacro4Macro.Text = tag.TimeRangeMacro4Macro;

                checkBoxActive.Checked = true;

                textBoxNotes.Text = string.Empty;
            }
        }
        private void listBoxMacroTags_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            MacroTag tag = _macroTagCollection.GetByName((string)listBoxMacroTags.SelectedItem);

            labelHelp.Text = _macroParser.ParseTags(config: false, tag.Description, _macroTagCollection, _log);
        }
Пример #6
0
        private void enabledStatus_Click(object sender, EventArgs e)
        {
            Label label = (Label)sender;

            if (label.Tag.GetType() == typeof(Region))
            {
                Region region = (Region)label.Tag;

                if (region.Enable)
                {
                    region.Enable   = false;
                    label.BackColor = Color.PaleVioletRed;
                }
                else
                {
                    region.Enable   = true;
                    label.BackColor = Color.PaleGreen;
                }

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

            if (label.Tag.GetType() == typeof(Schedule))
            {
                Schedule schedule = (Schedule)label.Tag;

                if (schedule.Enable)
                {
                    schedule.Enable = false;
                    label.BackColor = Color.PaleVioletRed;
                }
                else
                {
                    schedule.Enable = true;
                    label.BackColor = Color.PaleGreen;
                }

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

            if (label.Tag.GetType() == typeof(Screen))
            {
                Screen screen = (Screen)label.Tag;

                if (screen.Enable)
                {
                    screen.Enable   = false;
                    label.BackColor = Color.PaleVioletRed;
                }
                else
                {
                    screen.Enable   = true;
                    label.BackColor = Color.PaleGreen;
                }

                if (!_formScreen.ScreenCollection.SaveToXmlFile(_config.Settings, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }
            }

            if (label.Tag.GetType() == typeof(MacroTag))
            {
                MacroTag tag = (MacroTag)label.Tag;

                if (tag.Enable)
                {
                    tag.Enable      = false;
                    label.BackColor = Color.PaleVioletRed;
                }
                else
                {
                    tag.Enable      = true;
                    label.BackColor = Color.PaleGreen;
                }

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

            if (label.Tag.GetType() == typeof(Trigger))
            {
                Trigger trigger = (Trigger)label.Tag;

                if (trigger.Enable)
                {
                    trigger.Enable  = false;
                    label.BackColor = Color.PaleVioletRed;
                }
                else
                {
                    trigger.Enable  = true;
                    label.BackColor = Color.PaleGreen;
                }

                if (!_formTrigger.TriggerCollection.SaveToXmlFile(_config, _fileSystem, _log))
                {
                    _screenCapture.ApplicationError = true;
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Replaces a tag (such as "%year%") with an appropriate value (such as "2020").
        /// </summary>
        /// <param name="preview">Determines if this is a preview of a macro. We either use screen capture date/time or DateTime.Now depending on this boolean.</param>
        /// <param name="name">The name of a region or screen when parsing the %name% tag.</param>
        /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param>
        /// <param name="screenNumber">The screen number. For example, if this is the second display then the screen number is 2.</param>
        /// <param name="format">The image format to use as an image file extension when parsing the %format% tag.</param>
        /// <param name="activeWindowTitle">The title of the active window.</param>
        /// <param name="tag">The macro tag to use during parsing.</param>
        /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns>
        private string ParseTag(bool preview, string name, string macro, int screenNumber, ImageFormat format, string activeWindowTitle, MacroTag tag)
        {
            int      count;
            DateTime dt;

            if (preview || screenCapture == null)
            {
                count = 1;
                dt    = DateTime.Now;
            }
            else
            {
                count = screenCapture.Count;
                dt    = screenCapture.DateTimeScreenshotsTaken;
            }

            // Strip out any backslash characters from the name so we avoid creating unnecessary directories based on the name.
            name = name.Replace("\\", string.Empty);

            if (!tag.Active)
            {
                return(macro);
            }

            switch (tag.Type)
            {
            case MacroTagType.ActiveWindowTitle:
                macro = macro.Replace(tag.Name, activeWindowTitle);
                break;

            case MacroTagType.DateTimeFormat:
                macro = macro.Replace(tag.Name, dt.ToString(tag.DateTimeFormatValue));
                break;

            case MacroTagType.ImageFormat:
                macro = format != null && !string.IsNullOrEmpty(format.Name) ? macro.Replace(tag.Name, format.Name.ToLower()) : macro;
                break;

            case MacroTagType.ScreenCaptureCycleCount:
                macro = macro.Replace(tag.Name, count.ToString());
                break;

            case MacroTagType.ScreenName:
                macro = !string.IsNullOrEmpty(name) ? macro.Replace(tag.Name, name) : macro;
                break;

            case MacroTagType.ScreenNumber:
                macro = macro.Replace(tag.Name, screenNumber.ToString());
                break;

            case MacroTagType.User:
                macro = macro.Replace(tag.Name, Environment.UserName);
                break;

            case MacroTagType.Machine:
                macro = macro.Replace(tag.Name, Environment.MachineName);
                break;

            case MacroTagType.DateTimeFormatExpression:
                macro = macro.Replace(tag.Name,
                                      _macroTagExpressionParser.ParseTagExpressionForDateTimeFormat(dt, tag.DateTimeFormatValue, this));
                break;

            case MacroTagType.QuarterYear:
                macro = macro.Replace(tag.Name, ((dt.Month - 1) / 3 + 1).ToString());
                break;
            }

            return(StripInvalidWindowsCharacters(macro));
        }
Пример #8
0
        /// <summary>
        /// Replaces a tag (such as "%year%") with an appropriate value (such as "2020").
        /// </summary>
        /// <param name="preview">Determines if this is a preview of a macro. We either use screen capture date/time or DateTime.Now depending on this boolean.</param>
        /// <param name="name">The name of a region or screen when parsing the %name% tag.</param>
        /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param>
        /// <param name="screenNumber">The screen number. For example, if this is the second display then the screen number is 2.</param>
        /// <param name="x">The current X value.</param>
        /// <param name="y">The current Y value.</param>
        /// <param name="width">The current Width value.</param>
        /// <param name="height">The current Height value.</param>
        /// <param name="format">The image format to use as an image file extension when parsing the %format% tag.</param>
        /// <param name="activeWindowTitle">The title of the active window.</param>
        /// <param name="processName">The name of the current process.</param>
        /// <param name="label">The label that is applied to the saved screenshot.</param>
        /// <param name="tag">The macro tag to use during parsing.</param>
        /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns>
        private string ParseTag(bool preview, string name, string macro, int screenNumber, int x, int y, int width, int height, ImageFormat format, string activeWindowTitle, string processName, string label, MacroTag tag)
        {
            int      count;
            DateTime dt;

            if (preview || screenCapture == null)
            {
                count = 1;
                dt    = DateTime.Now;
            }
            else
            {
                count = screenCapture.CycleCount;
                dt    = screenCapture.DateTimeScreenshotsTaken;
            }

            // Strip out any backslash characters from the name so we avoid creating unnecessary directories based on the name.
            name = name.Replace("\\", string.Empty);

            if (!tag.Enable)
            {
                return(macro);
            }

            switch (tag.Type)
            {
            case MacroTagType.ActiveWindowTitle:
                macro = macro.Replace(tag.Name, activeWindowTitle);
                break;

            case MacroTagType.DateTimeFormat:
                macro = macro.Replace(tag.Name, dt.ToString(tag.DateTimeFormatValue));
                break;

            case MacroTagType.ImageFormat:
                macro = format != null && !string.IsNullOrEmpty(format.Name) ? macro.Replace(tag.Name, format.Name.ToLower()) : macro;
                break;

            case MacroTagType.ScreenCaptureCycleCount:
                macro = macro.Replace(tag.Name, count.ToString());
                break;

            case MacroTagType.ScreenName:
                macro = !string.IsNullOrEmpty(name) ? macro.Replace(tag.Name, name) : macro;
                break;

            case MacroTagType.ScreenNumber:
                macro = macro.Replace(tag.Name, screenNumber.ToString());
                break;

            case MacroTagType.User:
                macro = macro.Replace(tag.Name, Environment.UserName);
                break;

            case MacroTagType.Machine:
                macro = macro.Replace(tag.Name, Environment.MachineName);
                break;

            case MacroTagType.DateTimeFormatExpression:
                macro = macro.Replace(tag.Name,
                                      _macroTagExpressionParser.ParseTagExpressionForDateTimeFormat(dt, tag.DateTimeFormatValue, this));
                break;

            case MacroTagType.QuarterYear:
                macro = macro.Replace(tag.Name, ((dt.Month - 1) / 3 + 1).ToString());
                break;

            case MacroTagType.X:
                macro = macro.Replace(tag.Name, x.ToString());
                break;

            case MacroTagType.Y:
                macro = macro.Replace(tag.Name, y.ToString());
                break;

            case MacroTagType.Width:
                macro = macro.Replace(tag.Name, width.ToString());
                break;

            case MacroTagType.Height:
                macro = macro.Replace(tag.Name, height.ToString());
                break;

            case MacroTagType.Process:
                macro = macro.Replace(tag.Name, processName);
                break;

            case MacroTagType.Label:
                macro = macro.Replace(tag.Name, label);
                break;

            case MacroTagType.CaptureNowCount:
                macro = macro.Replace(tag.Name, screenCapture == null ? "0" : screenCapture.CaptureNowCount.ToString());
                break;
            }

            // If we encounter "$AppDataLocal$" then replace it with the user's local AppData directory.
            // This is used by the installer in case the user puts the application in the "Program Files" folder
            // where we can't write any files to since we don't have permissions to write files in that folder
            // unless the application is running as Administrator so for it to work for normal users we have to
            // make sure that we write all the necessary XML files to the user's local AppData folder.
            macro = macro.Replace("$AppDataLocal$", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));

            // For roaming profiles.
            macro = macro.Replace("$AppDataRoaming$", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));

            // The user's Desktop.
            macro = macro.Replace("$Desktop$", Environment.GetFolderPath(Environment.SpecialFolder.Desktop));

            // The user's "My Documents" folder.
            macro = macro.Replace("$MyDocuments$", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

            return(StripInvalidWindowsCharacters(macro));
        }