-
Notifications
You must be signed in to change notification settings - Fork 205
/
UpdateThread.cs
64 lines (62 loc) · 1.99 KB
/
UpdateThread.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using GeekDesk.Constant;
using GeekDesk.Control.Windows;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
namespace GeekDesk.Thread
{
public class UpdateThread
{
private static AppConfig appConfig = MainWindow.appData.AppConfig;
public static void Update()
{
System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(UpdateApp))
{
IsBackground = true
};
t.Start();
}
private static void UpdateApp()
{
try
{
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);
string onlineVersion = jo["version"].ToString();
if (onlineVersion.CompareTo(nowVersion) > 0)
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
//检测到版本更新
UpdateWindow.Show(jo);
}));
}
}
} catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
}
}