//解析xml文件
        public void AnalysisXml(String path, bool isEnableToModify = true)
        {
            this.ClearList();
            this.configFileName      = System.IO.Path.GetFileName(path);
            this.configLabel.Content = "配置文件: " + this.configFileName;

            XmlDocument conXml = new XmlDocument();

            conXml.Load(path);

            XmlNode     xn  = conXml.SelectSingleNode("Files"); //得到根节点Files
            XmlNodeList xnl = xn.ChildNodes;                    //得到根节点的所有子节点

            if (!isEnableToModify)
            {
                this.AddButton.Visibility    = System.Windows.Visibility.Hidden;
                this.SaveAsButton.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                this.AddButton.Visibility    = System.Windows.Visibility.Visible;
                this.SaveAsButton.Visibility = System.Windows.Visibility.Visible;
            }


            foreach (XmlNode file in xnl)
            {
                ConfigInformation configInformation;
                if (isEnableToModify)
                {
                    configInformation = new ConfigInformation();
                }
                else
                {
                    configInformation = new ConfigInformation("Hidden", "False");
                }

                XmlNodeList fileList = file.ChildNodes;

                configInformation.path = fileList.Item(0).InnerText;
                exist.Add(configInformation.path, true);

                configInformation.fileName     = fileList.Item(1).InnerText;
                configInformation.updateMethod = fileList.Item(2).InnerText;
                configInformation.md5          = fileList.Item(3).InnerText;

                if (configInformation.fileName == "Auto Upgrade.exe")
                {
                    configInformation.setEnable("False");
                }
                configInformationList.Add(configInformation);
            }

            listView.Items.Refresh();
            this.AutoSetWidth();
        }
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            string path = SelectPath();

            if (path == "" || exist.ContainsKey(path))
            {
                return;
            }
            exist.Add(path, true);

            string            fileName = System.IO.Path.GetFileName(path);
            ConfigInformation c        = new ConfigInformation(fileName, path, "Visible", "True");

            if (fileName == "Auto Upgrade.exe")
            {
                c.setUpdateMethod("替换");
                c.setEnable("False");
            }
            configInformationList.Add(c);

            listView.Items.Refresh();
            this.AutoSetWidth();
        }
Exemplo n.º 3
0
        private List <ConfigInformation> AnalysisXml(String path)
        {
            XmlDocument conXml = new XmlDocument();

            conXml.Load(path);

            XmlNode     xm  = conXml.SelectSingleNode("Files"); //得到根节点Files
            XmlNodeList xml = xm.ChildNodes;                    //得到根节点的所有子节点

            List <ConfigInformation> config = new List <ConfigInformation>();

            foreach (XmlNode file in xml)
            {
                ConfigInformation configInformation;
                configInformation = new ConfigInformation();
                XmlNodeList fileList = file.ChildNodes;
                configInformation.path         = fileList.Item(0).InnerText;
                configInformation.fileName     = fileList.Item(1).InnerText;
                configInformation.updateMethod = fileList.Item(2).InnerText;
                configInformation.md5          = fileList.Item(3).InnerText;
                config.Add(configInformation);
            }
            return(config);
        }
Exemplo n.º 4
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            listView.SelectedItem = ((System.Windows.Controls.Button)sender).DataContext;
            string path = configList[listView.SelectedIndex].path;

            if (listView.Items.Count - 2 == listView.SelectedIndex)
            {
                // 更新软件
                List <ConfigInformation> remoteConfig  = AnalysisXml(path);
                List <ConfigInformation> currentConfig = AnalysisXml(configList[listView.Items.Count - 1].path);

                List <AddFileInformation> addFileList = new List <AddFileInformation>();

                foreach (ConfigInformation file in remoteConfig)
                {
                    if (file.fileName == "Auto Upgrade.exe")
                    {
                        if (file.md5 != ConfigInformation.createMd5(System.AppDomain.CurrentDomain.BaseDirectory + "Auto Upgrade.exe"))
                        {
                            isGoToUpdate       = true;
                            updateSoftwarePath = file.path;
                        }
                        continue;
                    }
                    if (file.updateMethod == "新增" || file.updateMethod == "替换")
                    {
                        FileInfo f = new FileInfo(file.path);
                        if (File.Exists(currentConfigFilePath + file.fileName))
                        {
                            foreach (ConfigInformation config in currentConfig)
                            {
                                if (config.fileName == file.fileName)
                                {
                                    config.md5          = file.md5;
                                    config.updateMethod = file.updateMethod;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            f.CopyTo(currentConfigFilePath + file.fileName, true);
                            addFileList.Add(new AddFileInformation(file.fileName, currentConfigFilePath + file.fileName));
                        }
                    }
                    else if (file.updateMethod == "删除")
                    {
                        FileInfo f = new FileInfo(file.path);
                        foreach (ConfigInformation cf in currentConfig)
                        {
                            if (file.md5 == cf.md5)
                            {
                                FileInfo ff = new FileInfo(cf.path);
                                ff.Delete();
                                currentConfig.Remove(cf);
                                break;
                            }
                        }
                    }
                }

                ThreadHelper arg = new Auto_Upgrade.ConfigListView.ThreadHelper {
                    c = currentConfig, a = addFileList
                };
                Thread t = new Thread(new ParameterizedThreadStart(updateConfig));
                t.Start(arg);
                if (isGoToUpdate)
                {
                    parent.ShutDown();
                }
            }
            else
            {
                string targetPath = SelectPath();
                if (targetPath == "")
                {
                    return;
                }
                CopyToFloder(path, targetPath);
            }
        }