| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 6215 人关注过本帖, 2 人收藏
标题:[求助]打包部署后自动更新
只看楼主 加入收藏
我爱一条柴
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-8-30
收藏
得分:0 
思路很好,很不错
2008-08-30 14:38
icwin
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-2-19
收藏
得分:0 
关注啊
2008-09-06 16:48
qindewan
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-9-2
收藏
得分:0 
用c#的clickonce技术可以实现
2008-09-07 19:04
hxhfg
Rank: 1
等 级:新手上路
帖 子:284
专家分:0
注 册:2006-4-18
收藏
得分:0 
clickonce技术不能发布配置文件呀,比如INI文件

2008-09-08 11:04
ihitu
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-27
收藏
得分:0 
http://www.这里可以下载
2012-03-27 22:30
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
呵呵,恰巧在实际应用中做过,说下我的方法:

1. 有一个固定IP地址的数据库服务器。数据库中存放一个软件版本表,有版本字段,下载路径字段,更新时间等(楼主的是在文件里,我的是写在库里的)
2. 发布的程序中标识一个版本号,添加一个资源,这个资源是升级程序,在program.cs中加一个检查升级的方法:
private static void CheckUpdate()
        {
            //升级程序名
            string UpdateFile = "SystemUpdate.exe";
            if (("rar.exe"))
                ("rar.exe");
            if (("Compress.rar"))
                ("Compress.rar");
            if ((UpdateFile))
                (UpdateFile);//释放升级程序前删除现有的升级文件
            UpdateService.Service1 Updater = new UpdateService.Service1();//这是个WEB服务,放在固定IP的服务器上
            int newver = int.Parse(Updater.GetNewVersion());//从服务器获取最新版本号
            if (newver > version)//与当前系统版本做对比
            {
                IsNeedUpdate = true;//需要升级
                byte[] bytUpdate = resUpdate.SystemUpdate;//读取升级程序字节流
                //创建升级程序文件写入器
                fs = new (UpdateFile,
                                                            ,
                                                            );
                //二进制写文件
                bWriter = new (fs);
                //输出内容到升级程序
                bWriter.Write(bytUpdate, 0, bytUpdate.Length);
                bWriter.Close();
                fs.Close();
                fs.Dispose();
                //开启一个进程执行升级程序
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = UpdateFile;
                proc.Start();
                proc.Close();
                proc.Dispose();
                //退出当前程序
                Environment.Exit(Environment.ExitCode);
            }
        }
