Exemplo 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);
        }
Exemplo n.º 2
0
        public void SelfUpdate(string latestVersion)
        {
            var    executingAssembly = Assembly.GetExecutingAssembly();
            string exePath           = executingAssembly.Location;
            var    localVersion      = FileSystemProxy.GetLocalFileVersion(exePath);

            if (localVersion.StartsWith(latestVersion))
            {
                ConsoleImpl.WriteDebug("Bootstrapper is up to date. Nothing to do.");
                return;
            }

            var url = String.Format("https://github.com/fsprojects/Paket/releases/download/{0}/paket.bootstrapper.exe", latestVersion);

            ConsoleImpl.WriteDebug("Starting download of bootstrapper from {0}", url);

            string renamedPath     = BootstrapperHelper.GetTempFile("oldBootstrapper");
            string tmpDownloadPath = BootstrapperHelper.GetTempFile("newBootstrapper");

            WebRequestProxy.DownloadFile(url, tmpDownloadPath);

            try
            {
                FileSystemProxy.MoveFile(exePath, renamedPath);
                FileSystemProxy.MoveFile(tmpDownloadPath, exePath);
                ConsoleImpl.WriteDebug("Self update of bootstrapper was successful.");
            }
            catch (Exception)
            {
                ConsoleImpl.WriteDebug("Self update failed. Resetting bootstrapper.");
                FileSystemProxy.MoveFile(renamedPath, exePath);
                throw;
            }
        }
Exemplo n.º 3
0
        protected override void DownloadVersionCore(string latestVersion, string target, PaketHashFile hashfile)
        {
            string url = String.Format(Constants.PaketNupkgDownloadUrlTemplate, latestVersion);

            ConsoleImpl.WriteInfo("Starting download from {0}", url);

            var tmpFile = BootstrapperHelper.GetTempFile("paketnupkg");

            WebRequestProxy.DownloadFile(url, tmpFile);

            string packageName = Path.GetFileName(url);

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

            FileSystemProxy.CreateDirectory(randomFullPath);

            string packagePath = Path.Combine(randomFullPath, packageName);

            FileSystemProxy.CopyFile(tmpFile, packagePath, true);
            FileSystemProxy.DeleteFile(tmpFile);

            var installAsTool = new InstallKind.InstallAsTool(FileSystemProxy);

            installAsTool.Run(randomFullPath, target, latestVersion);

            FileSystemProxy.DeleteDirectory(randomFullPath, true);
        }
Exemplo n.º 4
0
        protected override void DownloadVersionCore(string latestVersion, string target, PaketHashFile hashfile)
        {
            var url = String.Format(Constants.PaketExeDownloadUrlTemplate, latestVersion);

            ConsoleImpl.WriteInfo("Starting download from {0}", url);

            var tmpFile = BootstrapperHelper.GetTempFile("paket");

            WebRequestProxy.DownloadFile(url, tmpFile);

            if (!BootstrapperHelper.ValidateHash(FileSystemProxy, hashfile, latestVersion, tmpFile))
            {
                ConsoleImpl.WriteWarning("Hash of downloaded paket.exe is invalid, retrying once");

                WebRequestProxy.DownloadFile(url, tmpFile);

                if (!BootstrapperHelper.ValidateHash(FileSystemProxy, hashfile, latestVersion, tmpFile))
                {
                    ConsoleImpl.WriteWarning("Hash of downloaded paket.exe still invalid (Using the file anyway)");
                }
                else
                {
                    ConsoleImpl.WriteTrace("Hash of downloaded file successfully found in {0}", hashfile);
                }
            }
            else
            {
                ConsoleImpl.WriteTrace("Hash of downloaded file successfully found in {0}", hashfile);
            }

            FileSystemProxy.CopyFile(tmpFile, target, true);
            FileSystemProxy.DeleteFile(tmpFile);
        }
