示例#1
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);
        }
示例#2
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);
        }
        public void ImportingTaskStart()
        {
            var temporaryDirectory = TemporaryFileService.AllocateTemporaryDirectory(TimeSpan.FromHours(1));

            DirectoryHelpers.DirectoryCopy(Modification.RepositoryPath, temporaryDirectory, true);
            Directory.Move(temporaryDirectory, finalRepositoryPath);
            Modification = ModificationLoader.FromPath(finalRepositoryPath);
            PhaseFactory.SetModification(Modification);
            ViewModel.SetModification(Modification);

            var enabledComponent = Modification.GetComponent <EnabledComponent>();

            enabledComponent.IsEnabled = true;

            var thumbnailDirectory = Path.Combine(finalRepositoryPath, "thumbnails");

            FileSystemProxy.PrepareDirectory(thumbnailDirectory);
            var thumbnailGenerationTask = Task.Factory.StartNew(() => {
                using (var ms = new MemoryStream())
                    using (var writer = new BinaryWriter(ms)) {
                        PofSerializer.Serialize(writer, new ThumbnailGenerationParameters {
                            DestinationDirectory = thumbnailDirectory,
                            SourceDirectory      = importedDirectoryPath,
                            ThumbnailsToGenerate = 3
                        });
                        ExeggutorService.SpawnHatchling(
                            "thumbnail-generator",
                            new SpawnConfiguration {
                            InstanceName = "thumbnail-generator-" + DateTime.UtcNow.GetUnixTime(),
                            Arguments    = ms.GetBuffer()
                        });
                        var thumbnailComponent = Modification.GetComponent <ThumbnailComponent>();
                        thumbnailComponent.SelectThumbnailIfUnselected();
                    }
            }, TaskCreationOptions.LongRunning);

            var contentDirectory = Path.Combine(finalRepositoryPath, "content");

            FileSystemProxy.PrepareDirectory(contentDirectory);
            for (var i = 0; i < relativeImportedFilePaths.Length; i++)
            {
                var sourceFile      = Path.Combine(importedDirectoryPath, relativeImportedFilePaths[i]);
                var destinationFile = Path.Combine(contentDirectory, relativeImportedFilePaths[i]);
                FileSystemProxy.PrepareParentDirectory(destinationFile);
                FileSystemProxy.CopyFile(sourceFile, destinationFile);
                UpdateProgress(0.333 * ((double)i / relativeImportedFilePaths.Length));
            }

            LeagueBuildUtilities.ResolveModification(Modification, CancellationToken.None);
            UpdateProgress(0.666);

            LeagueBuildUtilities.CompileModification(Modification, CancellationToken.None);
            UpdateProgress(1);
            thumbnailGenerationTask.Wait();
            PhaseManager.Transition(PhaseFactory.Idle());
        }
        public void CopyFile_FileSourceFileName_DestinationFileName()
        {
            var testFileSource = GetTestFilePath();
            var testFileDest   = GetTestFilePath();

            // Write and copy file
            WriteFile(testFileSource, SourceData);
            WriteFile(testFileDest, DestData);
            Assert.Throws <System.IO.IOException>(() => _fileSystem.CopyFile(testFileSource, testFileDest));

            // Ensure copy didn't overwrite existing data
            Assert.True(HasExpectedData(testFileDest, DestData));

            // Get a new destination name
            testFileDest = GetTestFilePath();
            _fileSystem.CopyFile(testFileSource, testFileDest);

            // Ensure copy transferred written data
            Assert.True(HasExpectedData(testFileDest, SourceData));
        }
示例#5
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);
        }
示例#6
0
        protected override void SelfUpdateCore(string latestVersion)
        {
            string target       = Assembly.GetExecutingAssembly().Location;
            var    localVersion = FileSystemProxy.GetLocalFileVersion(target);

            if (localVersion.StartsWith(latestVersion))
            {
                ConsoleImpl.WriteInfo("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());

            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);

                WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile);
            }

            FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath);

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

            try
            {
                FileSystemProxy.MoveFile(target, renamedPath);
                FileSystemProxy.MoveFile(paketSourceFile, target);
                ConsoleImpl.WriteInfo("Self update of bootstrapper was successful.");
            }
            catch (Exception)
            {
                ConsoleImpl.WriteInfo("Self update failed. Resetting bootstrapper.");
                FileSystemProxy.MoveFile(renamedPath, target);
                throw;
            }
            FileSystemProxy.DeleteDirectory(randomFullPath, true);
        }
示例#7
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);
        }