Exemplo n.º 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);
        }
Exemplo n.º 2
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)
 {
     this.archiveInfo = (ArchiveInfo)info.GetValue(
         "archiveInfo", typeof(ArchiveInfo));
     this.name          = info.GetString("name");
     this.path          = info.GetString("path");
     this.initialized   = info.GetBoolean("initialized");
     this.exists        = info.GetBoolean("exists");
     this.archiveNumber = info.GetInt32("archiveNumber");
     this.attributes    = (FileAttributes)info.GetValue(
         "attributes", typeof(FileAttributes));
     this.lastWriteTime = info.GetDateTime("lastWriteTime");
     this.length        = info.GetInt64("length");
 }
Exemplo n.º 3
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)
            : base()
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            this.Archive = archiveInfo;

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

            this.attributes    = FileAttributes.Normal;
            this.lastWriteTime = DateTime.MinValue;
        }
Exemplo n.º 4
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)
            : base()
        {
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            this.Archive = archiveInfo;

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

            this.attributes = FileAttributes.Normal;
            this.lastWriteTime = DateTime.MinValue;
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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)
 {
     this.archiveInfo = (ArchiveInfo) info.GetValue(
         "archiveInfo", typeof(ArchiveInfo));
     this.name = info.GetString("name");
     this.path = info.GetString("path");
     this.initialized = info.GetBoolean("initialized");
     this.exists = info.GetBoolean("exists");
     this.archiveNumber = info.GetInt32("archiveNumber");
     this.attributes = (FileAttributes) info.GetValue(
         "attributes", typeof(FileAttributes));
     this.lastWriteTime = info.GetDateTime("lastWriteTime");
     this.length = info.GetInt64("length");
 }