Пример #1
0
        /// <summary>
        /// Checks chocolatey for updates of this instance.
        /// </summary>
        public void Update()
        {
            var info = new ChocolateyInfo(Packagename);

            if (info.Version > new Version(Version) && ChocolateySupport)
            {
                if (!string.IsNullOrEmpty(info.Powershell.URL86))
                {
                    ChocolateyDownloader.StartDownload(info.Powershell.URL86, $"{BasePath}{Executable}", Packagename);
                }

                if (!string.IsNullOrEmpty(info.Powershell.URL64))
                {
                    ChocolateyDownloader.StartDownload(info.Powershell.URL64, $"{BasePath}{Executablex64}",
                                                       $"{Packagename} x64");
                }

                Version = info.Version.ToString();
                Save(BasePath + FileName);
                NLogger.Debug($"{Packagename} is being updated.");
            }
            else
            {
                NLogger.Debug($"{Packagename} does not need updates");
            }
        }
Пример #2
0
        public static void StartDownload(string url, string path, string packagename = "")
        {
            ChocolateyDownloader downloader = new ChocolateyDownloader {
                PackageName = Utils.FirstCharToUpper(packagename)
            };

            if (DownloadProgressBar == null)
            {
                DownloadProgressBar = new ProgressBar(1, "Downloading", DefaultStyle);
            }
            else
            {
                DownloadProgressBar.UpdateMaxTicks(DownloadProgressBar.MaxTicks + 1);
            }

            #region Events
            downloader.WebHandler.DownloadProgressChanged += delegate(object b, DownloadProgressChangedEventArgs e)
            {
                downloader.ProgressBar.CurrentTick = (int)e.BytesReceived;
            };

            downloader.WebHandler.DownloadFileCompleted += delegate
            {
                downloader.ProgressBar.Dispose();
                DownloadProgressBar.Tick();
                NLogger.Info($"Sucessfully downloaded {downloader.PackageName}");
            };
            #endregion

            downloader.ProgressBar = DownloadProgressBar.Spawn(Utils.GetDownloadSize(url), Utils.FirstCharToUpper(packagename), DefaultStyle);
            downloader.WebHandler.DownloadFileAsync(new Uri(url), path);
        }
Пример #3
0
        /// <summary>
        /// Downloads the specified packaged.
        /// </summary>
        /// <param name="path">The path to download to.</param>
        public void Download(string path = "")
        {
            var downloadDirectory     = string.IsNullOrEmpty(path) ? $"Downloads\\{PackageName}\\" : path;
            var fullDownloadDirectory = Directory.GetCurrentDirectory() + $"\\{downloadDirectory}";

            new Package(PackageName, ChocolateyInfo.Version.ToString(), true, ChocolateyInfo.Powershell.Argument,
                        $"{PackageName}.{ChocolateyInfo.FileType}", $"{PackageName}64.{ChocolateyInfo.FileType}", 0,
                        fullDownloadDirectory).Save($"{downloadDirectory}{PackageName}{Package.FileType}");

            try
            {
                ChocolateyDownloader.StartDownload(ChocolateyInfo.Powershell.URL86,
                                                   $"{downloadDirectory}{PackageName}.{ChocolateyInfo.FileType}", PackageName);
                ChocolateyDownloader.StartDownload(ChocolateyInfo.Powershell.URL64,
                                                   $"{downloadDirectory}{PackageName}64.{ChocolateyInfo.FileType}", $"{PackageName} x64");
            }
            catch (Exception e)
            {
                ChocolateyDownloader.DownloadProgressBar.Tick();
                _nLogger.Error($"{PackageName} failed to download. {e}");
            }
        }