Exemplo n.º 5
0
        private string GetLatestStable()
        {
            var data    = WebRequestProxy.DownloadString(Constants.PaketReleasesLatestUrl);
            var title   = data.Substring(data.IndexOf("<title>") + 7, (data.IndexOf("</title>") + 8) - (data.IndexOf("<title>") + 7)); // grabs everything in the <title> tag
            var version = title.Split(' ')[1];                                                                                         // Release, 1.34.0, etc, etc, etc <-- the release number is the second part fo this split string

            return(version);
        }
Exemplo n.º 6
0
        protected override void DownloadHashFileCore(string latestVersion)
        {
            var url = String.Format(Constants.PaketCheckSumDownloadUrlTemplate, latestVersion);

            ConsoleImpl.WriteInfo("Starting download from {0}", url);

            var tmpFile = BootstrapperHelper.GetTempFile("paket-sha256.txt");

            WebRequestProxy.DownloadFile(url, tmpFile);
        }
Exemplo n.º 7
0
        protected override PaketHashFile DownloadHashFileCore(string latestVersion)
        {
            var url = string.Format(Constants.PaketCheckSumDownloadUrlTemplate, latestVersion);

            ConsoleImpl.WriteInfo("Starting download from {0}", url);

            var content = WebRequestProxy.DownloadString(url);

            return(PaketHashFile.FromString(content));
        }
Exemplo n.º 8
0
        public void DownloadVersion(string latestVersion, string target)
        {
            var url = String.Format(Constants.PaketExeDownloadUrlTemplate, latestVersion);

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

            var tmpFile = BootstrapperHelper.GetTempFile("paket");

            WebRequestProxy.DownloadFile(url, tmpFile);

            FileSystemProxy.CopyFile(tmpFile, target, true);
            FileSystemProxy.DeleteFile(tmpFile);
        }
Exemplo n.º 9
0
        public void DownloadVersion(string latestVersion, string target)
        {
            var url = String.Format(Constants.PaketExeDownloadUrlTemplate, latestVersion);

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

            var tmpFile = BootstrapperHelper.GetTempFile("paket");

            using (var fileStream = FileProxy.Create(tmpFile))
            {
                WebRequestProxy.DownloadFile(url, fileStream, HttpBufferSize);
            }

            FileProxy.Copy(tmpFile, target, true);
            FileProxy.Delete(tmpFile);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        private string GetLatestPrerelease()
        {
            var data = WebRequestProxy.DownloadString(Constants.PaketReleasesUrl);

            return(GetVersions(data).FirstOrDefault(s => s.Contains("-")));
        }
Exemplo n.º 13
0
        protected override void DownloadVersionCore(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());

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

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

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

                FileSystemProxy.CopyFile(sourcePath, paketPackageFile);
            }
            else
            {
                ConsoleImpl.WriteInfo("Starting download from {0}", paketDownloadUrl);

                try
                {
                    WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile);
                }
                catch (WebException webException)
                {
                    if (webException.Status == WebExceptionStatus.ProtocolError && !string.IsNullOrEmpty(latestVersion))
                    {
                        var response = (HttpWebResponse)webException.Response;
                        if (response.StatusCode == HttpStatusCode.NotFound)
                        {
                            throw new WebException(String.Format("Version {0} wasn't found (404)", latestVersion),
                                                   webException);
                        }
                        if (response.StatusCode == HttpStatusCode.BadRequest)
                        {
                            // For cases like "The package version is not a valid semantic version"
                            throw new WebException(String.Format("Unable to get version '{0}': {1}", latestVersion, response.StatusDescription),
                                                   webException);
                        }
                    }
                    Console.WriteLine(webException.ToString());
                    throw;
                }
            }

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

            FileSystemProxy.CopyFile(paketSourceFile, target, true);
            FileSystemProxy.DeleteDirectory(randomFullPath, true);
        }
Exemplo n.º 14
0
 public DefaultProxyProvider()
 {
     FileSystemProxy = new FileSystemProxy();
     EnvProxy        = new EnvProxy();
     WebRequestProxy = new WebRequestProxy(EnvProxy);
 }