C#自动更新(1)

C#自动更新(1)
2011-11-18 15:57
自动更新思路:

在client根据server的配置文件判断是否有新版本,有的话下载更新信息:更新Ip、版本号、更新文件等,下载到本地。

再根据ip进行下载到本地临时文件中,下载完成后,提示用户是否更新。如果更新关闭当前系统,启动更新服务将临时文件中的文件替换到要替换的程序目录下,代码如下:

client:


/// <summary> /// 根据服务器上的数据进行同步数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnKeepUser_Click(object sender, EventArgs e) { #region web download bool isUpdate = false; string[] fileName = new string[] { "Accounting_Client.dll", "Accounting_Component.dll", "Accounting_Entity.dll", "Accounting_UI.dll" }; //要下载的文件 AutoUpdate update = new AutoUpdate(); for (int i = 0; i < fileName.Length; i++) { isUpdate= update.start(fileName[i]); if (isUpdate ==false) { break; } } if (isUpdate ==false) { MessageBox.Show("Update failure"); } else { //自动下载完成后,将保存的路径和要替换的路径保存到ini配置文件中 #region 写入INI文件 //写入ini文件 string s = Application.ExecutablePath; string s1; s1 = s.Replace("ini.exe", "updateVersionConfig.ini"); //写入版本信息 string origin = System.Windows.Forms.Application.StartupPath + ""; string destination = System.Windows.Forms.Application.StartupPath; string path = "C:\\updateVersionConfig.ini"; WritePrivateProfileString("updateInfo", "origin", origin, path); //写入源地址 WritePrivateProfileString("updateInfo", "destination" , destination, path); //写入更新地址 #endregion #region 启动自动更新,关闭当前系统 //System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("TIMS"); 关闭原有应用程序的所有进程 //foreach (System.Diagnostics.Process pro in proc) //{ // pro.Kill(); //} //启动更新程序 string strUpdaterPath = System.Windows.Forms.Application.StartupPath + ""; this.Close(); System.Diagnostics.Process.Start(strUpdaterPath); #endregion } #endregion //ProgressBar bar = new ProgressBar(); //string curVersion = GetLastestVersionByFtp(""); //#region 读取本地当前的版本 此处获得软件的版本信息 //string currentUser = "info"; //StringBuilder temp = new StringBuilder(80000000); //string section = "versionInfo"; //string iniPath = GlobalFile.GlobalConfigurationInfo.AddressOfIni; //"G:\\test\\userConfig.ini"; //int i = GetPrivateProfileString(section, currentUser, "", temp, 80000000, iniPath); //string versionInfo = temp.ToString(); //int versionPos = versionInfo.LastIndexOf("="); //versionInfo = versionInfo.Substring(versionPos + 1, versionInfo.Length - (versionPos + 1)); //#endregion 获得本地版本 //string localVersion = versionInfo; 获得服务器上的版本信息 //UserLoginClient ftpInfo = new UserLoginClient(); //string[] result = ftpInfo.getFtpInformation(localVersion); //if (result == null) //{ // label2.Text = "已是最新版本!"; // return; //} 获得FTP返回的消息 0:最新版本号 1: FTP登陆名 2:FTP登陆密码 3: FTP登陆IP //string ftpVersion = result[0]; //string ftpLoginName = result[1]; //string ftpLoginPwd = result[2]; //string ftpIp = result[3]; 如果已是最新版本 //if (ftpVersion == localVersion) //{ // label2.Text = "已是最新版本!"; //} //else //{ // //根据最新的版本号下载程序到本地 // label2.Text = "已不是最新版本!"; //} }

  

转载于:https://www.cnblogs.com/laojiefang/archive/2012/04/12/2443377.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值