Files
GeekDesk/MyThread/UpdateThread.cs

88 lines
2.8 KiB
C#
Raw Normal View History

2021-07-20 13:37:11 +08:00
using GeekDesk.Constant;
2021-07-20 17:30:12 +08:00
using GeekDesk.Control.Windows;
2021-07-20 13:37:11 +08:00
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Newtonsoft.Json.Linq;
using System;
using System.Configuration;
2021-07-16 17:34:16 +08:00
using System.Threading;
2022-03-25 16:23:14 +08:00
namespace GeekDesk.MyThread
2021-07-16 17:34:16 +08:00
{
public class UpdateThread
{
2021-07-20 13:37:11 +08:00
private static AppConfig appConfig = MainWindow.appData.AppConfig;
2021-07-16 17:34:16 +08:00
public static void Update()
{
2021-07-20 13:37:11 +08:00
System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(UpdateApp))
{
IsBackground = true
};
2021-07-16 17:34:16 +08:00
t.Start();
}
2021-07-20 13:37:11 +08:00
private static void UpdateApp()
2021-07-16 17:34:16 +08:00
{
2021-07-20 13:37:11 +08:00
try
{
2021-07-29 17:09:25 +08:00
//等待1分钟后再检查更新 有的网络连接过慢
2022-05-25 16:45:47 +08:00
int sleepTime = 60 * 1000;
if (Constants.DEV)
{
sleepTime = 1;
}
System.Threading.Thread.Sleep(sleepTime);
2021-07-29 17:09:25 +08:00
2021-07-20 13:37:11 +08:00
string updateUrl;
string nowVersion = ConfigurationManager.AppSettings["Version"];
switch (appConfig.UpdateType)
{
case UpdateType.GitHub:
updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"];
break;
default:
updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
break;
}
string updateInfo = HttpUtil.Get(updateUrl);
if (!StringUtil.IsEmpty(updateInfo))
{
JObject jo = JObject.Parse(updateInfo);
2023-04-19 22:19:44 +08:00
2023-04-21 14:16:58 +08:00
try
2023-04-19 22:19:44 +08:00
{
if (jo["statisticUrl"] != null)
2023-04-21 14:16:58 +08:00
{
string statisticUrl = jo["statisticUrl"].ToString();
if (!string.IsNullOrEmpty(statisticUrl))
{
//用户统计 只通过uuid统计用户数量 不收集任何信息
statisticUrl += "?uuid=" + CommonCode.GetUniqueUUID();
HttpUtil.Get(statisticUrl);
}
2023-04-21 14:16:58 +08:00
}
} catch (Exception){}
2023-04-19 22:19:44 +08:00
2021-07-20 13:37:11 +08:00
string onlineVersion = jo["version"].ToString();
if (onlineVersion.CompareTo(nowVersion) > 0)
2021-07-20 13:37:11 +08:00
{
2021-07-20 17:30:12 +08:00
App.Current.Dispatcher.Invoke((Action)(() =>
{
//检测到版本更新
UpdateWindow.Show(jo);
}));
2021-07-20 13:37:11 +08:00
}
}
}
catch (Exception ex)
2021-07-20 13:37:11 +08:00
{
2022-01-09 17:36:15 +08:00
LogUtil.WriteErrorLog(ex, "获取更新失败!");
2021-07-20 13:37:11 +08:00
}
2021-07-16 17:34:16 +08:00
}
}
}