Esempio n. 1
0
        public string GetLatestVersion(bool ignorePrerelease)
        {
            IEnumerable <string> allVersions = null;

            if (DirectoryProxy.Exists(NugetSource))
            {
                var paketPrefix = "paket.";
                allVersions = DirectoryProxy.
                              EnumerateFiles(NugetSource, "paket.*.nupkg", SearchOption.TopDirectoryOnly).
                              Select(x => Path.GetFileNameWithoutExtension(x)).
                              // If the specified character isn't a digit, then the file
                              // likely contains the bootstrapper or paket.core
                              Where(x => x.Length > paketPrefix.Length && Char.IsDigit(x[paketPrefix.Length])).
                              Select(x => x.Substring(paketPrefix.Length));
            }
            else
            {
                var apiHelper         = new NugetApiHelper(PaketNugetPackageName, NugetSource);
                var versionRequestUrl = apiHelper.GetAllPackageVersions(!ignorePrerelease);
                var versions          = WebRequestProxy.DownloadString(versionRequestUrl);
                allVersions = versions.
                              Trim('[', ']').
                              Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).
                              Select(x => x.Trim('"'));
            }
            var latestVersion = allVersions.
                                Select(SemVer.Create).
                                Where(x => !ignorePrerelease || (x.PreRelease == null)).
                                OrderBy(x => x).
                                LastOrDefault(x => !String.IsNullOrWhiteSpace(x.Original));

            return(latestVersion != null ? latestVersion.Original : String.Empty);
        }
Esempio n. 2
0
        public void DownloadVersion(string latestVersion, string target)
        {
            var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource);

            const string paketNupkgFile         = "paket.latest.nupkg";
            const string paketNupkgFileTemplate = "paket.{0}.nupkg";

            var paketDownloadUrl = apiHelper.GetLatestPackage();
            var paketFile        = paketNupkgFile;

            if (!String.IsNullOrWhiteSpace(latestVersion))
            {
                paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion);
                paketFile        = String.Format(paketNupkgFileTemplate, latestVersion);
            }

            var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName());

            DirectoryProxy.CreateDirectory(randomFullPath);
            var paketPackageFile = Path.Combine(randomFullPath, paketFile);

            if (DirectoryProxy.Exists(NugetSource))
            {
                if (String.IsNullOrWhiteSpace(latestVersion))
                {
                    latestVersion = GetLatestVersion(false);
                }
                var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion));

                ConsoleImpl.WriteDebug("Starting download from {0}", sourcePath);

                FileProxy.Copy(sourcePath, paketPackageFile);
            }
            else
            {
                ConsoleImpl.WriteDebug("Starting download from {0}", paketDownloadUrl);

                WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile);
            }

            FileProxy.ExtractToDirectory(paketPackageFile, randomFullPath);
            var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe");

            FileProxy.Copy(paketSourceFile, target, true);
            DirectoryProxy.Delete(randomFullPath, true);
        }
Esempio n. 3
0
        public void SelfUpdate(string latestVersion)
        {
            string target       = Assembly.GetExecutingAssembly().Location;
            var    localVersion = FileProxy.GetLocalFileVersion(target);

            if (localVersion.StartsWith(latestVersion))
            {
                ConsoleImpl.WriteDebug("Bootstrapper is up to date. Nothing to do.");
                return;
            }
            var apiHelper = new NugetApiHelper(PaketBootstrapperNugetPackageName, NugetSource);

            const string paketNupkgFile         = "paket.bootstrapper.latest.nupkg";
            const string paketNupkgFileTemplate = "paket.bootstrapper.{0}.nupkg";
            var          getLatestFromNugetUrl  = apiHelper.GetLatestPackage();

            var paketDownloadUrl = getLatestFromNugetUrl;
            var paketFile        = paketNupkgFile;

            if (!String.IsNullOrWhiteSpace(latestVersion))
            {
                paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion);
                paketFile        = String.Format(paketNupkgFileTemplate, latestVersion);
            }

            var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName());

            DirectoryProxy.CreateDirectory(randomFullPath);
            var paketPackageFile = Path.Combine(randomFullPath, paketFile);

            if (DirectoryProxy.Exists(NugetSource))
            {
                if (String.IsNullOrWhiteSpace(latestVersion))
                {
                    latestVersion = GetLatestVersion(false);
                }
                var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion));

                ConsoleImpl.WriteDebug("Starting download from {0}", sourcePath);

                FileProxy.Copy(sourcePath, paketPackageFile);
            }
            else
            {
                ConsoleImpl.WriteDebug("Starting download from {0}", paketDownloadUrl);

                WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile);
            }

            FileProxy.ExtractToDirectory(paketPackageFile, randomFullPath);

            var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.bootstrapper.exe");
            var renamedPath     = BootstrapperHelper.GetTempFile("oldBootstrapper");

            try
            {
                FileProxy.FileMove(target, renamedPath);
                FileProxy.FileMove(paketSourceFile, target);
                ConsoleImpl.WriteDebug("Self update of bootstrapper was successful.");
            }
            catch (Exception)
            {
                ConsoleImpl.WriteDebug("Self update failed. Resetting bootstrapper.");
                FileProxy.FileMove(renamedPath, target);
                throw;
            }
            DirectoryProxy.Delete(randomFullPath, true);
        }