3.升级程序。同要添加一个资源,里面放rar.exe,这个程序在WINRAR里就有,我是把所有程序中用的都打成一个包,包括DLL和BIN文件,还可以设置密码
下面是升级方法的主要内容:
private void BegionUpdate()
        {
            lblTips.Text = "删除当前版的系统……";
            string currentshell = Process.GetCurrentProcess().MainModule.FileName;
            string path = currentshell.Substring(0, currentshell.LastIndexOf(@"\"));
            DirectoryInfo dir = new DirectoryInfo(path);
            FileInfo[] files = dir.GetFiles();
            List<string> lstFileToBeDeleted = new List<string>();
            Dictionary<string, List<string>> dic = new Dictionary<string, List<string>>();
            lblTips.Text = "收集文件……";
            pgs.Maximum = files.Length - 1;
            int iValue = 0;
            foreach (FileInfo file in files)
            {
                pgs.Value = iValue++;
                if (currentshell != file.FullName)
                {
                    string ExtName = file.Name.Substring(file.Name.LastIndexOf(".")).ToUpper();
                    string MainName = file.Name.Substring(0, file.Name.LastIndexOf("."));
                    List<string> lstExt = new List<string>();
                    if (!dic.ContainsKey(MainName))
                    {
                        lstExt.Add(ExtName);
                        dic.Add(MainName, lstExt);
                    }
                    else
                    {
                        lstExt = dic[MainName];
                        if (!lstExt.Contains(ExtName))
                            lstExt.Add(ExtName);
                        dic[MainName] = lstExt;
                    }
                    if (!lstFileToBeDeleted.Contains(file.Name))
                        lstFileToBeDeleted.Add(file.Name);
                }
            }
            lblTips.Text = "检查系统中是否有平台相关进程在运行……";
            Process[] execute = Process.GetProcesses();
            pgs.Maximum = execute.Length - 1;
            iValue = 0;
            foreach (Process proc in execute)
            {
                pgs.Value = iValue++;
                if (dic.ContainsKey(proc.ProcessName))
                {
                    if (dic[proc.ProcessName].Contains(".EXE"))
                        proc.Kill();
                }
            }

            if (lstFileToBeDeleted.Count > 0)
            {
                lblTips.Text = "删除旧版本的系统……";
                pgs.Maximum = lstFileToBeDeleted.Count - 1;
                iValue = 0;
                foreach (string delFile in lstFileToBeDeleted)
                {
                    try
                    {
                        pgs.Value = iValue++;
                        File.Delete(delFile);
                    }
                    catch
                    {
                        MessageBox.Show("删除" + delFile + "失败,请手工删除\r\n否则可能导致升级失败");
                        continue;
                    }
                }
            }

            lblTips.Text = "获取系统升级信息";
            RemoteData.Service1 rmtService = new RemoteData.Service1();//从这行起的4行代码最好调用WebService,用Remoting可能被防火墙拦下
            string url = rmtService.GetDownloadURL();//         
            string date = rmtService.GetNewVersionDate();//
            string times = rmtService.GetNewVersion();//

            lblTips.Text = "正在下载" + date + "第" + times + "次更新";
            HTMLPAGE downloader = new HTMLPAGE();//这是个封闭的类,只用到下载功能,大家可以自己实现
            downloader.Download(url, "Compress.rar");

            try
            {
                lblTips.Text = "开始升级系统……";
                //clsWinrar rar = new clsWinrar();
                //rar.unCompressRAR(path, path, "Compress.rar");

                string rarTool = "rar.exe";

                byte[] bytUpdate = resRAR.Rar;//读取升级程序字节流
                //创建升级程序文件写入器
                fs = new (rarTool,
                                                            ,
                                                            );
                //二进制写文件
                bWriter = new (fs);
                //输出内容到升级程序
                bWriter.Write(bytUpdate, 0, bytUpdate.Length);
                bWriter.Close();
                fs.Close();
                fs.Dispose();
                //开启一个进程执行升级程序
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo srtInfo = new ProcessStartInfo();
                srtInfo.FileName = rarTool;
                srtInfo.Arguments = " x Compress.rar";
                srtInfo.CreateNoWindow = true;
                srtInfo.UseShellExecute = true;
                srtInfo.WindowStyle = ProcessWindowStyle.Hidden;
                proc.StartInfo = srtInfo;
                proc.Start();
                try
                {
                    while (System.Diagnostics.Process.GetProcessById(proc.Id) != null)
                        Application.DoEvents();
                }
                catch (Exception err)
                {
                    if (err.Message.IndexOf("进程当前未运行") != -1)
                        Application.DoEvents();
                }
                proc.Close();
                proc.Dispose();

                Process system = new Process();
                system.StartInfo.FileName = "发布程序启动的可执行文件名.exe";
                system.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
                system.StartInfo.CreateNoWindow = false;
                system.Start();
                //system.Close();
                //system.Dispose();
            }
            catch
            {
                MessageBox.Show("成功下载升级包,请手工解压运行");
            }

            this.Close();
        }

其实我也很无聊!
2012-04-27 09:56
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
回复 10楼 mlrh3838
这个问题在我的方法中已经解决了,WebService中查询版本号时Select的最新版本号(MAX函数),直接升级到最新版就可以。
升级文件的路径是写在数据库中的,文件名随意,但实际格式必须是压缩包,解压前的名字在升级程序下载时更名。

其实我也很无聊!
2012-04-27 10:02
快速回复:[求助]打包部署后自动更新
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018992 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved