public void UnZip() { byte[] buffer = new byte[65536]; var fileInputStream = System.IO.File.OpenRead(_zipFile); var zipInputStream = new ZipInputStream(fileInputStream); ZipEntry zipEntry = null; int j = 0; int bestRead = 0; while ((zipEntry = zipInputStream.NextEntry) != null) { OnContinue?.Invoke(zipEntry.Name + ", " + bestRead); if (zipEntry.IsDirectory) { DirChecker(zipEntry.Name); } else { if (System.IO.File.Exists(_location + zipEntry.Name)) System.IO.File.Delete(_location + zipEntry.Name); var foS = new FileOutputStream(_location + zipEntry.Name, true); int read; while ((read = zipInputStream.Read(buffer)) > 0) { if (read > bestRead) bestRead = read; foS.Write(buffer, 0, read); } foS.Close(); zipInputStream.CloseEntry(); } } zipInputStream.Close(); fileInputStream.Close(); }
public bool UnzipFiles(string path, string zipname) { var f = new Java.IO.File(path); if (!f.Exists()) { f.Mkdir(); } try { String filename; var inputstream = System.IO.File.Open(Path.Combine(path, zipname + ".zip"), FileMode.Open); var zis = new Java.Util.Zip.ZipInputStream(inputstream); Java.Util.Zip.ZipEntry ze; byte[] buffer = new byte[1024]; int count; while ((ze = zis.NextEntry) != null) { filename = ze.Name; // Need to create directories if not exists, or // it will generate an Exception... if (ze.IsDirectory) { Java.IO.File fmd = new Java.IO.File(Path.Combine(Path.Combine(path, zipname), filename)); fmd.Mkdirs(); continue; } var fout = new Java.IO.FileOutputStream(Path.Combine(Path.Combine(path, zipname), filename)); while ((count = zis.Read(buffer)) != -1) { fout.Write(buffer, 0, count); } fout.Close(); zis.CloseEntry(); } zis.Close(); } catch (Java.IO.IOException iox) { System.Console.WriteLine(iox.Message); return(false); } return(true); }
public static void SetupShell(string target) { // Unzip var root = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal); if(!Directory.Exists(root + "/" + target)) { Log.Debug ("Ruly", "extracting default Shell..."); using (var s = Application.Context.Assets.Open ("Shell/" + target + ".zip")) using (var z = new ZipInputStream(s)) { ZipEntry ze; byte[] buf = new byte[1024]; while ((ze = z.NextEntry) != null) { if (!ze.IsDirectory) { string name = root + "/" + ze.Name; Util.EnsureDirectory (System.IO.Path.GetDirectoryName(name)); using (var ws = File.OpenWrite (name)) { var i = 0; while (i < ze.Size) { int num = z.Read (buf, 0, 1024); ws.Write (buf, 0, num); i += num; } z.CloseEntry (); Log.Debug ("Ruly", "Extract File " + ze.Name); } } } } } }