private async Task CopyPackageFileToPath(string installPath, IPackageFile packageFile)
 {
     using (var fileStream = File.Create(Path.Combine(installPath, Path.GetFileName(packageFile.Path))))
     {
         await packageFile.GetStream().CopyToAsync(fileStream);
     }
 }
 internal static string Process(IPackageFile file, IPropertyProvider propertyProvider)
 {
     using (var stream = file.GetStream())
     {
         return(Process(stream, propertyProvider, throwIfNotFound: false));
     }
 }
Beispiel #3
0
 internal static string Process(IPackageFile file, IPropertyProvider propertyProvider)
 {
     using (Stream stream = file.GetStream())
     {
         return(Process(stream, propertyProvider, false));
     }
 }
        private static string CheckFile(string url, IPackageFile file)
        {
            var binary = new BinaryStoreManager();
            var symbol = new SymbolStoreManager();

            var name = Path.ChangeExtension(Path.GetFileName(file.Path), "pdb");
            var compressedName = name.Substring(0, name.Length - 1) + '_';

            string hash;

            using (var stream = file.GetStream())
                hash = binary.ReadPdbHash(stream);

            byte[] buffer;

            try
            {
                using (var client = new WebClient())
                    buffer = client.DownloadData(string.Format("{0}/{1}/{2}/{3}", url, name, hash, compressedName));
            }
            catch (WebException exception)
            {
                return ((HttpWebResponse)exception.Response).StatusCode.ToString();
            }

            //using (var stream = new MemoryStream(buffer))
            //    if (symbol.ReadHash(stream) != hash)
            //        return "MISMATCHED";

            return "FOUND";
        }
            void copyFileToLocation(FileSystemInfo target, IPackageFile x)
            {
                var targetPath = Path.Combine(target.FullName, x.EffectivePath);

                var fi = new FileInfo(targetPath);

                if (fi.Exists)
                {
                    fi.Delete();
                }

                var dir = new DirectoryInfo(Path.GetDirectoryName(targetPath));

                if (!dir.Exists)
                {
                    dir.Create();
                }

                this.ErrorIfThrows(() => {
                    using (var inf = x.GetStream())
                        using (var of = fi.Open(FileMode.CreateNew, FileAccess.Write)) {
                            inf.CopyTo(of);
                        }
                }, "Failed to write file: " + target.FullName);
            }
Beispiel #6
0
 private static XElement GetElement(IPackageFile file)
 {
     using (Stream stream = file.GetStream())
     {
         return(XElement.Load(stream));
     }
 }
Beispiel #7
0
 internal static string Process(IPackageFile file, IPropertyProvider propertyProvider)
 {
     using (var stream = file.GetStream())
     {
         return Process(stream, propertyProvider, throwIfNotFound: false);
     }
 }
Beispiel #8
0
        private void AddFiles(PackageBuilder builder, string itemType, string targetFolder)
        {
            // Skip files that are added by dependency packages
            string             packagesConfig = GetPackagesConfig();
            IPackageRepository repository     = GetPackagesRepository();
            var contentFilesInDependencies    = new List <IPackageFile>();

            if (packagesConfig != null && repository != null)
            {
                var references = new PackageReferenceFile(packagesConfig).GetPackageReferences();
                contentFilesInDependencies = references.Select(reference => repository.FindPackage(reference.Id, reference.Version))
                                             .SelectMany(a => a.GetContentFiles())
                                             .ToList();
            }

            // Get the content files from the project
            foreach (var item in _project.GetItems(itemType))
            {
                string fullPath = item.GetMetadataValue("FullPath");

                if (_excludeFiles.Contains(Path.GetFileName(fullPath)))
                {
                    continue;
                }

                string targetFilePath = GetTargetPath(item);

                if (!File.Exists(fullPath))
                {
                    Logger.Log(MessageLevel.Warning, NuGetResources.Warning_FileDoesNotExist, targetFilePath);
                    continue;
                }

                // Check that file is added by dependency
                string       targetPath = Path.Combine(targetFolder, targetFilePath);
                IPackageFile targetFile = contentFilesInDependencies.Find(a => a.Path.Equals(targetPath, StringComparison.OrdinalIgnoreCase));
                if (targetFile != null)
                {
                    // Compare contents as well
                    using (var dependencyFileStream = targetFile.GetStream())
                        using (var fileContentsStream = File.Open(fullPath, FileMode.Open))
                        {
                            var isEqual = FileHelper.AreFilesEqual(dependencyFileStream, fileContentsStream);
                            if (isEqual)
                            {
                                Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsNotChanged, targetFilePath);
                                continue;
                            }

                            Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsChanged, targetFilePath);
                        }
                }

                builder.Files.Add(new PhysicalPackageFile
                {
                    SourcePath = fullPath,
                    TargetPath = targetPath
                });
            }
        }
 void UpdateFile(string path, IPackageFile file)
 {
     using (Stream fromStream = file.GetStream(), toStream = File.Create(path))
     {
         fromStream.CopyTo(toStream);
     }
 }
 protected virtual void UpdateFile(string exePath, IPackageFile file)
 {
     using (Stream fromStream = file.GetStream(), toStream = File.Create(exePath))
     {
         fromStream.CopyTo(toStream);
     }
 }
