Example #1
0
        //public event XAPFileReadHandler FileRead;

        protected void OnXAPFileUnzipped(object xap, XAPFileInfoEventArgs fileInfo)
        {
            if (FileUnzipped != null)
            {
                FileUnzipped(this, fileInfo);
            }
        }
Example #2
0
 //public event XAPFileReadHandler FileRead;
 protected void OnXAPFileUnzipped(object xap, XAPFileInfoEventArgs fileInfo)
 {
     if (FileUnzipped != null) FileUnzipped(this, fileInfo);
 }
Example #3
0
        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;
        }
Example #4
0
        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);
        }