Commit 78db6e2a authored by 段廷瑞's avatar 段廷瑞

1、自动更新:逻辑优化

parent a5c81d7c
...@@ -144,4 +144,10 @@ ...@@ -144,4 +144,10 @@
<UserId>sa</UserId> <UserId>sa</UserId>
<Pwd>sa</Pwd> <Pwd>sa</Pwd>
</links> </links>
<links>
<Link>119.190.10.248,1800</Link>
<DbName>FTT_U6</DbName>
<UserId>sa</UserId>
<Pwd>a*1</Pwd>
</links>
</DocumentElement> </DocumentElement>
\ No newline at end of file
...@@ -62,6 +62,7 @@ namespace AutoUpdate ...@@ -62,6 +62,7 @@ namespace AutoUpdate
ProcessStartInfo info = new ProcessStartInfo() ProcessStartInfo info = new ProcessStartInfo()
{ {
FileName = startup, FileName = startup,
Arguments = "1",
UseShellExecute = false, UseShellExecute = false,
RedirectStandardError = true, RedirectStandardError = true,
}; };
......
...@@ -16,14 +16,16 @@ namespace Tools ...@@ -16,14 +16,16 @@ namespace Tools
/// 应用程序的主入口点。 /// 应用程序的主入口点。
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() static void Main(string[] args)
{ {
Application.ThreadException += Application_ThreadException; Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new wMain());
bool isUpdated = args.Length > 0 && args[0] == "1";
Application.Run(new wMain(isUpdated));
} }
//UI未处理异常 //UI未处理异常
......
...@@ -32,14 +32,20 @@ namespace Tools ...@@ -32,14 +32,20 @@ namespace Tools
/// 数据库访问对象 /// 数据库访问对象
/// </summary> /// </summary>
DBHelper _db = null; DBHelper _db = null;
/// <summary>
/// 是否更新后启动
/// </summary>
bool IsUpdated = false;
public wMain() public wMain(bool isUpdated)
{ {
InitializeComponent(); InitializeComponent();
//基础属性设置 //基础属性设置
this.IsMdiContainer = true; this.IsMdiContainer = true;
//重置窗体大小 //重置窗体大小
this.SetWinMinimized(); this.SetWinMinimized();
//
this.IsUpdated = isUpdated;
//窗体基本事件 //窗体基本事件
this.Load += WMain_Load; this.Load += WMain_Load;
this.Shown += WMain_Shown; this.Shown += WMain_Shown;
...@@ -263,6 +269,14 @@ namespace Tools ...@@ -263,6 +269,14 @@ namespace Tools
private void CheckUpdate(bool IsSilentWhenNotFound = false) private void CheckUpdate(bool IsSilentWhenNotFound = false)
{ {
var m = Utils.GetJsonConfig<LoginMemory>(); var m = Utils.GetJsonConfig<LoginMemory>();
//更新后打开,记录更新日期,并返回
if (IsUpdated)
{
m.UpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
Utils.SaveJsonConfig(m);
return;
}
//检查更新
var updateTime = m.UpdateTime; var updateTime = m.UpdateTime;
var dt =this._db.GetDataTable($"SELECT TOP 1 UDate, URemark FROM dbo.FTT_AutoUpdate WHERE UDate > '{updateTime}' ORDER BY UDate DESC", "FTT_AutoUpdate"); var dt =this._db.GetDataTable($"SELECT TOP 1 UDate, URemark FROM dbo.FTT_AutoUpdate WHERE UDate > '{updateTime}' ORDER BY UDate DESC", "FTT_AutoUpdate");
if (dt.DefaultView.Count > 0) if (dt.DefaultView.Count > 0)
...@@ -279,19 +293,7 @@ namespace Tools ...@@ -279,19 +293,7 @@ namespace Tools
RedirectStandardError = true, RedirectStandardError = true,
}; };
//启动更新程序 //启动更新程序
Task.Run(() => new Process() { StartInfo = info }.Start()) Task.Run(() => new Process() { StartInfo = info }.Start());
.ContinueWith((x) => {
if (x.IsCompleted && x.Exception == null)
{
var date = Convert.ToDateTime(drv["UDate"]);
m.UpdateTime = date.ToString("yyyy-MM-dd HH:mm:ss.fff");
Utils.SaveJsonConfig(m);
}
else
{
Utils.Tip(x.Exception.Message);
}
});
//退出运行环境 //退出运行环境
Application.Exit(); Application.Exit();
} }
......
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