免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
C# 程序自動(dòng)升級(jí)的代碼,C#代碼片段分享,

自動(dòng)更新的軟件的目的在于讓客戶(hù)不在為了尋找最新軟件花費(fèi)時(shí)間。也不用去到開(kāi)發(fā)商的網(wǎng)站上查找??蛻?hù)端的軟件自動(dòng)會(huì)在程序啟動(dòng)前查找服務(wù)器上最新的版本。和自己當(dāng)前軟件的版本比較,如果服務(wù)器的是最新版本。客戶(hù)端則進(jìn)行自動(dòng)下載、解壓、安裝。當(dāng)然了下載是要有網(wǎng)絡(luò)的,并且用戶(hù)可以根據(jù)提示去完成操作。再也不用為找不到最新版本的軟件而頭疼。
轉(zhuǎn)自:http://blog.csdn.net/lybwwp/article/details/8426022

下面是我的大體思路,已經(jīng)得到了實(shí)現(xiàn): 1、  寫(xiě)一個(gè)webservice,提供一個(gè)獲取服務(wù)器xml中版本的數(shù)據(jù)的方法。|
<?xml version="1.0" encoding="utf-8" ?>
<Content>
  <Project id="程序名稱(chēng)" Edition="1.0"> </Project>
</Content>
2、  在WinForm應(yīng)用程序啟動(dòng)的時(shí)候,首先訪問(wèn)webservice獲取服務(wù)器的xml中的版本號(hào),然后獲取客戶(hù)端的xml中的版本號(hào)。將兩個(gè)版本號(hào)比較,若服務(wù)器中的版本號(hào)大,則提示提示可以在線更新應(yīng)用程序。

3、  然后客戶(hù)端自動(dòng)下載網(wǎng)絡(luò)上的zip壓縮包到本機(jī)的指定位置,進(jìn)行自動(dòng)解壓縮到安裝的目錄進(jìn)行覆蓋。解壓縮完畢之后,用進(jìn)程打開(kāi)所解壓過(guò)的exe文件進(jìn)行軟件安裝。同時(shí)關(guān)閉客戶(hù)端軟件所在的進(jìn)程。

