最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > asp教程

ASPEyesBaby功能实现之软件更新技巧

日期:09-08    来源:中国设计秀    作者:cnwebshow.com

奉上CODE:p8b中国设计秀
p8b中国设计秀
1.access操作类:p8b中国设计秀
p8b中国设计秀
代码 p8b中国设计秀
using System;p8b中国设计秀
using System.Collections.Generic;p8b中国设计秀
using System.Text;p8b中国设计秀
using System.Data.OleDb;p8b中国设计秀
p8b中国设计秀
namespace LogHelper.BLLp8b中国设计秀
{p8b中国设计秀
    /// <summary>p8b中国设计秀
    /// 更新错误日志处理类p8b中国设计秀
    /// </summary>p8b中国设计秀
    public class Logp8b中国设计秀
    {p8b中国设计秀
        PRivate string _connStr;p8b中国设计秀
p8b中国设计秀
        public Log(string connStr)p8b中国设计秀
        {p8b中国设计秀
            _connStr = connStr;p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 添加一条日志p8b中国设计秀
        /// </summary>p8b中国设计秀
        /// <param name="title"></param>p8b中国设计秀
        /// <param name="content"></param>p8b中国设计秀
        /// <returns></returns>p8b中国设计秀
        public bool Add(LogHelper.Model.Log modLog)p8b中国设计秀
        {p8b中国设计秀
            bool b = false;p8b中国设计秀
            if (!string.IsNullOrEmpty(_connStr))p8b中国设计秀
            {p8b中国设计秀
                OleDbConnection objConnection = new OleDbConnection(_connStr);p8b中国设计秀
                tryp8b中国设计秀
                {p8b中国设计秀
p8b中国设计秀
                    objConnection.Open();p8b中国设计秀
                    string insertSql = "insert into LogInfo(Title,Content,CreateDate) values('" + modLog.Title + "','" + modLog.Content + "','" + modLog.CreateDate + "')";p8b中国设计秀
                    OleDbCommand cmd = new OleDbCommand(insertSql,objConnection);p8b中国设计秀
                    cmd.ExecuteNonQuery();p8b中国设计秀
                    b= true;p8b中国设计秀
                }p8b中国设计秀
                catch (Exception ex)p8b中国设计秀
                { }p8b中国设计秀
                finallyp8b中国设计秀
                {p8b中国设计秀
                    objConnection.Close();p8b中国设计秀
                }p8b中国设计秀
p8b中国设计秀
            }p8b中国设计秀
            return b;p8b中国设计秀
        }p8b中国设计秀
    }p8b中国设计秀
}p8b中国设计秀
p8b中国设计秀
namespace LogHelper.Modelp8b中国设计秀
{p8b中国设计秀
    /// <summary>p8b中国设计秀
    /// UpdateErrorLog模型p8b中国设计秀
    /// </summary>p8b中国设计秀
    public class Logp8b中国设计秀
    {p8b中国设计秀
        string _title;p8b中国设计秀
p8b中国设计秀
        public string Titlep8b中国设计秀
        {p8b中国设计秀
            get { return _title; }p8b中国设计秀
            set { _title = value; }p8b中国设计秀
        }p8b中国设计秀
        string _content;p8b中国设计秀
p8b中国设计秀
        public string Contentp8b中国设计秀
        {p8b中国设计秀
            get { return _content; }p8b中国设计秀
            set { _content = value; }p8b中国设计秀
        }p8b中国设计秀
        string _createDate;p8b中国设计秀
p8b中国设计秀
        public string CreateDatep8b中国设计秀
        {p8b中国设计秀
            get { return _createDate; }p8b中国设计秀
            set { _createDate = value; }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
    }p8b中国设计秀
}p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
2.xml当前版本配置操作类:p8b中国设计秀
p8b中国设计秀
代码 p8b中国设计秀
using System;p8b中国设计秀
using System.Collections.Generic;p8b中国设计秀
using System.Text;p8b中国设计秀
using System.Windows.Forms;p8b中国设计秀
p8b中国设计秀
namespace EyesBabyp8b中国设计秀
{p8b中国设计秀
    /// <summary>p8b中国设计秀
    /// 当前版本配置操作类p8b中国设计秀
    /// </summary>p8b中国设计秀
    public class CurrentVesionHelperp8b中国设计秀
    {p8b中国设计秀
        private const string _configName = "CurrentInfo.config";p8b中国设计秀
p8b中国设计秀
        private const string _currentVesionKeyName = "currentVesion";p8b中国设计秀
p8b中国设计秀
        private const string _updateDateKeyName = "updateDate";p8b中国设计秀
p8b中国设计秀
        private const string _programNameKeyName = "programName";p8b中国设计秀
p8b中国设计秀
        private const string _installDirKeyName = "installDir";p8b中国设计秀
p8b中国设计秀
        XMLHandle xml = null;p8b中国设计秀
p8b中国设计秀
        private string _currentVesion;p8b中国设计秀
p8b中国设计秀
        private string _updateDate;p8b中国设计秀
p8b中国设计秀
        private string _installDir;p8b中国设计秀
p8b中国设计秀
        private string _programName;p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 安装目录p8b中国设计秀
        /// </summary>p8b中国设计秀
        public string InstallDirp8b中国设计秀
        {p8b中国设计秀
            get { return _installDir; }p8b中国设计秀
            set { _installDir = value; }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 应用程序名称p8b中国设计秀
        /// </summary>p8b中国设计秀
        public string ProgramNamep8b中国设计秀
        {p8b中国设计秀
            get { return _programName; }p8b中国设计秀
            set { _programName = value; }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 当前版本p8b中国设计秀
        /// </summary>p8b中国设计秀
        public string CurrentVesionp8b中国设计秀
        {p8b中国设计秀
            get { return _currentVesion; }p8b中国设计秀
            set { _currentVesion = value; }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 更新日期p8b中国设计秀
        /// </summary>p8b中国设计秀
        public string UpdateDatep8b中国设计秀
        {p8b中国设计秀
            get { return _updateDate; }p8b中国设计秀
            set { _updateDate = value; }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        public CurrentVesionHelper()p8b中国设计秀
        {p8b中国设计秀
            if (!string.IsNullOrEmpty(_configName))p8b中国设计秀
            {p8b中国设计秀
                string filepath = application.StartupPath +""+ _configName;p8b中国设计秀
                xml = new XMLHandle();p8b中国设计秀
                xml.Load(filepath);p8b中国设计秀
                _currentVesion = xml.GetValueByID(_currentVesionKeyName);p8b中国设计秀
                _updateDate = xml.GetValueByID(_updateDateKeyName);p8b中国设计秀
                _installDir = xml.GetValueByID(_installDirKeyName);p8b中国设计秀
                _programName = xml.GetValueByID(_programNameKeyName);p8b中国设计秀
            }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 更新保存p8b中国设计秀
        /// </summary>p8b中国设计秀
        public void UpdateVesion()p8b中国设计秀
        {p8b中国设计秀
            xml.SetValueByID(_currentVesionKeyName, _currentVesion);p8b中国设计秀
            xml.SetValueByID(_updateDateKeyName, _updateDate);p8b中国设计秀
            xml.SetValueByID(_installDirKeyName, _installDir);p8b中国设计秀
            xml.SetValueByID(_programNameKeyName, _programName);p8b中国设计秀
        }p8b中国设计秀
    }p8b中国设计秀
}p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
3.HttpWebRequest下载文件p8b中国设计秀
p8b中国设计秀
代码 p8b中国设计秀
using System;p8b中国设计秀
using System.Collections.Generic;p8b中国设计秀
using System.Text;p8b中国设计秀
using System.Net;p8b中国设计秀
using System.IO;p8b中国设计秀
p8b中国设计秀
namespace EyesBabyp8b中国设计秀
{p8b中国设计秀
    /// <summary>p8b中国设计秀
    /// 文件下载类p8b中国设计秀
    /// </summary>p8b中国设计秀
    public class DownloadClassp8b中国设计秀
    {p8b中国设计秀
        public string StrUrl;//文件下载网址p8b中国设计秀
        public string StrFileName;//下载文件保存地址 p8b中国设计秀
        public string strError;//返回结果p8b中国设计秀
        public long lStartPos = 0; //返回上次下载字节p8b中国设计秀
        public long lCurrentPos = 0;//返回当前下载字节p8b中国设计秀
        public long lDownloadFile;//返回当前下载文件长度p8b中国设计秀
p8b中国设计秀
        public void DownloadFile()p8b中国设计秀
        {p8b中国设计秀
            System.IO.FileStream fs;p8b中国设计秀
            if (System.IO.File.Exists(StrFileName))p8b中国设计秀
            {p8b中国设计秀
                fs = System.IO.File.OpenWrite(StrFileName);p8b中国设计秀
                lStartPos = fs.Length;p8b中国设计秀
                fs.Seek(lStartPos, System.IO.SeekOrigin.Current);p8b中国设计秀
                //移动文件流中的当前指针 p8b中国设计秀
            }p8b中国设计秀
            elsep8b中国设计秀
            {p8b中国设计秀
                fs = new System.IO.FileStream(StrFileName, System.IO.FileMode.Create);p8b中国设计秀
                lStartPos = 0;p8b中国设计秀
            }p8b中国设计秀
p8b中国设计秀
            //打开网络连接 p8b中国设计秀
            tryp8b中国设计秀
            {p8b中国设计秀
                System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(StrUrl);p8b中国设计秀
                long length = request.GetResponse().ContentLength;p8b中国设计秀
                lDownloadFile = length;p8b中国设计秀
                if (lStartPos > 0)p8b中国设计秀
                    request.AddRange((int)lStartPos); //设置Range值p8b中国设计秀
p8b中国设计秀
                //向服务器请求,获得服务器回应数据流 p8b中国设计秀
                System.IO.Stream ns = request.GetResponse().GetResponseStream();p8b中国设计秀
p8b中国设计秀
                byte[] nbytes = new byte[512];p8b中国设计秀
                int nReadSize = 0;p8b中国设计秀
                nReadSize = ns.Read(nbytes, 0, 512);p8b中国设计秀
                while (nReadSize > 0)p8b中国设计秀
                {p8b中国设计秀
                    fs.Write(nbytes, 0, nReadSize);p8b中国设计秀
                    nReadSize = ns.Read(nbytes, 0, 512);p8b中国设计秀
                    lCurrentPos = fs.Length;p8b中国设计秀
                }p8b中国设计秀
p8b中国设计秀
                fs.Close();p8b中国设计秀
                ns.Close();p8b中国设计秀
                strError = "下载完成";p8b中国设计秀
p8b中国设计秀
            }p8b中国设计秀
            catch (Exception ex)p8b中国设计秀
            {p8b中国设计秀
                fs.Close();p8b中国设计秀
                strError = "下载过程中出现错误:" + ex.ToString();p8b中国设计秀
            }p8b中国设计秀
p8b中国设计秀
        }p8b中国设计秀
    } p8b中国设计秀
p8b中国设计秀
}p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
4.GZipStream解压缩文件包p8b中国设计秀
p8b中国设计秀
代码 p8b中国设计秀
using System;p8b中国设计秀
using System.Collections.Generic;p8b中国设计秀
using System.Text;p8b中国设计秀
using System.IO;p8b中国设计秀
using System.IO.Compression;p8b中国设计秀
using System.Windows.Forms;p8b中国设计秀
using ICSharpCode.SharpZipLib.Zip;p8b中国设计秀
p8b中国设计秀
namespace EyesBabyp8b中国设计秀
{p8b中国设计秀
p8b中国设计秀
    public class clsZipp8b中国设计秀
    {p8b中国设计秀
        public void CompressFile(string sourceFile, string destinationFile)p8b中国设计秀
        {p8b中国设计秀
            // make sure the source file is therep8b中国设计秀
            if (File.Exists(sourceFile) == false)p8b中国设计秀
                throw new FileNotFoundException();p8b中国设计秀
p8b中国设计秀
            // Create the streams and byte arrays neededp8b中国设计秀
            byte[] buffer = null;p8b中国设计秀
            FileStream sourceStream = null;p8b中国设计秀
            FileStream destinationStream = null;p8b中国设计秀
            GZipStream compressedStream = null;p8b中国设计秀
p8b中国设计秀
            tryp8b中国设计秀
            {p8b中国设计秀
                // Read the bytes from the source file into a byte arrayp8b中国设计秀
                sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read);p8b中国设计秀
p8b中国设计秀
                // Read the source stream values into the bufferp8b中国设计秀
                buffer = new byte[sourceStream.Length];p8b中国设计秀
                int checkCounter = sourceStream.Read(buffer, 0, buffer.Length);p8b中国设计秀
p8b中国设计秀
                if (checkCounter != buffer.Length)p8b中国设计秀
                {p8b中国设计秀
                    throw new ApplicationException();p8b中国设计秀
                }p8b中国设计秀
p8b中国设计秀
                // Open the FileStream to write top8b中国设计秀
                destinationStream = new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write);p8b中国设计秀
p8b中国设计秀
                // Create a compression stream pointing to the destiantion streamp8b中国设计秀
                compressedStream = new GZipStream(destinationStream, CompressionMode.Compress, true);p8b中国设计秀
p8b中国设计秀
                // Now write the compressed data to the destination filep8b中国设计秀
                compressedStream.Write(buffer, 0, buffer.Length);p8b中国设计秀
            }p8b中国设计秀
            catch (ApplicationException ex)p8b中国设计秀
            {p8b中国设计秀
                MessageBox.Show(ex.Message, "压缩文件时发生错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);p8b中国设计秀
            }p8b中国设计秀
            finallyp8b中国设计秀
            {p8b中国设计秀
                // Make sure we allways close all streamsp8b中国设计秀
                if (sourceStream != null)p8b中国设计秀
                    sourceStream.Close();p8b中国设计秀
p8b中国设计秀
                if (compressedStream != null)p8b中国设计秀
                    compressedStream.Close();p8b中国设计秀
p8b中国设计秀
                if (destinationStream != null)p8b中国设计秀
                    destinationStream.Close();p8b中国设计秀
            }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        public void DecompressFile(string sourceFile, string destinationFile)p8b中国设计秀
        {p8b中国设计秀
            // make sure the source file is therep8b中国设计秀
            if (File.Exists(sourceFile) == false)p8b中国设计秀
                throw new FileNotFoundException();p8b中国设计秀
p8b中国设计秀
            // Create the streams and byte arrays neededp8b中国设计秀
            FileStream sourceStream = null;p8b中国设计秀
            FileStream destinationStream = null;p8b中国设计秀
            GZipStream decompressedStream = null;p8b中国设计秀
            byte[] quartetBuffer = null;p8b中国设计秀
p8b中国设计秀
            tryp8b中国设计秀
            {p8b中国设计秀
                // Read in the compressed source streamp8b中国设计秀
                sourceStream = new FileStream(sourceFile, FileMode.Open);p8b中国设计秀
p8b中国设计秀
                // Create a compression stream pointing to the destiantion streamp8b中国设计秀
                decompressedStream = new GZipStream(sourceStream, CompressionMode.Decompress, true);p8b中国设计秀
p8b中国设计秀
                // Read the footer to determine the length of the destiantion filep8b中国设计秀
                quartetBuffer = new byte[4];p8b中国设计秀
                int position = (int)sourceStream.Length - 4;p8b中国设计秀
                sourceStream.Position = position;p8b中国设计秀
                sourceStream.Read(quartetBuffer, 0, 4);p8b中国设计秀
                sourceStream.Position = 0;p8b中国设计秀
                int checkLength = BitConverter.ToInt32(quartetBuffer, 0);p8b中国设计秀
p8b中国设计秀
                byte[] buffer = new byte[checkLength + 100];p8b中国设计秀
p8b中国设计秀
                int offset = 0;p8b中国设计秀
                int total = 0;p8b中国设计秀
p8b中国设计秀
                // Read the compressed data into the bufferp8b中国设计秀
                while (true)p8b中国设计秀
                {p8b中国设计秀
                    int bytesRead = decompressedStream.Read(buffer, offset, 100);p8b中国设计秀
p8b中国设计秀
                    if (bytesRead == 0)p8b中国设计秀
                        break;p8b中国设计秀
p8b中国设计秀
                    offset += bytesRead;p8b中国设计秀
                    total += bytesRead;p8b中国设计秀
                }p8b中国设计秀
p8b中国设计秀
                // Now write everything to the destination filep8b中国设计秀
                destinationStream = new FileStream(destinationFile, FileMode.Create);p8b中国设计秀
                destinationStream.Write(buffer, 0, total);p8b中国设计秀
p8b中国设计秀
                // and flush everyhting to clean out the bufferp8b中国设计秀
                destinationStream.Flush();p8b中国设计秀
            }p8b中国设计秀
            catch (ApplicationException ex)p8b中国设计秀
            {p8b中国设计秀
                MessageBox.Show(ex.Message, "解压文件时发生错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);p8b中国设计秀
            }p8b中国设计秀
            finallyp8b中国设计秀
            {p8b中国设计秀
                // Make sure we allways close all streamsp8b中国设计秀
                if (sourceStream != null)p8b中国设计秀
                    sourceStream.Close();p8b中国设计秀
p8b中国设计秀
                if (decompressedStream != null)p8b中国设计秀
                    decompressedStream.Close();p8b中国设计秀
p8b中国设计秀
                if (destinationStream != null)p8b中国设计秀
                    destinationStream.Close();p8b中国设计秀
            }p8b中国设计秀
p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 功能:解压zip格式的文件。p8b中国设计秀
        /// </summary>p8b中国设计秀
        /// <param name="zipFilePath">压缩文件路径</param>p8b中国设计秀
        /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>p8b中国设计秀
        /// <param name="err">出错信息</param>p8b中国设计秀
        /// <returns>解压是否成功</returns>p8b中国设计秀
        public bool UnZipFile(string zipFilePath, string unZipDir, out string err)p8b中国设计秀
        {p8b中国设计秀
            err = "";p8b中国设计秀
            if (zipFilePath == string.Empty)p8b中国设计秀
            {p8b中国设计秀
                err = "压缩文件不能为空!";p8b中国设计秀
                return false;p8b中国设计秀
            }p8b中国设计秀
            if (!File.Exists(zipFilePath))p8b中国设计秀
            {p8b中国设计秀
                err = "压缩文件不存在!";p8b中国设计秀
                return false;p8b中国设计秀
            }p8b中国设计秀
            //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹p8b中国设计秀
            if (unZipDir == string.Empty)p8b中国设计秀
                unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));p8b中国设计秀
            if (!unZipDir.EndsWith(""))p8b中国设计秀
                unZipDir += "";p8b中国设计秀
            if (!Directory.Exists(unZipDir))p8b中国设计秀
                Directory.CreateDirectory(unZipDir);p8b中国设计秀
p8b中国设计秀
            tryp8b中国设计秀
            {p8b中国设计秀
                using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath)))p8b中国设计秀
                {p8b中国设计秀
p8b中国设计秀
                    ZipEntry theEntry;p8b中国设计秀
                    while ((theEntry = s.GetNextEntry()) != null)p8b中国设计秀
                    {p8b中国设计秀
                        string directoryName = Path.GetDirectoryName(theEntry.Name);p8b中国设计秀
                        string fileName = Path.GetFileName(theEntry.Name);p8b中国设计秀
                        if (directoryName.Length > 0)p8b中国设计秀
                        {p8b中国设计秀
                            Directory.CreateDirectory(unZipDir + directoryName);p8b中国设计秀
                        }p8b中国设计秀
                        if (!directoryName.EndsWith(""))p8b中国设计秀
                            directoryName += "";p8b中国设计秀
                        if (fileName != String.Empty)p8b中国设计秀
                        {p8b中国设计秀
                            using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name))p8b中国设计秀
                            {p8b中国设计秀
p8b中国设计秀
                                int size = 2048;p8b中国设计秀
                                byte[] data = new byte[2048];p8b中国设计秀
                                while (true)p8b中国设计秀
                                {p8b中国设计秀
                                    size = s.Read(data, 0, data.Length);p8b中国设计秀
                                    if (size > 0)p8b中国设计秀
                                    {p8b中国设计秀
                                        streamWriter.Write(data, 0, size);p8b中国设计秀
                                    }p8b中国设计秀
                                    elsep8b中国设计秀
                                    {p8b中国设计秀
                                        break;p8b中国设计秀
                                    }p8b中国设计秀
                                }p8b中国设计秀
                            }p8b中国设计秀
                        }p8b中国设计秀
                    }//whilep8b中国设计秀
                }p8b中国设计秀
            }p8b中国设计秀
            catch (Exception ex)p8b中国设计秀
            {p8b中国设计秀
                err = ex.Message;p8b中国设计秀
                return false;p8b中国设计秀
            }p8b中国设计秀
            return true;p8b中国设计秀
        }//p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
    }p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
}p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
5.System.Diagnostics.Process操作进程p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
                 // 关闭程序p8b中国设计秀
                    System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName(programName);p8b中国设计秀
                    foreach (System.Diagnostics.Process p in ps)p8b中国设计秀
                    {p8b中国设计秀
                        p.Kill();p8b中国设计秀
                    }p8b中国设计秀
           // 重启程序p8b中国设计秀
                    System.Diagnostics.Process.Start(startpath);p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
   p8b中国设计秀
6.System.IO文件夹/文件复制p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
代码 p8b中国设计秀
using System;p8b中国设计秀
using System.Collections.Generic;p8b中国设计秀
using System.Text;p8b中国设计秀
using System.IO;p8b中国设计秀
p8b中国设计秀
namespace EyesBabyp8b中国设计秀
{p8b中国设计秀
    public class CopyFolderp8b中国设计秀
    { p8b中国设计秀
          private   static   int   total   =   0;  p8b中国设计秀
          private   int   FileNumber   =   0;     //文件夹文件总数  p8b中国设计秀
   p8b中国设计秀
          ///   <summary>  p8b中国设计秀
          ///   复制文件夹  p8b中国设计秀
          ///   </summary>  p8b中国设计秀
          ///   <param   name="sourceDirName">源文件夹</param>  p8b中国设计秀
          ///   <param   name="destDirName">目标文件夹</param>  p8b中国设计秀
          //复制文件夹  p8b中国设计秀
        public void CopyDirectory(string sourceDirName, string destDirName)p8b中国设计秀
        {p8b中国设计秀
            if (!Directory.Exists(destDirName))p8b中国设计秀
            {p8b中国设计秀
                Directory.CreateDirectory(destDirName);p8b中国设计秀
                File.SetAttributes(destDirName, File.GetAttributes(sourceDirName));p8b中国设计秀
                //File.SetAttributes(destDirName,FileAttributes.Normal);  p8b中国设计秀
            }p8b中国设计秀
p8b中国设计秀
            if (destDirName[destDirName.Length - 1] != Path.DirectorySeparatorChar)p8b中国设计秀
                destDirName = destDirName + Path.DirectorySeparatorChar;p8b中国设计秀
p8b中国设计秀
            string[] files = Directory.GetFiles(sourceDirName);p8b中国设计秀
            foreach (string file in files)p8b中国设计秀
            {p8b中国设计秀
                File.Copy(file, destDirName + Path.GetFileName(file), true);p8b中国设计秀
                File.SetAttributes(destDirName + Path.GetFileName(file), FileAttributes.Normal);p8b中国设计秀
                total++;p8b中国设计秀
            }p8b中国设计秀
            string[] dirs = Directory.GetDirectories(sourceDirName);p8b中国设计秀
            foreach (string dir in dirs)p8b中国设计秀
            {p8b中国设计秀
                CopyDirectory(dir, destDirName + Path.GetFileName(dir));p8b中国设计秀
            }p8b中国设计秀
        }p8b中国设计秀
     p8b中国设计秀
        public   static   int   GetFilesCount(System.IO.DirectoryInfo   dirInfo)    p8b中国设计秀
        {p8b中国设计秀
              int   totalFile   =   0;    p8b中国设计秀
              totalFile   +=   dirInfo.GetFiles().Length;    p8b中国设计秀
              foreach   (System.IO.DirectoryInfo   subdir   in   dirInfo.GetDirectories())    p8b中国设计秀
              {    p8b中国设计秀
                  totalFile   +=   GetFilesCount(subdir);    p8b中国设计秀
              }    p8b中国设计秀
              return   totalFile;    p8b中国设计秀
        }p8b中国设计秀
    }p8b中国设计秀
}p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
7.ProgressBar和BackgroundWorker显示整个更新版本进度p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
代码 p8b中国设计秀
        // 启动执行p8b中国设计秀
        bkgWorker.RunWorkerAsync();p8b中国设计秀
p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 设置加载时间值p8b中国设计秀
        /// </summary>p8b中国设计秀
        /// <param name="text"></param>p8b中国设计秀
        /// <param name="value"></param>p8b中国设计秀
        private void SetValue(string text, int value)p8b中国设计秀
        {p8b中国设计秀
            // 更新进度p8b中国设计秀
            for (int i = 1; i <= value; i++)p8b中国设计秀
            {p8b中国设计秀
                bkgWorker.ReportProgress(1, text);p8b中国设计秀
                System.Threading.Thread.Sleep(10);p8b中国设计秀
            }p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 执行工作p8b中国设计秀
        /// </summary>p8b中国设计秀
        /// <param name="sender"></param>p8b中国设计秀
        /// <param name="e"></param>p8b中国设计秀
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)p8b中国设计秀
        {p8b中国设计秀
            // 调用更新p8b中国设计秀
            CallUpdate();p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 操作进程p8b中国设计秀
         /// </summary>p8b中国设计秀
        /// <param name="sender"></param>p8b中国设计秀
        /// <param name="e"></param>p8b中国设计秀
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)p8b中国设计秀
        {p8b中国设计秀
            lblMsg.Text = e.UserState.ToString();p8b中国设计秀
            prgUpdate.Value += e.ProgressPercentage;p8b中国设计秀
        }p8b中国设计秀
p8b中国设计秀
        /// <summary>p8b中国设计秀
        /// 调用更新p8b中国设计秀
         /// </summary>p8b中国设计秀
        private void CallUpdate()p8b中国设计秀
        {p8b中国设计秀
            LogHelper.Model.Log modLog = new LogHelper.Model.Log();p8b中国设计秀
p8b中国设计秀
            // 判断是否有新版本p8b中国设计秀
             AutoUpdate autoUpdate = new AutoUpdate();p8b中国设计秀
            CurrentVesionHelper currentVesion = new CurrentVesionHelper();p8b中国设计秀
p8b中国设计秀
            string updatexmlpath = System.Configuration.ConfigurationSettings.AppSettings["updateXmlPath"];p8b中国设计秀
            UpdateXmlHelper updateXml = new UpdateXmlHelper(updatexmlpath);p8b中国设计秀
            string oldVesion = currentVesion.CurrentVesion;p8b中国设计秀
            string newVesion = updateXml.Vesion;p8b中国设计秀
            string newDownURL = updateXml.DownURL;p8b中国设计秀
            bool b = autoUpdate.IsNewVesion(newVesion, oldVesion);p8b中国设计秀
            p8b中国设计秀
            if (b)p8b中国设计秀
            {                p8b中国设计秀
                string filename = newDownURL.Substring(newDownURL.LastIndexOf('/') + 1);p8b中国设计秀
                string savePath = Application.StartupPath + "/update/" + filename;p8b中国设计秀
                SetValue("正在下载新版本……", 10);p8b中国设计秀
                if (autoUpdate.DownNewEdition(newDownURL, savePath))p8b中国设计秀
                {p8b中国设计秀
                    string installDir = currentVesion.InstallDir = Application.StartupPath;p8b中国设计秀
                    string programName = currentVesion.ProgramName;p8b中国设计秀
                   p8b中国设计秀
                    string error = string.Empty;p8b中国设计秀
                    string zipfilepath = savePath;p8b中国设计秀
                    string unzipdir = Application.StartupPath + "update" + DateTime.Now.ToString("yyyy-MM-dd") + "";p8b中国设计秀
                    SetValue("正在解压文件包……", 20);p8b中国设计秀
                    // 解压文件包p8b中国设计秀
                      clsZip zip = new clsZip();p8b中国设计秀
                    zip.UnZipFile(zipfilepath, unzipdir, out error);p8b中国设计秀
                    SetValue("正在关闭程序……", 10);p8b中国设计秀
                    // 关闭程序p8b中国设计秀
                      System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName(programName);p8b中国设计秀
                    foreach (System.Diagnostics.Process p in ps)p8b中国设计秀
                    {p8b中国设计秀
                        p.Kill();p8b中国设计秀
                    }p8b中国设计秀
                    SetValue("正在覆盖原安装程序……", 20);p8b中国设计秀
                    #region 覆盖原安装程序p8b中国设计秀
                       // 休息1秒p8b中国设计秀
                       System.Threading.Thread.Sleep(1000);p8b中国设计秀
                    string installPath = installDir + "" + programName;p8b中国设计秀
                    //if (System.IO.Directory.Exists(installPath))p8b中国设计秀
                    //{p8b中国设计秀
                    //    // 先删除原安装路径p8b中国设计秀
                       //    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(installPath);p8b中国设计秀
                    //     dir.Delete(true);p8b中国设计秀
                    //    //System.IO.Directory.Delete(installPath, true);p8b中国设计秀
                    //}p8b中国设计秀
                    //// 休息3秒p8b中国设计秀
                       //System.Threading.Thread.Sleep(5000);p8b中国设计秀
                    // 再将新版本复制到原安装目录p8b中国设计秀
                       CopyFolder copy = new CopyFolder();p8b中国设计秀
                    copy.CopyDirectory(unzipdir, installDir);p8b中国设计秀
                    //System.IO.Directory.Move(unzipdir, installDir);p8b中国设计秀
p8b中国设计秀
                    #endregionp8b中国设计秀
                    string exepath = "EyesBaby.exe";p8b中国设计秀
                    // 休息3秒p8b中国设计秀
                       System.Threading.Thread.Sleep(3000);p8b中国设计秀
                    string startpath = installPath + "" + exepath;p8b中国设计秀
                    SetValue("记录新版本……", 20);p8b中国设计秀
p8b中国设计秀
                    // 记录新版本到CurrentInfo.configp8b中国设计秀
                    currentVesion.CurrentVesion = newVesion;p8b中国设计秀
                    currentVesion.UpdateDate = DateTime.Now.ToShortDateString();p8b中国设计秀
                    currentVesion.UpdateVesion();p8b中国设计秀
p8b中国设计秀
                    modLog.Content = "更新成功--新版本号:" + newVesion;p8b中国设计秀
                    //MessageBox.Show("更新成功!");p8b中国设计秀
                    SetValue("重启程序……", 20);p8b中国设计秀
                    // 重启程序p8b中国设计秀
                      System.Diagnostics.Process.Start(startpath);p8b中国设计秀
p8b中国设计秀
                }p8b中国设计秀
                elsep8b中国设计秀
                {p8b中国设计秀
                    modLog.Content = "下载最新版本失败";p8b中国设计秀
                    MessageBox.Show("下载最新版本失败!");p8b中国设计秀
                }p8b中国设计秀
            }p8b中国设计秀
            elsep8b中国设计秀
                modLog.Content = "没有发现新版本";p8b中国设计秀
            modLog.Title = "调用更新服务";p8b中国设计秀
            modLog.CreateDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");p8b中国设计秀
            bllLog.Add(modLog);p8b中国设计秀
        }p8b中国设计秀

本文引用地址:/bc/article_46167.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明