//public event XAPFileReadHandler FileRead; protected void OnXAPFileUnzipped(object xap, XAPFileInfoEventArgs fileInfo) { if (FileUnzipped != null) { FileUnzipped(this, fileInfo); } }
//public event XAPFileReadHandler FileRead; protected void OnXAPFileUnzipped(object xap, XAPFileInfoEventArgs fileInfo) { if (FileUnzipped != null) FileUnzipped(this, fileInfo); }
public string UnZip(string filePath) { string tmpPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tmpPath); try { using (ZipInputStream zipStream = new ZipInputStream(File.OpenRead(filePath))) { ZipEntry zipThing; while ((zipThing = zipStream.GetNextEntry()) != null) { if (zipThing.IsFile) { if (zipThing.Name != "") { if (zipThing.Name.Contains("\\") || zipThing.Name.Contains("/")) { string tmpFilename = zipThing.Name.Replace("/", "\\"); int pos = tmpFilename.LastIndexOf("\\"); string str = tmpFilename.Substring(0, pos); string cdir = ""; string[] dirs = str.Split(new char[] { '\\' }); foreach (string dir in dirs) { if (!Directory.Exists(tmpPath + "\\" + cdir + "\\" + dir)) Directory.CreateDirectory(tmpPath + "\\" + cdir + "\\" + dir); cdir = cdir + "\\" + dir; } } string strNewFile = @"" + tmpPath + @"\" + zipThing.Name; using (FileStream streamWriter = File.Create(strNewFile)) { XAPFileInfoEventArgs fileInfo = new XAPFileInfoEventArgs(strNewFile); OnXAPFileUnzipped(this,fileInfo); byte[] yData = new byte[2048]; while (true) { int nSize = zipStream.Read(yData, 0, yData.Length); if (nSize > 0) streamWriter.Write(yData, 0, nSize); else break; } streamWriter.Close(); } } } else if (zipThing.IsDirectory) { string strNewDir = @"" + tmpPath + @"\" + zipThing.Name; if (!Directory.Exists(strNewDir)) Directory.CreateDirectory(strNewDir); } } zipStream.Close(); } } catch (Exception ex) { throw new Exception("Exception occured while decompressing the source XAP file: " + ex.Message); } this.isUnpacked = true; this._UnpackPath = tmpPath; return tmpPath; }
public string UnZip(string filePath) { string tmpPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(tmpPath); try { using (ZipInputStream zipStream = new ZipInputStream(File.OpenRead(filePath))) { ZipEntry zipThing; while ((zipThing = zipStream.GetNextEntry()) != null) { if (zipThing.IsFile) { if (zipThing.Name != "") { if (zipThing.Name.Contains("\\") || zipThing.Name.Contains("/")) { string tmpFilename = zipThing.Name.Replace("/", "\\"); int pos = tmpFilename.LastIndexOf("\\"); string str = tmpFilename.Substring(0, pos); string cdir = ""; string[] dirs = str.Split(new char[] { '\\' }); foreach (string dir in dirs) { if (!Directory.Exists(tmpPath + "\\" + cdir + "\\" + dir)) { Directory.CreateDirectory(tmpPath + "\\" + cdir + "\\" + dir); } cdir = cdir + "\\" + dir; } } string strNewFile = @"" + tmpPath + @"\" + zipThing.Name; using (FileStream streamWriter = File.Create(strNewFile)) { XAPFileInfoEventArgs fileInfo = new XAPFileInfoEventArgs(strNewFile); OnXAPFileUnzipped(this, fileInfo); byte[] yData = new byte[2048]; while (true) { int nSize = zipStream.Read(yData, 0, yData.Length); if (nSize > 0) { streamWriter.Write(yData, 0, nSize); } else { break; } } streamWriter.Close(); } } } else if (zipThing.IsDirectory) { string strNewDir = @"" + tmpPath + @"\" + zipThing.Name; if (!Directory.Exists(strNewDir)) { Directory.CreateDirectory(strNewDir); } } } zipStream.Close(); } } catch (Exception ex) { throw new Exception("Exception occured while decompressing the source XAP file: " + ex.Message); } this.isUnpacked = true; this._UnpackPath = tmpPath; return(tmpPath); }