/// <summary> /// Loads the configuration file. /// </summary> public static void Load() { try { if (!FileSystem.DirectoryExists(FileSystem.GetDirectoryName(FileSystem.ConfigFile))) { FileSystem.CreateDirectory(FileSystem.GetDirectoryName(FileSystem.ConfigFile)); } if (!FileSystem.FileExists(FileSystem.ConfigFile)) { string[] linesToWrite = { "# Auto Screen Capture Configuration File", "# Use this file to tell the application what folders and files it should utilize.", "# Each key-value pair can be the name of a folder or file or a path to a folder or file.", "# If only the folder name is given then it will be parsed as the sub-folder of the folder", "# where the executed autoscreen.exe binary is located.", "", "# This is the folder where screenshots will be stored by default.", "ScreenshotsFolder=" + FileSystem.DefaultScreenshotsFolder, "", "# If any errors are encountered then you will find them in this folder when DebugMode is enabled.", "DebugFolder=" + FileSystem.DefaultDebugFolder, "", "# Logs are stored in this folder when either Logging or DebugMode is enabled.", "LogsFolder=" + FileSystem.DefaultLogsFolder, "", "# This file is monitored by the application for commands issued from the command line while it's running.", "CommandFile=" + FileSystem.DefaultCommandFile, "", "# The application settings (such as DebugMode).", "ApplicationSettingsFile=" + FileSystem.DefaultApplicationSettingsFile, "", "# Your personal settings.", "UserSettingsFile=" + FileSystem.DefaultUserSettingsFile, "", "# References to image editors.", "EditorsFile=" + FileSystem.DefaultEditorsFile, "", "# References to regions.", "RegionsFile=" + FileSystem.DefaultRegionsFile, "", "# References to screens.", "ScreensFile=" + FileSystem.DefaultScreensFile, "", "# References to triggers.", "TriggersFile=" + FileSystem.DefaultTriggersFile, "", "# References to screenshots.", "ScreenshotsFile=" + FileSystem.DefaultScreenshotsFile, "", "# References to tags.", "TagsFile=" + FileSystem.DefaultTagsFile, "", "# References to schedules.", "SchedulesFile=" + FileSystem.DefaultSchedulesFile, "" }; FileSystem.WriteToFile(FileSystem.ConfigFile, linesToWrite); } foreach (string line in FileSystem.ReadFromFile(FileSystem.ConfigFile)) { string path; if (GetPath(line, REGEX_SCREENSHOTS_FOLDER, out path)) { FileSystem.ScreenshotsFolder = path; } if (GetPath(line, REGEX_DEBUG_FOLDER, out path)) { FileSystem.DebugFolder = path; } if (GetPath(line, REGEX_LOGS_FOLDER, out path)) { FileSystem.LogsFolder = path; } if (GetPath(line, REGEX_COMMAND_FILE, out path)) { FileSystem.CommandFile = path; } if (GetPath(line, REGEX_APPLICATION_SETTINGS_FILE, out path)) { FileSystem.ApplicationSettingsFile = path; } if (GetPath(line, REGEX_USER_SETTINGS_FILE, out path)) { FileSystem.UserSettingsFile = path; } if (GetPath(line, REGEX_EDITORS_FILE, out path)) { FileSystem.EditorsFile = path; } if (GetPath(line, REGEX_REGIONS_FILE, out path)) { FileSystem.RegionsFile = path; } if (GetPath(line, REGEX_SCREENS_FILE, out path)) { FileSystem.ScreensFile = path; } if (GetPath(line, REGEX_TRIGGERS_FILE, out path)) { FileSystem.TriggersFile = path; } if (GetPath(line, REGEX_SCREENSHOTS_FILE, out path)) { FileSystem.ScreenshotsFile = path; } if (GetPath(line, REGEX_TAGS_FILE, out path)) { FileSystem.TagsFile = path; } if (GetPath(line, REGEX_SCHEDULES_FILE, out path)) { FileSystem.SchedulesFile = path; } } CheckAndCreateFolders(); CheckAndCreateFiles(); } catch (Exception ex) { Log.WriteExceptionMessage("Config::Load", ex); } }
/// <summary> /// The timer used for checking help tips, monitoring externally-issued commands, running Schedules, and displaying capture information. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timerScheduledCapture_Tick(object sender, EventArgs e) { try { DateTime dtNow = DateTime.Now; // Display help tip message from any class that isn't part of FormMain. if (!string.IsNullOrEmpty(HelpTip.Message)) { RestartHelpTipTimer(); HelpMessage(HelpTip.Message); HelpTip.Message = string.Empty; } // Parse commands issued externally via the command line. if (FileSystem.FileExists(FileSystem.CommandFile)) { string[] args = FileSystem.ReadFromFile(FileSystem.CommandFile); if (args.Length > 0) { ParseCommandLineArguments(args); } } else { FileSystem.CreateFile(FileSystem.CommandFile); } // Displays the next time screenshots are going to be captured in the system tray icon's tool tip. ShowInfo(); // Process the list of schedules we need to consider. foreach (Schedule schedule in _formSchedule.ScheduleCollection) { if ((dtNow.DayOfWeek == DayOfWeek.Monday && schedule.Monday) || (dtNow.DayOfWeek == DayOfWeek.Tuesday && schedule.Tuesday) || (dtNow.DayOfWeek == DayOfWeek.Wednesday && schedule.Wednesday) || (dtNow.DayOfWeek == DayOfWeek.Thursday && schedule.Thursday) || (dtNow.DayOfWeek == DayOfWeek.Friday && schedule.Friday) || (dtNow.DayOfWeek == DayOfWeek.Saturday && schedule.Saturday) || (dtNow.DayOfWeek == DayOfWeek.Sunday && schedule.Sunday)) { if (schedule.ModeOneTime) { if ((dtNow.Hour == schedule.CaptureAt.Hour) && (dtNow.Minute == schedule.CaptureAt.Minute) && (dtNow.Second == schedule.CaptureAt.Second)) { TakeScreenshot(captureNow: true); } } if (schedule.ModePeriod) { if ((dtNow.Hour == schedule.StartAt.Hour) && (dtNow.Minute == schedule.StartAt.Minute) && (dtNow.Second == schedule.StartAt.Second)) { StartScreenCapture(); } if ((dtNow.Hour == schedule.StopAt.Hour) && (dtNow.Minute == schedule.StopAt.Minute) && (dtNow.Second == schedule.StopAt.Second)) { StopScreenCapture(); } } } } // Process the list of triggers of condition type Date/Time and condition type Time. foreach (Trigger trigger in _formTrigger.TriggerCollection) { if (trigger.ConditionType == TriggerConditionType.DateTime && trigger.Date.ToString(MacroParser.DateFormat).Equals(dtNow.ToString(MacroParser.DateFormat)) && trigger.Time.ToString(MacroParser.TimeFormatForTrigger).Equals(dtNow.ToString(MacroParser.TimeFormatForTrigger))) { DoTriggerAction(trigger); } if (trigger.ConditionType == TriggerConditionType.Time && trigger.Time.ToString(MacroParser.TimeFormatForTrigger).Equals(dtNow.ToString(MacroParser.TimeFormatForTrigger))) { DoTriggerAction(trigger); } } } catch (Exception ex) { _screenCapture.ApplicationError = true; Log.WriteExceptionMessage("FormMain-Schedules::timerScheduledCapture_Tick", ex); } }
/// <summary> /// Loads the configuration file. /// </summary> public void Load(FileSystem fileSystem) { try { FileSystem = fileSystem; Settings = new Settings(); MacroParser = new MacroParser(Settings); string configDirectory = FileSystem.GetDirectoryName(FileSystem.ConfigFile); if (!string.IsNullOrEmpty(configDirectory) && !FileSystem.DirectoryExists(configDirectory)) { FileSystem.CreateDirectory(configDirectory); } if (!FileSystem.FileExists(FileSystem.ConfigFile)) { string[] linesToWrite = { "# Auto Screen Capture Configuration File", "# Use this file to tell the application what folders and files it should utilize.", "# Each key-value pair can be the name of a folder or file or a path to a folder or file.", "# If only the folder name is given then it will be parsed as the sub-folder of the folder", "# where the executed autoscreen.exe binary is located.", "", "# This is the folder where screenshots will be stored by default.", "ScreenshotsFolder=" + FileSystem.DefaultScreenshotsFolder, "", "# If any errors are encountered then you will find them in this folder when DebugMode is enabled.", "DebugFolder=" + FileSystem.DefaultDebugFolder, "", "# Logs are stored in this folder when either Logging or DebugMode is enabled.", "LogsFolder=" + FileSystem.DefaultLogsFolder, "", "# This file is monitored by the application for commands issued from the command line while it's running.", "CommandFile=" + FileSystem.DefaultCommandFile, "", "# The application settings (such as DebugMode).", "ApplicationSettingsFile=" + FileSystem.DefaultApplicationSettingsFile, "", "# Your personal settings.", "UserSettingsFile=" + FileSystem.DefaultUserSettingsFile, "", "# SMTP settings for emailing screenshots using an email server.", "SMTPSettingsFile=" + FileSystem.DefaultSmtpSettingsFile, "", "# SFTP settings for uploading screenshots to a file server.", "SFTPSettingsFile=" + FileSystem.DefaultSftpSettingsFile, "", "# References to image editors.", "EditorsFile=" + FileSystem.DefaultEditorsFile, "", "# References to regions.", "RegionsFile=" + FileSystem.DefaultRegionsFile, "", "# References to screens.", "ScreensFile=" + FileSystem.DefaultScreensFile, "", "# References to triggers.", "TriggersFile=" + FileSystem.DefaultTriggersFile, "", "# References to screenshots.", "ScreenshotsFile=" + FileSystem.DefaultScreenshotsFile, "", "# References to tags.", "TagsFile=" + FileSystem.DefaultTagsFile, "", "# References to schedules.", "SchedulesFile=" + FileSystem.DefaultSchedulesFile, "" }; FileSystem.WriteToFile(FileSystem.ConfigFile, linesToWrite); } foreach (string line in FileSystem.ReadFromFile(FileSystem.ConfigFile)) { if (string.IsNullOrEmpty(line) || line.StartsWith("#")) { continue; } string path; if (GetPathAndCreateIfNotFound(line, REGEX_SCREENSHOTS_FOLDER, out path)) { FileSystem.ScreenshotsFolder = path; } if (GetPathAndCreateIfNotFound(line, REGEX_DEBUG_FOLDER, out path)) { FileSystem.DebugFolder = path; } if (GetPathAndCreateIfNotFound(line, REGEX_LOGS_FOLDER, out path)) { FileSystem.LogsFolder = path; } if (GetPathAndCreateIfNotFound(line, REGEX_COMMAND_FILE, out path)) { FileSystem.CommandFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_APPLICATION_SETTINGS_FILE, out path)) { FileSystem.ApplicationSettingsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_SMTP_SETTINGS_FILE, out path)) { FileSystem.SmtpSettingsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_SFTP_SETTINGS_FILE, out path)) { FileSystem.SftpSettingsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_USER_SETTINGS_FILE, out path)) { FileSystem.UserSettingsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_EDITORS_FILE, out path)) { FileSystem.EditorsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_REGIONS_FILE, out path)) { FileSystem.RegionsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_SCREENS_FILE, out path)) { FileSystem.ScreensFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_TRIGGERS_FILE, out path)) { FileSystem.TriggersFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_SCREENSHOTS_FILE, out path)) { FileSystem.ScreenshotsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_TAGS_FILE, out path)) { FileSystem.TagsFile = path; } if (GetPathAndCreateIfNotFound(line, REGEX_SCHEDULES_FILE, out path)) { FileSystem.SchedulesFile = path; } } CheckAndCreateFolders(); Settings.Load(FileSystem); Log = new Log(Settings, FileSystem, MacroParser); ScreenCapture = new ScreenCapture(this, MacroParser, FileSystem, Log); Security security = new Security(); CheckAndCreateFiles(security, ScreenCapture, Log); } catch (Exception ex) { Log.WriteExceptionMessage("Config::Load", ex); } }