Example #1
0
        public void OpenFile(string path)
        {
            textBoxFilePath.Text = path;
            cab      = new CabInfo(path);
            cabFiles = cab.GetFiles();
            Files    = new List <EFile>();

            string xml;

            using (StreamReader streamreader = new StreamReader(cab.OpenRead("_setup.xml"), Encoding.UTF8))
            {
                xml = streamreader.ReadToEnd();
            }



            XmlDocument setupxml = new XmlDocument();

            setupxml.LoadXml(xml);



            XmlNodeList xnList = setupxml.SelectNodes("/wap-provisioningdoc/characteristic/characteristic/characteristic");

            foreach (XmlNode xn in xnList)
            {
                foreach (XmlNode cxn in xn.ChildNodes)
                {
                    if (cxn.Attributes["type"].Value.ToString() == "Extract")
                    {
                        foreach (XmlNode xnFile in cxn.ChildNodes)
                        {
                            if (xnFile.Attributes["name"].Value.ToString() == "Source")
                            {
                                CabFileInfo cabfileinfo = cabFiles.Where(x => x.Name == xnFile.Attributes["value"].Value.ToString()).FirstOrDefault();
                                EFile       file        = new EFile();
                                file.Source     = xnFile.Attributes["value"].Value.ToString();
                                file.FileName   = xn.Attributes["type"].Value.ToString();
                                file.LastUpDate = cabfileinfo.LastWriteTime;
                                file.Lenght     = cabfileinfo.Length;
                                file.FileIcon   = FileIconLoader.GetFileIcon(file.FileName, false);


                                Files.Add(file);
                            }
                        }
                    }
                }
            }

            BindDataGrid();
            buttonExtract.Enabled     = true;
            buttonInsertFiles.Enabled = true;
        }
Example #2
0
        private void buttonExtract_Click(object sender, EventArgs e)
        {
            folderBrowserDialogSelectExtractFolder.Description = "Dosyaların Çıkartılacağı Dizini Seçiniz.";
            if (textBoxFilePath.Text != null)
            {
                if (folderBrowserDialogSelectExtractFolder.ShowDialog() == DialogResult.OK)
                {
                    string directoryName = folderBrowserDialogSelectExtractFolder.SelectedPath + "\\" + Path.GetFileNameWithoutExtension(cab.FullName);

                    CheckDirectoryForExtract(ref directoryName);

                    foreach (var file in Files)
                    {
                        Stream cabStream = cab.OpenRead(file.Source);



                        FileStream fs = File.Create(directoryName + "\\" + file.FileName);

                        byte[] buffer = new byte[cabStream.Length];
                        int    read;

                        while ((read = cabStream.Read(buffer, 0, buffer.Length)) > 0)
                        {
                            fs.Write(buffer, 0, read);
                        }



                        fs.Close();
                        fs.Dispose();
                        cabStream.Close();
                        cabStream.Dispose();
                    }



                    if (MessageBox.Show("Files Has Been Extracted to Path :\n" + directoryName + "\nDo you want to open file directory ?", "Files Extracted Succesfully !", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        Process.Start(directoryName);
                    }
                }
            }
            else
            {
                MessageBox.Show("First, You Must Select Cab File", "Cab File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }