Beispiel #1
0
        /// <summary>
        /// Extracts the package to the specified <see cref="DirectoryMap"/>
        /// </summary>
        /// <param name="directory"></param>
        /// <param name="args"></param>
        public void ExtractTo(DirectoryMap directory, TurtleExtractArgs args)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            else if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            ExtractFiles(args, delegate(ExtractorEventArgs e)
            {
                PackFile file        = e.PackFile;
                DirectoryMapFile dmf = directory.GetFile(file.RelativePath);

                if ((dmf == null) || !dmf.Unmodified() || !QQnCryptoHelpers.HashComparer.Equals(dmf.FileHash, file.FileHash))
                {
                    using (Stream s = directory.CreateFile(file.RelativePath, file.FileHash, file.FileSize))
                    {
                        QQnPath.CopyStream(e.Stream, s);
                    }
                }
                else
                {
                    directory.UnscheduleDelete(file.RelativePath);                     // Make sure it stays
                }
            });
        }
Beispiel #2
0
        /// <summary>
        /// Extracts the package to the specified directory
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="args">The args.</param>
        public void ExtractTo(string directory, TurtleExtractArgs args)
        {
            if (string.IsNullOrEmpty(directory))
            {
                throw new ArgumentNullException("directory");
            }
            else if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            if (args.UseDirectoryMap)
            {
                using (DirectoryMap dm = DirectoryMap.Get(directory))
                {
                    ExtractTo(dm, args);
                }
                return;
            }

            ExtractFiles(args, delegate(ExtractorEventArgs e)
            {
                using (Stream s = File.Create(QQnPath.Combine(directory, e.PackFile.RelativePath)))
                {
                    QQnPath.CopyStream(e.Stream, s);
                }
            });
        }
Beispiel #3
0
        private void ExtractFiles(TurtleExtractArgs args, Extractor extractor)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            else if (extractor == null)
            {
                throw new ArgumentNullException("extract");
            }

            ZipStream.Seek(0, SeekOrigin.Begin);

            Dictionary <string, PackFile> extract = new Dictionary <string, PackFile>(StringComparer.OrdinalIgnoreCase);

            // Prepare a list of items to extract
            foreach (PackContainer container in _pack.Containers)
            {
                if (!args.ExtractContainer(container.Name))
                {
                    continue;
                }

                foreach (PackFile pf in container.Files)
                {
                    extract.Add(pf.StreamName, pf);
                }
            }

            // TODO: Perhaps optimize the case where we don't have anything
            // to extract at all

            // Extract them in zip-order to optimize reading
            using (ZipFile zip = new ZipFile(ZipStream))
            {
                foreach (ZipEntry entry in zip)
                {
                    PackFile pf;

                    if (extract.TryGetValue(entry.Name, out pf))
                    {
                        extractor(new ExtractorEventArgs(pf, zip, entry));
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Extracts the specified containers to the specified directory
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="useMap">if set to <c>true</c> [use map].</param>
        /// <param name="containers">The containers.</param>
        public void ExtractTo(string directory, bool useMap, string[] containers)
        {
            if (string.IsNullOrEmpty(directory))
            {
                throw new ArgumentNullException("directory");
            }

            TurtleExtractArgs args = new TurtleExtractArgs();

            if (containers != null)
            {
                args.Containers = containers;
            }

            args.UseDirectoryMap = useMap;

            ExtractTo(directory, args);
        }