Beispiel #11
0
 private static XElement GetXml(IPackageFile file, IProjectSystem projectSystem)
 {
     using (Stream stream = file.GetStream()) {
         var content = Preprocessor.Process(file, projectSystem);
         return(XElement.Parse(content));
     }
 }
        private static string CheckFile(string url, IPackageFile file)
        {
            var binary = new BinaryStoreManager();
            var symbol = new SymbolStoreManager();

            var name           = Path.ChangeExtension(Path.GetFileName(file.Path), "pdb");
            var compressedName = name.Substring(0, name.Length - 1) + '_';

            string hash;

            using (var stream = file.GetStream())
                hash = binary.ReadPdbHash(stream);

            byte[] buffer;

            try
            {
                using (var client = new WebClient())
                    buffer = client.DownloadData(string.Format("{0}/{1}/{2}/{3}", url, name, hash, compressedName));
            }
            catch (WebException exception)
            {
                return(((HttpWebResponse)exception.Response).StatusCode.ToString());
            }

            //using (var stream = new MemoryStream(buffer))
            //    if (symbol.ReadHash(stream) != hash)
            //        return "MISMATCHED";

            return("FOUND");
        }
Beispiel #13
0
 private static void UpdateFile(string newFilePath, IPackageFile file)
 {
     EnsureDirectory(newFilePath);
     using (Stream fromStream = file.GetStream(), toStream = File.Create(newFilePath))
     {
         fromStream.CopyTo(toStream);
     }
 }
Beispiel #14
0
 private static XElement GetXml(IPackageFile file, IProjectSystem projectSystem)
 {
     using (Stream stream = file.GetStream())
     {
         var content = Preprocessor.Process(file, projectSystem);
         return XElement.Parse(content);
     }
 }
Beispiel #15
0
        private void SaveAssemblyFile(string installPath, IPackageFile file)
        {
            var targetPath = installPath.AppendPath(file.Path);

            Directory.CreateDirectory(targetPath.ParentDirectory());
            using (Stream outputStream = File.Create(targetPath)){
                file.GetStream().CopyTo(outputStream);
            }
        }
 internal static bool ContentEquals(IPackageFile targetFile, string fullPath)
 {
     bool isEqual;
     using (var dependencyFileStream = targetFile.GetStream())
     using (var fileContentStream = File.OpenRead(fullPath))
     {
         isEqual = dependencyFileStream.ContentEquals(fileContentStream);
     }
     return isEqual;
 }
 private static bool VerifySigned(IPackageFile packageFile)
 {
     bool result;
     using (Stream stream = packageFile.GetStream())
     {
         System.IO.StreamReader streamReader = new System.IO.StreamReader(stream);
         string text = streamReader.ReadToEnd();
         result = (text.IndexOf("# SIG # Begin signature block", StringComparison.OrdinalIgnoreCase) > -1 && text.IndexOf("# SIG # End signature block", StringComparison.OrdinalIgnoreCase) > -1);
     }
     return result;
 }
