Exemplo n.º 1
0
        public bool ExtractFiles(string[] filesToExtract)
        {
            if (filesToExtract == null)
            {
                return(false);
            }

            if (filesToExtract.Length == 0)
            {
                return(false);
            }

            UnzipOptionsFlags  opts = PrepareOptionsFlags();
            UnzipUserFunctions unzipUserFunctions = PrepareCallBack();

            try
            {
                UnZipError ret = NativeMethods.Wiz_SingleEntryUnzip(filesToExtract.Length, filesToExtract, 0, null, ref opts, ref unzipUserFunctions);
                return(ret == UnZipError.PK_OK);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public byte[] ExtractToMemory(string fileToExtract)
        {
            UnzipUserFunctions unzipUserFunctions = PrepareCallBack();

            UnzipMemoryBuffer buf = new UnzipMemoryBuffer();

            // note: on successfull memory allocation and initialization,
            // Wiz_UnzipToMemory() returns a Longbool instead of a return code.
            // therefore the return value needs to be translated if < PK_BADERR.
            UnZipError res = NativeMethods.Wiz_UnzipToMemory(fileName, fileToExtract, ref unzipUserFunctions, ref buf);

            if (res == UnZipError.PK_WARN)
            {
                res = UnZipError.PK_OK;
            }
            else
            if (res == UnZipError.PK_OK)
            {
                res = UnZipError.PK_ERR;
            }

            if (res != UnZipError.PK_OK)
            {
                try
                {
                    NativeMethods.UzpFreeMemBuffer(ref buf);
                }
                catch
                {
                }
                return(null);
            }

            if (buf.TotalSize > 0)
            {
                try
                {
                    byte[] result = new byte[buf.TotalSize];
                    Marshal.Copy(buf.Buffer, result, 0, buf.TotalSize);
                    NativeMethods.UzpFreeMemBuffer(ref buf);
                    return(result);
                }
                catch
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }