Esempio n. 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;
        }
Esempio n. 2
0
        private void InsertUpdateFileToCab(string filePath)
        {
            EFile file;


            using (FileStream fs = new FileStream(filePath, FileMode.Open))
            {
                FileInfo fileInfo = new FileInfo(filePath);
                file            = new EFile();
                file.FileName   = Path.GetFileName(filePath);
                file.Lenght     = fileInfo.Length;
                file.LastUpDate = DateTime.Now;
                file.Source     = "New File";
                file.FileIcon   = FileIconLoader.GetFileIcon(file.FileName, false);
            }
            string temp = Path.GetTempPath() + "TempCab";

            cab.Unpack(temp);

            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(Path.GetTempPath() + "TempCab/_setup.xml");
            XmlNode root = xmldoc.SelectSingleNode("/wap-provisioningdoc/characteristic[@type='FileOperation']/characteristic[@translation='install']");
            //XmlNode root = xmldoc.SelectSingleNode("/wap-provisioningdoc/characteristic[@type='FileOperation']");


            //root.Attributes[""] = "";

            bool isExist = false;

            foreach (EFile f in Files)
            {
                if ((f.FileName.ToLower() == file.FileName.ToLower()) || (f.FileName.ToUpper() == file.FileName.ToUpper()))
                {
                    isExist     = true;
                    file.Source = f.Source;

                    f.Lenght     = file.Lenght;
                    f.LastUpDate = file.LastUpDate;

                    File.Copy(filePath, temp + "\\" + file.Source, true);
                }
            }

            if (!isExist)
            {
                File.Copy(filePath, temp + "\\" + file.FileName, true);

                //XmlNode node = xmldoc.CreateNode(XmlNodeType.Element, "characteristic",null);

                //XmlAttribute attr_type = xmldoc.CreateAttribute("type");
                //attr_type.Value = file.FileName;

                //XmlAttribute attr_translation = xmldoc.CreateAttribute("install");
                //attr_translation.Value = "install";

                //node.Attributes.Append(attr_type);
                //node.Attributes.Append(attr_translation);

                //root.AppendChild(node);

                //xmldoc.Save(Path.GetTempPath() + "TempCab/_setup.xml");

                Files.Add(file);
            }



            cab.Pack(temp, true, Microsoft.Deployment.Compression.CompressionLevel.None, null);

            Directory.Delete(temp, true);

            BindDataGrid();
        }