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

1、自动更新:逻辑优化

parent a5c81d7c
......@@ -144,4 +144,10 @@
<UserId>sa</UserId>
<Pwd>sa</Pwd>
</links>
<links>
<Link>119.190.10.248,1800</Link>
<DbName>FTT_U6</DbName>
<UserId>sa</UserId>
<Pwd>a*1</Pwd>
</links>
</DocumentElement>
\ No newline at end of file
......@@ -62,6 +62,7 @@ namespace AutoUpdate
ProcessStartInfo info = new ProcessStartInfo()
{
FileName = startup,
Arguments = "1",
UseShellExecute = false,
RedirectStandardError = true,
};
......
......@@ -16,14 +16,16 @@ namespace Tools
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
static void Main(string[] args)
{
Application.ThreadException += Application_ThreadException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new wMain());
bool isUpdated = args.Length > 0 && args[0] == "1";
Application.Run(new wMain(isUpdated));
}
//UI未处理异常
......
......@@ -32,14 +32,20 @@ namespace Tools
/// 数据库访问对象
/// </summary>
DBHelper _db = null;
/// <summary>
/// 是否更新后启动
/// </summary>
bool IsUpdated = false;
public wMain()
public wMain(bool isUpdated)
{
InitializeComponent();
//基础属性设置
this.IsMdiContainer = true;
//重置窗体大小
this.SetWinMinimized();
//
this.IsUpdated = isUpdated;
//窗体基本事件
this.Load += WMain_Load;
this.Shown += WMain_Shown;
......@@ -263,6 +269,14 @@ namespace Tools
private void CheckUpdate(bool IsSilentWhenNotFound = false)
{
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 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)
......@@ -279,19 +293,7 @@ namespace Tools
RedirectStandardError = true,
};
//启动更新程序
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);
}
});
Task.Run(() => new Process() { StartInfo = info }.Start());
//退出运行环境
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