Exemple #1
0
        /// <summary>
        /// Extract single file from cabinet into file
        /// </summary>
        /// <param name="fileToExtract"></param>
        /// <param name="destDir"></param>
        /// <returns></returns>
        public bool ExtractSingleFile(string fileToExtract, string destDir)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("CabExtract");
            }

            DecompressFile fileToDecompress = new DecompressFile
            {
                Found = false,
                Name  = fileToExtract
            };

            _decompressAll = false;
            _decompressFiles.Add(fileToDecompress);

            FdiCopy(FdiContext, NotifyCallback);

            if (fileToDecompress.Found)
            {
                fileToDecompress.WriteToFile(destDir);
                _decompressFiles.Remove(fileToDecompress);
                return(true);
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Extract single file from cabinet into memory
        /// </summary>
        /// <param name="fileToExtract"></param>
        /// <param name="outputData"></param>
        /// <param name="outputLength"></param>
        /// <returns></returns>
        public bool ExtractSingleFile(string fileToExtract, out byte[] outputData, out int outputLength)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("CabExtract");
            }

            DecompressFile fileToDecompress = new DecompressFile
            {
                Found = false,
                Name  = fileToExtract
            };

            _decompressAll = false;
            _decompressFiles.Add(fileToDecompress);

            FdiCopy(FdiContext, NotifyCallback);

            if (fileToDecompress.Found)
            {
                outputData   = fileToDecompress.Data;
                outputLength = fileToDecompress.Length;
                _decompressFiles.Remove(fileToDecompress);
                return(true);
            }

            outputData   = null;
            outputLength = 0;
            return(false);
        }
Exemple #3
0
        private IntPtr OutputFileOpen(FdiNotification fdin)
        {
            if (_decompressAll)
            { // Extract all files
                DecompressFile extractFile = new DecompressFile();
                _decompressFiles.Add(extractFile);

                MemoryStream stream = new MemoryStream();
                GCHandle     gch    = GCHandle.Alloc(stream);
                extractFile.Name   = fdin.psz1;
                extractFile.Handle = (IntPtr)gch;

                return(extractFile.Handle);
            }
            else
            { // Extract only some files
                DecompressFile extractFile = _decompressFiles.Where(ef => ef.Name == fdin.psz1).SingleOrDefault();
                if (extractFile == null)
                { // Do not extract, not in the decompress list
                    return(IntPtr.Zero);
                }
                else
                { // Do extract, found in the decompress List
                    MemoryStream stream = new MemoryStream();
                    GCHandle     gch    = GCHandle.Alloc(stream);
                    extractFile.Handle = (IntPtr)gch;

                    return(extractFile.Handle);
                }
            }
        }
        public void DecompressFilesByExtension(string extension)
        {
            string path = ConfigurationWikimedia.GetPath();

            DirectoryInfo directorySelected = new DirectoryInfo(path);

            foreach (FileInfo fileToDecompress in directorySelected.GetFiles("*.gz"))
            {
                DecompressFile.Decompress(fileToDecompress);
            }
        }
Exemple #5
0
        private IntPtr OutputFileClose(FdiNotification fdin)
        {
            DecompressFile extractFile = _decompressFiles.Where(ef => ef.Handle == fdin.hf).Single();

            using (Stream stream = StreamFromHandle(fdin.hf))
            {
                extractFile.Found  = true;
                extractFile.Length = (int)stream.Length;

                if (0 < stream.Length)
                {
                    extractFile.Data = new byte[stream.Length];
                    stream.Position  = 0;
                    stream.Read(extractFile.Data, 0, (int)stream.Length);
                }
            }

            return((IntPtr)TRUE);
        }
Exemple #6
0
 public Part2()
 {
     decompressFile = new DecompressFile();
 }