Exemplo n.º 1
0
 /// <summary>
 /// Download castUrl resource and parse it
 /// </summary>
 public bool DownloadAndParse()
 {
     try
     {
         _logWriter.PrintMessage("Downloading app cast data...");
         var  appcast         = _dataDownloader.DownloadAndGetAppCastData(_castUrl);
         var  signatureNeeded = Utilities.IsSignatureNeeded(_signatureVerifier.SecurityMode, _signatureVerifier.HasValidKeyInformation(), false);
         bool isValidAppcast  = true;
         if (signatureNeeded)
         {
             _logWriter.PrintMessage("Downloading app cast signature data...");
             var signature = "";
             var extension = SignatureFileExtension?.TrimStart('.') ?? "signature";
             try
             {
                 signature = _dataDownloader.DownloadAndGetAppCastData(_castUrl + "." + extension);
             }
             catch (Exception e)
             {
                 _logWriter.PrintMessage("Error reading app cast {0}.{2}: {1} ", _castUrl, e.Message, extension);
             }
             if (string.IsNullOrWhiteSpace(signature))
             {
                 // legacy: check for .dsa file
                 try
                 {
                     signature = _dataDownloader.DownloadAndGetAppCastData(_castUrl + ".dsa");
                 }
                 catch (Exception e)
                 {
                     _logWriter.PrintMessage("Error reading app cast {0}.dsa: {1} ", _castUrl, e.Message);
                 }
             }
             isValidAppcast = VerifyAppCast(appcast, signature);
         }
         if (isValidAppcast)
         {
             _logWriter.PrintMessage("Appcast is valid! Parsing...");
             ParseAppCast(appcast);
             return(true);
         }
     }
     catch (Exception e)
     {
         _logWriter.PrintMessage("Error reading app cast {0}: {1} ", _castUrl, e.Message);
     }
     _logWriter.PrintMessage("Appcast is not valid");
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the available updates.
        /// </summary>
        /// <returns>List&lt;AppCastItem&gt;.</returns>
        public List <AppCastItem> GetAvailableUpdates()
        {
            Version installed          = new Version(config.InstalledVersion);
            var     signatureNeeded    = Utilities.IsSignatureNeeded(signatureVerifier.SecurityMode, signatureVerifier.HasValidKeyInformation(), false);
            var     allowAlphaVersions = updaterService.Get().CheckForPrerelease;

            var results = appCast.Items.Where((item) =>
            {
                // Filter out prerelease tags if specified as such
                if (!allowAlphaVersions && prereleaseVersionTags.Any(p => item.Title.Contains(p, StringComparison.OrdinalIgnoreCase)))
                {
                    return(false);
                }
                // Filter out by os
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // Filter out if using portable or installer version
                    var fileName = item.DownloadLink.Split("/", StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
                    if (!item.IsWindowsUpdate)
                    {
                        return(false);
                    }
                    else if (IsInstallerVersion && !fileName.Contains("setup", StringComparison.OrdinalIgnoreCase))
                    {
                        return(false);
                    }
                    else if (!IsInstallerVersion && fileName.Contains("setup", StringComparison.OrdinalIgnoreCase))
                    {
                        return(false);
                    }
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && !item.IsMacOSUpdate)
                {
                    return(false);
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !item.IsLinuxUpdate)
                {
                    return(false);
                }
                // Base validation stuff
                if (new Version(item.Version).CompareTo(installed) <= 0)
                {
                    return(false);
                }
                if (signatureNeeded && string.IsNullOrEmpty(item.DownloadSignature) && !string.IsNullOrEmpty(item.DownloadLink))
                {
                    return(false);
                }
                return(true);
            }).ToList();

            return(results);
        }