資源簡介
實現c#開發的winform程序根據程序版本號是否需要更新程序,啟動更新程序從服務器下載新版本程序并解壓覆蓋主程序,運行主程序。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Runtime.InteropServices;
using?System.IO;
using?COMMON;
using?Update;
namespace?autoUpdate
{
????public?partial?class?Form1?:?Form
????{
????????[DllImport(“zipfile.dll“)]
????????public?static?extern?int?MyZip_ExtractFileAll(string?zipfile?string?pathname);
????????public?Form1()
????????{
????????????InitializeComponent();
????????????//清除之前下載來的rar文件
????????????if?(File.Exists(Application.StartupPath?+?“\\Update_autoUpdate.zip“))
????????????{
????????????????try
????????????????{
????????????????????File.Delete(Application.StartupPath?+?“\\Update_autoUpdate.zip“);
????????????????}
????????????????catch?(Exception)
????????????????{
????????????????}
????????????}
????????????if?(Directory.Exists(Application.StartupPath?+?“\\autoupload“))
????????????{
????????????????try
????????????????{
????????????????????Directory.Delete(Application.StartupPath?+?“\\autoupload“?true);
????????????????}
????????????????catch?(Exception)
????????????????{
????????????????}
????????????}
????????????//檢查服務端是否有新版本程序
????????????checkUpdate();
????????????timer1.Enabled?=?true;
????????}
????????SoftUpdate?app?=?new?SoftUpdate(Application.ExecutablePath?“ExceTransforCsv“);
????????public?void?checkUpdate()
????????{
????????????app.UpdateFinish?+=?new?UpdateState(app_UpdateFinish);
????????????try
????????????{
????????????????if?(app.IsUpdate)
????????????????{
????????????????????app.Update();
????????????????}
????????????????else
????????????????{
????????????????????MessageBox.Show(“未檢測到新版本!“);
????????????????????Application.Exit();
????????????????}
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????MessageBox.Show(ex.Message);
????????????}
????????}
????????void?app_UpdateFinish()
????????{
????????????//解壓下載后的文件
????????????string?path?=?app.FinalZipName;
????????????if?(File.Exists(path))
????????????{
????????????????//后改的?先解壓濾波zip植入ini然后再重新壓縮
????????????????string?dirEcgPath?=?Application.StartupPath?+?“\\“?+?“autoupload“;
????????????????if?(!Directory.Exists(dirEcgPath))
????????????????{
????????????????????Directory.CreateDirectory(dirEcgPath);
????????????????}
????????????????//開始解壓壓縮包
????????????????MyZip_ExtractFileAll(path?dirEcgPath);
????????????????try
????????????????{
????????????????????//復制新文件替換舊文件
????????????????????DirectoryInfo?TheFolder?=?new?DirectoryInfo(dirEcgPath);
????????????????????foreach?(FileInfo?NextFile?in?TheFolder.GetFiles())
????????????????????{
????????????????????????File.Copy(NextFile.FullName?Application.StartupPath?+?“\\program\\“?+?NextFile.Name?true);
????????????????????}
????????????????????Directory.Delete(dirEcgPath?true);
????????????????????File.Delete(path);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4096??2018-12-17?10:20??COMMON\bin\Debug\COMMON.dll
?????文件???????7680??2018-12-17?10:20??COMMON\bin\Debug\COMMON.pdb
?????文件???????2306??2018-07-17?16:53??COMMON\COMMON.csproj
?????文件????????201??2018-07-17?16:45??COMMON\CommonMethod.cs
?????文件????????456??2018-12-17?10:20??COMMON\obj\Debug\COMMON.csproj.FileListAbsolute.txt
?????文件???????4096??2018-12-17?10:20??COMMON\obj\Debug\COMMON.dll
?????文件???????7680??2018-12-17?10:20??COMMON\obj\Debug\COMMON.pdb
?????文件???????5674??2018-12-26?14:43??COMMON\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1344??2018-07-17?16:44??COMMON\Properties\AssemblyInfo.cs
?????文件???????4096??2018-12-17?10:20??ExceTransforCsv\bin\Debug\COMMON.dll
?????文件???????7680??2018-12-17?10:20??ExceTransforCsv\bin\Debug\COMMON.pdb
?????文件??????17408??2018-12-18?15:25??ExceTransforCsv\bin\Debug\ExceTransforCsv.exe
?????文件??????40448??2018-12-18?15:25??ExceTransforCsv\bin\Debug\ExceTransforCsv.pdb
?????文件??????11600??2018-12-26?14:43??ExceTransforCsv\bin\Debug\ExceTransforCsv.vshost.exe
?????文件????????490??2018-04-12?07:35??ExceTransforCsv\bin\Debug\ExceTransforCsv.vshost.exe.manifest
?????文件?????200704??2017-04-30?14:19??ExceTransforCsv\bin\Debug\ICSharpCode.SharpZipLib.dll
?????文件????1624064??2013-03-06?07:17??ExceTransforCsv\bin\Debug\NPOI.dll
?????文件?????387072??2013-03-06?07:17??ExceTransforCsv\bin\Debug\NPOI.OOxm
?????文件??????79872??2013-03-06?07:17??ExceTransforCsv\bin\Debug\NPOI.Openxm
?????文件????1316864??2013-03-06?07:17??ExceTransforCsv\bin\Debug\NPOI.Openxm
?????文件????2145032??2013-03-06?07:13??ExceTransforCsv\bin\Debug\NPOI.xm
?????文件???????8192??2018-12-17?10:20??ExceTransforCsv\bin\Debug\Update.dll
?????文件??????19968??2018-12-17?10:20??ExceTransforCsv\bin\Debug\Update.pdb
?????文件??????10240??2018-07-17?16:53??ExceTransforCsv\bin\Debug\程序運行順序\autoUpdate.exe
?????文件??????22016??2018-07-17?16:53??ExceTransforCsv\bin\Debug\程序運行順序\autoUpdate.pdb
?????文件??????11600??2018-07-17?16:41??ExceTransforCsv\bin\Debug\程序運行順序\autoUpdate.vshost.exe
?????文件????????490??2018-04-12?07:35??ExceTransforCsv\bin\Debug\程序運行順序\autoUpdate.vshost.exe.manifest
?????文件???????4096??2018-07-17?16:53??ExceTransforCsv\bin\Debug\程序運行順序\COMMON.dll
?????文件???????7680??2018-07-17?16:53??ExceTransforCsv\bin\Debug\程序運行順序\COMMON.pdb
?????文件???????4096??2018-07-17?16:53??ExceTransforCsv\bin\Debug\程序運行順序\program\COMMON.dll
............此處省略116個文件信息
評論
共有 條評論