Ejemplo n.º 1
0
 void UpdateSelf()
 {
     if (checkUpdate())
     {
         download = new DownloadFiles();
         download.DownloadFile("https://sites.google.com/site/pow7000web/mysoftware/autoupdater/AutoUpdater.zip", Path.Combine(Application.StartupPath, "AutoUpdater.zip"));
         TimerIO(true, timer1);
     }
 }
Ejemplo n.º 2
0
        void UpdateOtherAPP()
        {
            download = new DownloadFiles();
            ChangeControlText("正在讀取更新包資訊...", label3);
            {//下載到temp\APP.ini
                HttpWebRequest   httpRequest  = (HttpWebRequest)WebRequest.Create(ini_AutoUpdater.IniReadValue("AutoUpdater_URL", "APP_Info_ini", 200));
                HttpWebResponse  httpResponse = (HttpWebResponse)httpRequest.GetResponse();
                System.IO.Stream dataStream   = httpResponse.GetResponseStream();
                byte[]           buffer       = new byte[8192];

                FileStream fs   = new FileStream(Path.Combine(Path.GetTempPath(), ini_AutoUpdater.IniReadValue("APP_Info", "APP_Name", 200) + ".ini"), FileMode.Create, FileAccess.Write);
                int        size = 0;


                do
                {
                    if (download.GetStatus().StopNow)
                    {
                        break;
                    }
                    size = dataStream.Read(buffer, 0, buffer.Length);
                    if (size > 0)
                    {
                        fs.Write(buffer, 0, size);
                    }
                } while (size > 0);
                fs.Close();
                httpResponse.Close();
            }

            //載入APP.ini到updateinfo

            updateinfo = new UpdateInfo(new IniFile(Path.Combine(Path.GetTempPath(), ini_AutoUpdater.IniReadValue("APP_Info", "APP_Name", 200) + ".ini")));
            updateinfo.LodeIni();

            Version Version_localFile = new Version(), Version_UpdateFile = new Version();

            bool au = false;

            if (CheckFile.GetVersion(updateinfo.APP_FileName) != "Error")
            {
                Version_localFile = new Version(CheckFile.GetVersion(updateinfo.APP_FileName));
            }
            else
            {
                //ChangeControlText("找不到\"" + updateinfo.APP_FileName+"\"", label3);
                au = true;
                //  return;
            }
            try
            {
                Version_UpdateFile = new Version(updateinfo.APP_Version);
            }
            catch { ChangeControlText("APP_Version有問題", label3); }
            if (download.GetStatus().StopNow)
            {
                return;
            }
            int tm;

            if (!au)
            {
                tm = Version_UpdateFile.CompareTo(Version_localFile);
            }
            else//永遠更新
            {
                tm = 100;
            }
            if (tm <= 0)
            {
                //沒有更新
                if (WithForm)
                {
                    FormClose(this);
                    return;
                }
                else
                {
                    MessageBox.Show("無須更新");
                    return;
                }
            }
            else
            {//發現更新
                ChangeControlText(String.Format("發現新版本({0}), 現行版本 {1}", updateinfo.APP_Version, Version_localFile.ToString()), label3);

                if (updateinfo.Update_DoNotAsk)
                {
                    UsePackUpdate();
                }
                else
                {
                    if (MessageBox.Show(String.Format("現行版本:{0}\r\n最新版本:{1}\r\nChangeLog:\r\n  {2}", Version_localFile.ToString(), updateinfo.APP_Version, updateinfo.APP_ChangeLog), "是否立即更新?", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.No)
                    {//否
                        FormClose(this);
                    }
                    else
                    {//立即更新
                        UsePackUpdate();
                    }
                }
            }
        }