Exemple #1
0
        public IPackageInfo Publish(string packageFileName, Stream packageStream)
        {
            packageFileName = PackageNameUtility.NormalizeFileName(packageFileName);

            var wrapFile = BasePath.GetFile(packageFileName);

            if (wrapFile.Exists)
            {
                return(null);
            }

            using (var file = wrapFile.OpenWrite())
                StreamExtensions.CopyTo(packageStream, file);

            var newPackageCacheDir = _rootCacheDirectory.GetDirectory(wrapFile.NameWithoutExtension);
            var newPackage         = new CachedZipPackage(this, wrapFile, newPackageCacheDir);

            Packages.Add(new PackageLocation(newPackageCacheDir, newPackage));
            return(newPackage);
        }
Exemple #2
0
        protected static bool ExtractPackage(IFile wrapFile, IDirectory destinationDirectory)
        {
            try
            {
                var nt = new WindowsNameTransform(destinationDirectory.Path.FullPath);
                using (var zipFile = new ZipFile(wrapFile.OpenRead()))
                {
                    foreach (ZipEntry zipEntry in zipFile)
                    {
                        if (zipEntry.IsFile)
                        {
                            IFile destinationFile;

                            if (System.IO.Path.DirectorySeparatorChar == '\\')
                            {
                                destinationFile = destinationDirectory.FileSystem.GetFile(nt.TransformFile(zipEntry.Name));
                            }
                            else
                            {
                                destinationFile = destinationDirectory.GetFile(zipEntry.Name);
                            }

                            using (var targetFile = destinationFile.MustExist().OpenWrite())
                                using (var sourceFile = zipFile.GetInputStream(zipEntry))
                                    StreamExtensions.CopyTo(sourceFile, targetFile);

                            destinationFile.LastModifiedTimeUtc = zipEntry.DateTime.ToUniversalTime();
                        }
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }