Пример #1
0
        private void CheckForUpdate()
        {
            //get the current version of IceChat 2009 in the Same Folder
            System.Diagnostics.FileVersionInfo fv;
            double currentVersion;
            try
            {
                fv = System.Diagnostics.FileVersionInfo.GetVersionInfo(currentFolder + Path.DirectorySeparatorChar + "IceChat2009.exe");
                System.Diagnostics.Debug.WriteLine(fv.FileVersion);
                labelCurrent.Text = "Current Version: " + fv.FileVersion;
                currentVersion = Convert.ToDouble(fv.FileVersion.Replace(".", String.Empty));
            }
            catch(Exception)
            {
                currentVersion = 000000000;
                labelCurrent.Text = "Current Version: 0.0.0000.0000";
                System.Diagnostics.Debug.WriteLine("IceChat EXE not found");
            }

            //delete the current update.xml file if it exists
            if (File.Exists(Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "update9.xml"))
                File.Delete(Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "update9.xml");

            System.Net.WebClient webClient = new System.Net.WebClient();
            webClient.DownloadFile("http://www.icechat.net/update9.xml", Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "update9.xml");
            System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
            xmlDoc.Load(Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "update9.xml");

            System.Xml.XmlNodeList version = xmlDoc.GetElementsByTagName("version");
            System.Xml.XmlNodeList versiontext = xmlDoc.GetElementsByTagName("versiontext");

            labelLatest.Text = "Latest Version: " + versiontext[0].InnerText;

            if (Convert.ToDouble(version[0].InnerText) > currentVersion)
            {
                XmlNodeList files = xmlDoc.GetElementsByTagName("file");
                foreach (XmlNode node in files)
                {
                    DownloadItem dl = new DownloadItem();
                    dl.FileName = node.InnerText;
                    dl.ShortName = Path.GetFileName(node.InnerText);
                    dl.FileType = "core";
                    listFiles.Items.Add(dl);
                }

                buttonDownload.Visible = true;
                labelUpdate.Visible = true;
            }
            else
                labelNoUpdate.Visible = true;

            //return;

            //check plugins that need to be updated as well
            //check the plugins folder
            if (Directory.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "Plugins"))
            {
                string[] plugins = Directory.GetFiles(currentFolder + System.IO.Path.DirectorySeparatorChar + "Plugins", "*.dll");
                foreach (string fileName in plugins)
                {

                    //System.Diagnostics.Debug.WriteLine(fileName);
                    //look for a match to plugins online
                    FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName);

                    XmlNodeList plgs = xmlDoc.GetElementsByTagName("plugin");

                    foreach (XmlNode plg in plgs)
                    {
                        //System.Diagnostics.Debug.WriteLine(plg["file"].InnerText);
                        //System.Diagnostics.Debug.WriteLine(plg["version"].InnerText);
                        if (Path.GetFileName(plg["pluginfile"].InnerText).ToLower() == fvi.InternalName.ToLower())
                        {
                            //check versions
                            //System.Diagnostics.Debug.WriteLine(fvi.FileVersion + ":" + plg["pluginversion"].InnerText + ":" + plg["pluginfile"].InnerText);
                            //System.Diagnostics.Debug.WriteLine(Convert.ToSingle(fvi.FileVersion));
                            if (Convert.ToSingle(fvi.FileVersion.Replace(".", "")) < Convert.ToSingle(plg["pluginversion"].InnerText.Replace(".", "")))
                            {
                                System.Diagnostics.Debug.WriteLine("Upgrade needed for " + fvi.InternalName);

                                DownloadItem dl = new DownloadItem();
                                dl.FileName = plg["pluginfile"].InnerText;
                                dl.ShortName = Path.GetFileName(plg["pluginfile"].InnerText);
                                dl.FileType = "plugin";
                                listFiles.Items.Add(dl);

                                buttonDownload.Visible = true;
                                labelUpdate.Visible = true;

                            }
                        }
                    }

                }
            }
        }