Ejemplo n.º 1
0
        public InstalledUpdate ApplyPreparedUpdate(IPreparedUpdate preparedUpdate)
        {
            AssertCanUpdate(preparedUpdate.Version);

            var oldVersionDir = _oldVersionDir;
            var basePrepDir   = Path.Combine(_fileSystem.AppDirectory, ".updates");
            var prepDir       = Path.Combine(basePrepDir, preparedUpdate.Version.ToString());

            if (_fileSystem.DirectoryExists(oldVersionDir))
            {
                _fileSystem.DeleteDirectory(oldVersionDir, true);
            }

            foreach (var filePath in preparedUpdate.Files)
            {
                var fileName    = Get(filePath, relativeTo: prepDir);
                var appFilePath = Path.Combine(_fileSystem.AppDirectory, fileName);
                if (_fileSystem.FileExists(appFilePath))
                {
                    _fileSystem.MoveFile(appFilePath, Path.Combine(oldVersionDir, fileName));
                }

                _fileSystem.MoveFile(filePath, appFilePath);
            }

            _fileSystem.DeleteDirectory(basePrepDir, true);

            return(new InstalledUpdate(CurrentVersion, preparedUpdate.Version));
        }
Ejemplo n.º 2
0
        public override bool Execute()
        {
            if (string.IsNullOrWhiteSpace(SpecFile))
            {
                Log.LogError(Resources.NuGetResources.SpecFileMustNotBeEmpty);
                return(false);
            }

            if (!_fileSystem.FileExists(SpecFile))
            {
                Log.LogError(Resources.NuGetResources.SpecFileDoesNotExist);
                return(false);
            }

            if (!string.IsNullOrWhiteSpace(PackageDir) && !_fileSystem.DirectoryExists(PackageDir))
            {
                Log.LogError(Resources.NuGetResources.PackageDirDoesNotExist);
                return(false);
            }

            string workingDir = _fileSystem.GetCurrentDirectory();
            string packageDir = PackageDir;

            if (packageDir == null || string.IsNullOrWhiteSpace(packageDir))
            {
                packageDir = workingDir;
            }

            string specFilePath = Path.Combine(workingDir, SpecFile);

            try {
                IPackageBuilder packageBuilder = _packageBuilderFactory.CreateFrom(specFilePath);
                packageBuilder.Files.RemoveAll(file => _fileExtensionsToIgnore.Contains(Path.GetExtension(file.Path)));

                string packageFile = String.Format(
                    "{0}.{1}{2}",
                    packageBuilder.Id,
                    packageBuilder.Version,
                    Constants.PackageExtension);
                string packageFilePath = Path.Combine(packageDir, packageFile);

                Log.LogMessage(String.Format(
                                   Resources.NuGetResources.CreatingPackage,
                                   _fileSystem.GetFullPath(specFilePath),
                                   _fileSystem.GetFullPath(packageFilePath)));

                using (Stream stream = _fileSystem.CreateFile(packageFilePath)) {
                    packageBuilder.Save(stream);
                }

                OutputPackage = packageFilePath;

                Log.LogMessage(String.Format(
                                   Resources.NuGetResources.CreatedPackage,
                                   _fileSystem.GetFullPath(specFilePath),
                                   _fileSystem.GetFullPath(packageFilePath)));
            }
            catch (Exception ex) {
                Log.LogError(Resources.NuGetResources.UnexpectedError, ex.ToString());
                return(false);
            }

            return(true);
        }