Ejemplo n.º 1
0
        /// <summary>
        /// Looks for newer versions of the software than the currently known version.
        /// </summary>
        /// <returns>Returns an AvailableSoftware instance with the information
        /// that was retrieved from the net.</returns>
        public override AvailableSoftware searchForNewer()
        {
            logger.Debug("Searching for newer version of Thunderbird (" + languageCode + ")...");
            string newerVersion = determineNewestVersion();

            if (string.IsNullOrWhiteSpace(newerVersion))
            {
                return(null);
            }
            var currentInfo   = knownInfo();
            var newTriple     = new versions.Triple(newerVersion);
            var currentTriple = new versions.Triple(currentInfo.newestVersion);

            if (newerVersion == currentInfo.newestVersion || newTriple < currentTriple)
            {
                // fallback to known information
                return(currentInfo);
            }
            string[] newerChecksums = determineNewestChecksums(newerVersion);
            if (null == newerChecksums || newerChecksums.Length != 2 ||
                string.IsNullOrWhiteSpace(newerChecksums[0]) ||
                string.IsNullOrWhiteSpace(newerChecksums[1]))
            {
                return(null);
            }
            // replace all stuff
            string oldVersion = currentInfo.newestVersion;

            currentInfo.newestVersion            = newerVersion;
            currentInfo.install32Bit.downloadUrl = currentInfo.install32Bit.downloadUrl.Replace(oldVersion, newerVersion);
            currentInfo.install32Bit.checksum    = newerChecksums[0];
            currentInfo.install64Bit.downloadUrl = currentInfo.install64Bit.downloadUrl.Replace(oldVersion, newerVersion);
            currentInfo.install64Bit.checksum    = newerChecksums[1];
            return(currentInfo);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Looks for newer versions of the software than the currently known version.
        /// </summary>
        /// <returns>Returns an AvailableSoftware instance with the information
        /// that was retrieved from the net.</returns>
        public override AvailableSoftware searchForNewer()
        {
            logger.Debug("Searching for newer version of WinSCP...");
            string htmlCode = null;

            using (var client = new WebClient())
            {
                try
                {
                    htmlCode = client.DownloadString("https://winscp.net/eng/download.php");
                }
                catch (Exception ex)
                {
                    logger.Warn("Exception occurred while checking for newer version of WinSCP: " + ex.Message);
                    return(null);
                }
                client.Dispose();
            }

            Regex reExe    = new Regex("WinSCP\\-[1-9]+\\.[0-9]+\\.[0-9]+\\-Setup\\.exe");
            Match matchExe = reExe.Match(htmlCode);

            if (!matchExe.Success)
            {
                return(null);
            }
            // extract new version number
            string newVersion = matchExe.Value.Replace("WinSCP-", "").Replace("-Setup.exe", "");

            versions.Triple newTriple = new versions.Triple(newVersion);
            versions.Triple oldTriple = new versions.Triple(knownInfo().newestVersion);
            if (newTriple < oldTriple)
            {
                return(null);
            }
            // version number should match usual scheme, e.g. 5.x.y, where x and y are digits
            Regex version = new Regex("^[1-9]+\\.[0-9]+\\.[0-9]+$");

            if (!version.IsMatch(newVersion))
            {
                return(null);
            }

            // Readme (e.g. https://winscp.net/download/WinSCP-5.9.5-ReadMe.txt) contains hash.
            htmlCode = null;
            using (var client = new WebClient())
            {
                try
                {
                    htmlCode = client.DownloadString("https://winscp.net/download/WinSCP-" + newVersion + "-ReadMe.txt");
                }
                catch (Exception ex)
                {
                    logger.Warn("Exception occurred while checking for newer version of WinSCP: " + ex.Message);
                    return(null);
                }
                client.Dispose();
            } // using
            // extract hash - .exe occurs first, so first hash is the one we want
            Regex hash      = new Regex("SHA\\-256\\: [0-9a-f]{64}");
            Match matchHash = hash.Match(htmlCode);

            if (!matchHash.Success)
            {
                return(null);
            }
            string newHash = matchHash.Value.Replace("SHA-256: ", "").Trim();

            // The "file" https://winscp.net/download/WinSCP-5.9.5-Setup.exe or
            // similar is just a HTML page that starts the download of the real
            // file after a few seconds, so we have to parse the direct link of
            // the download and use that.
            htmlCode = null;
            using (var client = new WebClient())
            {
                try
                {
                    htmlCode = client.DownloadString("https://winscp.net/download/WinSCP-" + newVersion + "-Setup.exe");
                }
                catch (Exception ex)
                {
                    logger.Warn("Exception occurred while checking for newer version of WinSCP: " + ex.Message);
                    return(null);
                }
                client.Dispose();
            } // using

            // URL for direct download is something like
            // https://winscp.net/download/files/201704212143f42467fc64e4c84259bce4a07a98edbd/WinSCP-5.9.5-Setup.exe,
            // where the middle part (date plus random MD5 hash?) varies.
            Regex downloadUrl = new Regex(Regex.Escape("https://winscp.net/download/files/")
                                          + "[0-9]{12}[0-9a-f]{32}" + "/WinSCP\\-" + Regex.Escape(newVersion)
                                          + "\\-Setup\\.exe");
            Match matchUrl = downloadUrl.Match(htmlCode);

            if (!matchUrl.Success)
            {
                return(null);
            }

            // construct new version information
            var newInfo = knownInfo();

            // replace version number - both as newest version and in URL for download
            newInfo.newestVersion            = newVersion;
            newInfo.install32Bit.downloadUrl = matchUrl.Value;
            newInfo.install32Bit.checksum    = newHash;
            return(newInfo);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Determines whether the detected software is older than the newest known software.
 /// </summary>
 /// <param name="detected">the corresponding detected software</param>
 /// <returns>Returns true, if the detected software version is older
 /// than the newest software version, thus needing an update.
 /// Returns false, if no update is necessary.</returns>
 public override bool needsUpdate(DetectedSoftware detected)
 {
     versions.Triple verDetected = new versions.Triple(detected.displayVersion);
     versions.Triple verNewest   = new versions.Triple(info().newestVersion);
     return(verNewest.CompareTo(verDetected) > 0);
 }