/// <summary> /// Gets the path from the configuration file based on what line is being processed and a regex pattern. /// If the path cannot be found then the directory or file will be created. /// </summary> /// <param name="line">The line to read from the file.</param> /// <param name="regex">The regex pattern to use against the line.</param> /// <param name="path">The output of the path being returned.</param> /// <returns>A boolean to indicate if getting a path was successful or not.</returns> private bool GetPathAndCreateIfNotFound(string line, string regex, out string path) { if (!Regex.IsMatch(line, regex)) { path = null; return(false); } path = Regex.Match(line, regex).Groups["Path"].Value; MacroTagCollection tagCollection = new MacroTagCollection(); tagCollection.Add(new MacroTag(MacroParser, "user", "The user using this computer (%user%)", MacroTagType.User, active: true)); tagCollection.Add(new MacroTag(MacroParser, "machine", "The name of the computer (%machine%)", MacroTagType.Machine, active: true)); path = MacroParser.ParseTags(config: true, path, tagCollection, Log); if (FileSystem.HasExtension(path)) { string dir = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dir) && !FileSystem.DirectoryExists(dir)) { FileSystem.CreateDirectory(dir); } } else { if (!path.EndsWith(FileSystem.DirectorySeparatorChar().ToString())) { path += FileSystem.DirectorySeparatorChar(); } if (!string.IsNullOrEmpty(path) && !FileSystem.DirectoryExists(path)) { FileSystem.CreateDirectory(path); } } return(true); }
private void AddMacroTag() { if (InputValid()) { TrimInput(); if (MacroTagCollection.GetByName(textBoxName.Text) == null) { MacroTagCollection.Add(new MacroTag(textBoxName.Text, textBoxDescription.Text, (MacroTagType)comboBoxType.SelectedIndex, textBoxDateTimeFormatValue.Text, dateTimePickerMacro1Start.Value, dateTimePickerMacro1End.Value, textBoxMacro1Macro.Text, dateTimePickerMacro2Start.Value, dateTimePickerMacro2End.Value, textBoxMacro2Macro.Text, dateTimePickerMacro3Start.Value, dateTimePickerMacro3End.Value, textBoxMacro3Macro.Text, dateTimePickerMacro4Start.Value, dateTimePickerMacro4End.Value, textBoxMacro4Macro.Text, checkBoxActive.Checked, textBoxNotes.Text )); Okay(); } else { MessageBox.Show("A macro tag 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); } }