Пример #1
0
        /// <param name="uri">should contain a valid Uri</param>
        /// <returns>true/false if the process started or not</returns>
        public static bool TryProcessStart(Uri uri)
        {
            if (uri == null)
            {
                return(false);
            }
            ProcessStartInfo processStartInfo = new ProcessStartInfo(uri.AbsoluteUri);

            return(ProcessExecution.TryProcessStart(processStartInfo));
        }
Пример #2
0
        /// <param name="filepath">should contain a valid file path</param>
        /// <returns>true/false if the process started or not</returns>
        public static bool TryProcessStart(string filePath)
        {
            if (File.Exists(filePath) == false)
            {
                // Don't even try to start the process if the file doesn't exist.
                return(false);
            }
            ProcessStartInfo processStartInfo = new ProcessStartInfo
            {
                FileName = filePath
            };

            return(ProcessExecution.TryProcessStart(processStartInfo));
        }
Пример #3
0
        /// Try to start the Windows file explorer on the provided folder path.
        /// <param name="folderpath">should contain a valid file path, as its otherwise aborted</param>
        /// <returns>true/false if the process started or not</returns>
        public static bool TryProcessStartUsingFileExplorer(string folderPath)
        {
            if (Directory.Exists(folderPath) == false)
            {
                // Don't even try to start the process if the file doesn't exist.
                return(false);
            }
            ProcessStartInfo processStartInfo = new ProcessStartInfo
            {
                FileName  = "explorer.exe",
                Arguments = folderPath
            };

            return(ProcessExecution.TryProcessStart(processStartInfo));
        }
Пример #4
0
        /// <summary>
        /// Checks for updates by comparing the current version number of Timelapse or the Editor with a version stored on the Timelapse website in an xml file in either
        /// timelapse_version.xml or timelapse_template_version.xml (as specified in the latestVersionAddress).
        /// Displays a notification with recent update information
        /// Optionally displays a message to the user (if showNoUpdatesMessage is false) indicating the status
        /// </summary>
        /// <param name="showNoUpdatesMessage"></param>
        /// <returns>True if an update is available, else false</returns>
        public bool TryCheckForNewVersionAndDisplayResultsAsNeeded(bool showNoUpdatesMessage)
        {
            string  url = String.Empty;         // THE URL where the new version is located
            Version latestVersionNumber = null; // if a new version is available, store the new version number here

            XmlReader reader = null;

            try
            {
                // This pattern follows recommended correction to CA3075: Insecure DTD Processing
                // provide the XmlReader with the URL of our xml document
                XmlReaderSettings settings = new XmlReaderSettings()
                {
                    XmlResolver = null
                };
                reader = XmlReader.Create(this.latestVersionAddress.AbsoluteUri, settings);
                reader.MoveToContent(); // skip the junk at the beginning

                // As the XmlTextReader moves only forward, we save current xml element name in elementName variable.
                // When we parse a  text node, we refer to elementName to check what was the node name
                string elementName = String.Empty;
                // Check if the xml starts with a <timelapse> Element
                if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == Constant.VersionXml.Timelapse))
                {
                    // Read the various elements and their associated contents
                    while (reader.Read())
                    {
                        // when we find an element node, we remember its name
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            elementName = reader.Name;
                        }
                        else
                        {
                            // for text nodes...
                            if ((reader.NodeType == XmlNodeType.Text) && reader.HasValue)
                            {
                                // we check what the name of the node was
                                switch (elementName)
                                {
                                case Constant.VersionXml.Version:
                                    // we keep the version info in xxx.xxx.xxx.xxx format as the Version class does the  parsing for us
                                    latestVersionNumber = new Version(reader.Value);
                                    break;

                                case Constant.VersionXml.Url:
                                    url = reader.Value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            // get the running version
            Version currentVersionNumber = VersionChecks.GetTimelapseCurrentVersionNumber();

            // compare the versions
            if (currentVersionNumber < latestVersionNumber)
            {
                NewVersionNotification newVersionNotification = new NewVersionNotification(this.window, this.applicationName, currentVersionNumber, latestVersionNumber);

                bool?result = newVersionNotification.ShowDialog();
                if (result == true)
                {
                    // navigate the default web browser to our app homepage (the url comes from the xml content)
                    ProcessExecution.TryProcessStart(new Uri(url));
                }
            }
            else if (showNoUpdatesMessage)
            {
                Dialogs.NoUpdatesAvailableDialog(Application.Current.MainWindow, this.applicationName, currentVersionNumber);
            }
            return(true);
        }