public static void ExtractFileAndSave(string APKFilePath, string fileResourceLocation, string FilePathToSave, int index) { using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(APKFilePath))) { using (var filestream = new FileStream(APKFilePath, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { if (item.Name.ToLower() == fileResourceLocation) { string fileLocation = Path.Combine(FilePathToSave, string.Format("{0}-{1}", index, fileResourceLocation.Split(Convert.ToChar(@"/")).Last())); using (Stream strm = zipfile.GetInputStream(item)) using (FileStream output = File.Create(fileLocation)) { try { strm.CopyTo(output); } catch (Exception ex) { throw ex; } } } } } } }
/// <summary> /// Unzip a local file and return its contents via streamreader: /// </summary> public static StreamReader UnzipStreamToStreamReader(Stream zipstream) { StreamReader reader = null; try { //Initialise: MemoryStream file; //If file exists, open a zip stream for it. using (var zipStream = new ZipInputStream(zipstream)) { //Read the file entry into buffer: var entry = zipStream.GetNextEntry(); var buffer = new byte[entry.Size]; zipStream.Read(buffer, 0, (int)entry.Size); //Load the buffer into a memory stream. file = new MemoryStream(buffer); } //Open the memory stream with a stream reader. reader = new StreamReader(file); } catch (Exception err) { Log.Error(err); } return(reader); } // End UnZip
public static void unZip(byte[] dataZip, string path) { try { using (Stream zipFile = new MemoryStream(dataZip)) { using (ICSharpCode.SharpZipLib.Zip.ZipInputStream ZipStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(zipFile)) { ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry; theEntry = ZipStream.GetNextEntry(); if (theEntry.IsFile) { if (theEntry.Name != "") { FileStream outputStream = new FileStream(path, FileMode.OpenOrCreate); StreamUtils.Copy(ZipStream, outputStream, new byte[4096]); ZipStream.Close(); outputStream.Close(); } } } } } catch (Exception ex) { //Console.WriteLine(ex.Message); throw ex; } }
public ArquivoPdf[] DescomprimirBase64(byte[] ArquivosZip) { MemoryStream baseInputStream = new MemoryStream(ArquivosZip); ICSharpCode.SharpZipLib.Zip.ZipInputStream zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(baseInputStream); IList <ArquivoPdf> list = new List <ArquivoPdf>(); ICSharpCode.SharpZipLib.Zip.ZipEntry nextEntry; while ((nextEntry = zipInputStream.GetNextEntry()) != null) { MemoryStream memoryStream = new MemoryStream(); ArquivoPdf arquivoPdf = new ArquivoPdf(); long num = nextEntry.Size; arquivoPdf.Nome = nextEntry.Name; byte[] array = new byte[1024]; while (true) { num = (long)zipInputStream.Read(array, 0, array.Length); if (num <= 0L) { break; } memoryStream.Write(array, 0, (int)num); } memoryStream.Close(); arquivoPdf.Dados = memoryStream.ToArray(); list.Add(arquivoPdf); } return(list.ToArray <ArquivoPdf>()); }
public string[] retornaListaDeArquivos(string strNomeArquivoZip) { string[] strArrayRetorno = new string[0]; try { ICSharpCode.SharpZipLib.Zip.ZipInputStream clsZipInStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(strNomeArquivoZip)); int nCount = 0; System.Collections.ArrayList arlArquivos = new System.Collections.ArrayList(); ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry; while ((theEntry = clsZipInStream.GetNextEntry()) != null) { arlArquivos.Add(theEntry.Name); nCount++; } clsZipInStream.Close(); strArrayRetorno = new string[nCount]; int nIndice = 0; foreach (string strFile in arlArquivos) { strArrayRetorno[nIndice] = strFile; nIndice++; } } catch (Exception err) { Object erro = err; m_cls_ter_tratadorErro.trataErro(ref erro); } return(strArrayRetorno); }
// ZIP ファイルかチェック private bool isZipFile(string filePath) { System.IO.FileStream fs = new System.IO.FileStream( filePath, FileMode.Open, FileAccess.Read); //ZipInputStreamオブジェクトの作成 ICSharpCode.SharpZipLib.Zip.ZipInputStream zis = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(fs); try { ICSharpCode.SharpZipLib.Zip.ZipEntry ze; while ((ze = zis.GetNextEntry()) != null) { //Console.WriteLine(ze.Name); fs.Close(); return(true); } } catch { fs.Close(); return(false); } fs.Close(); return(false); }
/* Unzips dirName + ".zip" --> dirName, removing dirName * first */ public virtual void Unzip(System.String zipName, System.String destDirName) { #if SHARP_ZIP_LIB // get zip input stream ICSharpCode.SharpZipLib.Zip.ZipInputStream zipFile; zipFile = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipName + ".zip")); // get dest directory name System.String dirName = FullDir(destDirName); System.IO.FileInfo fileDir = new System.IO.FileInfo(dirName); // clean up old directory (if there) and create new directory RmDir(fileDir.FullName); System.IO.Directory.CreateDirectory(fileDir.FullName); // copy file entries from zip stream to directory ICSharpCode.SharpZipLib.Zip.ZipEntry entry; while ((entry = zipFile.GetNextEntry()) != null) { System.IO.Stream streamout = new System.IO.BufferedStream(new System.IO.FileStream(new System.IO.FileInfo(System.IO.Path.Combine(fileDir.FullName, entry.Name)).FullName, System.IO.FileMode.Create)); byte[] buffer = new byte[8192]; int len; while ((len = zipFile.Read(buffer, 0, buffer.Length)) > 0) { streamout.Write(buffer, 0, len); } streamout.Close(); } zipFile.Close(); #else Assert.Fail("Needs integration with SharpZipLib"); #endif }
public static void EnumZip(string zipFileName, string password) { SharpZipLib.Zip.ZipInputStream s = new SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFileName)); s.Password = password; SharpZipLib.Zip.ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { LogUtil.Log(theEntry.Name + "," + theEntry.ZipFileIndex + "," + theEntry.Offset); } }
private void _Check_ZIP(string pathFileZip, IDTSComponentEvents componentEvents) { bool b = false; if (_testarchive) { using (ICSharpCode.SharpZipLib.Zip.ZipInputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(pathFileZip))) { if (!string.IsNullOrEmpty(_password)) { fz.Password = _password; } try { ICSharpCode.SharpZipLib.Zip.ZipEntry ze = fz.GetNextEntry(); componentEvents.FireInformation(1, "UnZip SSIS", "Start verify file ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b); while (ze != null) { componentEvents.FireInformation(1, "UnZip SSIS", "Verifying Entry: " + ze.Name, null, 0, ref b); fz.CopyTo(System.IO.MemoryStream.Null); fz.Flush(); fz.CloseEntry(); ze = fz.GetNextEntry(); } componentEvents.FireInformation(1, "UnZip SSIS", "File ZIP verified ZIP (" + _folderSource + _fileZip + ")", null, 0, ref b); } catch (Exception ex) { throw new Exception("Verify file: " + _fileZip + " failed. (" + ex.Message + ")"); } finally { fz.Close(); } } } }
private void SelectAPK(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); packageNameLBL.Text = "Package Name: LENDO ARQUIVO"; openFileDialog1.Filter = "APK Files|*.APK"; openFileDialog1.Title = "Selecione um arquivo .APK"; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { NomeAPK = openFileDialog1.FileName; using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(openFileDialog1.FileName))) { using (var filestream = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; try { while ((item = zip.GetNextEntry()) != null) { if (item.Name.ToLower() == "androidmanifest.xml") { manifestData = new byte[50 * 1024]; using (Stream strm = zipfile.GetInputStream(item)) { strm.Read(manifestData, 0, manifestData.Length); } } if (item.Name.ToLower() == "resources.arsc") { using (Stream strm = zipfile.GetInputStream(item)) { using (BinaryReader s = new BinaryReader(strm)) { resourcesData = s.ReadBytes((int)s.BaseStream.Length); } } } } } catch (Exception) { } } } ApkReader apkReader = new ApkReader(); ApkInfo info = apkReader.extractInfo(manifestData, resourcesData); packageNameLBL.Text = "Package Name: " + info.packageName; versionLBL.Text = "Version: " + info.versionName; installAPKBTN.Enabled = true; } }
public void SharpZipLibBaseInputStreamIsNotReadToEnd() { using (var dataStream = ResourceManager.Load("Data.METERING_REQUEST_20150531.zip")) using (var eventingStream = new EventingReadStream(dataStream)) using (var decompressingStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(eventingStream)) { var eosReached = false; eventingStream.AfterLastReadEvent += (sender, args) => { eosReached = true; }; decompressingStream.GetNextEntry(); decompressingStream.Drain(); Assert.That(eosReached, Is.False); } }
//private static void CopyStream(Stream input, Stream output) //{ // byte[] buffer = new byte[8 * 1024]; // int len; // while ((len = input.Read(buffer, 0, buffer.Length)) > 0) // { // output.Write(buffer, 0, len); // } //} public static AndroidManifestData GetManifestData(String apkFilePath) { byte[] manifestData = null; byte[] resourcesData = null; using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(apkFilePath))) { using (var filestream = new FileStream(apkFilePath, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { if (item.Name.ToLower() == "androidmanifest.xml") { manifestData = new byte[50 * 1024]; using (Stream strm = zipfile.GetInputStream(item)) { strm.Read(manifestData, 0, manifestData.Length); } } if (item.Name.ToLower() == "resources.arsc") { using (Stream strm = zipfile.GetInputStream(item)) { using (BinaryReader s = new BinaryReader(strm)) { resourcesData = s.ReadBytes((int)s.BaseStream.Length); } } } } } } Iteedee.ApkReader.ApkReader reader = new ApkReader.ApkReader(); Iteedee.ApkReader.ApkInfo info = reader.extractInfo(manifestData, resourcesData); string AppName = info.label; return(new AndroidManifestData() { VersionCode = info.versionCode, VersionName = info.versionName, PackageName = info.packageName, ApplicationName = info.label, ApplicationIconName = GetBestIconAvailable(info.iconFileNameToGet) }); }
public void UnZIP(string SourceFile, string DestPath, bool PreservePath, string[] ZipEntry) { FileStream fs = File.OpenRead(SourceFile); ICSharpCode.SharpZipLib.Zip.ZipInputStream s = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(fs); ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { if (theEntry.IsDirectory) { continue; } if (null != ZipEntry && ZipEntry.Length > 0 && Array.BinarySearch(ZipEntry, Path.GetFileName(theEntry.Name), System.Collections.CaseInsensitiveComparer.Default) < 0) { continue; } int size = 2048; byte[] data = new byte[2048]; string outputFileName = null; if (PreservePath) { outputFileName = Path.Combine(DestPath, theEntry.Name); } else { outputFileName = Path.Combine(DestPath, Path.GetFileName(theEntry.Name)); } if (!Directory.Exists(Path.GetDirectoryName(outputFileName))) { Directory.CreateDirectory(Path.GetDirectoryName(outputFileName)); } FileStream destFS = new FileStream(outputFileName, FileMode.Create); while (s.Available > 0) { int readLen = s.Read(data, 0, size); destFS.Write(data, 0, readLen); } destFS.Flush(); destFS.Close(); } s.Close(); }
/// <summary> /// 解压缩(将压缩的文件解压到指定的文件夹下面)—解压到指定文件夹下面 /// </summary> /// <param name="zipFilePath">源压缩的文件路径</param> /// <param name="savePath">解压后保存文件到指定的文件夹</param> public static void ZipUnFileInfo(string zipFilePath, string savePath) { try { using (var zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFilePath))) { ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry; while ((zipEntry = zipInputStream.GetNextEntry()) != null) { string directoryName = Path.GetDirectoryName(zipEntry.Name); string fileName = Path.GetFileName(zipEntry.Name); string serverFolder = savePath; //创建一个文件目录信息 Directory.CreateDirectory(serverFolder + "/" + directoryName); //如果解压的文件不等于空,则执行以下步骤 if (fileName != string.Empty) { using (FileStream fileStream = File.Create((serverFolder + "/" + zipEntry.Name))) { int size = 2048; byte[] data = new byte[2048]; //初始化字节数为2兆,后面根据需要解压的内容扩展字节数 while (true) { size = zipInputStream.Read(data, 0, data.Length); if (size > 0) { fileStream.Write(data, 0, size); } else { break; } } fileStream.Close(); } } } zipInputStream.Close(); } } catch (Exception exception) { throw new Exception("出现错误了,不能解压缩,错误原因:" + exception.Message); } }
/// <summary> /// Разжатие /// </summary> /// <param name="ms"></param> /// <returns></returns> public static MemoryStream Decompress(MemoryStream ms) { ms.Seek(0, System.IO.SeekOrigin.Begin); ICSharpCode.SharpZipLib.Zip.ZipInputStream zs = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(ms); ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry; try { theEntry = zs.GetNextEntry(); } catch (Exception e) { return(ms); } MemoryStream resstream = new MemoryStream(); //**** byte[] data = new byte[4096]; int size; do { size = zs.Read(data, 0, data.Length); resstream.Write(data, 0, size); } while (size > 0); //***** //b = new byte[zs.Length]; //zs.Read(b,0,b.Length); //resstream.Write(b,0,b.Length); resstream.Seek(0, SeekOrigin.Begin); zs.Close(); return(resstream); }
public void descompacta(string strNomeArquivoZip) { try { ICSharpCode.SharpZipLib.Zip.ZipInputStream clsZipInStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(strNomeArquivoZip)); ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry; while ((theEntry = clsZipInStream.GetNextEntry()) != null) { if (theEntry.Size > 0) { byte[] conteudoArquivo = new byte[theEntry.Size]; int bytesReaded, posInFile = 0; long fileSize = theEntry.Size; do { bytesReaded = clsZipInStream.Read(conteudoArquivo, posInFile, (int)fileSize); posInFile += bytesReaded; fileSize -= bytesReaded; } while (fileSize > 0 || bytesReaded == 0); if (bytesReaded > 0) { System.IO.FileStream fsOutFile = new System.IO.FileStream(theEntry.Name, System.IO.FileMode.Create, System.IO.FileAccess.Write); System.IO.BinaryWriter bwOutFile = new System.IO.BinaryWriter(fsOutFile); bwOutFile.Write(conteudoArquivo); bwOutFile.Flush(); bwOutFile.Close(); fsOutFile.Close(); } conteudoArquivo = null; } } clsZipInStream.Close(); } catch (Exception err) { Object erro = err; m_cls_ter_tratadorErro.trataErro(ref erro); } }
private static string GetContentXml(System.IO.Stream fileStream) { string contentXml = ""; using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(fileStream)) { ICSharpCode.SharpZipLib.Zip.ZipEntry contentEntry = null; while ((contentEntry = zipInputStream.GetNextEntry()) != null) { if (!contentEntry.IsFile) { continue; } if (contentEntry.Name.ToLower() == "content.xml") { break; } } if (contentEntry.Name.ToLower() != "content.xml") { throw new System.Exception("Cannot find content.xml"); } byte[] bytesResult = new byte[] { }; byte[] bytes = new byte[2000]; int i = 0; while ((i = zipInputStream.Read(bytes, 0, bytes.Length)) != 0) { int arrayLength = bytesResult.Length; System.Array.Resize <byte>(ref bytesResult, arrayLength + i); System.Array.Copy(bytes, 0, bytesResult, arrayLength, i); } contentXml = System.Text.Encoding.UTF8.GetString(bytesResult); } return(contentXml); }
private static Dictionary<string,object> GetIpaPList(string filePath) { Dictionary<string, object> plist = new Dictionary<string, object>(); ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(filePath)); using (var filestream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { Match match = Regex.Match(item.Name.ToLower(), @"Payload/([A-Za-z0-9\-. ]+)\/info.plist$", RegexOptions.IgnoreCase); if (match.Success) { byte[] bytes = new byte[50 * 1024]; using( Stream strm = zipfile.GetInputStream(item)) { int size = strm.Read(bytes, 0, bytes.Length); using (BinaryReader s = new BinaryReader(strm)) { byte[] bytes2 = new byte[size]; Array.Copy(bytes, bytes2, size); plist = (Dictionary<string, object>)PlistCS.readPlist(bytes2); } } break; } } } return plist; }
/// <summary> /// Uncompress zip data byte array into a dictionary string array of filename-contents. /// </summary> /// <param name="zipData">Byte data array of zip compressed information</param> /// <param name="encoding">Specifies the encoding used to read the bytes. If not specified, defaults to ASCII</param> /// <returns>Uncompressed dictionary string-sting of files in the zip</returns> public static Dictionary <string, string> UnzipData(byte[] zipData, Encoding encoding = null) { // Initialize: var data = new Dictionary <string, string>(); try { using (var ms = new MemoryStream(zipData)) { //Read out the zipped data into a string, save in array: using (var zipStream = new ZipInputStream(ms)) { while (true) { //Get the next file var entry = zipStream.GetNextEntry(); if (entry != null) { //Read the file into buffer: var buffer = new byte[entry.Size]; zipStream.Read(buffer, 0, (int)entry.Size); //Save into array: var str = (encoding ?? Encoding.ASCII).GetString(buffer); data.Add(entry.Name, str); } else { break; } } } // End Zip Stream. } // End Using Memory Stream } catch (Exception err) { Log.Error(err); } return(data); }
static void TestZipArchive(string filename) { Console.WriteLine("testing zip archive " + filename); try { using (var file = File.OpenRead(filename)) using (var stream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(file)) { for (var entry = stream.GetNextEntry(); entry != null; entry = stream.GetNextEntry()) { Console.WriteLine(entry.Name + ":"); stream.CopyTo(Console.OpenStandardOutput()); Console.WriteLine(""); } } } catch (Exception e) { Console.Write(e.Message + e.StackTrace); } }
static object Deserialize(string PathName) { // not compressed (try) using (var s = File.OpenRead(PathName)) try { IFormatter formatter = new BinaryFormatter(); var res = (MyData)formatter.Deserialize(s); return(res); } catch { } // compressed using (var s = File.OpenRead(PathName)) using (var gs = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(s)) { gs.GetNextEntry(); var bf = new BinaryFormatter(); return(bf.Deserialize(gs)); } }
/// <summary> /// 解压缩—结果不包含文件夹 /// </summary> /// <param name="zipFilePath">源压缩的文件路径</param> /// <param name="savePath">解压后的文件保存路径</param> public static void ZipUnFileWithOutFolderInfo(string zipFilePath, string savePath) { try { using (var zipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(zipFilePath))) { ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry; while ((zipEntry = zipInputStream.GetNextEntry()) != null) { string fileName = Path.GetFileName(zipEntry.Name); if (fileName != string.Empty) { using (var fileStream = File.Create(savePath)) { int size = 2084; //初始化字节数为2兆,后面根据需要解压的内容扩展字节数 byte[] data = new byte[2048]; while (true) { size = zipInputStream.Read(data, 0, data.Length); if (size > 0) { fileStream.Write(data, 0, size); } else { break; } } fileStream.Close(); } } } zipInputStream.Close(); } } catch (Exception exception) { throw new Exception("解压缩出现错误了,错误原因:" + exception.Message); } }
protected virtual void DeserializeHieghtmap(Map map, Stream stream) { // Heightmap serialization method 3 var d = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(stream); d.GetNextEntry(); var br = new BinaryReader(d); var height = br.ReadInt32(); var width = br.ReadInt32(); var hm = new Graphics.Software.Texel.R32F[height, width]; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { hm[y, x] = new Graphics.Software.Texel.R32F(br.ReadSingle()); } } map.Ground.Heightmap = hm; d.Close(); }
public static string getAPKVersion(string path) { byte[] manifestData = null; byte[] resourcesData = null; using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(path))) { using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { if (item.Name.ToLower() == "androidmanifest.xml") { manifestData = new byte[50 * 1024]; using (Stream strm = zipfile.GetInputStream(item)) { strm.Read(manifestData, 0, manifestData.Length); } } if (item.Name.ToLower() == "resources.arsc") { using (Stream strm = zipfile.GetInputStream(item)) { using (BinaryReader s = new BinaryReader(strm)) { resourcesData = s.ReadBytes((int)s.BaseStream.Length); } } } } } } ApkReader apkReader = new ApkReader(); return(apkReader.getVersion(manifestData, resourcesData)); }
public void ExtractFileAndSave(string APKFilePath, string fileResourceLocation, string FilePathToSave, string pkg) { try { using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(APKFilePath))) { using (var filestream = new FileStream(APKFilePath, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { if (item.Name.ToLower() == fileResourceLocation) { string fileLocation = System.IO.Path.Combine(FilePathToSave, pkg + ".png"); using (Stream strm = zipfile.GetInputStream(item)) using (FileStream output = File.Create(fileLocation)) { try { strm.CopyTo(output); } catch (Exception ex) { throw ex; } } } } } } } catch { textBox1.AppendText("Extract Icon Failed!" + "\n"); return; } }
public void WrapsMessageStreamInZipOutputStream() { const string location = "sftp://host/folder/file.txt"; MessageMock .Setup(m => m.GetProperty(BizTalkFactoryProperties.OutboundTransportLocation)) .Returns(location); var bodyPart = new Mock <IBaseMessagePart>(); bodyPart.Setup(p => p.GetOriginalDataStream()).Returns(new StringStream("content")); bodyPart.SetupProperty(p => p.Data); MessageMock.Setup(m => m.BodyPart).Returns(bodyPart.Object); var sut = new ZipEncoder(); sut.Execute(PipelineContextMock.Object, MessageMock.Object); Assert.IsInstanceOf <ZipOutputStream>(MessageMock.Object.BodyPart.Data); var clearStream = new ZipInputStream(MessageMock.Object.BodyPart.Data); var entry = clearStream.GetNextEntry(); Assert.That(entry.Name, Is.EqualTo(System.IO.Path.GetFileName(location))); }
public static void ZipList(string zipPath) { var fs = new FileStream(zipPath, FileMode.Open, FileAccess.Read); var zis = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(fs); while (true) { // ZipEntryを取得 var ze = zis.GetNextEntry(); if (ze == null) { break; } if (ze.IsFile) { // ファイルのとき Console.WriteLine("名前 : {0}", ze.Name); Console.WriteLine("サイズ : {0} bytes", ze.Size); Console.WriteLine("格納サイズ : {0} bytes", ze.CompressedSize); Console.WriteLine("圧縮方法 : {0}", ze.CompressionMethod); Console.WriteLine("CRC : {0:X}", ze.Crc); Console.WriteLine("日時 : {0}", ze.DateTime); Console.WriteLine(); } else if (ze.IsDirectory) { // ディレクトリのとき Console.WriteLine("ディレクトリ名 : {0}", ze.Name); Console.WriteLine("日時 : {0}", ze.DateTime); Console.WriteLine(); } } zis.Close(); fs.Close(); }
private string ReadInfo(string apkPath) { if (string.IsNullOrEmpty(apkPath) || !File.Exists(apkPath)) { return(string.Empty); } ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(apkPath)); var filestream = new FileStream(apkPath, FileMode.Open, FileAccess.Read); ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; string content = string.Empty; while ((item = zip.GetNextEntry()) != null) { if (item.Name == "AndroidManifest.xml") { byte[] bytes = new byte[50 * 1024]; Stream strm = zipfile.GetInputStream(item); int size = strm.Read(bytes, 0, bytes.Length); using (BinaryReader s = new BinaryReader(strm)) { byte[] bytes2 = new byte[size]; Array.Copy(bytes, bytes2, size); AndroidDecompress decompress = new AndroidDecompress(); content = decompress.decompressXML(bytes); break; } } } return(content); }
private static Dictionary <string, object> GetIpaPList(string filePath) { Dictionary <string, object> plist = new Dictionary <string, object>(); ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(filePath)); using (var filestream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { Match match = Regex.Match(item.Name.ToLower(), @"Payload/([A-Za-z0-9\-. ]+)\/info.plist$", RegexOptions.IgnoreCase); if (match.Success) { byte[] bytes = new byte[50 * 1024]; using (Stream strm = zipfile.GetInputStream(item)) { int size = strm.Read(bytes, 0, bytes.Length); using (BinaryReader s = new BinaryReader(strm)) { byte[] bytes2 = new byte[size]; Array.Copy(bytes, bytes2, size); plist = (Dictionary <string, object>)PlistCS.readPlist(bytes2); } } break; } } } return(plist); }
/// <summary> 解压数据 </summary> public static byte[] Decompress(Stream source) { #if false//SCORPIO_UWP && !UNITY_EDITOR using (MemoryStream stream = new MemoryStream()) { System.IO.Compression.ZipArchive zipStream = new System.IO.Compression.ZipArchive(source, System.IO.Compression.ZipArchiveMode.Read); System.IO.Compression.ZipArchiveEntry zipEntry = zipStream.Entries[0]; Stream entryStream = zipEntry.Open(); int count = 0; byte[] data = new byte[4096]; while ((count = entryStream.Read(data, 0, data.Length)) != 0) { stream.Write(data, 0, count); } zipStream.Dispose(); byte[] ret = stream.ToArray(); stream.Dispose(); return(ret); } #else using (MemoryStream stream = new MemoryStream()) { ICSharpCode.SharpZipLib.Zip.ZipInputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(source); zipStream.GetNextEntry(); int count = 0; byte[] data = new byte[4096]; while ((count = zipStream.Read(data, 0, data.Length)) != 0) { stream.Write(data, 0, count); } zipStream.Flush(); byte[] ret = stream.ToArray(); zipStream.Dispose(); stream.Dispose(); return(ret); } #endif }
static bool FindEntry(SharpZipLib.Zip.ZipInputStream s, string entryname, out SharpZipLib.Zip.ZipEntry entry) { try { entry = null; SharpZipLib.Zip.ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { string name = theEntry.Name; if (0 == string.Compare(name.Replace('\\', '/'), entryname.Replace('\\', '/'), false)) { entry = theEntry; break; } } return(true); } catch (Exception e) { LogUtil.LogError(e.Message); entry = null; return(false); } }
// Uncomment these cases & run them on an older Lucene // version, to generate an index to test backwards // compatibility. Then, cd to build/test/index.cfs and // run "zip index.<VERSION>.cfs.zip *"; cd to // build/test/index.nocfs and run "zip // index.<VERSION>.nocfs.zip *". Then move those 2 zip // files to your trunk checkout and add them to the // oldNames array. /* public void testCreatePreLocklessCFS() throws IOException { createIndex("index.cfs", true); } public void testCreatePreLocklessNoCFS() throws IOException { createIndex("index.nocfs", false); } */ /* Unzips dirName + ".zip" --> dirName, removing dirName first */ public virtual void Unzip(System.String zipName, System.String destDirName) { #if SHARP_ZIP_LIB // get zip input stream ICSharpCode.SharpZipLib.Zip.ZipInputStream zipFile; zipFile = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipName + ".zip")); // get dest directory name System.String dirName = FullDir(destDirName); System.IO.FileInfo fileDir = new System.IO.FileInfo(dirName); // clean up old directory (if there) and create new directory RmDir(fileDir.FullName); System.IO.Directory.CreateDirectory(fileDir.FullName); // copy file entries from zip stream to directory ICSharpCode.SharpZipLib.Zip.ZipEntry entry; while ((entry = zipFile.GetNextEntry()) != null) { System.IO.Stream streamout = new System.IO.BufferedStream(new System.IO.FileStream(new System.IO.FileInfo(System.IO.Path.Combine(fileDir.FullName, entry.Name)).FullName, System.IO.FileMode.Create)); byte[] buffer = new byte[8192]; int len; while ((len = zipFile.Read(buffer, 0, buffer.Length)) > 0) { streamout.Write(buffer, 0, len); } streamout.Close(); } zipFile.Close(); #else Assert.Fail("Needs integration with SharpZipLib"); #endif }
private void menuImportTeamData_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.CheckFileExists = true; d.CheckPathExists = true; d.Filter = T("Tutti i file ZIP (*.zip)")+"|*.zip"; d.InitialDirectory = My.Dir.Desktop; d.Multiselect = false; d.Title = T("Importa dati precedentemente importati"); if (d.ShowDialog() == DialogResult.OK) { string file = d.FileName; try { if (!System.IO.Directory.Exists(PATH_HISTORY)) System.IO.Directory.CreateDirectory(PATH_HISTORY); using (ICSharpCode.SharpZipLib.Zip.ZipInputStream s = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(file))) { ICSharpCode.SharpZipLib.Zip.ZipEntry theEntry; while ((theEntry = s.GetNextEntry()) != null) { lStatus.Text = string.Format(T("Importazione di {0}"), theEntry.Name); string fileName = System.IO.Path.GetFileName(theEntry.Name); if (fileName != String.Empty) { string new_path = PATH_HISTORY + "\\" + fileName; using (System.IO.FileStream streamWriter = System.IO.File.Create(new_path)) { 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; } } } } lStatus.Text = T("Import ultimato correttamente"); } } catch (Exception ex) { My.Box.Errore(T("Errore durante l'importazione del backup")+"\r\n" + ex.Message); } } }
/// <summary> /// Unzip a local file and return its contents via streamreader: /// </summary> public static StreamReader UnzipStream(Stream zipstream) { StreamReader reader = null; try { //Initialise: MemoryStream file; //If file exists, open a zip stream for it. using (var zipStream = new ZipInputStream(zipstream)) { //Read the file entry into buffer: var entry = zipStream.GetNextEntry(); var buffer = new byte[entry.Size]; zipStream.Read(buffer, 0, (int)entry.Size); //Load the buffer into a memory stream. file = new MemoryStream(buffer); } //Open the memory stream with a stream reader. reader = new StreamReader(file); } catch (Exception err) { Log.Error(err, "Data.UnZip(): Stream >> " + err.Message); } return reader; }
/// <summary> /// Uncompress zip data byte array into a dictionary string array of filename-contents. /// </summary> /// <param name="zipData">Byte data array of zip compressed information</param> /// <returns>Uncompressed dictionary string-sting of files in the zip</returns> public static Dictionary<string, string> UnzipData(byte[] zipData) { // Initialize: var data = new Dictionary<string, string>(); try { using (var ms = new MemoryStream(zipData)) { //Read out the zipped data into a string, save in array: using (var zipStream = new ZipInputStream(ms)) { while (true) { //Get the next file var entry = zipStream.GetNextEntry(); if (entry != null) { //Read the file into buffer: var buffer = new byte[entry.Size]; zipStream.Read(buffer, 0, (int)entry.Size); //Save into array: data.Add(entry.Name, buffer.GetString()); } else { break; } } } // End Zip Stream. } // End Using Memory Stream } catch (Exception err) { Log.Error("Data.UnzipData(): " + err.Message); } return data; }
public void OnEnteredStateImpl() { FileStream zipFileRead = new FileStream(this.extractMe, FileMode.Open, FileAccess.Read, FileShare.Read); FileStream exeFileWrite = null; try { ICSharpCode.SharpZipLib.Zip.ZipInputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(zipFileRead); // Search for the first .msi file in the exe, and extract it ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry; bool foundExe = false; while (true) { zipEntry = zipStream.GetNextEntry(); if (zipEntry == null) { break; } if (!zipEntry.IsDirectory && string.Compare(".exe", Path.GetExtension(zipEntry.Name), true, CultureInfo.InvariantCulture) == 0) { foundExe = true; break; } } if (!foundExe) { this.exception = new FileNotFoundException(); StateMachine.QueueInput(PrivateInput.GoToError); } else { int maxBytes = (int)zipEntry.Size; int bytesSoFar = 0; this.installerPath = Path.Combine(Path.GetDirectoryName(this.extractMe), zipEntry.Name); exeFileWrite = new FileStream(this.installerPath, FileMode.Create, FileAccess.Write, FileShare.Read); SiphonStream siphonStream2 = new SiphonStream(exeFileWrite, 4096); this.abortMeStream = siphonStream2; IOEventHandler ioFinishedDelegate = delegate(object sender, IOEventArgs e) { bytesSoFar += e.Count; double percent = 100.0 * ((double)bytesSoFar / (double)maxBytes); OnProgress(percent); }; OnProgress(0.0); if (maxBytes > 0) { siphonStream2.IOFinished += ioFinishedDelegate; } Utility.CopyStream(zipStream, siphonStream2); if (maxBytes > 0) { siphonStream2.IOFinished -= ioFinishedDelegate; } this.abortMeStream = null; siphonStream2 = null; exeFileWrite.Close(); exeFileWrite = null; zipStream.Close(); zipStream = null; StateMachine.QueueInput(PrivateInput.GoToReadyToInstall); } } catch (Exception ex) { if (this.AbortRequested) { StateMachine.QueueInput(PrivateInput.GoToAborted); } else { this.exception = ex; StateMachine.QueueInput(PrivateInput.GoToError); } } finally { if (exeFileWrite != null) { exeFileWrite.Close(); exeFileWrite = null; } if (zipFileRead != null) { zipFileRead.Close(); zipFileRead = null; } if (this.exception != null || this.AbortRequested) { if (this.installerPath != null) { try { File.Delete(this.installerPath); } catch { } } } if (this.extractMe != null) { try { File.Delete(this.extractMe); } catch { } } } }
//private static void CopyStream(Stream input, Stream output) //{ // byte[] buffer = new byte[8 * 1024]; // int len; // while ((len = input.Read(buffer, 0, buffer.Length)) > 0) // { // output.Write(buffer, 0, len); // } //} public static AndroidManifestData GetManifestData(String apkFilePath) { byte[] manifestData = null; byte[] resourcesData = null; using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(apkFilePath))) { using (var filestream = new FileStream(apkFilePath, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { if (item.Name.ToLower() == "androidmanifest.xml") { manifestData = new byte[50 * 1024]; using (Stream strm = zipfile.GetInputStream(item)) { strm.Read(manifestData, 0, manifestData.Length); } } if (item.Name.ToLower() == "resources.arsc") { using (Stream strm = zipfile.GetInputStream(item)) { using (BinaryReader s = new BinaryReader(strm)) { resourcesData = s.ReadBytes((int)s.BaseStream.Length); } } } } } } Iteedee.ApkReader.ApkReader reader = new ApkReader.ApkReader(); Iteedee.ApkReader.ApkInfo info = reader.extractInfo(manifestData, resourcesData); string AppName = info.label; return new AndroidManifestData() { VersionCode = info.versionCode, VersionName = info.versionName, PackageName = info.packageName, ApplicationName = info.label, ApplicationIconName = GetBestIconAvailable(info.iconFileNameToGet) }; }
public static ApkInfo ReadApkFromPath(string path) { byte[] manifestData = null; byte[] resourcesData = null; using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(path))) { using (var filestream = new FileStream(path, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { if (item.Name.ToLower() == "androidmanifest.xml") { manifestData = new byte[50 * 1024]; using (Stream strm = zipfile.GetInputStream(item)) { strm.Read(manifestData, 0, manifestData.Length); } } if (item.Name.ToLower() == "resources.arsc") { using (Stream strm = zipfile.GetInputStream(item)) { using (BinaryReader s = new BinaryReader(strm)) { resourcesData = s.ReadBytes((int)s.BaseStream.Length); } } } } } } ApkReader apkReader = new ApkReader(); ApkInfo info = apkReader.extractInfo(manifestData, resourcesData); Console.WriteLine(string.Format("Package Name: {0}", info.packageName)); Console.WriteLine(string.Format("Version Name: {0}", info.versionName)); Console.WriteLine(string.Format("Version Code: {0}", info.versionCode)); Console.WriteLine(string.Format("App Has Icon: {0}", info.hasIcon)); if(info.iconFileName.Count > 0) Console.WriteLine(string.Format("App Icon: {0}", info.iconFileName[0])); Console.WriteLine(string.Format("Min SDK Version: {0}", info.minSdkVersion)); Console.WriteLine(string.Format("Target SDK Version: {0}", info.targetSdkVersion)); if (info.Permissions != null && info.Permissions.Count > 0) { Console.WriteLine("Permissions:"); info.Permissions.ForEach(f => { Console.WriteLine(string.Format(" {0}", f)); }); } else Console.WriteLine("No Permissions Found"); Console.WriteLine(string.Format("Supports Any Density: {0}", info.supportAnyDensity)); Console.WriteLine(string.Format("Supports Large Screens: {0}", info.supportLargeScreens)); Console.WriteLine(string.Format("Supports Normal Screens: {0}", info.supportNormalScreens)); Console.WriteLine(string.Format("Supports Small Screens: {0}", info.supportSmallScreens)); return info; }
private static void SaveUnCrushedAppIcon(string ipaFilePath, string iconDirectory, string appIdentifier, bool GetRetina) { Dictionary<string, object> plistInfo = GetIpaPList(ipaFilePath); List<string> iconFiles = GetiOSBundleIconNames(plistInfo); string fileName = string.Empty; if (iconFiles.Count > 1) { iconFiles.ForEach(f => { if (GetRetina && f.ToLower().Contains("icon@2x")) fileName = f; else if (!GetRetina && !f.ToLower().Contains("icon@2x")) fileName = f; }); } else if (iconFiles.Count == 1) { fileName = iconFiles[0]; } //Rea string uniqueIconFileName = String.Format("{0}{1}", appIdentifier, Path.GetExtension(fileName)); ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.OpenRead(ipaFilePath)); using (var filestream = new FileStream(ipaFilePath, FileMode.Open, FileAccess.Read)) { ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream); ICSharpCode.SharpZipLib.Zip.ZipEntry item; while ((item = zip.GetNextEntry()) != null) { Match match = Regex.Match(item.Name.ToLower(), string.Format(@"Payload/([A-Za-z0-9\-.]+)\/{0}", fileName.ToLower()), RegexOptions.IgnoreCase); if (match.Success) { using (Stream strm = zipfile.GetInputStream(item)) { //int size = strm.Read(bytes, 0, bytes.Length); //using (BinaryReader s = new BinaryReader(strm)) //{ // byte[] bytes2 = new byte[size]; // Array.Copy(bytes, bytes2, size); // using (MemoryStream input = new MemoryStream(bytes2)) // { // using (FileStream output = File.Create(Path.Combine(iconDirectory, uniqueIconFileName))) // { // try // { // PNGDecrush.PNGDecrusher.Decrush(strm, output); // } // catch (InvalidDataException ex) // { // //Continue, unable to resolve icon data // } // } // } //} byte[] ret = null; ret = new byte[item.Size]; strm.Read(ret, 0, ret.Length); using (MemoryStream input = new MemoryStream(ret)) { using (FileStream output = File.Create(Path.Combine(iconDirectory, uniqueIconFileName))) { try { PNGDecrush.PNGDecrusher.Decrush(input, output); } catch (InvalidDataException ex) { //Continue, unable to resolve icon data } } } //using (MemoryStream input = new MemoryStream()) //{ // using (FileStream output = File.Create(Path.Combine(iconDirectory, uniqueIconFileName))) // { // try // { // PNGDecrush.PNGDecrusher.Decrush(strm, output); // } // catch (InvalidDataException ex) // { // //Continue, unable to resolve icon data // } // } //} } break; } } } }
protected virtual void DeserializeHieghtmap(Map map, Stream stream) { // Heightmap serialization method 3 var d = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(stream); d.GetNextEntry(); var br = new BinaryReader(d); var height = br.ReadInt32(); var width = br.ReadInt32(); var hm = new Graphics.Software.Texel.R32F[height, width]; for (var y = 0; y < height; y++) for (var x = 0; x < width; x++) hm[y, x] = new Graphics.Software.Texel.R32F(br.ReadSingle()); map.Ground.Heightmap = hm; d.Close(); }
/// <summary> /// Extractor function /// </summary> /// <param name="zipFilename">zipFilename</param> /// <param name="ExtractDir">ExtractDir</param> /// <param name="deleteZippedfile">if true, zipped file will be deleted after extraction.</param> public void ExtractArchive(string zipFilename, string ExtractDir, bool deleteZippedfile) { // int Redo = 1; ICSharpCode.SharpZipLib.Zip.ZipInputStream MyZipInputStream; FileStream MyFileStream; MyZipInputStream = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new FileStream(zipFilename, FileMode.Open, FileAccess.Read)); ICSharpCode.SharpZipLib.Zip.ZipEntry MyZipEntry = MyZipInputStream.GetNextEntry(); Directory.CreateDirectory(ExtractDir); while (!(MyZipEntry == null)) { if (MyZipEntry.IsDirectory) { Directory.CreateDirectory(ExtractDir + "\\" + MyZipEntry.Name); } else { if (!Directory.Exists(ExtractDir + "\\" + Path.GetDirectoryName(MyZipEntry.Name))) { Directory.CreateDirectory(ExtractDir + "\\" + Path.GetDirectoryName(MyZipEntry.Name)); } MyFileStream = new FileStream(ExtractDir + "\\" + MyZipEntry.Name, FileMode.OpenOrCreate, FileAccess.Write); int count; byte[] buffer = new byte[4096]; count = MyZipInputStream.Read(buffer, 0, 4096); while (count > 0) { MyFileStream.Write(buffer, 0, count); count = MyZipInputStream.Read(buffer, 0, 4096); } MyFileStream.Close(); } try { MyZipEntry = MyZipInputStream.GetNextEntry(); } catch (Exception ex) { MyZipEntry = null; } } //dispose active objects try { if (!(MyZipInputStream == null)) MyZipInputStream.Close(); } catch (Exception ex) { } finally { if (deleteZippedfile) { //delete the zip file if (System.IO.File.Exists(zipFilename)) System.IO.File.Delete(zipFilename); } } }