c# 升级程序怎么做?? 思路?? 如题?没做过这方面的...望高手 指点下... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Net;using System.IO;using System.Reflection;namespace Update{ public partial class UpdateFomr : Form { public UpdateFomr() { InitializeComponent(); } /// <summary> /// 升级按扭事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUpdate_Click(object sender, EventArgs e) { try { WebClient webClient = new WebClient(); //指定路径的文件下载到当前目录下创建名为:update.txt webClient.DownloadFile(@"F:\Game\Mir2\UpdateFile\update.txt", "update.txt"); StreamReader sr = new StreamReader("update.txt"); List<UpdateFile> files = new List<UpdateFile>(); //升级文件的版本号 string version = sr.ReadLine(); //MessageBox.Show(version); //将应用程序更名复制 File.Copy(@"Game.exe", "Game_Old.exe", true); //反射备份的应用程序 得到版本号 Assembly assembly = Assembly.LoadFile(Application.StartupPath + @"\Game.exe"); //程序原来的版本号 string currentVersion = assembly.GetName().Version.ToString(); assembly = null; //如果版本不一致,则升级程序 if (currentVersion != version) { //读出有几个文件需要更新 int newFileCount = Convert.ToInt32(sr.ReadLine()); for (int i = 0; i < newFileCount; i++) { //取得文件下载路径和文件名 UpdateFile updateFile = new UpdateFile(); updateFile.FileName = sr.ReadLine(); updateFile.DownLoadPath = sr.ReadLine(); files.Add(updateFile); } foreach (UpdateFile file in files) { WebClient webClientNew = new WebClient(); //更新每个文件 - 注意web服务器的配置 webClientNew.DownloadFile(file.DownLoadPath, file.FileName); } MessageBox.Show("升级成功!"); Application.Exit(); //退出更新程序窗体 System.Diagnostics.Process.Start("Game.exe"); //打开游戏窗体可执行文件 } else { MessageBox.Show("您的游戏已经是最新版本!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } /// <summary> /// 不升级按扭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDeUpdate_Click(object sender, EventArgs e) { Application.Exit(); //退出更新程序窗体 System.Diagnostics.Process.Start("Game.exe"); //打开游戏窗体 } }} 前几天做了一个自动更新组件,但是没有仔细分析每个文件是否需要更新,而是把所有文件打包,到客户再解压完成。需要在客户端和服务端使用XML等配置文件设定文件版本号以确定是否更新。 哪个语言都差不多,本地放一个文档,可以是text或者其他的文档文档里面放着本机系统版本。在网站上面放一个XML,XML写一个节点,标示着最新版本和升级版本范围程序启动,用gethttp()获取网站上面XML文档,比较本地版本,根据需要升级然后用UDP下载文件安装或者直接覆盖 如果是c/s的呢?说的详细一点好不就像qq那样的升级。。 1.写一个主程序;一个升级程序。2.启动升级程序,升级程序连接到网站,下载新的主程序。升级程序获取原有客户端应用程序的最近一次更新日期或版本号或文件大小,两者进行比较。3.升级程序获取服务器端XML配置文件中新版本程序的更新日期或版本号或文件大小。4.如果用户选择升级,则获取下载文件列表,开始进行批量下载文档。 用AppUpdater,使用方法参照下边的文章:http://dev.yesky.com/msdn/398/2340398.shtml try { WebClient webClient = new WebClient(); //指定路径的文件下载到当前目录下创建名为:update.txt webClient.DownloadFile(@"F:\Game\Mir2\UpdateFile\update.txt", "update.txt"); StreamReader sr = new StreamReader("update.txt"); List <UpdateFile> files = new List <UpdateFile>(); //升级文件的版本号 string version = sr.ReadLine(); //MessageBox.Show(version); //将应用程序更名复制 File.Copy(@"Game.exe", "Game_Old.exe", true); //反射备份的应用程序 得到版本号 Assembly assembly = Assembly.LoadFile(Application.StartupPath + @"\Game.exe"); //程序原来的版本号 string currentVersion = assembly.GetName().Version.ToString(); assembly = null; //如果版本不一致,则升级程序 if (currentVersion != version) { //读出有几个文件需要更新 int newFileCount = Convert.ToInt32(sr.ReadLine()); for (int i = 0; i < newFileCount; i++) { //取得文件下载路径和文件名 UpdateFile updateFile = new UpdateFile(); updateFile.FileName = sr.ReadLine(); updateFile.DownLoadPath = sr.ReadLine(); files.Add(updateFile); } foreach (UpdateFile file in files) { WebClient webClientNew = new WebClient(); //更新每个文件 - 注意web服务器的配置 webClientNew.DownloadFile(file.DownLoadPath, file.FileName); } MessageBox.Show("升级成功!"); Application.Exit(); //退出更新程序窗体 System.Diagnostics.Process.Start("Game.exe"); //打开游戏窗体可执行文件 } else { MessageBox.Show("您的游戏已经是最新版本!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } 如何给构造函数有参数的 实体类 建实体数组? 询问WPF程序通过网页打开后,指纹仪API调用有问题。 如何用c#生成柱形百分比图? cookie字段 C# 关于前台后台的问题 怎样布署.Net Remoting服务器端的程序或软件?有经验的朋友谈谈! 关于自动命令生成 2005中的webBrowser控件如何读取js变量 那位老大可以提供这样的一个控件,或者指导怎么做:类似个文本框,要求可以输入 年:月:日:小时:分钟:秒 超级特难问题,有谁解决了,我出200大洋 visual studio 2008打包的问题 C#开发的wince程序的自动升级问题?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Reflection;namespace Update
{
public partial class UpdateFomr : Form
{
public UpdateFomr()
{
InitializeComponent();
} /// <summary>
/// 升级按扭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
WebClient webClient = new WebClient(); //指定路径的文件下载到当前目录下创建名为:update.txt
webClient.DownloadFile(@"F:\Game\Mir2\UpdateFile\update.txt", "update.txt"); StreamReader sr = new StreamReader("update.txt"); List<UpdateFile> files = new List<UpdateFile>(); //升级文件的版本号
string version = sr.ReadLine(); //MessageBox.Show(version); //将应用程序更名复制
File.Copy(@"Game.exe", "Game_Old.exe", true); //反射备份的应用程序 得到版本号
Assembly assembly = Assembly.LoadFile(Application.StartupPath
+ @"\Game.exe"); //程序原来的版本号
string currentVersion = assembly.GetName().Version.ToString(); assembly = null; //如果版本不一致,则升级程序
if (currentVersion != version)
{ //读出有几个文件需要更新
int newFileCount = Convert.ToInt32(sr.ReadLine()); for (int i = 0; i < newFileCount; i++)
{
//取得文件下载路径和文件名
UpdateFile updateFile = new UpdateFile();
updateFile.FileName = sr.ReadLine();
updateFile.DownLoadPath = sr.ReadLine();
files.Add(updateFile);
} foreach (UpdateFile file in files)
{
WebClient webClientNew = new WebClient();
//更新每个文件 - 注意web服务器的配置
webClientNew.DownloadFile(file.DownLoadPath, file.FileName);
}
MessageBox.Show("升级成功!"); Application.Exit(); //退出更新程序窗体 System.Diagnostics.Process.Start("Game.exe"); //打开游戏窗体可执行文件
}
else
{
MessageBox.Show("您的游戏已经是最新版本!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
} /// <summary>
/// 不升级按扭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDeUpdate_Click(object sender, EventArgs e)
{
Application.Exit(); //退出更新程序窗体 System.Diagnostics.Process.Start("Game.exe"); //打开游戏窗体
}
}
}
需要在客户端和服务端使用XML等配置文件设定文件版本号以确定是否更新。
文档里面放着本机系统版本。
在网站上面放一个XML,XML写一个节点,标示着最新版本和升级版本范围
程序启动,用gethttp()获取网站上面XML文档,比较本地版本,根据需要升级
然后用UDP下载文件安装或者直接覆盖
说的详细一点好不就像qq那样的升级。。
2.启动升级程序,升级程序连接到网站,下载新的主程序。升级程序获取原有客户端应用程序的最近一次更新日期或版本号或文件大小,两者进行比较。
3.升级程序获取服务器端XML配置文件中新版本程序的更新日期或版本号或文件大小。
4.如果用户选择升级,则获取下载文件列表,开始进行批量下载文档。
http://dev.yesky.com/msdn/398/2340398.shtml
{
WebClient webClient = new WebClient(); //指定路径的文件下载到当前目录下创建名为:update.txt
webClient.DownloadFile(@"F:\Game\Mir2\UpdateFile\update.txt", "update.txt"); StreamReader sr = new StreamReader("update.txt"); List <UpdateFile> files = new List <UpdateFile>(); //升级文件的版本号
string version = sr.ReadLine(); //MessageBox.Show(version); //将应用程序更名复制
File.Copy(@"Game.exe", "Game_Old.exe", true); //反射备份的应用程序 得到版本号
Assembly assembly = Assembly.LoadFile(Application.StartupPath
+ @"\Game.exe"); //程序原来的版本号
string currentVersion = assembly.GetName().Version.ToString(); assembly = null; //如果版本不一致,则升级程序
if (currentVersion != version)
{ //读出有几个文件需要更新
int newFileCount = Convert.ToInt32(sr.ReadLine()); for (int i = 0; i < newFileCount; i++)
{
//取得文件下载路径和文件名
UpdateFile updateFile = new UpdateFile();
updateFile.FileName = sr.ReadLine();
updateFile.DownLoadPath = sr.ReadLine();
files.Add(updateFile);
} foreach (UpdateFile file in files)
{
WebClient webClientNew = new WebClient();
//更新每个文件 - 注意web服务器的配置
webClientNew.DownloadFile(file.DownLoadPath, file.FileName);
}
MessageBox.Show("升级成功!"); Application.Exit(); //退出更新程序窗体 System.Diagnostics.Process.Start("Game.exe"); //打开游戏窗体可执行文件
}
else
{
MessageBox.Show("您的游戏已经是最新版本!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}