예제 #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
                }
            });
        }
예제 #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);
                }
            });
        }