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;
|
2024-08-08 11:16:22 +08:00
|
|
|
|
using System.Collections.Generic;
|
2021-07-20 13:37:11 +08:00
|
|
|
|
using System.Configuration;
|
2024-08-08 11:16:22 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2021-07-16 17:34:16 +08:00
|
|
|
|
|
2024-08-08 11:16:22 +08:00
|
|
|
|
namespace GeekDesk.Task
|
2021-07-16 17:34:16 +08:00
|
|
|
|
{
|
2024-08-08 11:16:22 +08:00
|
|
|
|
internal class UpdateTask
|
2021-07-16 17:34:16 +08:00
|
|
|
|
{
|
2024-08-08 11:16:22 +08:00
|
|
|
|
|
2021-07-20 13:37:11 +08:00
|
|
|
|
private static AppConfig appConfig = MainWindow.appData.AppConfig;
|
2024-08-08 11:16:22 +08:00
|
|
|
|
public static void Start()
|
2021-07-16 17:34:16 +08:00
|
|
|
|
{
|
2024-08-08 11:16:22 +08:00
|
|
|
|
System.Timers.Timer timer = new System.Timers.Timer
|
2021-07-20 13:37:11 +08:00
|
|
|
|
{
|
2024-08-08 11:16:22 +08:00
|
|
|
|
Enabled = true,
|
2025-03-10 10:28:11 +08:00
|
|
|
|
Interval = 60 * 1000 * 60 * 12, //60秒 * 60 * 12 12小时触发一次
|
2024-08-08 11:16:22 +08:00
|
|
|
|
//Interval = 6000,
|
2021-07-20 13:37:11 +08:00
|
|
|
|
};
|
2024-08-08 11:16:22 +08:00
|
|
|
|
timer.Start();
|
|
|
|
|
|
timer.Elapsed += Timer_Elapsed; ;
|
2021-07-16 17:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-08 11:16:22 +08:00
|
|
|
|
private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
2021-07-16 17:34:16 +08:00
|
|
|
|
{
|
2021-07-20 13:37:11 +08:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2024-08-08 11:16:22 +08:00
|
|
|
|
string updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
|
2021-07-20 13:37:11 +08:00
|
|
|
|
string nowVersion = ConfigurationManager.AppSettings["Version"];
|
2024-08-08 11:16:22 +08:00
|
|
|
|
if (appConfig != null)
|
2021-07-20 13:37:11 +08:00
|
|
|
|
{
|
2024-08-08 11:16:22 +08:00
|
|
|
|
switch (appConfig.UpdateType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case UpdateType.GitHub:
|
|
|
|
|
|
updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"];
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2021-07-20 13:37:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2023-04-21 18:05:06 +08:00
|
|
|
|
if (jo["statisticUrl"] != null)
|
2023-04-21 14:16:58 +08:00
|
|
|
|
{
|
2023-04-21 18:05:06 +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
|
|
|
|
}
|
2024-08-08 11:16:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception) { }
|
|
|
|
|
|
|
2023-04-21 14:16:58 +08:00
|
|
|
|
|
2023-04-19 22:19:44 +08:00
|
|
|
|
|
2021-07-20 13:37:11 +08:00
|
|
|
|
string onlineVersion = jo["version"].ToString();
|
2021-12-13 10:04:15 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-05-20 15:39:52 +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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|