private void ExtractCallBack(ExtractFileCallbackArgs efc, IEventListener iel, CancellationToken iCancellationToken)
        {
            switch (efc.Reason)
            {
                case ExtractFileCallbackReason.Start:

                    string nd = null;
                    bool root = false;

                    if (efc.ArchiveFileInfo.FileName == MusicExporter.XMLName)
                    {
                        nd = _ICC.Folders.Temp;
                        root = true;
                    }
                    else
                    {
                        nd = _ICC.Folders.File;
                    }

                    efc.ExtractToFile = FileInternalToolBox.CreateNewAvailableName(Path.Combine(nd, efc.ArchiveFileInfo.FileName));
                    if (root)
                        _RX = efc.ExtractToFile;
                    else
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(efc.ExtractToFile));
                    }

                    if ((!efc.ArchiveFileInfo.IsDirectory) && !(root))
                    {
                        iel.Report(new ExtractProgessEventArgs(string.Format("{0} from {1}", Path.GetFileName(efc.ArchiveFileInfo.SafePath()), _Sex.FileName)));
                        AddAssociationIfNeeded(efc.ArchiveFileInfo.FileName, efc.ExtractToFile);
                    }

                    DescompactedFiles.Add(efc.ExtractToFile);
                    break;

                case ExtractFileCallbackReason.Failure:
                    iel.OnFactorisableError<UnableToExtractFileFromRar>(string.Format("{0} from {1} : {2}", Path.GetFileName(efc.ArchiveFileInfo.FileName), _Sex.FileName, efc.Exception));
                    efc.Exception = null;
                    efc.ExtractToFile = null;
                    _Success = false;
                    break;
            }

            if (iCancellationToken.IsCancellationRequested)
            {
                _Success = false;
                efc.CancelExtraction = true;
            }
        }
 /// <summary>
 /// Extracts files from the archive, giving a callback the choice what
 /// to do with each file. The order of the files is given by the archive.
 /// 7-Zip (and any other solid) archives are NOT supported.
 /// </summary>
 /// <param name="extractFileCallback">The callback to call for each file in the archive.</param>
 public void ExtractFiles(ExtractFileCallback extractFileCallback)
 {
     DisposedCheck();
     InitArchiveFileData(false);
     if (IsSolid)
     {
         // solid strategy
     }
     else
     {
         foreach (ArchiveFileInfo archiveFileInfo in ArchiveFileData)
         {
             var extractFileCallbackArgs = new ExtractFileCallbackArgs(archiveFileInfo);
             extractFileCallback(extractFileCallbackArgs);
             if (extractFileCallbackArgs.CancelExtraction)
             {
                 break;
             }
             if (extractFileCallbackArgs.ExtractToStream != null || extractFileCallbackArgs.ExtractToFile != null)
             {
                 bool callDone = false;
                 try
                 {
                     if (extractFileCallbackArgs.ExtractToStream != null)
                     {
                         ExtractFile(archiveFileInfo.Index, extractFileCallbackArgs.ExtractToStream);
                     }
                     else
                     {
                         using (var file = new FileStream(extractFileCallbackArgs.ExtractToFile, FileMode.CreateNew,
                                                       FileAccess.Write, FileShare.None, 8192))
                         {
                             ExtractFile(archiveFileInfo.Index, file);
                         }
                     }
                     callDone = true;
                 }
                 catch (Exception ex)
                 {
                     extractFileCallbackArgs.Exception = ex;
                     extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Failure;
                     extractFileCallback(extractFileCallbackArgs);
                     if (!ThrowException(null, ex))
                     {
                         return;
                     }
                 }
                 if (callDone)
                 {
                     extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Done;
                     extractFileCallback(extractFileCallbackArgs);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Extracts files from the archive, giving a callback the choice what
        /// to do with each file. The order of the files is given by the archive.
        /// 7-Zip (and any other solid) archives are NOT supported.
        /// </summary>
        /// <param name="extractFileCallback">The callback to call for each file in the archive.</param>
        /// <exception cref="SevenZipExtractionFailedException">Thrown when trying to extract from solid archives.</exception>
        public void ExtractFiles(ExtractFileCallback extractFileCallback)
        {
            DisposedCheck();
            InitArchiveFileData(false);

            if (IsSolid)
            {
                throw new SevenZipExtractionFailedException("Solid archives are not supported.");
            }

            foreach (var archiveFileInfo in ArchiveFileData)
            {
                var extractFileCallbackArgs = new ExtractFileCallbackArgs(archiveFileInfo);
                extractFileCallback(extractFileCallbackArgs);

                if (extractFileCallbackArgs.CancelExtraction)
                {
                    break;
                }

                if (extractFileCallbackArgs.ExtractToStream != null || extractFileCallbackArgs.ExtractToFile != null)
                {
                    var callDone = false;

                    try
                    {
                        if (extractFileCallbackArgs.ExtractToStream != null)
                        {
                            ExtractFile(archiveFileInfo.Index, extractFileCallbackArgs.ExtractToStream);
                        }
                        else
                        {
                            using (var file = new FileStream(extractFileCallbackArgs.ExtractToFile, FileMode.CreateNew,
                                                             FileAccess.Write, FileShare.None, 8192))
                            {
                                ExtractFile(archiveFileInfo.Index, file);
                            }
                        }

                        callDone = true;
                    }
                    catch (Exception ex)
                    {
                        extractFileCallbackArgs.Exception = ex;
                        extractFileCallbackArgs.Reason    = ExtractFileCallbackReason.Failure;
                        extractFileCallback(extractFileCallbackArgs);

                        if (!ThrowException(null, ex))
                        {
                            return;
                        }
                    }

                    if (callDone)
                    {
                        extractFileCallbackArgs.Reason = ExtractFileCallbackReason.Done;
                        extractFileCallback(extractFileCallbackArgs);
                    }
                }
            }
        }
            private void ExtractCallBack(ExtractFileCallbackArgs efc, IEventListener iel, CancellationToken iCancellationToken)
            {
                switch (efc.Reason)
                {
                    case ExtractFileCallbackReason.Start:

                        string Dest = GetFileName(efc.ArchiveFileInfo);

                        if (Dest == null)
                        {
                            efc.ExtractToFile = null;
                            break;
                        }

                        efc.ExtractToFile = Dest;

                        if (!efc.ArchiveFileInfo.IsDirectory)
                            iel.Report(new ExtractProgessEventArgs(string.Format("{0} from {1}", Path.GetFileName(efc.ArchiveFileInfo.SafePath()), RarContext.DisplayName)));

                        Files.Add(Dest);
                        break;

                    case ExtractFileCallbackReason.Failure:
                        iel.OnFactorisableError<UnableToExtractFileFromRar>(string.Format("{0} from {1} : {2}", Path.GetFileName(efc.ArchiveFileInfo.SafePath()), RarContext.DisplayName, efc.Exception));
                        efc.Exception = null;
                        efc.ExtractToFile = null;
                        _DOK = false;
                        break;
                }

                if (iCancellationToken.IsCancellationRequested)
                    efc.CancelExtraction = true;
            }