Exemplo n.º 1
0
        /// <summary>
        /// Выполняет распаковку CAB-архива
        /// </summary>
        public void Decompress()
        {
            using (CabDecompressor decompressor = new CabDecompressor())
            {
                decompressor.NotifyCopyFile += OnCopyFile;
                decompressor.NotifyCloseFile += OnCloseFile;
                FdiCabinetInfo cabInfo = new FdiCabinetInfo();

                // является ли файл CAB-архивом
                if (decompressor.IsCabinetFile(_cabName, cabInfo))
                {
                    // распаковка
                    decompressor.ExtractFiles(_cabName);
                }
            }

            if (_deleteSourceCab)
                File.Delete(_cabName);
        }
Exemplo n.º 2
0
        public virtual void ExtractFile(FileInfo fileInfo, string targetFileName, bool overwriteExisting)
        {
            CFFOLDER containingFolder = m_folders[fileInfo.CFFILE.iFolder];

            using (System.IO.Stream input = System.IO.File.Open(FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
            {
                int toRead = (int)fileInfo.CFFILE.cbFile;

                CabDecompressor decompressor = new CabDecompressor((CompressionType)containingFolder.typeCompress);
                CabFolderStream folderStream = new CabFolderStream(input, containingFolder.coffCabStart, containingFolder.Compressed);

                // skip to the beginning of the file. this is done by decompressing into a null stream
                if (fileInfo.CFFILE.uoffFolderStart > 0)
                {
                    using (NullStream ns = new NullStream())
                    {
                        decompressor.DecompressBlock((int)fileInfo.CFFILE.uoffFolderStart, folderStream.SizeCompressed, folderStream.SizeUncompressed, folderStream, ns);
                    }
                }

                using (SizeLimitedOutputStream output = new SizeLimitedOutputStream(targetFileName, System.IO.FileMode.OpenOrCreate, (int)fileInfo.CFFILE.cbFile))
                {
                    while (toRead > 0)
                    {
                        int nextBlock = Math.Min(toRead, folderStream.SizeUncompressed);
                        if (folderStream.SizeUncompressed == -1)
                        {
                            nextBlock = toRead;
                        }
                        //System.Diagnostics.Debug.WriteLine(string.Format("Reading {0} bytes", nextBlock));
                        decompressor.DecompressBlock(nextBlock, folderStream.SizeCompressed, folderStream.SizeUncompressed, folderStream, output);
                        toRead -= nextBlock;
                        output.Flush();
                    }
                }
            }
        }
Exemplo n.º 3
0
        static bool doFdiTest(string cabinetFullPath)
        {
            using (CabDecompressor decomp = new CabDecompressor())
            {
                
                // setup event handlers
                decomp.NotifyCabinetInfo += new NotifyEventHandler(decomp_NotifyCabinetInfo);
                decomp.NotifyCloseFile += new NotifyEventHandler(decomp_NotifyCloseFile);
                decomp.NotifyCopyFile += new NotifyEventHandler(decomp_NotifyCopyFile);
                decomp.NotifyEnumerate += new NotifyEventHandler(decomp_NotifyEnumerate);
                decomp.NotifyNextCabinet += new NotifyEventHandler(decomp_NotifyNextCabinet);
                decomp.NotifyPartialFile += new NotifyEventHandler(decomp_NotifyPartialFile);

                FdiCabinetInfo cabInfo = new FdiCabinetInfo();

                using (FileStream fs = new FileStream(cabinetFullPath, FileMode.Open, FileAccess.Read))
                {
                    if (!decomp.IsCabinetFile(fs, cabInfo))
                    {
                        Console.WriteLine("File is not a cabinet.");
                        return false;
                    }
#if DO_OUTPUT
                    // The file is a cabinet.  Display some info.
                    Console.WriteLine(
                        "Information on cabinet file '{0}'\n" +
                        "   Total length of cabinet file : {1}\n" +
                        "   Number of folders in cabinet : {2}\n" +
                        "   Number of files in cabinet   : {3}\n" +
                        "   Cabinet set ID               : {4}\n" +
                        "   Cabinet number in set        : {5}\n" +
                        "   RESERVE area in cabinet?     : {6}\n" +
                        "   Chained to prev cabinet?     : {7}\n" +
                        "   Chained to next cabinet?     : {8}\n",
                        cabinetFullPath,
                        cabInfo.Length,
                        cabInfo.FolderCount,
                        cabInfo.FileCount,
                        cabInfo.SetId,
                        cabInfo.CabinetNumber,
                        cabInfo.HasReserve,
                        cabInfo.HasPrev,
                        cabInfo.HasNext);
#endif
                }
                // extract path and filename
                string cabinetName = Path.GetFileName(cabinetFullPath);
                string cabinetPath = Path.GetDirectoryName(cabinetFullPath);
                if (cabinetPath != string.Empty)
                    cabinetPath = cabinetPath + Path.DirectorySeparatorChar;
                
                // let's copy some files!
                if (!decomp.ExtractFiles(cabinetFullPath))
                {
                    Console.WriteLine("FdiCopy failed.  Error code {0}", decomp.ErrorInfo.FdiErrorCode);
                    return false;
                }
              
                return true;

            }
        }
Exemplo n.º 4
0
        static bool doFdiTest(string cabinetFullPath)
        {
            using (CabDecompressor decomp = new CabDecompressor())
            {
                // setup event handlers
                decomp.NotifyCabinetInfo += new NotifyEventHandler(decomp_NotifyCabinetInfo);
                decomp.NotifyCloseFile   += new NotifyEventHandler(decomp_NotifyCloseFile);
                decomp.NotifyCopyFile    += new NotifyEventHandler(decomp_NotifyCopyFile);
                decomp.NotifyEnumerate   += new NotifyEventHandler(decomp_NotifyEnumerate);
                decomp.NotifyNextCabinet += new NotifyEventHandler(decomp_NotifyNextCabinet);
                decomp.NotifyPartialFile += new NotifyEventHandler(decomp_NotifyPartialFile);

                FdiCabinetInfo cabInfo = new FdiCabinetInfo();

                using (FileStream fs = new FileStream(cabinetFullPath, FileMode.Open, FileAccess.Read))
                {
                    if (!decomp.IsCabinetFile(fs, cabInfo))
                    {
                        Console.WriteLine("File is not a cabinet.");
                        return(false);
                    }
#if DO_OUTPUT
                    // The file is a cabinet.  Display some info.
                    Console.WriteLine(
                        "Information on cabinet file '{0}'\n" +
                        "   Total length of cabinet file : {1}\n" +
                        "   Number of folders in cabinet : {2}\n" +
                        "   Number of files in cabinet   : {3}\n" +
                        "   Cabinet set ID               : {4}\n" +
                        "   Cabinet number in set        : {5}\n" +
                        "   RESERVE area in cabinet?     : {6}\n" +
                        "   Chained to prev cabinet?     : {7}\n" +
                        "   Chained to next cabinet?     : {8}\n",
                        cabinetFullPath,
                        cabInfo.Length,
                        cabInfo.FolderCount,
                        cabInfo.FileCount,
                        cabInfo.SetId,
                        cabInfo.CabinetNumber,
                        cabInfo.HasReserve,
                        cabInfo.HasPrev,
                        cabInfo.HasNext);
#endif
                }
                // extract path and filename
                string cabinetName = Path.GetFileName(cabinetFullPath);
                string cabinetPath = Path.GetDirectoryName(cabinetFullPath);
                if (cabinetPath != string.Empty)
                {
                    cabinetPath = cabinetPath + Path.DirectorySeparatorChar;
                }

                // let's copy some files!
                if (!decomp.ExtractFiles(cabinetFullPath))
                {
                    Console.WriteLine("FdiCopy failed.  Error code {0}", decomp.ErrorInfo.FdiErrorCode);
                    return(false);
                }

                return(true);
            }
        }