Ejemplo n.º 1
0
        private void ExtractTo(string format, byte[] data, string path)
        {
            Console.WriteLine("Unpacking binary package from " + format + " archive");
            switch (format)
            {
            case PackageManager.ARCHIVE_FORMAT_TAR_GZIP:
            {
                using (var memory = new MemoryStream(data))
                {
                    using (var decompress = new GZipStream(memory, CompressionMode.Decompress))
                    {
                        using (var memory2 = new MemoryStream())
                        {
                            decompress.CopyTo(memory2);
                            memory2.Seek(0, SeekOrigin.Begin);
                            var reader       = new tar_cs.TarReader(memory2);
                            var reduplicator = new Reduplicator();
                            reduplicator.UnpackTarToFolder(reader, path);
                        }
                    }
                }
                break;
            }

            case PackageManager.ARCHIVE_FORMAT_TAR_LZMA:
            {
                using (var inMemory = new MemoryStream(data))
                {
                    using (var outMemory = new MemoryStream())
                    {
                        LZMA.LzmaHelper.Decompress(inMemory, outMemory);
                        outMemory.Seek(0, SeekOrigin.Begin);
                        var reader       = new tar_cs.TarReader(outMemory);
                        var reduplicator = new Reduplicator();
                        reduplicator.UnpackTarToFolder(reader, path);
                    }
                }
                break;
            }

            default:
                throw new InvalidOperationException(
                          "This version of Protobuild does not support the " +
                          format + " package format.");
            }
        }
Ejemplo n.º 2
0
 public void ExtractTo(string path)
 {
     Console.WriteLine("Unpacking binary package from " + this.Format + " archive");
     switch (this.Format)
     {
         case PackageManager.ARCHIVE_FORMAT_TAR_GZIP:
             {
                 using (var memory = new MemoryStream(this.PackageData))
                 {
                     using (var decompress = new GZipStream(memory, CompressionMode.Decompress))
                     {
                         using (var memory2 = new MemoryStream())
                         {
                             decompress.CopyTo(memory2);
                             memory2.Seek(0, SeekOrigin.Begin);
                             var reader = new tar_cs.TarReader(memory2);
                             var reduplicator = new Reduplicator();
                             reduplicator.UnpackTarToFolder(reader, path);
                         }
                     }
                 }
                 break;
             }
         case PackageManager.ARCHIVE_FORMAT_TAR_LZMA:
             {
                 using (var inMemory = new MemoryStream(this.PackageData))
                 {
                     using (var outMemory = new MemoryStream())
                     {
                         LZMA.LzmaHelper.Decompress(inMemory, outMemory);
                         outMemory.Seek(0, SeekOrigin.Begin);
                         var reader = new tar_cs.TarReader(outMemory);
                         var reduplicator = new Reduplicator();
                         reduplicator.UnpackTarToFolder(reader, path);
                     }
                 }
                 break;
             }
         default:
             throw new InvalidOperationException(
                 "This version of Protobuild does not support the " +
                 this.Format + " package format.");
     }
 }
Ejemplo n.º 3
0
        private void ExtractTo(string workingDirectory, string packageName, string format, byte[] data, string path, string platform)
        {
            RedirectableConsole.WriteLine("Unpacking binary package from " + format + " archive");
            switch (format)
            {
            case PackageManager.ARCHIVE_FORMAT_TAR_GZIP:
            {
                using (var memory = new MemoryStream(data))
                {
                    using (var decompress = new GZipStream(memory, CompressionMode.Decompress))
                    {
                        using (var memory2 = new MemoryStream())
                        {
                            decompress.CopyTo(memory2);
                            memory2.Seek(0, SeekOrigin.Begin);
                            var reader       = new tar_cs.TarReader(memory2);
                            var reduplicator = new Reduplicator();
                            reduplicator.UnpackTarToFolder(reader, path);
                        }
                    }
                }
                break;
            }

            case PackageManager.ARCHIVE_FORMAT_TAR_LZMA:
            {
                using (var inMemory = new MemoryStream(data))
                {
                    using (var outMemory = new MemoryStream())
                    {
                        LZMA.LzmaHelper.Decompress(inMemory, outMemory);
                        outMemory.Seek(0, SeekOrigin.Begin);
                        var reader       = new tar_cs.TarReader(outMemory);
                        var reduplicator = new Reduplicator();
                        reduplicator.UnpackTarToFolder(reader, path);
                    }
                }
                break;
            }

            case PackageManager.ARCHIVE_FORMAT_NUGET_ZIP:
            {
                using (var inMemory = new MemoryStream(data))
                {
                    using (var zipStorer = ZipStorer.Open(inMemory, FileAccess.Read, true))
                    {
                        var reduplicator   = new Reduplicator();
                        var extractedFiles = reduplicator.UnpackZipToFolder(
                            zipStorer,
                            path,
                            candidatePath => candidatePath.Replace('\\', '/').StartsWith("protobuild/" + platform + "/"),
                            outputPath => outputPath.Replace('\\', '/').Substring(("protobuild/" + platform + "/").Length));

                        if (extractedFiles.Count == 0)
                        {
                            // There were no files that matched protobuild/ which means this is
                            // not a Protobuild-aware NuGet package.  We need to convert it on-the-fly
                            // to a compatible Protobuild format.
                            ConvertNuGetOnlyPackage(reduplicator, zipStorer, path, packageName, workingDirectory, platform);
                        }
                    }
                }
                break;
            }

            default:
                throw new InvalidOperationException(
                          "This version of Protobuild does not support the " +
                          format + " package format.");
            }
        }