Beispiel #18
0
        private string ExtractToSymbols(IPackage package, IPackageFile symbolFile)
        {
            var path = symbolsPathResolver.GetSymbolsPath(package, symbolFile);

            EnsureDirectory(path);

            using (var file = File.Open(path, FileMode.OpenOrCreate))
                symbolFile.GetStream().CopyTo(file);

            return(path);
        }
        private static bool VerifySigned(IPackageFile packageFile)
        {
            bool result;

            using (Stream stream = packageFile.GetStream())
            {
                System.IO.StreamReader streamReader = new System.IO.StreamReader(stream);
                string text = streamReader.ReadToEnd();
                result = (text.IndexOf("# SIG # Begin signature block", StringComparison.OrdinalIgnoreCase) > -1 && text.IndexOf("# SIG # End signature block", StringComparison.OrdinalIgnoreCase) > -1);
            }
            return(result);
        }
        private static byte[] GetConfigurationFileAsBytes(IPackageFile agentConfigurationFile)
        {
            var agentConfigurationFileStream = agentConfigurationFile.GetStream();

            byte[] configBytes;

            using (var memoryStream = new MemoryStream())
            {
                agentConfigurationFileStream.CopyTo(memoryStream);
                configBytes = memoryStream.ToArray();
                memoryStream.Close();
            }
            return configBytes;
        }
Beispiel #21
0
        private bool VerifySigned(IPackageFile packageFile)
        {
            const string SignatureStartBlock = "# SIG # Begin signature block";
            const string SignatureEndBlock   = "# SIG # End signature block";

            using (Stream stream = packageFile.GetStream())
            {
                var    streamReader = new StreamReader(stream);
                string fullText     = streamReader.ReadToEnd();

                return(fullText.IndexOf(SignatureStartBlock, StringComparison.OrdinalIgnoreCase) > -1 &&
                       fullText.IndexOf(SignatureEndBlock, StringComparison.OrdinalIgnoreCase) > -1);
            }
        }
Beispiel #22
0
 /// <summary>
 /// Try to add the specified the project with the target path. If there's an existing file in the project with the same name,
 /// it will ask the logger for the resolution, which has 4 choices: Overwrite|Ignore|Overwrite All|Ignore All
 /// </summary>
 /// <param name="project"></param>
 /// <param name="file"></param>
 /// <param name="path"></param>
 public static void TryAddFile(IProjectSystem project, IPackageFile file, string path)
 {
     if (project.FileExists(path) && project.FileExistsInProject(path))
     {
         // file exists in project, ask user if he wants to overwrite or ignore
         string conflictMessage            = String.Format(CultureInfo.CurrentCulture, NuGetResources.FileConflictMessage, path, project.ProjectName);
         FileConflictResolution resolution = project.Logger.ResolveFileConflict(conflictMessage);
         if (resolution == FileConflictResolution.Overwrite || resolution == FileConflictResolution.OverwriteAll)
         {
             // overwrite
             project.Logger.Log(MessageLevel.Info, NuGetResources.Info_OverwriteExistingFile, path);
             project.AddFile(path, file.GetStream());
         }
         else
         {
             // ignore
             project.Logger.Log(MessageLevel.Info, NuGetResources.Warning_FileAlreadyExists, path);
         }
     }
     else
     {
         project.AddFile(path, file.GetStream());
     }
 }
Beispiel #23
0
        /// <summary>
        /// Given a list of resolved files,
        /// determine which file will be used as the icon file and validate its size.
        /// </summary>
        /// <param name="files">Files resolved from the file entries in the nuspec</param>
        /// <param name="iconPath">iconpath found in the .nuspec</param>
        /// <exception cref="PackagingException">When a validation rule is not met</exception>
        private void ValidateIconFile(IEnumerable <IPackageFile> files, string iconPath)
        {
            if (!PackageTypes.Contains(PackageType.SymbolsPackage) && !string.IsNullOrEmpty(iconPath))
            {
                // Validate entry
                var iconPathStripped = PathUtility.StripLeadingDirectorySeparators(iconPath);

                var iconFileList = files.Where(f =>
                                               iconPathStripped.Equals(
                                                   PathUtility.StripLeadingDirectorySeparators(f.Path),
                                                   PathUtility.GetStringComparisonBasedOnOS()));

                if (iconFileList.Count() == 0)
                {
                    throw new PackagingException(
                              NuGetLogCode.NU5046,
                              string.Format(CultureInfo.CurrentCulture, NuGetResources.IconNoFileElement, iconPath));
                }

                IPackageFile iconFile = iconFileList.First();

                try
                {
                    // Validate Icon open file
                    using (var iconStream = iconFile.GetStream())
                    {
                        // Validate file size
                        long fileSize = iconStream.Length;

                        if (fileSize > MaxIconFileSize)
                        {
                            throw new PackagingException(Common.NuGetLogCode.NU5047, NuGetResources.IconMaxFileSizeExceeded);
                        }

                        if (fileSize == 0)
                        {
                            throw new PackagingException(Common.NuGetLogCode.NU5047, NuGetResources.IconErrorEmpty);
                        }
                    }
                }
                catch (FileNotFoundException e)
                {
                    throw new PackagingException(
                              NuGetLogCode.NU5046,
                              string.Format(CultureInfo.CurrentCulture, NuGetResources.IconCannotOpenFile, iconPath, e.Message));
                }
            }
        }
Beispiel #24
0
        public ExtensionDescriptor GetExtensionDescriptor(IPackage package, string extensionType)
        {
            IPackageFile packageFile = package.GetFiles().FirstOrDefault(file =>
                                                                         Path.GetFileName(file.Path).Equals(
                                                                             DefaultExtensionTypes.IsModule(extensionType) ? "module.txt" : "theme.txt",
                                                                             StringComparison.OrdinalIgnoreCase));

            if (packageFile != null)
            {
                string extensionId = Path.GetFileName(Path.GetDirectoryName(packageFile.Path).TrimEnd('/', '\\'));
                using (StreamReader streamReader = new StreamReader(packageFile.GetStream())) {
                    return(ExtensionFolders.GetDescriptorForExtension("", extensionId, extensionType, streamReader.ReadToEnd()));
                }
            }

            return(null);
        }
Beispiel #25
0
        void CopyFileToLocation(FileSystemInfoBase target, IPackageFile x)
        {
            var targetPath = Path.Combine(target.FullName, x.EffectivePath);

            var fi = fileSystem.GetFileInfo(targetPath);

            if (fi.Exists)
            {
                fi.Delete();
            }

            var dir = fileSystem.GetDirectoryInfo(Path.GetDirectoryName(targetPath));

            if (!dir.Exists)
            {
                dir.Create();
            }

            using (var inf = x.GetStream())
                using (var of = fi.Open(FileMode.CreateNew, FileAccess.Write)) {
                    inf.CopyTo(of);
                }
        }
Beispiel #26
0
 protected static T ReadFile <T>(IPackageFile file)
 {
     using (var stream = file.GetStream())
         using (var reader = new StreamReader(stream))
             return(JsonConvert.DeserializeObject <T>(reader.ReadToEnd()));
 }
 public ZipPackageFile(IPackageFile file)
     : this(file.Path, file.GetStream().ToStreamFactory())
 {
 }
Beispiel #28
0
 /// <summary>
 /// Access to the stream content in read mode.
 /// </summary>
 /// <returns>A new stream reading file pointed by <see cref="Path"/>.</returns>
 public Stream GetStream()
 {
     return(packageFile?.GetStream() ?? File.OpenRead(FullPath));
 }
Beispiel #29
0
 public ZipPackageFile(IPackageFile file)
     : this(file.Path, file.GetStream().ToStreamFactory())
 {
 }
Beispiel #30
0
 public ZipPackageFile(IPackageFile file)
 {
     Path = file.Path;
     _streamFactory = file.GetStream().ToStreamFactory();
 }
Beispiel #31
0
 private static XElement GetElement(IPackageFile file)
 {
     using (Stream stream = file.GetStream())
     {
         return XElement.Load(stream);
     }
 }
Beispiel #32
0
 internal static string Process(IPackageFile file, IPropertyProvider propertyProvider)
 {
     return(Process(file.GetStream(), propertyProvider));
 }
        private bool UpdateFile(string exePath, IPackageFile file)
        {
            using (Stream fromStream = file.GetStream())
            {
                if (fromStream == null)
                {
                    return false;
                }

                using (Stream toStream = this.filesystemAccessor.GetWriteStream(exePath))
                {
                    if (toStream == null)
                    {
                        return false;
                    }

                    fromStream.CopyTo(toStream);

                    return true;
                }
            }
        }
 private void UnpackFile(string fileOut, IPackageFile file)
 {
     var stream = File.OpenWrite(fileOut);
     file.GetStream().CopyTo(stream);
 }
Beispiel #35
0
 /// <summary>
 /// Access to the stream content in read mode.
 /// </summary>
 /// <returns>A new stream reading file pointed by <see cref="Path"/>.</returns>
 public Stream GetStream()
 {
     return(packageFile.GetStream());
 }
Beispiel #36
0
 public ZipPackageFile(IPackageFile file)
 {
     Path           = file.Path;
     _streamFactory = file.GetStream().ToStreamFactory();
 }
