Exemple #1
0
        public InstallDialog(IHost host, UpdateInfo[] infos)
        {
            Init();

            _host = host;
            _infos = new List<UpdateInfo>(infos);

            _unzipBaseDir = Path.Combine(_host.App.AppCurrentDir, "tmp");
            if (!Directory.Exists(_unzipBaseDir))
            {
                Directory.CreateDirectory(_unzipBaseDir);
            }

            DownloadNextPlugin();
        }
Exemple #2
0
        /// <summary>
        /// 解压
        /// </summary>
        private bool Unzip(UpdateInfo info)
        {
            var zipFile = Path.Combine(_unzipBaseDir, Path.GetFileName(info.DownloadUrl)??info.Name+".zip");
            var unzipDir = Path.Combine(_unzipBaseDir, info.Name);

            return ZipUtil.Decompress(zipFile, unzipDir, true);
        }
Exemple #3
0
 /// <summary>
 /// 安装插件
 /// </summary>
 private void InstallPlugin(UpdateInfo info)
 {
     var msg = "";
     //解压
     DownloadUrl = string.Format("Unzip {0} ...", info.Name);
     Progress += 25;
     if (!Unzip(info))
     {
         msg = string.Format("Unzip {0} failed", info.Name);
         MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxType.Error);
     }
     //拷贝
     DownloadUrl = string.Format("Install {0} ...", info.Name);
     Progress += 25;
     var unzipDir = Path.Combine(_unzipBaseDir, info.Name);
     if (CopyPluginFiles(info.Install.CopyFiles, unzipDir, _host.App.AppCurrentDir, _host.App.AppPluginDir, info.Name))
     {
         msg = string.Format("Install {0} success", info.Name);
         MessageBox.Show(msg, "Success", MessageBoxButtons.OK, MessageBoxType.Information);
     }
     else
     {
         msg = string.Format("Install {0} failed", info.Name);
         MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxType.Error);
     }
 }
Exemple #4
0
        private void DownloadPlugin(UpdateInfo info)
        {
            var downloadUrl = info.DownloadUrl;
            var saveName = Path.Combine(_unzipBaseDir, Path.GetFileName(info.DownloadUrl) ?? info.Name+".zip");

            DownloadUrl = downloadUrl;
            Progress = 0;

            var client = new WebClient();
            client.DownloadProgressChanged += client_DownloadProgressChanged;
            client.DownloadFileCompleted += client_DownloadFileCompleted;
            client.DownloadFileAsync(new Uri(downloadUrl), saveName, info);
        }
        /// <summary>
        /// 读取xml文件
        /// </summary>
        public UpdateInfo[] ReadUpdateXml()
        {
            var filePath = _updateXmlPath;
            var infos = new List<UpdateInfo>();
            try
            {
                var xml = new XmlDocument(); //初始化一个xml实例
                xml.Load(filePath); //导入指定xml文件
                XmlNode root = xml.SelectSingleNode("/update/plugins"); //指定一个节点
                XmlNodeList childlist = root.ChildNodes; //获取节点下所有直接子节点
                foreach (XmlNode child in childlist)
                {
                    if (child.Name == "plugin")
                    {
                        var info = new UpdateInfo();

                        //判断name属性是否存在
                        if (child.Attributes["name"] == null) continue;
                        var name = child.Attributes["name"].Value;

                        XmlNode authorNode = child.SelectSingleNode("author");
                        if (authorNode == null) continue;
                        var author = authorNode.InnerText;

                        XmlNode desNode = child.SelectSingleNode("description");
                        if (desNode == null) continue;
                        var des = desNode.InnerText;

                        XmlNode versionNode = child.SelectSingleNode("version");
                        if (versionNode == null) continue;
                        var version = versionNode.Attributes["number"].Value;
                        var required = versionNode.Attributes["required"].Value;
                        var md5 = versionNode.Attributes["md5"].Value;

                        XmlNode downloadNode = child.SelectSingleNode("download");
                        if (downloadNode == null) continue;
                        var download = downloadNode.InnerText;

                        info.Name = name;
                        info.Author = author;
                        info.Description = des;
                        info.Version = new UpdateInfo.VersionInfo(version, required, md5);
                        info.DownloadUrl = download;

                        infos.Add(info);
                    }
                }
                return infos.ToArray();
            }
            catch (Exception ex)
            {
            }
            return null;
        }
Exemple #6
0
        private UpdateInfo ReadInfoXml(string infoPath)
        {
            if (!File.Exists(infoPath)) return null;
            try
            {
                var info = new UpdateInfo();
                var xml = new XmlDocument();
                xml.Load(infoPath);             
                var root = xml.SelectSingleNode("/plugin");

                var nameNode = root.SelectSingleNode("name");
                var name = nameNode != null ? nameNode.InnerText : "";

                var authorNode = root.SelectSingleNode("author");
                var author = authorNode != null ? authorNode.InnerText : "";

                var desNode = root.SelectSingleNode("description");
                var des = desNode != null ? desNode.InnerText : "";

                var versionNode = root.SelectSingleNode("version");
                var version = versionNode != null ? versionNode.Attributes["number"].Value : "";
                var required = versionNode != null ? versionNode.Attributes["required"].Value : "";

                info.Name = name;
                info.Author = author;
                info.Description = des;
                info.Version = new UpdateInfo.VersionInfo(version, required, "");
                info.CanUpdate = _host.App.AppVersion >= info.Version.RequiredVersion;

                return info;
            }
            catch (Exception ex)
            {
            }
            return null;      
        }