Ejemplo n.º 1
0
        private IntPtr IterateCallback(NativeMethods.FdiNotificationType fdint, NativeMethods.FdiNotification fdin)
        {
            switch (fdint)
            {
            case NativeMethods.FdiNotificationType.CopyFile:
                return(OutputFileOpen(fdin));

            default:
                return(IntPtr.Zero);
            }
        }
Ejemplo n.º 2
0
        private IntPtr ExtractCallback(NativeMethods.FdiNotificationType fdint, NativeMethods.FdiNotification fdin)
        {
            switch (fdint)
            {
            case NativeMethods.FdiNotificationType.CopyFile:
                return(CopyFiles(fdin));

            case NativeMethods.FdiNotificationType.CloseFileInfo:
                return(OutputFileClose(fdin));

            default:
                return(IntPtr.Zero);
            }
        }
    private IntPtr CopyFiles(NativeMethods.FdiNotification fdin)
    {
        var fileName    = GetFileName(fdin);
        var extractFile = _currentFileToDecompress.Name == fileName ? _currentFileToDecompress : null;

        if (extractFile != null)
        {
            var      stream = new MemoryStream();
            GCHandle gch    = GCHandle.Alloc(stream);
            extractFile.Handle = (IntPtr)gch;
            return(extractFile.Handle);
        }
        //Do not extract this file
        return(IntPtr.Zero);
    }
    private IntPtr OutputFileClose(NativeMethods.FdiNotification fdin)
    {
        var extractFile = _currentFileToDecompress.Handle == fdin.hf ? _currentFileToDecompress : null;
        var stream      = StreamFromHandle(fdin.hf);

        if (extractFile != null)
        {
            extractFile.Found  = true;
            extractFile.Length = (int)stream.Length;
            if (stream.Length > 0)
            {
                extractFile.Data = new byte[stream.Length];
                stream.Position  = 0;
                stream.Read(extractFile.Data, 0, (int)stream.Length);
            }
        }
        stream.Close();
        return(IntPtr.Zero);
    }
Ejemplo n.º 5
0
        private static string GetFileName(NativeMethods.FdiNotification notification)
        {
            var encoding = ((int)notification.attribs & 128) != 0 ? Encoding.UTF8 : Encoding.Default;
            int length   = 0;

            while (Marshal.ReadByte(notification.psz1, length) != 0)
            {
                checked { ++length; }
            }
            var numArray = new byte[length];

            Marshal.Copy(notification.psz1, numArray, 0, length);
            string path = encoding.GetString(numArray);

            if (Path.IsPathRooted(path))
            {
                path = path.Replace(String.Concat(Path.VolumeSeparatorChar), "");
            }
            return(path);
        }
Ejemplo n.º 6
0
        private IntPtr OutputFileOpen(NativeMethods.FdiNotification fdin)
        {
            var extractFile = new ArchiveFile {
                Name = GetFileName(fdin)
            };

            if (ShouldIgnoreFile(extractFile))
            {
                //ignore this file.
                return(IntPtr.Zero);
            }
            var      stream = new MemoryStream();
            GCHandle gch    = GCHandle.Alloc(stream);

            extractFile.Handle = (IntPtr)gch;

            AddToListOfFiles(extractFile);

            //return IntPtr.Zero so that the iteration will keep on going
            return(IntPtr.Zero);
        }