private int SaveToFile(Security security, int jpegQuality, Screenshot screenshot, ScreenshotCollection screenshotCollection) { int returnFlag = 0; string dirName = _fileSystem.GetDirectoryName(screenshot.FilePath); if (string.IsNullOrEmpty(dirName)) { _log.WriteDebugMessage("Directory name for screenshot with path \"" + screenshot.FilePath + "\" could not be found"); return(returnFlag | (int)ScreenSavingErrorLevels.DirNotFound); } try { if (!_fileSystem.DirectoryExists(dirName)) { _fileSystem.CreateDirectory(dirName); _log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created"); } // Attempt to process the screenshot before it's saved to disk. // This means we'll check for image diff tolerance (if Optimize Screen Capture is enabled). if (screenshotCollection.Process(screenshot)) { // Save the screenshot to disk if it processed successfully. SaveToFile(screenshot, security, jpegQuality); return(returnFlag & (int)ScreenSavingErrorLevels.None); } else { _log.WriteDebugMessage("Could not save screenshot with ID \"" + screenshot.Id + "\" and path \"" + screenshot.FilePath + "\" because the image difference percentage with the previous screenshot's image (" + screenshot.DiffPercentageWithPreviousImage + "%) wasn't significant enough"); return(returnFlag | (int)ScreenSavingErrorLevels.ImageDiffNotSignificant); } } catch { // We don't want to stop the screen capture session at this point because there may be other components that // can write to their given paths. If this is a misconfigured path for a particular component then just log an error. _log.WriteErrorMessage($"Cannot write to \"{screenshot.FilePath}\" because the user may not have the appropriate permissions to access the path"); return(returnFlag | (int)ScreenSavingErrorLevels.UserNotEnoughPermissions); } }
private void AddScreenshotAndSaveToFile(int jpegQuality, Screenshot screenshot, ScreenshotCollection screenshotCollection) { string dirName = FileSystem.GetDirectoryName(screenshot.Path); if (string.IsNullOrEmpty(dirName)) { Log.WriteDebugMessage("Directory name for screenshot with path \"" + screenshot.Path + "\" could not be found"); return; } try { if (!FileSystem.DirectoryExists(dirName)) { FileSystem.CreateDirectory(dirName); Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created"); } if (screenshotCollection.Add(screenshot)) { SaveToFile(screenshot.Path, screenshot.Format, jpegQuality, screenshot.Bitmap); } else { string hash = "hash"; if (!string.IsNullOrEmpty(screenshot.Hash)) { hash = "hash (" + screenshot.Hash + ")"; } Log.WriteDebugMessage("Could not save screenshot with path \"" + screenshot.Path + "\" because its " + hash + " may have matched with a previous hash that has already been used for an earlier screenshot"); } } catch (Exception) { // We don't want to stop the screen capture session at this point because there may be other components that // can write to their given paths. If this is a misconfigured path for a particular component then just log an error. Log.WriteErrorMessage($"Cannot write to \"{screenshot.Path}\" because the user may not have the appropriate permissions to access the path"); } }
/// <summary> /// Gets the path from the configuration file based on what line is being processed and a regex pattern. /// </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 static bool GetPath(string line, string regex, out string path) { if (line.StartsWith("#") || !Regex.IsMatch(line, regex)) { path = null; return(false); } path = Regex.Match(line, regex).Groups["Path"].Value; TagCollection tagCollection = new TagCollection(); tagCollection.Add(new Tag("user", "The user using this computer (%user%)", TagType.User, active: true)); tagCollection.Add(new Tag("machine", "The name of the computer (%machine%)", TagType.Machine, active: true)); path = MacroParser.ParseTags(path, tagCollection); 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); }
// Check the folders to make sure that each folder was included in the config file and the folder exists. private static void CheckAndCreateFolders() { if (string.IsNullOrEmpty(FileSystem.ScreenshotsFolder)) { FileSystem.ScreenshotsFolder = FileSystem.DefaultScreenshotsFolder; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nScreenshotsFolder=" + FileSystem.DefaultScreenshotsFolder); if (!FileSystem.DirectoryExists(FileSystem.DefaultScreenshotsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultScreenshotsFolder); } } if (string.IsNullOrEmpty(FileSystem.DebugFolder)) { FileSystem.DebugFolder = FileSystem.DefaultDebugFolder; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nDebugFolder=" + FileSystem.DefaultDebugFolder); if (!FileSystem.DirectoryExists(FileSystem.DefaultDebugFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultDebugFolder); } } if (string.IsNullOrEmpty(FileSystem.LogsFolder)) { FileSystem.LogsFolder = FileSystem.DefaultLogsFolder; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nLogsFolder=" + FileSystem.DefaultLogsFolder); if (!FileSystem.DirectoryExists(FileSystem.DefaultLogsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultLogsFolder); } } }
private void ShowScreenshotBySlideIndex() { textBoxLabel.Text = string.Empty; textBoxScreenshotTitle.Text = string.Empty; textBoxScreenshotFormat.Text = string.Empty; textBoxScreenshotWidth.Text = string.Empty; textBoxScreenshotHeight.Text = string.Empty; textBoxScreenshotDate.Text = string.Empty; textBoxScreenshotTime.Text = string.Empty; if (tabControlViews.TabCount > 0 && tabControlViews.SelectedTab != null) { TabPage selectedTabPage = tabControlViews.SelectedTab; ToolStrip toolStrip = (ToolStrip)selectedTabPage.Controls[selectedTabPage.Name + "toolStrip"]; ToolStripTextBox toolStripTextBox = (ToolStripTextBox)toolStrip.Items[selectedTabPage.Name + "toolStripTextBoxFilename"]; PictureBox pictureBox = (PictureBox)selectedTabPage.Controls[selectedTabPage.Name + "pictureBox"]; Screenshot selectedScreenshot = new Screenshot(); if (Slideshow.Index >= 0 && Slideshow.Index <= (Slideshow.Count - 1)) { Slideshow.SelectedSlide = (Slide)listBoxScreenshots.Items[Slideshow.Index]; if (selectedTabPage.Tag.GetType() == typeof(Screen)) { Screen screen = (Screen)selectedTabPage.Tag; selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, screen.ViewId); } if (selectedTabPage.Tag.GetType() == typeof(Region)) { Region region = (Region)selectedTabPage.Tag; selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, region.ViewId); } } string path = selectedScreenshot.Path; if (!string.IsNullOrEmpty(path)) { toolStripTextBox.Text = FileSystem.GetFileName(path); toolStripTextBox.ToolTipText = path; string dirName = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dirName)) { if (FileSystem.DirectoryExists(dirName) && FileSystem.FileExists(path)) { toolStripTextBox.BackColor = Color.PaleGreen; } else { toolStripTextBox.BackColor = Color.PaleVioletRed; toolStripTextBox.ToolTipText = $"Could not find or access image file at path \"{path}\""; } } pictureBox.Image = _screenCapture.GetImageByPath(path); if (pictureBox.Image != null) { textBoxLabel.Text = selectedScreenshot.Label; textBoxScreenshotTitle.Text = selectedScreenshot.WindowTitle; textBoxScreenshotFormat.Text = selectedScreenshot.Format.Name; textBoxScreenshotWidth.Text = pictureBox.Image.Width.ToString(); textBoxScreenshotHeight.Text = pictureBox.Image.Height.ToString(); textBoxScreenshotDate.Text = selectedScreenshot.Date; textBoxScreenshotTime.Text = selectedScreenshot.Time; } } else { toolStripTextBox.Text = string.Empty; toolStripTextBox.BackColor = Color.LightYellow; toolStripTextBox.ToolTipText = string.Empty; pictureBox.Image = null; } } }
/// <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); } }
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); } SettingCollection applicationSettingsCollection = new SettingCollection { Filepath = FileSystem.ApplicationSettingsFile }; applicationSettingsCollection.Save(); } 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); } SettingCollection userSettingsCollection = new SettingCollection { Filepath = FileSystem.ApplicationSettingsFile }; userSettingsCollection.Save(); } 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> /// Saves the captured bitmap image as a screenshot to an image file. /// </summary> /// <param name="path">The filepath of the image file to write to.</param> /// <param name="format">The format of the image file.</param> /// <param name="component">The component of the screenshot to be saved. This could be the active window or a screen.</param> /// <param name="screenshotType">The type of screenshot to save. This could be the active window, a region, or a screen.</param> /// <param name="jpegQuality">The JPEG quality setting for JPEG images being saved.</param> /// <param name="viewId">The unique identifier to identify a particular region or screen.</param> /// <param name="bitmap">The bitmap image to write to the image file.</param> /// <param name="label">The current label being used at the time of capture which we will apply to the screenshot object.</param> /// <param name="windowTitle">The title of the window being captured.</param> /// <param name="processName">The process name of the application being captured.</param> /// <param name="screenshotCollection">A collection of screenshot objects.</param> /// <returns>A boolean to determine if we successfully saved the screenshot.</returns> public bool SaveScreenshot(string path, ImageFormat format, int component, ScreenshotType screenshotType, int jpegQuality, Guid viewId, Bitmap bitmap, string label, string windowTitle, string processName, ScreenshotCollection screenshotCollection) { try { int filepathLengthLimit = Convert.ToInt32(Settings.Application.GetByKey("FilepathLengthLimit", DefaultSettings.FilepathLengthLimit).Value); bool optimizeScreenCapture = Convert.ToBoolean(Settings.Application.GetByKey("OptimizeScreenCapture", DefaultSettings.OptimizeScreenCapture).Value); if (!string.IsNullOrEmpty(path)) { if (path.Length > filepathLengthLimit) { Log.WriteMessage($"File path length exceeds the configured length of {filepathLengthLimit} characters so value was truncated. Correct the value for the FilepathLengthLimit application setting to prevent truncation"); path = path.Substring(0, filepathLengthLimit); } Log.WriteMessage("Attempting to write image to file at path \"" + path + "\""); // This is a normal path used in Windows (such as "C:\screenshots\"). if (!path.StartsWith(FileSystem.PathDelimiter)) { if (FileSystem.DriveReady(path)) { int lowDiskSpacePercentageThreshold = Convert.ToInt32(Settings.Application.GetByKey("LowDiskPercentageThreshold", DefaultSettings.LowDiskPercentageThreshold).Value); double freeDiskSpacePercentage = FileSystem.FreeDiskSpacePercentage(path); Log.WriteDebugMessage("Percentage of free disk space on drive for \"" + path + "\" is " + (int)freeDiskSpacePercentage + "% and low disk percentage threshold is set to " + lowDiskSpacePercentageThreshold + "%"); if (freeDiskSpacePercentage > lowDiskSpacePercentageThreshold) { string dirName = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dirName)) { if (!FileSystem.DirectoryExists(dirName)) { FileSystem.CreateDirectory(dirName); Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created"); } Screenshot lastScreenshotOfThisView = screenshotCollection.GetLastScreenshotOfView(viewId); Screenshot newScreenshotOfThisView = new Screenshot(windowTitle, DateTimeScreenshotsTaken) { ViewId = viewId, Path = path, Format = format, Component = component, ScreenshotType = screenshotType, ProcessName = processName + ".exe", Label = label }; if (optimizeScreenCapture) { newScreenshotOfThisView.Hash = GetMD5Hash(bitmap, format); if (lastScreenshotOfThisView == null || string.IsNullOrEmpty(lastScreenshotOfThisView.Hash) || !lastScreenshotOfThisView.Hash.Equals(newScreenshotOfThisView.Hash)) { screenshotCollection.Add(newScreenshotOfThisView); SaveToFile(path, format, jpegQuality, bitmap); } } else { screenshotCollection.Add(newScreenshotOfThisView); SaveToFile(path, format, jpegQuality, bitmap); } } } else { // There is not enough disk space on the drive so log an error message and change the system tray icon's colour to yellow. Log.WriteErrorMessage($"Unable to save screenshot due to lack of available disk space on drive for {path} (at " + freeDiskSpacePercentage + "%) which is lower than the LowDiskPercentageThreshold setting that is currently set to " + lowDiskSpacePercentageThreshold + "%"); bool stopOnLowDiskError = Convert.ToBoolean(Settings.Application.GetByKey("StopOnLowDiskError", DefaultSettings.StopOnLowDiskError).Value); if (stopOnLowDiskError) { Log.WriteErrorMessage("Running screen capture session has stopped because application setting StopOnLowDiskError was set to True when the available disk space on any drive was lower than the value of LowDiskPercentageThreshold"); ApplicationError = true; return(false); } ApplicationWarning = true; } } else { // Drive isn't ready so log an error message. Log.WriteErrorMessage($"Unable to save screenshot for \"{path}\" because the drive is not found or not ready"); } } else { // This is UNC network share path (such as "\\SERVER\screenshots\"). string dirName = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dirName)) { try { if (!FileSystem.DirectoryExists(dirName)) { FileSystem.CreateDirectory(dirName); Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created"); } Screenshot lastScreenshotOfThisView = screenshotCollection.GetLastScreenshotOfView(viewId); Screenshot newScreenshotOfThisView = new Screenshot(windowTitle, DateTimeScreenshotsTaken) { ViewId = viewId, Path = path, Format = format, Component = component, ScreenshotType = screenshotType, ProcessName = processName + ".exe", Label = label }; if (optimizeScreenCapture) { newScreenshotOfThisView.Hash = GetMD5Hash(bitmap, format); if (lastScreenshotOfThisView == null || string.IsNullOrEmpty(lastScreenshotOfThisView.Hash) || !lastScreenshotOfThisView.Hash.Equals(newScreenshotOfThisView.Hash)) { screenshotCollection.Add(newScreenshotOfThisView); SaveToFile(path, format, jpegQuality, bitmap); } } else { screenshotCollection.Add(newScreenshotOfThisView); SaveToFile(path, format, jpegQuality, bitmap); } } catch (Exception) { // We don't want to stop the screen capture session at this point because there may be other components that // can write to their given paths. If this is a misconfigured path for a particular component then just log an error. Log.WriteErrorMessage($"Cannot write to \"{path}\" because the user may not have the appropriate permissions to access the path"); } } } } return(true); } catch (System.IO.PathTooLongException ex) { Log.WriteErrorMessage($"The path is too long. I see the path is \"{path}\" but the length exceeds what Windows can handle so the file could not be saved. There is probably an exception error from Windows explaining why"); Log.WriteExceptionMessage("ScreenCapture::SaveScreenshot", ex); // This shouldn't be an error that should stop a screen capture session. return(true); } catch (Exception ex) { Log.WriteExceptionMessage("ScreenCapture::SaveScreenshot", ex); return(false); } }
/// <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); } }
private void CheckAndCreateFiles(Security security, ScreenCapture screenCapture, Log log) { 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.SmtpSettingsFile)) { FileSystem.SmtpSettingsFile = FileSystem.DefaultSmtpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSMTPSettingsFile=" + FileSystem.DefaultSmtpSettingsFile); if (!FileSystem.DirectoryExists(FileSystem.DefaultSettingsFolder)) { FileSystem.CreateDirectory(FileSystem.DefaultSettingsFolder); } } if (string.IsNullOrEmpty(FileSystem.SftpSettingsFile)) { FileSystem.SftpSettingsFile = FileSystem.DefaultSftpSettingsFile; FileSystem.AppendToFile(FileSystem.ConfigFile, "\nSFTPSettingsFile=" + FileSystem.DefaultSftpSettingsFile); 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.User.Load(Settings, FileSystem); Settings.SMTP.Load(Settings, FileSystem); Settings.SFTP.Load(Settings, FileSystem); Settings.VersionManager.OldApplicationSettings = Settings.Application.Clone(); Settings.VersionManager.OldUserSettings = Settings.User.Clone(); Settings.UpgradeApplicationSettings(Settings.Application, FileSystem); Settings.UpgradeUserSettings(Settings.User, screenCapture, security, FileSystem); Settings.UpgradeSmtpSettings(Settings.SMTP, FileSystem); Settings.UpgradeSftpSettings(Settings.SFTP, FileSystem); if (string.IsNullOrEmpty(FileSystem.ScreenshotsFile)) { ImageFormatCollection imageFormatCollection = new ImageFormatCollection(); ScreenCollection screenCollection = new ScreenCollection(); ScreenshotCollection screenshotCollection = new ScreenshotCollection(imageFormatCollection, screenCollection, screenCapture, this, FileSystem, log); screenshotCollection.SaveToXmlFile(this); } 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(this, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.RegionsFile)) { RegionCollection regionCollection = new RegionCollection(); regionCollection.SaveToXmlFile(Settings, FileSystem, log); } 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(), this, MacroParser, screenCapture, FileSystem, log); } 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(this, FileSystem, log); } if (string.IsNullOrEmpty(FileSystem.TagsFile)) { // Loading tags will automatically create the default tags and add them to the collection. MacroTagCollection tagCollection = new MacroTagCollection(); tagCollection.LoadXmlFileAndAddTags(this, MacroParser, FileSystem, log); } 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(this, FileSystem, log); } }
/// <summary> /// Saves the captured bitmap image as a screenshot to an image file. /// </summary> /// <param name="path">The filepath of the image file to write to.</param> /// <param name="format">The format of the image file.</param> /// <param name="component">The component of the screenshot to be saved. This could be the active window or a screen.</param> /// <param name="screenshotType">The type of screenshot to save. This could be the active window, a region, or a screen.</param> /// <param name="jpegQuality">The JPEG quality setting for JPEG images being saved.</param> /// <param name="viewId">The unique identifier to identify a particular region or screen.</param> /// <param name="bitmap">The bitmap image to write to the image file.</param> /// <param name="label">The current label being used at the time of capture which we will apply to the screenshot object.</param> /// <param name="windowTitle">The title of the window being captured.</param> /// <param name="processName">The process name of the application being captured.</param> /// <param name="screenshotCollection">A collection of screenshot objects.</param> /// <returns>A boolean to determine if we successfully saved the screenshot.</returns> public bool SaveScreenshot(string path, ImageFormat format, int component, ScreenshotType screenshotType, int jpegQuality, Guid viewId, Bitmap bitmap, string label, string windowTitle, string processName, ScreenshotCollection screenshotCollection) { try { if (!string.IsNullOrEmpty(path) && path.Length >= MAX_WINDOWS_PATH_LENGTH) { // We just want to log a normal message and not stop the screen capture session because we want to continue // for other components that are using paths which are still valid. Log.WriteMessage($"No path available at \"{path}\" or path length exceeds {MAX_WINDOWS_PATH_LENGTH} characters"); } if (!string.IsNullOrEmpty(path) && path.Length < MAX_WINDOWS_PATH_LENGTH) { Log.WriteDebugMessage("Attempting to write image to file at path \"" + path + "\""); // This is a normal path used in Windows (such as "C:\screenshots\"). if (!path.StartsWith(FileSystem.PathDelimiter)) { if (FileSystem.DriveReady(path)) { int lowDiskSpacePercentageThreshold = Convert.ToInt32(Settings.Application.GetByKey("LowDiskPercentageThreshold", defaultValue: 1).Value); double freeDiskSpacePercentage = FileSystem.FreeDiskSpacePercentage(path); Log.WriteDebugMessage("Percentage of free disk space on drive for \"" + path + "\" is " + (int)freeDiskSpacePercentage + "% and low disk percentage threshold is set to " + lowDiskSpacePercentageThreshold + "%"); if (freeDiskSpacePercentage > lowDiskSpacePercentageThreshold) { string dirName = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dirName)) { if (!FileSystem.DirectoryExists(dirName)) { FileSystem.CreateDirectory(dirName); Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created"); } Screenshot screenshot = new Screenshot(DateTimeScreenshotsTaken, path, format, component, screenshotType, windowTitle, processName, viewId, label); screenshotCollection.Add(screenshot); SaveToFile(path, format, jpegQuality, bitmap); } } else { // There is not enough disk space on the drive so stop the current running screen capture session and log an error message. Log.WriteErrorMessage($"Unable to save screenshot due to lack of available disk space on drive for {path} (at " + freeDiskSpacePercentage + "%) which is lower than the LowDiskPercentageThreshold setting that is currently set to " + lowDiskSpacePercentageThreshold + "% so screen capture session is being stopped"); return(false); } } else { // Drive isn't ready so log an error message. Log.WriteErrorMessage($"Unable to save screenshot for \"{path}\" because the drive is not found or not ready"); } } else { // This is UNC network share path (such as "\\SERVER\screenshots\"). string dirName = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dirName)) { try { if (!FileSystem.DirectoryExists(dirName)) { FileSystem.CreateDirectory(dirName); Log.WriteDebugMessage("Directory \"" + dirName + "\" did not exist so it was created"); } screenshotCollection.Add(new Screenshot(DateTimeScreenshotsTaken, path, format, component, screenshotType, windowTitle, processName, viewId, label)); SaveToFile(path, format, jpegQuality, bitmap); } catch (Exception) { // We don't want to stop the screen capture session at this point because there may be other components that // can write to their given paths. If this is a misconfigured path for a particular component then just log an error. Log.WriteErrorMessage($"Cannot write to \"{path}\" because the user may not have the appropriate permissions to access the path"); } } } } return(true); } catch (Exception ex) { Log.WriteExceptionMessage("ScreenCapture::SaveScreenshot", ex); return(false); } }
/// <summary> /// Writes a message (whether it be an error or just a general message) and the exception (if any). /// </summary> /// <param name="message">The message to write.</param> /// <param name="writeError">Determines if we write the message to the error file in the debug folder.</param> /// <param name="ex">The exception received from the .NET Framework.</param> private void Write(string message, bool writeError, Exception ex) { try { _mutexWriteFile.WaitOne(); string appVersion = "[(v" + _settings.ApplicationVersion + ") "; if (string.IsNullOrEmpty(_fileSystem.DebugFolder)) { _fileSystem.DebugFolder = AppDomain.CurrentDomain.BaseDirectory + @"!autoscreen" + _fileSystem.PathDelimiter + "debug" + _fileSystem.PathDelimiter; } if (string.IsNullOrEmpty(_fileSystem.LogsFolder)) { _fileSystem.LogsFolder = _fileSystem.DebugFolder + "logs" + _fileSystem.PathDelimiter; } if (!_fileSystem.DirectoryExists(_fileSystem.DebugFolder)) { _fileSystem.CreateDirectory(_fileSystem.DebugFolder); } if (!_fileSystem.DirectoryExists(_fileSystem.LogsFolder)) { _fileSystem.CreateDirectory(_fileSystem.LogsFolder); } // These are just general errors from the application so, if we have one, then write it out to the error file. if (writeError) { _fileSystem.AppendToFile(_fileSystem.DebugFolder + _fileSystem.ErrorFile, appVersion + DateTime.Now.ToString(_macroParser.DateFormat + " " + _macroParser.TimeFormat) + "] ERROR: " + message); } // Log any exception errors we encounter. if (ex != null) { string exceptionError = appVersion + DateTime.Now.ToString(_macroParser.DateFormat + " " + _macroParser.TimeFormat) + "] " + message + " - Exception Message: " + ex.Message + "\nInner Exception: " + (ex.InnerException != null ? ex.InnerException.Message : string.Empty) + "\nSource: " + ex.Source + "\nStack Trace: " + ex.StackTrace; _fileSystem.AppendToFile(_fileSystem.DebugFolder + _fileSystem.ErrorFile, exceptionError); _fileSystem.AppendToFile(_fileSystem.LogsFolder + _fileSystem.LogFile + _extension, exceptionError); // If we encounter an exception error it's probably better to just error out on exit // but we'll let the user decide if that's what they really want to do. if (_settings.Application == null || Convert.ToBoolean(_settings.Application.GetByKey("ExitOnError", _settings.DefaultSettings.ExitOnError).Value)) { Environment.Exit(1); } } else { // Write to the main log file. _fileSystem.AppendToFile(_fileSystem.LogsFolder + _fileSystem.LogFile + _extension, appVersion + DateTime.Now.ToString(_macroParser.DateFormat + " " + _macroParser.TimeFormat) + "] " + message); // Create a date-stamped directory if it does not already exist. if (!_fileSystem.DirectoryExists(_fileSystem.LogsFolder + DateTime.Now.ToString(_macroParser.DateFormat))) { _fileSystem.CreateDirectory(_fileSystem.LogsFolder + DateTime.Now.ToString(_macroParser.DateFormat)); } // Write to a log file within a directory representing the day when the message was logged. _fileSystem.AppendToFile(_fileSystem.LogsFolder + DateTime.Now.ToString(_macroParser.DateFormat) + _fileSystem.PathDelimiter + _fileSystem.LogFile + "_" + DateTime.Now.ToString(_macroParser.DateFormat) + ".txt", appVersion + DateTime.Now.ToString(_macroParser.DateFormat + " " + _macroParser.TimeFormat) + "] " + message); } } finally { _mutexWriteFile.ReleaseMutex(); } }
private void ShowScreenshotBySlideIndex() { _formScreenshotMetadata.textBoxLabel.Text = string.Empty; _formScreenshotMetadata.textBoxScreenshotTitle.Text = string.Empty; _formScreenshotMetadata.textBoxScreenshotFormat.Text = string.Empty; _formScreenshotMetadata.textBoxScreenshotWidth.Text = string.Empty; _formScreenshotMetadata.textBoxScreenshotHeight.Text = string.Empty; _formScreenshotMetadata.textBoxScreenshotDate.Text = string.Empty; _formScreenshotMetadata.textBoxScreenshotTime.Text = string.Empty; // Dashboard if (tabControlViews.TabCount > 0 && tabControlViews.SelectedTab != null && tabControlViews.SelectedTab.Name.Equals("tabPageDashboard")) { FlowLayoutPanel flowLayoutPanel = (FlowLayoutPanel)tabControlViews.SelectedTab.Controls["flowLayoutPanel"]; int i = 1; foreach (GroupBox groupBox in flowLayoutPanel.Controls) { PictureBox pictureBox = (PictureBox)groupBox.Controls["pictureBox" + i]; Screenshot selectedScreenshot = new Screenshot(); if (Slideshow.Index >= 0 && Slideshow.Index <= (Slideshow.Count - 1)) { Slideshow.SelectedSlide = (Slide)listBoxScreenshots.Items[Slideshow.Index]; if (groupBox.Tag.GetType() == typeof(Screen)) { Screen screen = (Screen)groupBox.Tag; selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, screen.ViewId); } if (groupBox.Tag.GetType() == typeof(Region)) { Region region = (Region)groupBox.Tag; selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, region.ViewId); } if (selectedScreenshot.ViewId.Equals(Guid.Empty)) { // *** Auto Screen Capture - Region Select / Auto Save *** selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, Guid.Empty); } } if (!string.IsNullOrEmpty(selectedScreenshot.Path)) { pictureBox.Image = _screenCapture.GetImageByPath(selectedScreenshot.Path); } else { pictureBox.Image = null; } i++; } return; } // Screens and Regions if (tabControlViews.TabCount > 0 && tabControlViews.SelectedTab != null) { TabPage selectedTabPage = tabControlViews.SelectedTab; ToolStrip toolStrip = (ToolStrip)selectedTabPage.Controls[selectedTabPage.Name + "toolStrip"]; ToolStripTextBox toolStripTextBox = (ToolStripTextBox)toolStrip.Items[selectedTabPage.Name + "toolStripTextBoxFilename"]; PictureBox pictureBox = (PictureBox)selectedTabPage.Controls[selectedTabPage.Name + "pictureBox"]; Screenshot selectedScreenshot = new Screenshot(); if (Slideshow.Index >= 0 && Slideshow.Index <= (Slideshow.Count - 1)) { Slideshow.SelectedSlide = (Slide)listBoxScreenshots.Items[Slideshow.Index]; if (selectedTabPage.Tag.GetType() == typeof(Screen)) { Screen screen = (Screen)selectedTabPage.Tag; selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, screen.ViewId); } if (selectedTabPage.Tag.GetType() == typeof(Region)) { Region region = (Region)selectedTabPage.Tag; selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, region.ViewId); } if (selectedScreenshot.ViewId.Equals(Guid.Empty)) { // *** Auto Screen Capture - Region Select / Auto Save *** selectedScreenshot = _screenshotCollection.GetScreenshot(Slideshow.SelectedSlide.Name, Guid.Empty); } } string path = selectedScreenshot.Path; if (!string.IsNullOrEmpty(path)) { toolStripTextBox.Text = FileSystem.GetFileName(path); toolStripTextBox.ToolTipText = path; string dirName = FileSystem.GetDirectoryName(path); if (!string.IsNullOrEmpty(dirName)) { if (FileSystem.DirectoryExists(dirName) && FileSystem.FileExists(path)) { toolStripTextBox.BackColor = Color.PaleGreen; } else { toolStripTextBox.BackColor = Color.PaleVioletRed; toolStripTextBox.ToolTipText = $"Could not find or access image file at path \"{path}\""; } } pictureBox.Image = _screenCapture.GetImageByPath(path); if (pictureBox.Image != null) { _formScreenshotMetadata.textBoxLabel.Text = selectedScreenshot.Label; _formScreenshotMetadata.textBoxScreenshotTitle.Text = selectedScreenshot.WindowTitle; _formScreenshotMetadata.textBoxScreenshotFormat.Text = selectedScreenshot.Format.Name; _formScreenshotMetadata.textBoxScreenshotWidth.Text = pictureBox.Image.Width.ToString(); _formScreenshotMetadata.textBoxScreenshotHeight.Text = pictureBox.Image.Height.ToString(); _formScreenshotMetadata.textBoxScreenshotDate.Text = selectedScreenshot.Date; _formScreenshotMetadata.textBoxScreenshotTime.Text = selectedScreenshot.Time; } } else { toolStripTextBox.Text = string.Empty; toolStripTextBox.BackColor = Color.LightYellow; toolStripTextBox.ToolTipText = string.Empty; pictureBox.Image = null; } } }
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(); } }