Ejemplo n.º 1
0
        /// <summary>
        /// Parser results of versions requested plugins, and set tabpage with plugin update visible
        /// if there are plugin update(s) are available.
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void httputil_pluginsversions_compleet(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            string result = (string)e.Result;

            if (result == null)
            {
                return;
            }

            if (result.Length < 1)
            {
                return;
            }

            this.updatableplugins = new List <DownloadDetailsPlugin>();
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.LoadXml(result);
            XmlNodeList xmlnodelist = xmldoc.SelectNodes("/plugins/plugin");

            foreach (XmlNode xmlnode in xmlnodelist)
            {
                if (xmlnode.ChildNodes.Count == 1)
                {
                    const int MAXLENMESSAGE = 500;
                    string    errormessage  = xmlnode.ChildNodes[0].InnerText;
                    if (errormessage.Length > MAXLENMESSAGE)
                    {
                        errormessage = errormessage.Substring(0, MAXLENMESSAGE);
                    }

                    Log.Write(LogType.error, errormessage);
                }
                else if (xmlnode.ChildNodes.Count > 1)
                {
                    bool minversionipluginokay = true;
                    DownloadDetailsPlugin downloaddetailsplugin = new DownloadDetailsPlugin();
                    for (int i = 0; (i < xmlnode.ChildNodes.Count && minversionipluginokay); ++i)
                    {
                        switch (xmlnode.ChildNodes[i].Name)
                        {
                        case "name":
                            downloaddetailsplugin.Name = xmlnode.ChildNodes[i].InnerText;
                            break;

                        case "version":
                            downloaddetailsplugin.Version = xmlnode.ChildNodes[i].InnerText;
                            break;

                        case "downloadurl":
                            downloaddetailsplugin.DownloadUrl = xmlnode.ChildNodes[i].InnerText;
                            break;

                        case "signature":
                            downloaddetailsplugin.Signature = xmlnode.ChildNodes[i].InnerText;
                            break;

                        case "minversioniplugin":
                            short[] pluginipluginversionneeded = new short[] { 0, 0, 0 };
                            try
                            {
                                pluginipluginversionneeded = Program.ParserVersionString(xmlnode.ChildNodes[i].InnerText);
                            }
                            catch (Exception)
                            {
                                Log.Write(LogType.error, "Server returned unknown minversioniplugin.");
                            }

                            if (Program.CompareVersions(pluginipluginversionneeded, PluginsManager.GetIPluginVersion()) > 1)
                            {
                                minversionipluginokay = false;
                            }

                            break;
                        }
                    }

                    if (downloaddetailsplugin.IsInstalledPlugin() && minversionipluginokay)
                    {
                        if (downloaddetailsplugin.IsNewerVersion())
                        {
                            this.updatableplugins.Add(downloaddetailsplugin);
                        }
                    }
                }
            }

            if (this.updatableplugins.Count > 0)
            {
                this.SetTabPageUpdatesVisible(true);
                this.tabControlPlugins.SelectedTab = this.tabPagePluginsUpdates;
            }

            for (int i = 0; i < this.updatableplugins.Count; i++)
            {
                this.chxlbxPluginUpdates.Items.Add(this.updatableplugins[i].Name, PLUGINUPDATECHECKEDDEFAULT);
            }
        }