Commit 988d4a63 authored by 罗显健's avatar 罗显健

1.更新器用系统默认应用打开sql文件。2.工具升级程序更新进度信息调整

parent 29829eb5
using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Zip;
using System; using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data; using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.IO; using System.IO;
using System.Linq;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
...@@ -72,8 +67,8 @@ namespace AutoUpdate ...@@ -72,8 +67,8 @@ namespace AutoUpdate
private void AppUpdate() private void AppUpdate()
{ {
string link = this.GetDbLinkString204("FTT_Work"); var dt = GetPackageData();
DataTable dt = this.GetDataTable(link, "SELECT TOP 1 * FROM dbo.FTT_AutoUpdate ORDER BY UDate DESC", "FTT_AutoUpdate"); this.AddProcessText(80);
if (dt.DefaultView.Count > 0) if (dt.DefaultView.Count > 0)
{ {
//结束原进程 //结束原进程
...@@ -85,30 +80,68 @@ namespace AutoUpdate ...@@ -85,30 +80,68 @@ namespace AutoUpdate
p.Kill(); p.Kill();
} }
} }
this.AddProcessText(10); this.AddProcessText(80);
//获取更新数据 //获取更新数据
var drv = dt.DefaultView[0]; var drv = dt.DefaultView[0];
var fileName = drv["UName"].ToString(); var fileName = drv["UName"].ToString();
var bytes = drv["UData"] as byte[]; var bytes = drv["UData"] as byte[];
//默认解压覆盖指定目录 //默认解压覆盖指定目录
var fileFullName = $@"{this._path}\{fileName}"; var fileFullName = $@"{this._path}\{fileName}";
this.AddProcessText(30); this.AddProcessText(85);
//创建本地更新包 //创建本地更新包
File.WriteAllBytes(fileFullName, bytes); File.WriteAllBytes(fileFullName, bytes);
this.AddProcessText(60); this.AddProcessText(90);
//解压更新包到指定目录 //解压更新包到指定目录
this.ZipDecompress(fileFullName, this._path); this.ZipDecompress(fileFullName, this._path);
this.AddProcessText(90); this.AddProcessText(95);
//删除更新包 //删除更新包
File.Delete(fileFullName); File.Delete(fileFullName);
this.AddProcessText(100); this.AddProcessText(100);
} }
} }
private DataTable GetPackageData()
{
string link = this.GetDbLinkString204("FTT_Work");
var task = Task.Run(() =>
{
return this.GetDataTable(link, "SELECT TOP 1 * FROM dbo.FTT_AutoUpdate ORDER BY UDate DESC", "FTT_AutoUpdate");
});
var progress = 0;
while (!task.IsCompleted)
{
Thread.Sleep(100);
Application.DoEvents();
AddProcessText("正在下载更新包", progress++ / 10, true, 79);
}
return task.Result;
}
private void AddProcessText(int value) private void AddProcessText(int value)
{ {
this.textBox1.Text += $"进度完成{value}%\r\n"; textBox1.Invoke(new MethodInvoker(() =>
{
textBox1.Text += $"进度完成{value}%\r\n";
}));
} }
private void AddProcessText(string processText, int value, bool isClearn = false, int maxValue = 100)
{
if (value >= maxValue) value = maxValue;
if (processText == null) processText = "进度完成";
textBox1.Invoke(new MethodInvoker(() =>
{
if (isClearn) textBox1.Text = "";
textBox1.Text += $"{processText}{value}%\r\n";
}));
}
#region 工具方法 #region 工具方法
/// <summary> /// <summary>
......
...@@ -10,7 +10,7 @@ using System.Runtime.InteropServices; ...@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FTT-Tools")] [assembly: AssemblyProduct("FTT-Tools")]
[assembly: AssemblyCopyright("Copyright © 2020")] [assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
...@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; ...@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示: //通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>false</Deterministic>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp> <NuGetPackageImportStamp>
</NuGetPackageImportStamp> </NuGetPackageImportStamp>
......
...@@ -219,7 +219,8 @@ namespace UpdateExecuter ...@@ -219,7 +219,8 @@ namespace UpdateExecuter
var fileFullName = (listViewMsg.SelectedItems[0] as ListViewItem).SubItems[2].Text; var fileFullName = (listViewMsg.SelectedItems[0] as ListViewItem).SubItems[2].Text;
if (!string.IsNullOrEmpty(fileFullName)) Process.Start("notepad.exe", fileFullName); //以操作系统默认应用打开文件。
if (!string.IsNullOrEmpty(fileFullName)) Process.Start(fileFullName);
} }
/// <summary> /// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment