Esempio n. 1
0
        public void Run(UnpackMethod unpackMethod, object options)
        {
            if (queue == null)
            {
                return;
            }

            sizeCompleted = 0;
            canceled = false;
            unpacker = null;

            switch (unpackMethod)
            {
                case UnpackMethod.UnRAR: unpacker = new UnRAR(); break;
            }

            unpacker.SetOptions(options);
            unpacker.ProgressChanged += new Action<int, DateTime>(unpacker_ProgressChanged);
            unpacker.OutputChanged += new Action<string>(unpacker_OutputChanged);

            queueStarted = DateTime.Now;
            OnStatusChanged(new QueueStarted());

            int length = queue.Count;
            for (currentPosition = 0; currentPosition < length; currentPosition++)
            {
                if (canceled)
                {
                    break;
                }

                QueueItem item = queue[currentPosition];
                string file = item.FileToExtract;
                string destination = item.Destination;

                OnStatusChanged(new ItemStarted(item));
                bool success = unpacker.Unpack(file, destination);

                if (canceled)
                {
                    break;
                }

                if (success)
                {
                    if (AutoAddUnpackedFiles)
                    {
                        GetAndAddExtractedItems(item);
                    }
                    queue[currentPosition].ErrorMessage = null;
                    OnStatusChanged(new ItemCompleted(item, CalculateItemsLeft()));
                }
                else
                {
                    OnStatusChanged(new UnpackerError(item, unpacker.ErrorMessage));
                    queue[currentPosition].ErrorMessage = unpacker.ErrorMessage;
                    CalculateAndReportProgress(0);
                }

                length = queue.Count;
            }

            if (canceled)
            {
                OnStatusChanged(new QueueCanceled());
            }
            else
            {
                OnStatusChanged(new QueueCompleted());
            }
        }
Esempio n. 2
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var warc   = arc as WarcFile;
            var wentry = entry as WarcEntry;

            if (null == warc || null == wentry || entry.Size < 8)
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            var enc_data = new byte[entry.Size];

            if (entry.Size != arc.File.View.Read(entry.Offset, enc_data, 0, entry.Size))
            {
                return(Stream.Null);
            }
            uint sig           = LittleEndian.ToUInt32(enc_data, 0);
            uint unpacked_size = LittleEndian.ToUInt32(enc_data, 4);

            sig ^= (unpacked_size ^ 0x82AD82) & 0xffffff;

            if (0 != (wentry.Flags & 0x80000000u) && entry.Size > 8) // encrypted entry
            {
                warc.Decoder.Decrypt(enc_data, 8, entry.Size - 8);
            }
            if (warc.Decoder.SchemeVersion >= 2490)
            {
                warc.Decoder.DecryptExtra(enc_data, 8, entry.Size - 8, 0x202);
            }
            if (0 != (wentry.Flags & 0x20000000u) && entry.Size > 8)
            {
                warc.Decoder.Decrypt2(enc_data, 8, entry.Size - 8);
            }

            byte[]       unpacked = enc_data;
            UnpackMethod unpack   = null;

            switch (sig & 0xffffff)
            {
            case 0x314859: // 'YH1'
                unpack = UnpackYH1;
                break;

            case 0x4b5059: // 'YPK'
                unpack = UnpackYPK;
                break;

            case 0x5a4c59: // 'YLZ'
                unpack = UnpackYLZ;
                break;
            }
            if (null != unpack)
            {
                unpacked = new byte[unpacked_size];
                unpack(enc_data, unpacked);
                if (0 != (wentry.Flags & 0x40000000))
                {
                    warc.Decoder.Decrypt2(unpacked, 0, (uint)unpacked.Length);
                }
                if (warc.Decoder.SchemeVersion >= 2490)
                {
                    warc.Decoder.DecryptExtra(unpacked, 0, (uint)unpacked.Length, 0x204);
                }
            }
            return(new MemoryStream(unpacked));
        }
Esempio n. 3
0
        public void Run(UnpackMethod unpackMethod, object options)
        {
            if (queue == null)
            {
                return;
            }

            sizeCompleted = 0;
            canceled      = false;
            unpacker      = null;

            switch (unpackMethod)
            {
            case UnpackMethod.UnRAR: unpacker = new UnRAR(); break;
            }

            unpacker.SetOptions(options);
            unpacker.ProgressChanged += new Action <int, DateTime>(unpacker_ProgressChanged);
            unpacker.OutputChanged   += new Action <string>(unpacker_OutputChanged);

            queueStarted = DateTime.Now;
            OnStatusChanged(new QueueStarted());

            int length = queue.Count;

            for (currentPosition = 0; currentPosition < length; currentPosition++)
            {
                if (canceled)
                {
                    break;
                }

                QueueItem item        = queue[currentPosition];
                string    file        = item.FileToExtract;
                string    destination = item.Destination;

                OnStatusChanged(new ItemStarted(item));
                bool success = unpacker.Unpack(file, destination);

                if (canceled)
                {
                    break;
                }

                if (success)
                {
                    if (AutoAddUnpackedFiles)
                    {
                        GetAndAddExtractedItems(item);
                    }
                    queue[currentPosition].ErrorMessage = null;
                    OnStatusChanged(new ItemCompleted(item, CalculateItemsLeft()));
                }
                else
                {
                    OnStatusChanged(new UnpackerError(item, unpacker.ErrorMessage));
                    queue[currentPosition].ErrorMessage = unpacker.ErrorMessage;
                    CalculateAndReportProgress(0);
                }

                length = queue.Count;
            }

            if (canceled)
            {
                OnStatusChanged(new QueueCanceled());
            }
            else
            {
                OnStatusChanged(new QueueCompleted());
            }
        }