/// <summary>
		/// Creates a cabinet extractor.
		/// </summary>
		public WixExtractCab()
		{
			int err = CabInterop.ExtractCabBegin();
			if (0 != err)
			{
				throw new WixCabExtractionException(new COMException(String.Concat("Failed to begin extracting cabinet, error: ", err), err));
			}
		}
Beispiel #2
0
        /// <summary>
        /// Enumerates all files in a cabinet.
        /// </summary>
        /// <param name="cabinetFile">path to cabinet</param>
        /// <returns>list of CabinetFileInfo</returns>
        public ArrayList Enumerate(string cabinetFile)
        {
            this.fileInfoList.Clear(); // we need to clear the list before starting new one

            // the callback (this.Notify) will populate the list for each file in cabinet
            CabInterop.EnumerateCab(cabinetFile, new CabInterop.PFNNOTIFY(this.Notify));

            return(this.fileInfoList);
        }
Beispiel #3
0
        /// <summary>
        /// Adds an array of files to the cabinet.
        /// </summary>
        /// <param name="filePaths">Path to files to add to cabinet.</param>
        /// <param name="fileIds">Identifiers for all files to add to cabinet.</param>
        public void AddFiles(string[] filePaths, string[] fileIds)
        {
            int error = CabInterop.CreateCabAddFiles(filePaths, fileIds, (uint)filePaths.Length, this.handle);

            if (0 != error)
            {
                throw new WixCabCreationException(error);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a cabinet.
        /// </summary>
        /// <param name="cabName">Name of cabinet to create.</param>
        /// <param name="cabDir">Directory to create cabinet in.</param>
        /// <param name="maxSize">Maximum size of cabinet.</param>
        /// <param name="maxThresh">Maximum threshold for each cabinet.</param>
        /// <param name="compressionLevel">Level of compression to apply.</param>
        public WixCreateCab(string cabName, string cabDir, int maxSize, int maxThresh, CompressionLevel compressionLevel)
        {
            int error = CabInterop.CreateCabBegin(cabName, cabDir, (uint)maxSize, (uint)maxThresh, (uint)compressionLevel, out this.handle);

            if (0 != error)
            {
                throw new WixCabCreationException(error);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Disposes the managed and unmanaged objects in this object.
        /// </summary>
        public void Dispose()
        {
            if (!this.disposed)
            {
                CabInterop.EnumerateCabFinish();

                GC.SuppressFinalize(this);
                this.disposed = true;
            }
        }
Beispiel #6
0
        /// <summary>
        /// Disposes the managed and unmanaged objects in this object.
        /// </summary>
        public void Dispose()
        {
            if (!this.disposed)
            {
                CabInterop.CreateCabFinish(this.handle);
                this.handle = IntPtr.Zero;

                GC.SuppressFinalize(this);
                this.disposed = true;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Closes the cabinet being created.
        /// </summary>
        public void Close()
        {
            if (IntPtr.Zero == this.handle)
            {
                throw new ArgumentNullException();
            }

            int error = CabInterop.CreateCabFinish(this.handle);

            if (0 != error)
            {
                throw new WixCabCreationException(error);
            }
            this.handle = IntPtr.Zero;
        }
Beispiel #8
0
 /// <summary>
 /// Adds a file to the cabinet.
 /// </summary>
 /// <param name="file">The file to add.</param>
 /// <param name="token">The token for the file.</param>
 public void AddFile(string file, string token)
 {
     try
     {
         CabInterop.CreateCabAddFile(file, token, this.handle);
     }
     catch (DirectoryNotFoundException)
     {
         throw new FileNotFoundException("The system cannot find the file specified.", file);
     }
     catch (FileNotFoundException)
     {
         throw new FileNotFoundException("The system cannot find the file specified.", file);
     }
 }
		/// <summary>
		/// Closes the cabinet being extracted.
		/// </summary>
		public void Close()
		{
			if (this.closed)
			{
				return;
			}

			this.closed = true;
			CabInterop.ExtractCabFinish();

			int err = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
			if (0 != err)
			{
				throw new WixCabExtractionException(new COMException(String.Concat("Failed to close cab extract object, error: ", err), err));
			}
		}
Beispiel #10
0
        /// <summary>
        /// Adds an array of files to the cabinet.
        /// </summary>
        /// <param name="filePaths">Path to files to add to cabinet.</param>
        /// <param name="fileIds">Identifiers for all files to add to cabinet.</param>
        /// <param name="batchAdd">Flag to add the files one at a time or in a batch.</param>
        public void AddFiles(string[] filePaths, string[] fileIds, bool batchAdd)
        {
            if (batchAdd)
            {
                this.AddFiles(filePaths, fileIds);
                return;
            }

            for (int i = 0; i < filePaths.Length; i++)
            {
                int error = CabInterop.CreateCabAddFile(filePaths[i], fileIds[i], this.handle);

                if (0 != error)
                {
                    throw new WixCabCreationException(filePaths[i], error);
                }
            }
        }
Beispiel #11
0
        public void CanExtractSingleFileCabinet()
        {
            var cabinetPath = TestData.Get(@"TestData\test.cab");

            using (var fs = new DisposableFileSystem())
            {
                var extractFolder = fs.GetFolder(true);

                var cabinet = new Cabinet(cabinetPath);
                cabinet.Extract(extractFolder);

                var files = Directory.EnumerateFiles(extractFolder);

                var file = new FileInfo(files.Single());
                CabInterop.DateTimeToCabDateAndTime(file.CreationTime, out var date, out var time);

                Assert.Equal("test.txt", file.Name);
                Assert.Equal(17, file.Length);
                Assert.Equal(19259, date);
                Assert.Equal(47731, time);
            }
        }
		/// <summary>
		/// Extracts all the files from a cabinet to a directory.
		/// </summary>
		/// <param name="cabinetFile">Cabinet file to extract from.</param>
		/// <param name="extractDir">Directory to extract files to.</param>
		public void Extract(string cabinetFile, string extractDir)
		{
			if (null == extractDir)
			{
				throw new ArgumentNullException("extractDir");
			}

			if (!extractDir.EndsWith("\\"))
			{
				extractDir = String.Concat(extractDir, "\\");
			}

			int err = CabInterop.ExtractCab(cabinetFile, extractDir);
			if (0 != err)
			{
				throw new WixCabExtractionException(extractDir, new COMException(String.Concat("Failed to extract files from cabinet, error: ", err), err));
			}
			err = System.Runtime.InteropServices.Marshal.GetLastWin32Error();
			if (0 != err)
			{
				throw new WixCabExtractionException(new COMException(String.Concat("Failed to execute cab extract, error: ", err), err));
			}
		}
Beispiel #13
0
        /// <summary>
        /// Extracts all the files from a cabinet to a directory.
        /// </summary>
        /// <param name="cabinetFile">Cabinet file to extract from.</param>
        /// <param name="extractDir">Directory to extract files to.</param>
        public void Extract(string cabinetFile, string extractDir)
        {
            if (null == cabinetFile)
            {
                throw new ArgumentNullException("cabinetFile");
            }

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

            if (this.disposed)
            {
                throw new ObjectDisposedException("WixExtractCab");
            }

            if (!extractDir.EndsWith("\\"))
            {
                extractDir = String.Concat(extractDir, "\\");
            }

            CabInterop.ExtractCab(cabinetFile, extractDir);
        }
Beispiel #14
0
 /// <summary>
 /// Creates a cabinet enumerator.
 /// </summary>
 public WixEnumerateCab()
 {
     this.fileInfoList = new ArrayList();
     CabInterop.EnumerateCabBegin();
 }
Beispiel #15
0
 /// <summary>
 /// Creates a cabinet extractor.
 /// </summary>
 public WixExtractCab()
 {
     CabInterop.ExtractCabBegin();
 }
Beispiel #16
0
 /// <summary>
 /// Creates a cabinet.
 /// </summary>
 /// <param name="cabName">Name of cabinet to create.</param>
 /// <param name="cabDir">Directory to create cabinet in.</param>
 /// <param name="maxSize">Maximum size of cabinet.</param>
 /// <param name="maxThresh">Maximum threshold for each cabinet.</param>
 /// <param name="compressionLevel">Level of compression to apply.</param>
 public WixCreateCab(string cabName, string cabDir, int maxSize, int maxThresh, CompressionLevel compressionLevel)
 {
     CabInterop.CreateCabBegin(cabName, cabDir, (uint)maxSize, (uint)maxThresh, (uint)compressionLevel, out this.handle);
 }