Beispiel #37
0
        private string ExtractToSymbols(IPackage package, IPackageFile symbolFile)
        {
            var path = symbolsPathResolver.GetSymbolsPath(package, symbolFile);

            EnsureDirectory(path);

            using (var file = File.Open(path, FileMode.OpenOrCreate))
                symbolFile.GetStream().CopyTo(file);

            return path;
        }
Beispiel #38
0
        void CopyFileToLocation(FileSystemInfoBase target, IPackageFile x)
        {
            var targetPath = Path.Combine(target.FullName, x.EffectivePath);

            var fi = fileSystem.GetFileInfo(targetPath);
            if (fi.Exists) fi.Delete();

            var dir = fileSystem.GetDirectoryInfo(Path.GetDirectoryName(targetPath));
            if (!dir.Exists) dir.Create();

            using (var inf = x.GetStream())
            using (var of = fi.Open(FileMode.CreateNew, FileAccess.Write)) {
                log.Debug("Writing {0} to app directory", targetPath);
                inf.CopyTo(of);
            }
        }
Beispiel #39
0
 /// <summary>
 /// Installs a new package file
 /// </summary>
 /// <param name="package">
 /// The package being installed
 /// </param>
 /// <param name="file">
 /// The file to install
 /// </param>
 private void InstallFile(IPackage package, IPackageFile file)
 {
     // map the package file to its deployment location (or suppress it)
      var path = GetFullPath(file);
      if (path == null)
     Log.Trace("Skipping file {0}", file);
      else
      {
     Log.Trace("Extracting file {0} to {1}", file, path);
     // extract the package file and stamp it with the package date
     ExtractFile(file.GetStream(), path);
     File.SetLastWriteTimeUtc(
        path,
        (package.Published ?? DateTimeOffset.UtcNow).UtcDateTime
     );
      }
 }
 public Stream GetStream()
 {
     return(_file.GetStream());
 }
Beispiel #41
0
 private static void UpdateFile(string newFilePath, IPackageFile file)
 {
     EnsureDirectory(newFilePath);
     using (Stream fromStream = file.GetStream(), toStream = File.Create(newFilePath))
     {
         fromStream.CopyTo(toStream);
     }
 }
Beispiel #42
0
 internal static bool ContentEquals(IPackageFile targetFile, string fullPath)
 {
     bool isEqual;
     using (var dependencyFileStream = targetFile.GetStream())
     using (var fileContentsStream = File.OpenRead(fullPath))
     {
         isEqual = dependencyFileStream.ContentEquals(fileContentsStream);
     }
     return isEqual;
 }
Beispiel #43
0
 /// <summary>
 /// Access to the stream content in read mode.
 /// </summary>
 /// <returns>A new stream reading file pointed by <see cref="Path"/>.</returns>
 public Stream GetStream()
 {
     return(packageFile?.GetStream() ?? File.OpenRead(System.IO.Path.Combine(packagePath, Path)));
 }
Beispiel #44
0
 protected virtual void UpdateFile(string exePath, IPackageFile file)
 {
     using (Stream fromStream = file.GetStream(), toStream = File.Create(exePath))
     {
         fromStream.CopyTo(toStream);
     }
 }
Beispiel #45
0
 private void SaveAssemblyFile(string installPath, IPackageFile file)
 {
     var targetPath = installPath.AppendPath(file.Path);
     Directory.CreateDirectory(targetPath.ParentDirectory());
     using (Stream outputStream = File.Create(targetPath)){
         file.GetStream().CopyTo(outputStream);
     }
 }
Beispiel #46
0
 internal static string Process(IPackageFile file, IPropertyProvider propertyProvider)
 {
     return Process(file.GetStream(), propertyProvider);
 }
            void copyFileToLocation(FileSystemInfo target, IPackageFile x)
            {
                var targetPath = Path.Combine(target.FullName, x.EffectivePath);

                var fi = new FileInfo(targetPath);
                if (fi.Exists) fi.Delete();

                var dir = new DirectoryInfo(Path.GetDirectoryName(targetPath));
                if (!dir.Exists) dir.Create();

                this.ErrorIfThrows(() => {
                    using (var inf = x.GetStream())
                    using (var of = fi.Open(FileMode.CreateNew, FileAccess.Write)) {
                        inf.CopyTo(of);
                    }
                }, "Failed to write file: " + target.FullName);
            }