Exemple #1
0
        /// <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);
            }
        }
Exemple #2
0
        /// <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);
            }
        }
Exemple #3
0
        /// <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);
            }
        }
Exemple #4
0
        /// <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);
            }
        }
        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;
                }
            }
        }
Exemple #6
0
        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;
                }
            }
        }