Ejemplo 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);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prepares the call back functions.
        /// </summary>
        /// <returns>Unzip callback functions structure</returns>
        internal UnzipUserFunctions PrepareCallBack()
        {
            UnzipUserFunctions unzipUserFunctions = new UnzipUserFunctions();

            unzipUserFunctions.PrintCallbackFunction    = new PrintCallbackDelegate(ProcessPrintCallback);
            unzipUserFunctions.ReplaceCallbackFunction  = new ServiceCallbackDelegate(ProcessReplaceCallback);
            unzipUserFunctions.SoundCallbackFunction    = new SoundCallbackDelegate(ProcessSoundCallback);
            unzipUserFunctions.PasswordCallbackFunction = new PasswordCallbackDelegate(ProcessPasswordCallback);
            unzipUserFunctions.ServiceCallbackFunction  = new ServiceCallbackDelegate(ProcessServiceMessageCallback);
            unzipUserFunctions.SendApplicationMessage   = new ServiceCallbackDelegate(ProcessApplicationMessageCallback);
            return(unzipUserFunctions);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 public static extern UnZipError Wiz_UnzipToMemory(string zip, string file, ref UnzipUserFunctions zuf, ref UnzipMemoryBuffer retstr);
Ejemplo n.º 5
0
 public static extern UnZipError Wiz_SingleEntryUnzip(int zipcnt, string[] zipnames, int zipncnt2, string[] zipnames2, ref UnzipOptionsFlags opts, ref UnzipUserFunctions zuf);