示例#1
0
        public static bool ExtractZip(string zipFile, string dest, Action <string> onProgress, Action <string> onError)
        {
            if (!File.Exists(zipFile))
            {
                onError("Invalid path: " + zipFile);
                return(false);
            }

            var extracted = new List <string>();

            try
            {
                using (var stream = File.OpenRead(zipFile))
                    using (var z = new ZipInputStream(stream))
                        z.ExtractZip(dest, extracted, s => onProgress("Extracting " + s));
            }
            catch (SharpZipBaseException)
            {
                foreach (var f in extracted)
                {
                    File.Delete(f);
                }

                onError("Invalid archive");
                return(false);
            }

            return(true);
        }