コード例 #1
0
ファイル: Form1.cs プロジェクト: Elenw/2dmmclauncher4th
 private void checkupdate()
 {
     WebClient verc = new WebClient();
     verc.DownloadFile("http://2dmmc.bangbang93.com/ver4th.txt", "ver.txt");
     //获取服务器上的版本标识,等待10秒后读取MC输出的版本号
     Thread.Sleep(10000);
     try
     {
         StreamReader ver = new StreamReader("ver.txt");
         StreamReader cver = new StreamReader(".minecraft\\bin\\ver.txt");
         string vers = ver.ReadLine();  //版本号,字符串类型
         string isMust = ver.ReadLine();  //是否为强制更新,0=false;1=true
         string updateurl = ver.ReadLine();  //升级URL,已放弃不用
         string cvers = cver.ReadLine();  //本地版本号
         ver.Close();
         cver.Close();
         Application.DoEvents();
         if (vers != cvers)
         {
             if (isMust == "1")
             {
                 if (MessageBox.Show("检测到强制更新版本,点击确定更新", "检测更新", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                 {
                     this.Hide();
                     normalExit = false;
                     launcher.EnableRaisingEvents = false;
                     launcher.Kill();
                     update Update = new update();
                     while (Update.ShowDialog() == DialogResult.Retry) { }
                     Application.Restart();
                 }
                 else
                 {
                     if (MessageBox.Show("不更新可能会导致无法进入服务器,确定不更新?", "确定不更新?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                     {
                         this.Hide();
                         normalExit = false;
                         launcher.EnableRaisingEvents = false;
                         launcher.Kill();
                         update Update = new update();
                         while (Update.ShowDialog() == DialogResult.Retry) { }
                         Application.Restart();
                     }
                 }
             }
             else
             {
                 if (MessageBox.Show("检测到版本更新,是否更新?当前版本:" + cvers + "更新版本" + vers, "检测到更新", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                 {
                     //this.Hide();
                     normalExit = false;
                     launcher.EnableRaisingEvents = false;
                     launcher.Kill();
                     update Update = new update();
                     while (Update.ShowDialog() == DialogResult.Retry) { }
                     Application.Restart();
                 }
             }
         }
         else
         {
             notifyIcon1.ShowBalloonTip(10, "废话二次元启动器", "已是最新版本:"+vers , System.Windows.Forms.ToolTipIcon.Info);
         }
     }
     catch (FileNotFoundException )
     {
         MessageBox.Show("获取本地版本号失败");
     }
     catch (WebException)
     {
         MessageBox.Show("网络错误,获取最新版本号失败");
     }
     Application.ExitThread();
 }
コード例 #2
0
        private void checkupdate()
        {
            WebClient verc = new WebClient();

            verc.DownloadFile("http://2dmmc.bangbang93.com/ver4th.txt", "ver.txt");
            //获取服务器上的版本标识,等待10秒后读取MC输出的版本号
            Thread.Sleep(10000);
            try
            {
                StreamReader ver       = new StreamReader("ver.txt");
                StreamReader cver      = new StreamReader(".minecraft\\bin\\ver.txt");
                string       vers      = ver.ReadLine();  //版本号,字符串类型
                string       isMust    = ver.ReadLine();  //是否为强制更新,0=false;1=true
                string       updateurl = ver.ReadLine();  //升级URL,已放弃不用
                string       cvers     = cver.ReadLine(); //本地版本号
                ver.Close();
                cver.Close();
                Application.DoEvents();
                if (vers != cvers)
                {
                    if (isMust == "1")
                    {
                        if (MessageBox.Show("检测到强制更新版本,点击确定更新", "检测更新", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                        {
                            this.Hide();
                            normalExit = false;
                            launcher.EnableRaisingEvents = false;
                            launcher.Kill();
                            update Update = new update();
                            while (Update.ShowDialog() == DialogResult.Retry)
                            {
                            }
                            Application.Restart();
                        }
                        else
                        {
                            if (MessageBox.Show("不更新可能会导致无法进入服务器,确定不更新?", "确定不更新?", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                            {
                                this.Hide();
                                normalExit = false;
                                launcher.EnableRaisingEvents = false;
                                launcher.Kill();
                                update Update = new update();
                                while (Update.ShowDialog() == DialogResult.Retry)
                                {
                                }
                                Application.Restart();
                            }
                        }
                    }
                    else
                    {
                        if (MessageBox.Show("检测到版本更新,是否更新?当前版本:" + cvers + "更新版本" + vers, "检测到更新", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                        {
                            //this.Hide();
                            normalExit = false;
                            launcher.EnableRaisingEvents = false;
                            launcher.Kill();
                            update Update = new update();
                            while (Update.ShowDialog() == DialogResult.Retry)
                            {
                            }
                            Application.Restart();
                        }
                    }
                }
                else
                {
                    notifyIcon1.ShowBalloonTip(10, "废话二次元启动器", "已是最新版本:" + vers, System.Windows.Forms.ToolTipIcon.Info);
                }
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("获取本地版本号失败");
            }
            catch (WebException)
            {
                MessageBox.Show("网络错误,获取最新版本号失败");
            }
            Application.ExitThread();
        }