資源簡介
客戶端直接鏈接數(shù)據(jù)庫是非常不推薦的方法,除非是自己使用的軟件,該示例僅共參考學(xué)習(xí),請勿用于生產(chǎn)環(huán)境(除非是自己用的軟件)
代碼片段和文件信息
using?System;
using?System.Windows.Forms;
using?System.Threading;
using?System.Diagnostics;
using?System.Net;
using?System.IO;
namespace?AutoUpdater
{
????public?partial?class?AutoUpdater?:?Form
????{
????????private?sysVersion?sysVersion?=?new?sysVersion();
????????public?AutoUpdater(sysVersion?uf)
????????{
????????????InitializeComponent();
????????????sysVersion?=?uf;
????????}
????????private?void?btnOk_Click(object?sender?EventArgs?e)
????????{
????????????this.btnDrop.Enabled?=?false;
????????????this.btnOk.Enabled?=?false;
????????????this.Height?=?282;
????????????Thread?t?=?new?Thread(()?=>
????????????{
????????????????foreach?(var?item?in?sysVersion.sysFile)
????????????????{
????????????????????this.DownloadFile(item?a?=>
????????????????????{
????????????????????????string?version?=?a.NewVersion;
????????????????????});
????????????????}
????????????????//啟動
????????????????Process.Start(sysVersion.ExcuteFileName);
????????????????this.Invoke(new?MethodInvoker(()?=>
????????????????{
????????????????????this.Close();
????????????????}));
????????????});
????????????t.IsBackground?=?true;
????????????t.Start();
????????}
????????private?void?Main_Load(object?sender?EventArgs?e)
????????{
????????????this.txtUpdate.Text?=?sysVersion.UpdateContent;
????????????this.Text?=?sysVersion.ExcuteName?+?“更新程序“;
????????????lbOldVersion.Text?=?sysVersion.OldVersion;
????????????lbNewVersion.Text?=?sysVersion.NewVersion;
????????}
????????private?void?btnDrop_Click(object?sender?EventArgs?e)
????????{
????????????if?(MessageBox.Show(“放棄此次更新,將不能繼續(xù)使用,確定要放棄更新嗎“?“取消更新確定“?MessageBoxButtons.YesNo?MessageBoxIcon.Question)?==?DialogResult.Yes)
????????????????Application.Exit();
????????}
????????///?
????????///?http下載文件
????????///?
????????///?
????????///?
????????public?void?DownloadFile(sysFile?sysFile?Action?action)
????????{
????????????float?percent?=?0;
????????????try
????????????{
????????????????string?fileUrl?=?sysVersion.ServerUrl?+?“/“?+?sysFile.FilePath;
????????????????string?fileName?=?Application.StartupPath?+?“\\“?+?sysFile.FileName;
????????????????HttpWebRequest?Myrq?=?(HttpWebRequest)WebRequest.Create(fileUrl);
????????????????HttpWebResponse?myrp?=?(HttpWebResponse)Myrq.GetResponse();
????????????????long?totalBytes?=?myrp.ContentLength;
????????????????if?(prog?!=?null)
????????????????{
????????????????????this.BeginInvoke(new?MethodInvoker(delegate?()
????????????????????{
????????????????????????prog.Maximum?=?(int)totalBytes;
????????????????????}));
????????????????}
????????????????Stream?st?=?myrp.GetResponseStream();
????????????????Stream?so?=?new?FileStream(fileName?FileMode.Create);
????????????????long?totalDownloadedByte?=?0;
????????????????byte[]?by?=?new?byte[1024];
????????????????int?osize?=?st.Read(by?0?(int)by.Length);
????????????????while?(osize?>?0)
????????????????{
???????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\.vs\
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\.vs\AutoUpdater\
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\.vs\AutoUpdater\v15\
?????文件???????83968??2020-12-07?15:48??AutoUpdater\.vs\AutoUpdater\v15\.suo
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\.vs\AutoUpdater\v15\Server\
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\.vs\AutoUpdater\v15\Server\sqlite3\
?????文件???????????0??2020-12-04?15:56??AutoUpdater\.vs\AutoUpdater\v15\Server\sqlite3\db.lock
?????文件?????1953792??2020-12-07?15:24??AutoUpdater\.vs\AutoUpdater\v15\Server\sqlite3\storage.ide
?????文件???????32768??2020-12-07?09:25??AutoUpdater\.vs\AutoUpdater\v15\Server\sqlite3\storage.ide-shm
?????文件?????4140632??2020-12-07?15:49??AutoUpdater\.vs\AutoUpdater\v15\Server\sqlite3\storage.ide-wal
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\.vs\AutoUpdater\v16\
?????文件???????98304??2020-12-08?21:57??AutoUpdater\.vs\AutoUpdater\v16\.suo
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\.vs\config\
?????文件???????85367??2020-09-28?08:41??AutoUpdater\.vs\config\applicationhost.config
?????文件????????4664??2020-12-07?15:46??AutoUpdater\1.sql
?????文件????????9029??2020-12-07?15:37??AutoUpdater\AutoUpdater.Designer.cs
?????文件????????4003??2020-12-08?21:57??AutoUpdater\AutoUpdater.cs
?????文件????????5784??2020-12-08?21:36??AutoUpdater\AutoUpdater.csproj
?????文件????????1608??2020-12-04?16:13??AutoUpdater\AutoUpdater.csproj.user
?????文件????????7849??2020-12-07?15:35??AutoUpdater\AutoUpdater.resx
?????文件????????1474??2020-12-07?14:13??AutoUpdater\AutoUpdater.sln
?????文件?????????352??2020-12-04?16:19??AutoUpdater\Config.json
?????目錄???????????0??2020-12-08?21:57??AutoUpdater\Lib\
?????文件???????37376??2020-12-08?21:36??AutoUpdater\Lib\AutoUpdater.exe
?????文件?????????411??2020-12-08?21:29??AutoUpdater\Lib\AutoUpdater.exe.config
?????文件???????40448??2020-12-08?21:36??AutoUpdater\Lib\AutoUpdater.pdb
?????文件?????????352??2020-12-04?16:19??AutoUpdater\Lib\Config.json
?????文件??????174080??2020-08-05?05:51??AutoUpdater\Lib\Dos.ORM.dll
?????文件??????276735??2020-08-05?05:51??AutoUpdater\Lib\Dos.ORM.xm
?????文件????????8752??2014-04-01?13:13??AutoUpdater\Main.Designer.cs
............此處省略82個文件信息
評論
共有 條評論