コード例 #1
0
ファイル: ArchiveInfo.cs プロジェクト: urmas69/Wix3.6Toolset
        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
 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
 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>
        /// 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;
        }
コード例 #5
0
ファイル: ArchiveInfo.cs プロジェクト: urmas69/Wix3.6Toolset
        /// <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);
            }
        }
コード例 #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");
 }
コード例 #7
0
ファイル: CompressionTestUtil.cs プロジェクト: zooba/wix3
        public static void TestTruncatedArchive(
            ArchiveInfo archiveInfo, Type expectedExceptionType)
        {
            for (long len = archiveInfo.Length - 1; len >= 0; len--)
            {
                string testArchive = String.Format("{0}.{1:d06}",
                    archiveInfo.FullName, len);
                if (File.Exists(testArchive))
                {
                    File.Delete(testArchive);
                }

                archiveInfo.CopyTo(testArchive);
                using (FileStream truncateStream =
                    File.Open(testArchive, FileMode.Open, FileAccess.ReadWrite))
                {
                    truncateStream.SetLength(len);
                }

                ArchiveInfo testArchiveInfo = (ArchiveInfo) archiveInfo.GetType()
                    .GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { testArchive });

                Exception caughtEx = null;
                try
                {
                    testArchiveInfo.GetFiles();
                }
                catch (Exception ex) { caughtEx = ex; }
                File.Delete(testArchive);

                if (caughtEx != null)
                {
                    Assert.IsInstanceOfType(caughtEx, expectedExceptionType,
                        String.Format("Caught exception listing archive truncated to {0}/{1} bytes",
                        len, archiveInfo.Length));
                }
            }
        }
コード例 #8
0
ファイル: CompressionTestUtil.cs プロジェクト: zooba/wix3
        public static void TestArchiveInfoNullParams(
            ArchiveInfo archiveInfo,
            string dirA,
            string dirB,
            string[] files)
        {
            Exception caughtEx = null;
            try
            {
                archiveInfo.PackFiles(null, null, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(null, files, new string[] { });
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentOutOfRangeException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFileSet(dirA, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(null, files, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(FileNotFoundException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(dirA, null, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.PackFiles(dirA, files, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Caught exception: " + caughtEx);

            caughtEx = null;
            try
            {
                archiveInfo.CopyTo(null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.CopyTo(null, true);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.MoveTo(null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.GetFiles(null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFile(null, "test.txt");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFile("test.txt", null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(null, dirB, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, null, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, null, files);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, dirB, null);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFiles(files, dirB, new string[] { });
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentOutOfRangeException), "Caught exception: " + caughtEx);
            caughtEx = null;
            try
            {
                archiveInfo.UnpackFileSet(null, dirB);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(ArgumentNullException), "Caught exception: " + caughtEx);
        }