-
Notifications
You must be signed in to change notification settings - Fork 3
/
AboutForm.cs
156 lines (126 loc) · 5.19 KB
/
AboutForm.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Net.NetworkInformation;
namespace WordAddIn1
{
public partial class AboutForm : Form
{
//全局路径
string latest_info = Ribbon1.latest_info;
string url = Properties.Resources.latest_info_url;
public AboutForm()
{
InitializeComponent();
//version
string mod = "";
#if DEBUG
mod = "DEBUG";
#endif
#if !DEBUG
mod = "RELEASE";
#endif
//label2.Text = "当前版本:" + Properties.Resources.current_ver + "\r\n内部版本:" + Assembly.GetExecutingAssembly().GetName().Version.ToString();
label2.Text = "当前版本:" + Properties.Resources.current_ver + " " + mod;
}
private void AboutForm_Load(object sender, EventArgs e)
{
}
private void help_doc_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start(Ribbon1.readme_path);
}
private void git_web_Click(object sender, EventArgs e)
{
if (GetNetStatus()) System.Diagnostics.Process.Start(Properties.Resources.github_code_url);
else MessageBox.Show("network error");
}
private void check_ver_Click(object sender, EventArgs e)
{
if (GetNetStatus())
{
if (File.Exists(latest_info))
{
File.Delete(latest_info);
}
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Mozilla/4.0 ((compatible; MSIE 8.0; Windows NT 6.1;.NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;)");
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48
| (SecurityProtocolType)192
| (SecurityProtocolType)768
| (SecurityProtocolType)3072;
webClient.DownloadFile(url, latest_info);
JObject js = ImportJSON(latest_info);
Version ver_cur = new Version(Properties.Resources.current_ver);
Version ver_latest = new Version(js["tag_name"].ToString().Substring(1));
if (ver_cur == ver_latest) MessageBox.Show("已是最新版啦!");
if (ver_cur < ver_latest) MessageBox.Show("有新版可用!");
if (ver_cur > ver_latest) MessageBox.Show("你怎么会比网站版本还要新?");
}
else MessageBox.Show("network error");
}
public static JObject ImportJSON(string jsonfile)
{
StreamReader reader = File.OpenText(jsonfile);
JsonTextReader jsonTextReader = new JsonTextReader(reader);
JObject jsonObject = (JObject)JToken.ReadFrom(jsonTextReader);
reader.Close();
return jsonObject;
}
private void download_latest_Click(object sender, EventArgs e)
{
if (GetNetStatus())
{
if (File.Exists(latest_info))
{
File.Delete(latest_info);
}
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Mozilla/4.0 ((compatible; MSIE 8.0; Windows NT 6.1;.NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;)");
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48
| (SecurityProtocolType)192
| (SecurityProtocolType)768
| (SecurityProtocolType)3072;
webClient.DownloadFile(url, latest_info);
JObject js = ImportJSON(latest_info);
//MessageBox.Show(js["assets"][0]["browser_download_url"].ToString());
System.Diagnostics.Process.Start(js["assets"][0]["browser_download_url"].ToString());
}
else MessageBox.Show("network error");
}
bool GetNetStatus()
{
Ping ping = new Ping();
try
{
PingReply pingReply = ping.Send("api.github.com");
if (pingReply.Status == IPStatus.Success)
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("https://github.com/FDscend/bibtex2gbt7714");
}
}
}