Пример #1
0
 private void UpdateSearchCompletionPercentage(
     Progress.IProgressEventsSink progress,
     long lastHandledPosition,
     FileRange.Range fullSearchPositionsRange,
     bool skipMessagesCountCheck)
 {
     if (progress == null)
     {
         return;
     }
     if (!skipMessagesCountCheck && (messagesReadSinceCompletionPercentageUpdate % 256) != 0)
     {
         ++messagesReadSinceCompletionPercentageUpdate;
     }
     else
     {
         double value;
         if (fullSearchPositionsRange.Length > 0)
         {
             value = Math.Max(0d, (double)(lastHandledPosition - fullSearchPositionsRange.Begin) / (double)fullSearchPositionsRange.Length);
         }
         else
         {
             value = 0;
         }
         progress.SetValue(value);
         messagesReadSinceCompletionPercentageUpdate = 0;
     }
 }
Пример #2
0
        async Task ExecuteInternal(IPreprocessingStepCallback callback, string specificFileToExtract, Func <PreprocessingStepParams, bool> onNext)
        {
            await callback.BecomeLongRunning();

            callback.TempFilesCleanupList.Add(sourceFile.Uri);

            using (var zipFile = new Ionic.Zip.ZipFile(sourceFile.Uri))
            {
                string currentEntryBeingExtracted     = null;
                Progress.IProgressEventsSink progress = null;
                zipFile.ExtractProgress += (s, evt) =>
                {
                    evt.Cancel = callback.Cancellation.IsCancellationRequested;
                    if (currentEntryBeingExtracted != null && evt.TotalBytesToTransfer != 0)
                    {
                        callback.SetStepDescription(string.Format("Unpacking {1}%: {0}",
                                                                  currentEntryBeingExtracted,
                                                                  evt.BytesTransferred * (long)100 / evt.TotalBytesToTransfer));
                        if (progress != null)
                        {
                            progress.SetValue(
                                (double)evt.BytesTransferred / (double)evt.TotalBytesToTransfer);
                        }
                    }
                };
                var entriesToEnum = specificFileToExtract != null?
                                    Enumerable.Repeat(zipFile[specificFileToExtract], 1) : zipFile.Entries;

                foreach (var entry in entriesToEnum.Where(e => e != null))
                {
                    if (entry.IsDirectory)
                    {
                        continue;
                    }

                    string entryFullPath = sourceFile.FullPath + "\\" + entry.FileName;
                    string tmpFileName   = callback.TempFilesManager.GenerateNewName();

                    callback.SetStepDescription("Unpacking " + entryFullPath);
                    using (FileStream tmpFs = new FileStream(tmpFileName, FileMode.CreateNew))
                        using (var entryProgress = progressAggregator.CreateProgressSink())
                        {
                            currentEntryBeingExtracted = entryFullPath;
                            progress = entryProgress;
                            entry.Extract(tmpFs);
                            currentEntryBeingExtracted = null;
                            progress = null;
                        }

                    string preprocessingStep = string.Format("{0} {1}", name, entry.FileName);

                    if (!onNext(new PreprocessingStepParams(tmpFileName, entryFullPath,
                                                            Utils.Concat(sourceFile.PreprocessingSteps, preprocessingStep))))
                    {
                        break;
                    }
                }
            }
        }
Пример #3
0
        private void DoExtract(
            IPreprocessingStepCallback callback,
            string specificFileToExtract,
            Func <PreprocessingStepParams, bool> onNext,
            string password)
        {
            using (var zipFile = new Ionic.Zip.ZipFile(@params.Location))
            {
                if (password != null)
                {
                    zipFile.Password = password;
                }
                string currentEntryBeingExtracted     = null;
                Progress.IProgressEventsSink progress = null;
                zipFile.ExtractProgress += (s, evt) =>
                {
                    evt.Cancel = callback.Cancellation.IsCancellationRequested;
                    if (currentEntryBeingExtracted != null && evt.TotalBytesToTransfer != 0)
                    {
                        callback.SetStepDescription(string.Format("Unpacking {1}%: {0}",
                                                                  currentEntryBeingExtracted,
                                                                  evt.BytesTransferred * (long)100 / evt.TotalBytesToTransfer));
                        if (progress != null)
                        {
                            progress.SetValue(
                                (double)evt.BytesTransferred / (double)evt.TotalBytesToTransfer);
                        }
                    }
                };
                var entriesToEnum = specificFileToExtract != null?
                                    Enumerable.Repeat(zipFile[specificFileToExtract], 1) : zipFile.Entries;

                foreach (var entry in entriesToEnum.Where(e => e != null))
                {
                    if (entry.IsDirectory)
                    {
                        continue;
                    }

                    string entryFullPath = @params.FullPath + "\\" + entry.FileName;
                    string tmpFileName   = callback.TempFilesManager.GenerateNewName();

                    callback.SetStepDescription("Unpacking " + entryFullPath);
                    using (FileStream tmpFs = new FileStream(tmpFileName, FileMode.CreateNew))
                        using (var entryProgress = progressAggregator.CreateProgressSink())
                        {
                            currentEntryBeingExtracted = entryFullPath;
                            progress = entryProgress;
                            entry.Extract(tmpFs);
                            currentEntryBeingExtracted = null;
                            progress = null;
                        }

                    if (!onNext(new PreprocessingStepParams(tmpFileName, entryFullPath,
                                                            @params.PreprocessingHistory.Add(new PreprocessingHistoryItem(name, entry.FileName)))))
                    {
                        break;
                    }
                }
            }
        }