国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

C#制作在線升級程序

2019-11-17 03:00:17
字體:
來源:轉載
供稿:網友
C#制作在線升級程序
//這是一個webservicePRivate AppUpdate.UpdateServ  UpdateSvr;  private void button1_Click(object sender, System.EventArgs e)  {       if(LinkWebServices()==true)   {    this.label1.Text="連接服務器....... PASS";        if(CheckVer()==true)    {     this.label2.Text="檢查最新版本并下載.......PASS";                       }    else    {     this.label2.Text="檢查最新版本并下載.......FAIL";    }   }   else   {    this.label1.Text="連接服務器.......FAIL";   }  }//這是用來與升級服務器建立連接  private bool LinkWebServices()  {   try   {    UpdateSvr=new UpdateServ();    return true;   }   catch   {    return false;   }  }//調用webservice用來檢查是不是有最新的版本  private bool CheckVer()  {   string path =application.StartupPath;   try   {    VersionCheck(path);    return true;   }   catch(Exception ex)   {    MessageBox.Show(ex.ToString());    return false;   }  }  private void VersionCheck(string desPath)  {   try   {    #region 查看文件和目錄    if(!desPath.EndsWith(@"/"))     desPath += @"/";    if(!System.IO.Directory.Exists(desPath))    {     System.IO.Directory.CreateDirectory(desPath);    }    string tempPath = desPath + @"tempDesPathCache/";    if(System.IO.Directory.Exists(tempPath))    {     System.IO.Directory.Delete(tempPath,true);     System.IO.Directory.CreateDirectory(tempPath);    }    else     System.IO.Directory.CreateDirectory(tempPath);    if(!System.IO.File.Exists(desPath + "UpdateConfig.xml"))    {     System.Xml.XmlDocument updateConfig = new System.Xml.XmlDocument();     updateConfig.LoadXml(@"<root></root>");     updateConfig.Save(desPath + "UpdateConfig.xml");    }    #endregion       System.Xml.XmlDocument serverXmlDoc = UpdateSvr.AppUpdateVertion();    System.Xml.XmlDocument localXmlDoc = new System.Xml.XmlDocument();    localXmlDoc.Load(desPath + "UpdateConfig.xml");    bool newVersionExist = false;    bool moduleExist = false;    System.Xml.XmlNode serverNode0 = serverXmlDoc.ChildNodes[0];    System.Xml.XmlNode localNode0 = localXmlDoc.ChildNodes[0];    foreach(System.Xml.XmlNode serverNode in serverNode0)    {     moduleExist = false;     foreach(System.Xml.XmlNode localNode in localNode0)     {      //找到對應模塊      if(localNode.ChildNodes[0].InnerText == serverNode.ChildNodes[0].InnerText)      {       moduleExist = true;       //版本號判斷       if(localNode.ChildNodes[1].InnerText.CompareTo(serverNode.ChildNodes[1].InnerText) < 0)       {        newVersionExist = true;        if(System.Configuration.ConfigurationSettings.AppSettings["NetStyle"].ToString()=="internet")        {         DownloadFile(serverNode.ChildNodes[2].InnerText,tempPath + serverNode.ChildNodes[0].InnerText);        }        else        {         DownloadFile(serverNode.ChildNodes[3].InnerText,tempPath + serverNode.ChildNodes[0].InnerText);        }       }       break;      }     }     //沒找到對應模塊     if(false == moduleExist)     {            if(System.Configuration.ConfigurationSettings.AppSettings["NetStyle"].ToString()=="internet")      {       DownloadFile(serverNode.ChildNodes[2].InnerText,tempPath + serverNode.ChildNodes[0].InnerText);      }      else      {       DownloadFile(serverNode.ChildNodes[3].InnerText,tempPath + serverNode.ChildNodes[0].InnerText);      }     }    }    //寫入新UpdateConfig.xml升級完畢后替換    if(newVersionExist)    {     serverXmlDoc.Save(tempPath + "UpdateConfig.xml");     if(DialogResult.Yes == MessageBox.Show("有新版本,是否更新?","提示",MessageBoxButtons.YesNo))     {      string[] dirs = System.IO.Directory.GetFiles(tempPath, "*.*");      string fileName;      foreach (string dir in dirs)      {       fileName = ((dir.Split(Convert.ToChar(@"/")))[dir.Split(Convert.ToChar(@"/")).Length - 1]);       if(System.IO.File.Exists(desPath + fileName))       {        //TODO:可以支持備份以前版本        System.IO.File.Delete(desPath + fileName);       }       //TODO:如果系統(tǒng)正在運行,您得停止系統(tǒng),至于如何停止,也許可以使用System.Diagnostics.Process       System.IO.File.Move(dir,desPath + fileName);      }      MessageBox.Show("升級完畢");     }     else     {      //TODO:可以支持重新提示升級     }    }   }   catch(Exception ex)   {    throw new Exception("升級失敗,原因是:" + ex.Message,ex);   }  }//下載最新的文件  private void DownloadFile(string source,string fileName)  {   try   {    System.Net.WebClient myWebClient = new System.Net.WebClient();    myWebClient.DownloadFile(source,fileName);   }   catch(Exception ex)   {    throw new Exception("下載失敗,原因是:" + ex.Message,ex);   }  }


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 马关县| 延长县| 金山区| 亚东县| 颍上县| 夏河县| 高安市| 博兴县| 永仁县| 开鲁县| 东辽县| 昆明市| 兴宁市| 忻城县| 永兴县| 屏东市| 伊金霍洛旗| 常德市| 辽阳县| 雷山县| 景谷| 砀山县| 于都县| 县级市| 霍邱县| 甘南县| 乡宁县| 萍乡市| 阜阳市| 高雄县| 云南省| 扎赉特旗| 丰都县| 双流县| 香港| 攀枝花市| 南康市| 延庆县| 新营市| 都兰县| 奇台县|