4、注意:升級(jí)程序和應(yīng)用程序都是單獨(dú)的,應(yīng)用程序在使用時(shí)不能對(duì)本身進(jìn)行升級(jí)(覆蓋會(huì)失?。?。

具體代碼如下:

第一部分 應(yīng)用程序如口Program:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Medicine_ERP;
using DevExpress.XtraEditors;
using System.Xml;
using Anshield_AutoFutures.BaseClase;
 
namespace Anshield_AutoFutures
{
    static class Program
    {
        private static void LoadMath()
        {
            //服務(wù)器上的版本號(hào)
            string NewEdition = "1.0";
            //應(yīng)用程序中的版本號(hào)
            string OldEdition = "1.0";
 
            try
            {
                //服務(wù)器上的版本號(hào)
                NewEdition = webserverClase.getCopyRightCode();
 
                //獲取系統(tǒng)中xml里面存儲(chǔ)的版本號(hào)              
                String fileName = Application.StartupPath + "\\XMLEdition.xml";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);
                XmlNode xn = xmlDoc.SelectSingleNode("Content");
                XmlNodeList xnl = xn.ChildNodes;
                foreach (XmlNode xnf in xnl)
                {
                    XmlElement xe = (XmlElement)xnf;
                    if (xe.GetAttribute("id") == "jigou_plz")
                    {
                        OldEdition = xe.GetAttribute("Edition");//動(dòng)態(tài)數(shù)組
                    }
                    break;
                }
                double newE = double.Parse(NewEdition);
                double oldE = double.Parse(OldEdition);
                //比較兩個(gè)版本號(hào),判斷應(yīng)用程序是否要更新
                if (newE > oldE)
                {
                    //更新程序¨
                    DialogResult dr = XtraMessageBox.Show("發(fā)現(xiàn)新的版本是否要更新該軟件", "平浪舟現(xiàn)貨程序化交易--更新提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    if (dr == DialogResult.OK)
                    {
                        //打開(kāi)下載窗口
                        // Application.Run(new DownUpdate());
 
                        //啟動(dòng)安裝程序                       
                        System.Diagnostics.Process.Start(Application.StartupPath + @"\Upgrade_Form.exe");
 
                        Application.Exit();
                    }
                    else
                    {
                        //若用戶(hù)取消,打開(kāi)初始界面
                        anshield_Login login = new anshield_Login();
                        if (login.ShowDialog() == DialogResult.OK)
                        {
                            Application.Run(new Main_AutoFutures());
                        }
                    }
                }
                else
                {
                    //若服務(wù)器版本低于或相等客戶(hù)端,打開(kāi)初始界面
                    anshield_Login login = new anshield_Login();
                    if (login.ShowDialog() == DialogResult.OK)
                    {
                        Application.Run(new Main_AutoFutures());
                    }
                }
            }
            catch
            {
                XtraMessageBox.Show("網(wǎng)絡(luò)鏈接失?。?, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
 
            }
        }
 
       
        /// <summary>
        /// 應(yīng)用程序的主入口點(diǎn)。
        /// </summary>
        [STAThread]
        static void Main()
        {
             
            //保證同時(shí)只有一個(gè)客戶(hù)端在運(yùn)行  
            System.Threading.Mutex mutexMyapplication = new System.Threading.Mutex(false, "jigou_plz.exe");
            if (!mutexMyapplication.WaitOne(100, false))
            {
                XtraMessageBox.Show("程序" + Application.ProductName + "已經(jīng)在運(yùn)行!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);             
                return;
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //漢化
                hugengyong hu = new hugengyong();              
                DevExpress.UserSkins.OfficeSkins.Register();
                DevExpress.Skins.SkinManager.EnableFormSkins();
                DevExpress.UserSkins.BonusSkins.Register();
 
                LoadMath();
                }
        }
    }
}
  
 
  
 
 
//該代碼片段來(lái)自于: http://www.sharejs.com/codes/csharp/6043
 第二部分:升級(jí)程序代碼如下:
  //debug目錄,用于存放壓縮文件
        string path = Application.StartupPath;
 
 private void btnDown_Click(object sender, EventArgs e)
        {
            string zipFile = path + @"\jigou_plz.zip";
            //關(guān)閉原有的應(yīng)用程序 
            killProess();
             
            btnDown.Enabled = false;
            button2.Enabled = false;
            //自動(dòng)下載壓縮包,并且解壓,最后關(guān)閉當(dāng)前進(jìn)程,進(jìn)行安裝
            try
            {
                //下載自動(dòng)更新
                string downUrl = ConfigurationManager.ConnectionStrings["DownUrl"].ConnectionString.ToString().Trim();
                if (!string.IsNullOrEmpty(downUrl))
                {
                    DownloadFile(downUrl, zipFile, progressBar1, label1);
                }
                else
                {
                    MessageBox.Show("Config中的下載路徑配置錯(cuò)誤!", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            catch
            {
                MessageBox.Show("當(dāng)前沒(méi)有網(wǎng)絡(luò)或者文件地址不正確");
                return;
            }         
            //解a壓1
            try
            {
                //關(guān)閉原有的應(yīng)用程序 
                killProess();
                //unCompressRAR(path, path, "setup.rar", true);
                BaseClase.Zip.UnZip(zipFile, path, "", true,true);
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            if (MessageBox.Show("升級(jí)完成!,請(qǐng)重新登陸!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
            {
                FileInfo file = new FileInfo(path + @"\Anshield_AutoFutures.exe");//文件地址
                if (file.Exists)
                {
                    Process.Start(path + @"\Anshield_AutoFutures.exe");
                }            
                Application.Exit();
            }
            
        }
        /// <summary>       
        /// c#.net 下載文件       
        /// </summary>       
        /// <param name="URL">下載文件地址</param>      
        ///
        /// <param name="Filename">下載后的存放地址</param>       
        /// <param name="Prog">用于顯示的進(jìn)度條</param>       
        ///
        public void DownloadFile(string URL, string filename, System.Windows.Forms.ProgressBar prog, System.Windows.Forms.Label label1)
        {
            float percent = 0;
            try
            {
                System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
                System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
                long totalBytes = myrp.ContentLength;
                if (prog != null)
                {
                    prog.Maximum = (int)totalBytes;
                }
                System.IO.Stream st = myrp.GetResponseStream();
                System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
                long totalDownloadedByte = 0;
                byte[] by = new byte[1024];
                int osize = st.Read(by, 0, (int)by.Length);
                while (osize > 0)
                {
                    totalDownloadedByte = osize + totalDownloadedByte;
                    System.Windows.Forms.Application.DoEvents();
                    so.Write(by, 0, osize);
                    if (prog != null)
                    {
                        prog.Value = (int)totalDownloadedByte;
                    }
                    osize = st.Read(by, 0, (int)by.Length);
 
                    percent = (float)totalDownloadedByte / (float)totalBytes * 100;
                    label1.Text = "下載進(jìn)度" + percent.ToString() + "%";
                    System.Windows.Forms.Application.DoEvents(); //必須加注這句代碼,否則label1將因?yàn)檠h(huán)執(zhí)行太快而來(lái)不及顯示信息
                }
                label1.Text = "下載完成。安裝中... ...";
                so.Flush();//將緩沖區(qū)內(nèi)在寫(xiě)入到基礎(chǔ)流中
                st.Flush();//將緩沖區(qū)內(nèi)在寫(xiě)入到基礎(chǔ)流中
                so.Close();
                st.Close();
            }
            catch (System.Exception)
            {
                throw;
            }
        }
 
  
 
 /// <summary>
        /// 關(guān)閉原有的應(yīng)用程序
        /// </summary>
        private void killProess()
        {
            this.label1.Text = "正在關(guān)閉程序....";
            System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("Anshield_AutoFutures");
            //關(guān)閉原有應(yīng)用程序的所有進(jìn)程
            foreach (System.Diagnostics.Process pro in proc)
            {
                pro.Kill();
            }
        }
 
  
 
 
//該代碼片段來(lái)自于: http://www.sharejs.com/codes/csharp/6043
zip壓縮文件解壓方法類(lèi)
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;
using ICSharpCode.SharpZipLib.Zip;
 
namespace Upgrade_Form.BaseClase
{
    class Zip
    {
      
        /// <summary>
        /// 解壓縮一個(gè) zip 文件。
        /// </summary>
        /// <param name="zipedFile">zip文件路徑</param>
        /// <param name="strDirectory">解壓路徑</param>
        /// <param name="password">zip文件的密碼</param>
        /// <param name="overWrite">是否覆蓋已存在的文件。</param>
        /// <param name="delteFile">解壓后是否刪除文件</param>
        public static void UnZip(string zipedFile, string strDirectory, string password, bool overWrite,bool delteFile)
        {
            //路徑不存在則創(chuàng)建
            if (Directory.Exists(strDirectory) == false)
            {
                Directory.CreateDirectory(strDirectory);
            }
            if (strDirectory == "")
                strDirectory = Directory.GetCurrentDirectory();
            if (!strDirectory.EndsWith("\\"))
                strDirectory = strDirectory + "\\";
 
            using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipedFile)))
            {
                s.Password = password;
                ZipEntry theEntry;
 
                while ((theEntry = s.GetNextEntry()) != null)
                {
                    string directoryName = "";
                    string pathToZip = "";
                    pathToZip = theEntry.Name;
 
                    if (pathToZip != "")
                        directoryName = Path.GetDirectoryName(pathToZip) + "\\";
 
                    string fileName = Path.GetFileName(pathToZip);
 
                    Directory.CreateDirectory(strDirectory + directoryName);
 
                    if (fileName != "")
                    {
                        if ((File.Exists(strDirectory + directoryName + fileName) && overWrite) || (!File.Exists(strDirectory + directoryName + fileName)))
                        {
                            using (FileStream streamWriter = File.Create(strDirectory + directoryName + fileName))
                            {
                                int size = 2048;
                                byte[] data = new byte[2048];
                                while (true)
                                {
                                    size = s.Read(data, 0, data.Length);
 
                                    if (size > 0)
                                        streamWriter.Write(data, 0, size);
                                    else
                                        break;
                                }
                                streamWriter.Close();
                            }
                        }
                    }
                }
 
                s.Close();
            }
            if (delteFile == true)
            {
                File.Delete(zipedFile);
            }
        }
 
    }
}
//該代碼片段來(lái)自于: http://www.sharejs.com/codes/csharp/6043

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
C#使用ICSharpCode.SharpZipLib.dll壓縮文件夾和文件
Web Services制作智能升級(jí)程序
如何在asp.net中如何在線播放視頻文件
C# 將數(shù)據(jù)導(dǎo)出到Excel匯總
C#獲取文件名稱(chēng)、路徑、后綴名
使用npoi做excel導(dǎo)出真心方便
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服