Exemplo n.º 1
0
        //检查更新
        public void checkUpdate()
        {
            try
            {
                String[] result           = HttpTools.getHtml(versionURL, 30).Split('-');
                String   versionText      = result[0];
                int      cversion         = int.Parse(result[1]);
                String   versionUpdateURL = result[2];
                if (cversion > version)
                {
                    DialogResult dr = MessageBox.Show("发现新版本:" + versionText + ",更新日期:" + cversion + ",立即更新吗?", "提示", MessageBoxButtons.OKCancel);

                    if (DialogResult.OK.Equals(dr))
                    {
                        try
                        {
                            int    index    = versionUpdateURL.LastIndexOf("/");
                            String filename = "update.rar";
                            if (index != -1)
                            {
                                filename = versionUpdateURL.Substring(index);
                            }
                            HttpDownloadFile(versionUpdateURL, AppDomain.CurrentDomain.BaseDirectory + filename);
                            MessageBox.Show("更新成功,请将压缩包解压后运行!");
                        }

                        catch (Exception other)
                        {
                            MessageBox.Show("更新失败,请访问官网更新!" + other.GetBaseException());
                        }
                    }
                }
                else
                {
                    this.rtxt_log.Invoke(new LogDelegate(LogMessage), "自动检查更新,没有发现新版本!");
                }
            }
            catch (Exception e)
            {
                this.rtxt_log.Invoke(new LogDelegate(LogWarning), "无法连接更新服务器!" + e.Message);
            }
        }