コード例 #1
0
ファイル: ExpandArchiveCommand.cs プロジェクト: nickchal/pash
		/*
        private void WireUpEvents(FileInfo fileInfo, SevenZipExtractor extractor)
        {
            // We need access to defaultrunspace, so use synchronous eventing
            extractor.EventSynchronization = EventSynchronizationStrategy.AlwaysSynchronous;

            extractor.FileExists += (sender, args) =>
            {
                // TODO: verify behaviour; in v3, add promptforchoice

                //args.Cancel = !this.Force; // abort entire process?
                //args.FileName = null; // skip this file

                if (!Force)
                {
                    WriteWarning(String.Format("File {0} already exists, skipping.", args.FileName));
                    args.FileName = null; // skip
                }
                else
                {
                    WriteVerbose("Overwrote already existing file " + args.FileName);
                }
            };

            if (ShowProgress)
            {
                WriteVerbose("Enabling progress reporting.");

                extractor.Extracting +=
                    (sender, args) =>
                        {
                            var progress = new ProgressRecord(
                                activityId: 1,
                                activity:
                                    "Expanding archive...",
                                statusDescription: fileInfo.FullName)
                                               {
                                                   RecordType = ProgressRecordType.Processing,
                                                   PercentComplete = args.PercentDone
                                               };

                            this.WriteProgress(progress);

                            if (this.Stopping)
                            {
                                // cancel entire extraction
                                args.Cancel = true;
                                WriteWarning("Extraction cancelled.");
                            }
                        };

                extractor.ExtractionFinished +=
                    (sender, args) =>
                        {
                            var progress = new ProgressRecord(
                                activityId: 1,
                                activity: "Expanding archive...",
                                statusDescription: fileInfo.FullName)
                                               {
                                                   PercentComplete = 100,
                                                   RecordType =
                                                       ProgressRecordType.Completed
                                               };

                            this.WriteProgress(progress);
                        };

                extractor.FileExtractionStarted +=
                    (sender, args) =>
                        {
                            // TODO
                        };

                extractor.FileExtractionFinished +=
                    (sender, args) =>
                        {
                            // TODO
                        };
            }
        }
		*/

        //private void EnsureArchiveFormat(FileInfo fileInfo)
        //{
        //    if (this.Format != ArchiveFormat.Unknown)
        //    {
        //        // user-specified
        //        return;
        //    }

        //    ArchiveFormat format = ArchiveFormat.Unknown;
        //    if (SevenZipBase.TryGetFormat(this, fileInfo, ref format))
        //    {
        //        WriteVerbose("Format is " + format);
        //        this.Format = format;
        //    }
        //    else
        //    {
        //        // todo: localize
        //        // unknown file extension / format - terminating
        //        ErrorHandler.HandleError(true,
        //             new ErrorRecord(new PSArgumentException("Unknown file extension/format."),
        //                "UnknownArchiveFormat", ErrorCategory.ReadError, fileInfo));
        //    }            
        //}

        private void ProcessArchive(ArchiveEntry entry)
        {
            WriteDebug(String.Format("ProcessArchive: {0}#{1}", entry.ArchivePath, entry.Path));

            string archivePath = entry.ArchivePath;


            if ((Index != null) || (EntryPath != null))
            {
                // todo: localize
                WriteWarning("Ignoring -Index and/or -EntryPath arguments.");
            }

            if (ShouldProcess(entry.Path, "Expand"))
            {
                var index = (int)entry.Index;
				entry.UnderlyingObject.WriteToDirectory (OutputPath.ProviderPath, SharpCompress.Common.ExtractOptions.ExtractFullPath);
            }
        }
コード例 #2
0
ファイル: ExpandArchiveCommand.cs プロジェクト: razaraz/Pscx
        private void ProcessArchive(ArchiveEntry entry)
        {
            WriteDebug(String.Format("ProcessArchive: {0}#{1}", entry.ArchivePath, entry.Path));

            string archivePath = entry.ArchivePath;

            SevenZipExtractor extractor;

            // cache extractor(s)
            if (!_extractors.ContainsKey(archivePath))
            {
                _extractors.Add(archivePath,
                    (extractor = new SevenZipExtractor(archivePath)));

                extractor.PreserveDirectoryStructure = !FlattenPaths;

                WireUpEvents(new FileInfo(archivePath), extractor);
            }

            extractor = _extractors[archivePath];

            if ((Index != null) || (EntryPath != null))
            {
                // todo: localize
                WriteWarning("Ignoring -Index and/or -EntryPath arguments.");
            }

            if (ShouldProcess(entry.Path + " from " + entry.ArchivePath, "Expand-Archive"))
            {
                var index = (int)entry.Index;
                extractor.ExtractFiles(OutputPath.ProviderPath, new[] { index });

                if (PassThru)
                {
                    WriteObject(new FileInfo(entry.ArchivePath));
                }
            }
        }
コード例 #3
0
 internal void Extract(ArchiveEntry wantedEntry)
 {
     Extract(entry => entry.Index == wantedEntry.Index);
 }