Exemplo n.º 1
0
        private void ExtractCallback(object ctx)
        {
            WorkUnit         unit = (WorkUnit)ctx;
            EmbeddedFileInfo efi  = unit.efi;

            byte[] buffer         = new byte[efi.size];
            IntPtr fileMemAddress = new IntPtr(unit.fileVolAddress);

            Marshal.Copy(fileMemAddress, buffer, 0, buffer.Length);
            if (unit.callback != null)
            {
                unit.callback(String.Format("Extracted {0} from VOL", efi.name));
            }

            // I tried async-ing this write in the decomp case, but it was magnitudes slower
            unit.destFile.Write(buffer, 0, buffer.Length);
            if (unit.callback != null)
            {
                unit.callback(String.Format("Finished writing {0} bytes of {1}", buffer.Length, efi.name));
            }
            if (unit.shouldDecompAfter)
            {
                // create a mem stream on the buffer so we can decomp without having to hit the filesystem
                // on both the read and the write
                MemoryStream memGz = new MemoryStream(buffer, false);
                using (FileStream destFile = GetUnzippedFileFromOrig(unit.destFile.Name))
                    using (GZipInputStream srcStream = new GZipInputStream(memGz))
                    {
                        byte[] readBuf = new byte[0x8000];
                        StreamUtils.Copy(srcStream, destFile, readBuf);
                        if (unit.callback != null)
                        {
                            unit.callback(String.Format("Ungzipped {0} bytes to {1} for {2}", memGz.Length, destFile.Position, efi.name));
                        }
                    }
            }
            unit.finishedHandle.Set();
            string fileName = unit.destFile.Name;

            unit.destFile.Close();
            DateTime fileTime = new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(unit.efi.dateTime);

            File.SetCreationTime(fileName, fileTime);
            File.SetLastWriteTime(fileName, fileTime);
            File.SetLastAccessTime(fileName, fileTime);
        }