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(); }
private Effect LoadEffect(string path) { byte[] bytes = null; try { AssetManager assetManager = Activity.ApplicationContext.Assets; System.IO.Stream inputStream = assetManager.Open(path, Access.Buffer); byte[] buffer = new byte[1024]; ZipInputStream zis = new ZipInputStream(inputStream); ZipEntry ze = zis.NextEntry; while (ze != null) { String filePath = ze.Name; //Log.i(TAG, "Found="+ze.getName()); //Log.i(TAG, "Open Output="+newFile.getAbsoluteFile()); int totalLength = 0; int len; List<byte[]> chunks = new List<byte[]>(); while ((len = zis.Read(buffer)) > 0) { Android.Util.Log.Info(TAG, string.Format("Read: {0} bytes", len)); totalLength += len; byte[] chunk = new byte[len]; Array.Copy(buffer, chunk, len); chunks.Add(chunk); } bytes = new byte[totalLength]; int index = 0; foreach (byte[] chunk in chunks) { Array.Copy(chunk, 0, bytes, index, chunk.Length); index += chunk.Length; } ze = zis.NextEntry; } zis.Close(); inputStream.Close(); } catch (Exception ex) { Android.Util.Log.Error(TAG, string.Format("Exception reading={0}", ex)); } Effect effect = null; if (null != bytes) { try { effect = new Effect(GraphicsDevice, bytes); } catch (Exception ex) { Android.Util.Log.Error(TAG, string.Format("Loading Effect Exception={0}", ex)); } } return effect; }
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); } } } } } }
/// <summary> /// 解压缩一个 zip 文件。 /// </summary> /// <param name="zipedFile">The ziped file.</param> /// <param name="strDirectory">The STR directory.</param> /// <param name="password">zip 文件的密码。</param> /// <param name="overWrite">是否覆盖已存在的文件。</param> public void UnZip(string zipedFile, string strDirectory, string password, bool overWrite) { if (strDirectory == "") strDirectory = Directory.GetCurrentDirectory(); if (!strDirectory.EndsWith("\\")) strDirectory = strDirectory + "\\"; using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipedFile))) { //s.Password = password; ZipEntry theEntry; while ((theEntry = s.NextEntry) != null) { string directoryName = ""; string pathToZip = ""; pathToZip = theEntry.Name; if (pathToZip != "") directoryName = Path.GetDirectoryName(pathToZip) + "\\"; string fileName = Path.GetFileName(pathToZip); Directory.CreateDirectory(strDirectory + directoryName); if (fileName != "") { if ((File.Exists(strDirectory + directoryName + fileName) && overWrite) || (!File.Exists(strDirectory + directoryName + fileName))) { using (FileStream streamWriter = File.Create(strDirectory + directoryName + fileName)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) streamWriter.Write(data, 0, size); else break; } streamWriter.Close(); } } } } s.Close(); } }