Beispiel #1
0
        public static ReleasePackage GetPreviousRelease(IEnumerable <ReleaseEntry> releaseEntries, IReleasePackage package, string targetDir, string prevReleasePath = null, IFullLogger log = null)
        {
            {
                if (releaseEntries == null || !releaseEntries.Any())
                {
                    return(null);
                }
                var first = releaseEntries
                            .Where(x => x.IsDelta == false).Where(x => x.IsDelta == false)
                            .Where(x => x.Version < package.ToSemanticVersion()).Where(x => x.Version < package.ToSemanticVersion())
                            .OrderByDescending(x => x.Version).OrderByDescending(x => x.Version)
                            .Select(x => new ReleasePackage(Path.Combine(targetDir, x.Filename), true))
                            .FirstOrDefault();

                if (first != null)
                {
                    var prevReleaseFilePath = Path.Combine(targetDir, first.SuggestedReleaseFileName);
                    if (!File.Exists(prevReleaseFilePath) && !string.IsNullOrEmpty(prevReleasePath))
                    {
                        IFileDownloader downloader;
                        if (Utility.IsHttpUrl(prevReleasePath))
                        {
                            downloader = new FileDownloader();
                        }
                        else if (Utility.IsFtpUrl(prevReleasePath))
                        {
                            downloader = new FtpFileDownloader();
                        }
                        else
                        {
                            return(null);
                        }

                        try
                        {
                            downloader.DownloadFile(Path.Combine(prevReleasePath, first.SuggestedReleaseFileName), prevReleaseFilePath, null);
                        }
                        catch (Exception)
                        {
                            return(null);
                        }
                    }

                    if (File.Exists(prevReleaseFilePath))
                    {
                        return(new ReleasePackage(prevReleaseFilePath, true));
                    }
                }

                return(null);
            }
        }
            public async Task DownloadReleases(string updateUrlOrPath, IEnumerable <ReleaseEntry> releasesToDownload, Action <int> progress = null, IFileDownloader urlDownloader = null)
            {
                progress = progress ?? (_ => { });
                if (urlDownloader == null && Utility.IsHttpUrl(updateUrlOrPath))
                {
                    urlDownloader = new FileDownloader();
                }
                else if (urlDownloader == null && Utility.IsFtpUrl(updateUrlOrPath))
                {
                    urlDownloader = new FtpFileDownloader();
                }
                var packagesDirectory = Path.Combine(rootAppDirectory, "packages");

                double current     = 0;
                double toIncrement = 100.0 / releasesToDownload.Count();

                if (Utility.IsHttpUrl(updateUrlOrPath) || Utility.IsFtpUrl(updateUrlOrPath))
                {
                    // From Internet
                    await releasesToDownload.ForEachAsync(async x => {
                        var targetFile   = Path.Combine(packagesDirectory, x.Filename);
                        double component = 0;
                        await downloadRelease(updateUrlOrPath, x, urlDownloader, targetFile, p => {
                            lock (progress) {
                                current  -= component;
                                component = toIncrement / 100.0 * p;
                                progress((int)Math.Round(current += component));
                            }
                        });

                        checksumPackage(x);
                    });
                }
                else
                {
                    // From Disk
                    await releasesToDownload.ForEachAsync(x => {
                        var targetFile = Path.Combine(packagesDirectory, x.Filename);

                        File.Copy(
                            Path.Combine(updateUrlOrPath, x.Filename),
                            targetFile,
                            true);

                        lock (progress) progress((int)Math.Round(current += toIncrement));
                        checksumPackage(x);
                    });
                }
            }