Пример #1
0
        public void UnpackFiles(
            IList <string> fileNames,
            string destDirectory,
            IList <string> destFileNames,
            EventHandler <ArchiveProgressEventArgs> progressHandler)
        {
            if (fileNames == null)
            {
                throw new ArgumentNullException("fileNames");
            }

            if (destFileNames == null)
            {
                if (destDirectory == null)
                {
                    throw new ArgumentNullException("destFileNames");
                }

                destFileNames = fileNames;
            }

            if (destFileNames.Count != fileNames.Count)
            {
                throw new ArgumentOutOfRangeException("destFileNames");
            }

            IDictionary <string, string> files =
                ArchiveInfo.CreateStringDictionary(fileNames, destFileNames);

            this.UnpackFileSet(files, destDirectory, progressHandler);
        }
Пример #2
0
        /// <summary>
        /// Creates a new ArchiveFileInfo object representing a file within
        /// an archive in a specified path.
        /// </summary>
        /// <param name="archiveInfo">An object representing the archive
        /// containing the file.</param>
        /// <param name="filePath">The path to the file within the archive.
        /// Usually, this is a simple file name, but if the archive contains
        /// a directory structure this may include the directory.</param>
        protected ArchiveFileInfo(ArchiveInfo archiveInfo, string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            Archive = archiveInfo;

            name = System.IO.Path.GetFileName(filePath);
            path = System.IO.Path.GetDirectoryName(filePath);

            attributes    = FileAttributes.Normal;
            lastWriteTime = DateTime.MinValue;
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the ArchiveFileInfo class with
 /// serialized data.
 /// </summary>
 /// <param name="info">The SerializationInfo that holds the serialized
 /// object data about the exception being thrown.</param>
 /// <param name="context">The StreamingContext that contains contextual
 /// information about the source or destination.</param>
 protected ArchiveFileInfo(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     archiveInfo = (ArchiveInfo)info.GetValue(
         "archiveInfo", typeof(ArchiveInfo));
     name          = info.GetString("name");
     path          = info.GetString("path");
     initialized   = info.GetBoolean("initialized");
     exists        = info.GetBoolean("exists");
     archiveNumber = info.GetInt32("archiveNumber");
     attributes    = (FileAttributes)info.GetValue(
         "attributes", typeof(FileAttributes));
     lastWriteTime = info.GetDateTime("lastWriteTime");
     length        = info.GetInt64("length");
 }
Пример #4
0
        /// <summary>
        /// Compresses files into the archive, specifying the names used to
        /// store the files in the archive.
        /// </summary>
        /// <param name="sourceDirectory">This parameter may be null, but if
        /// specified it is the root directory
        /// for any relative paths in <paramref name="sourceFileNames"/>.</param>
        /// <param name="sourceFileNames">The list of files to be included in
        /// the archive.</param>
        /// <param name="fileNames">The names of the files as they are stored in
        /// the archive. Each name includes the internal path of the file, if any.
        /// This parameter may be null, in which case the files are stored in the
        /// archive with their source file names and no path information.</param>
        /// <param name="compLevel">The compression level used when creating the
        /// archive.</param>
        /// <param name="progressHandler">Handler for receiving progress information;
        /// this may be null if progress is not desired.</param>
        /// <remarks>
        /// Duplicate items in the <paramref name="fileNames"/> array will cause
        /// an <see cref="ArchiveException"/>.
        /// </remarks>
        public void PackFiles(
            string sourceDirectory,
            IList <string> sourceFileNames,
            IList <string> fileNames,
            CompressionLevel compLevel,
            EventHandler <ArchiveProgressEventArgs> progressHandler)
        {
            if (sourceFileNames == null)
            {
                throw new ArgumentNullException("sourceFileNames");
            }

            if (fileNames == null)
            {
                string[] fileNamesArray = new string[sourceFileNames.Count];
                for (int i = 0; i < sourceFileNames.Count; i++)
                {
                    fileNamesArray[i] = Path.GetFileName(sourceFileNames[i]);
                }

                fileNames = fileNamesArray;
            }
            else if (fileNames.Count != sourceFileNames.Count)
            {
                throw new ArgumentOutOfRangeException("fileNames");
            }

            using (CompressionEngine compressionEngine = this.CreateCompressionEngine())
            {
                compressionEngine.Progress += progressHandler;
                IDictionary <string, string> contextFiles =
                    ArchiveInfo.CreateStringDictionary(fileNames, sourceFileNames);
                ArchiveFileStreamContext streamContext = new ArchiveFileStreamContext(
                    this.FullName, sourceDirectory, contextFiles);
                streamContext.EnableOffsetOpen     = true;
                compressionEngine.CompressionLevel = compLevel;
                compressionEngine.Pack(streamContext, fileNames);
            }
        }