/// <summary> /// Empty constructor for the Macro Tags tool window. /// </summary> public FormMacroTagsToolWindow(TagCollection tagCollection) { InitializeComponent(); _tagCollection = tagCollection; }
/// <summary> /// Replaces a series of tags with appropriate values. Assumes you are either parsing a folder path or just need a preview of the returned values. /// </summary> /// <param name="macro">The macro to parse. A macro usually includes tags such as %count% and %date%.</param> /// <param name="tagCollection">A collection of macro tags to parse.</param> /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns> public static string ParseTags(string macro, TagCollection tagCollection) { return(ParseTags(preview: true, string.Empty, macro, 0, new ImageFormat(ImageFormatSpec.NAME_JPEG, ImageFormatSpec.EXTENSION_JPEG), string.Empty, tagCollection)); }
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); } } 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.Initialize(); Log.WriteMessage("Loading user settings"); Settings.User.Load(); Log.WriteDebugMessage("User settings loaded"); Log.WriteDebugMessage("Attempting upgrade of application settings from old version of application (if needed)"); Settings.Application.Upgrade(); Log.WriteDebugMessage("Attempting upgrade of user settings from old version of application (if needed)"); Settings.User.Upgrade(); 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> /// Replaces series of tags with appropriate values. /// </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="tagCollection">A collection of macro tags to parse.</param> /// <returns>A parsed macro containing the appropriate values of respective tags in the provided macro.</returns> public static string ParseTags(bool preview, string name, string macro, int screenNumber, ImageFormat format, string activeWindowTitle, TagCollection tagCollection) { foreach (Tag tag in tagCollection) { if (tag.Type == TagType.TimeOfDay) { DateTime dt; if (preview || screenCapture == null) { dt = DateTime.Now; } else { dt = screenCapture.DateTimeScreenshotsTaken; } string morningValue = tag.TimeOfDayMorningValue; string afternoonValue = tag.TimeOfDayAfternoonValue; string eveningValue = tag.TimeOfDayEveningValue; // Temporarily make this tag a DateTimeFormat type because we're going to recursively call ParseTagsForFilePath // for each macro tag in the morning, afternoon, and evening fields. tag.Type = TagType.DateTimeFormat; // Recursively call the same method we're in to parse each field as if it was a date/time macro tag. // This can achieve some interesting results such as being able to call the same %timeofday% tag // in onto itself because it will use its own date/time format value, but the intention is to have tags // like %date%, %time%, %hour%, %minute%, and %second% be used in the morning, afternoon, and evening fields. morningValue = ParseTags(preview, name, morningValue, screenNumber, format, activeWindowTitle, tagCollection); afternoonValue = ParseTags(preview, name, afternoonValue, screenNumber, format, activeWindowTitle, tagCollection); eveningValue = ParseTags(preview, name, eveningValue, screenNumber, format, activeWindowTitle, tagCollection); // Now that we have the new parsed values based on date/time macro tags we can set this tag back to its TimeOfDay type. tag.Type = TagType.TimeOfDay; if (dt.TimeOfDay >= tag.TimeOfDayMorningStart.TimeOfDay && dt.TimeOfDay <= tag.TimeOfDayMorningEnd.TimeOfDay) { macro = macro.Replace(tag.Name, morningValue); } if (dt.TimeOfDay >= tag.TimeOfDayAfternoonStart.TimeOfDay && dt.TimeOfDay <= tag.TimeOfDayAfternoonEnd.TimeOfDay) { macro = macro.Replace(tag.Name, afternoonValue); } if (dt.TimeOfDay >= tag.TimeOfDayEveningStart.TimeOfDay && dt.TimeOfDay <= tag.TimeOfDayEveningEnd.TimeOfDay) { macro = macro.Replace(tag.Name, eveningValue); } // Split the evening start time and evening end time into separate checks if the user wants to extend // the time of what they consider "evening" to also include the next morning. if (tag.EveningExtendsToNextMorning) { DateTime dayStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0); DateTime dayEnd = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59); if (dt.TimeOfDay >= tag.TimeOfDayEveningStart.TimeOfDay && dt.TimeOfDay <= dayEnd.TimeOfDay) { macro = macro.Replace(tag.Name, eveningValue); } if (dt.TimeOfDay >= dayStart.TimeOfDay && dt.TimeOfDay <= tag.TimeOfDayEveningEnd.TimeOfDay) { macro = macro.Replace(tag.Name, eveningValue); } } } else { macro = ParseTag(preview, name, macro, screenNumber, format, activeWindowTitle, tag); } } return(StripInvalidWindowsCharacters(macro)); }