1
1
using System ;
2
+ using System . ComponentModel ;
2
3
using System . Diagnostics ;
3
4
using System . Drawing ;
5
+ using System . IO ;
6
+ using System . Net ;
4
7
using System . Reflection ;
5
8
using System . Windows . Forms ;
6
9
@@ -13,6 +16,18 @@ public partial class AboutForm:Form
13
16
{
14
17
// Переменные
15
18
private string projectLink , updatesLink , userManualLink ;
19
+ private SupportedLanguages al ;
20
+ private string updatesMessage = "" ;
21
+
22
+ /// <summary>
23
+ /// Основная Git-ссылка
24
+ /// </summary>
25
+ public const string DefaultGitLink = "https://github.com/adslbarxatov/" ;
26
+
27
+ /// <summary>
28
+ /// Часть ссылки на раздел Git-обновлений
29
+ /// </summary>
30
+ public const string GitUpdatesSublink = "/releases" ;
16
31
17
32
/// <summary>
18
33
/// Конструктор. Запускает форму
@@ -25,35 +40,53 @@ public partial class AboutForm:Form
25
40
/// кнопка отключается, если это значение не задано</param>
26
41
/// <param name="UserManualLink">Ссылка на страницу руководства пользователя;
27
42
/// кнопка отключается, если это значение не задано</param>
28
- public AboutForm ( SupportedLanguages InterfaceLanguage ,
29
- string ProjectLink , string UpdatesLink , string UserManualLink ,
30
- string Description )
43
+ public AboutForm ( SupportedLanguages InterfaceLanguage , string ProjectLink ,
44
+ string UpdatesLink , string UserManualLink , string Description )
31
45
{
32
46
// Инициализация
33
47
InitializeComponent ( ) ;
48
+ al = InterfaceLanguage ;
34
49
35
50
// Настройка контролов
36
- switch ( InterfaceLanguage )
51
+ switch ( al )
37
52
{
38
53
case SupportedLanguages . ru_ru :
39
- UserManualButton . Text = "Руководство пользователя" ;
40
- ProjectPageButton . Text = "Веб-страница проекта" ;
41
- UpdatesPageButton . Text = "Веб-страница обновлений" ;
54
+ UserManualButton . Text = "Руководство" ;
55
+ ProjectPageButton . Text = "О проекте" ;
56
+ UpdatesPageButton . Text = "Обновления" ;
57
+ ADPButton . Text = "Политика и EULA" ;
58
+ AvailableUpdatesLabel . Text = "проверяются..." ;
59
+
42
60
this . Text = "О программе" ;
43
61
break ;
44
62
45
63
default : // en_us
46
64
UserManualButton . Text = "User manual" ;
47
65
ProjectPageButton . Text = "Project webpage" ;
48
66
UpdatesPageButton . Text = "Updates webpage" ;
67
+ ADPButton . Text = "Policy and EULA" ;
68
+ AvailableUpdatesLabel . Text = "checking..." ;
69
+
49
70
this . Text = "About application" ;
50
71
break ;
51
72
}
52
73
53
74
// Получение параметров
54
75
userManualLink = ( ( UserManualLink == null ) ? "" : UserManualLink ) ;
55
- projectLink = ( ( ProjectLink == null ) ? "" : ProjectLink ) ;
56
- updatesLink = ( ( UpdatesLink == null ) ? "" : UpdatesLink ) ;
76
+
77
+ if ( ProjectLink == null )
78
+ projectLink = "" ;
79
+ else if ( ProjectLink == "*" )
80
+ projectLink = DefaultGitLink + ProgramDescription . AssemblyMainName ;
81
+ else
82
+ projectLink = ProjectLink ;
83
+
84
+ if ( UpdatesLink == null )
85
+ updatesLink = "" ;
86
+ else if ( UpdatesLink == "*" )
87
+ updatesLink = DefaultGitLink + ProgramDescription . AssemblyMainName + GitUpdatesSublink ;
88
+ else
89
+ updatesLink = UpdatesLink ;
57
90
58
91
DescriptionBox . Text = ( ( Description == null ) ? "" : Description ) ;
59
92
@@ -70,19 +103,26 @@ public AboutForm (SupportedLanguages InterfaceLanguage,
70
103
ProjectPageButton . Enabled = ( projectLink != "" ) ;
71
104
UpdatesPageButton . Enabled = ( updatesLink != "" ) ;
72
105
106
+ // Запуск проверки обновлений
107
+ HardWorkExecutor hwe = new HardWorkExecutor ( UpdatesChecker , null , "" ) ;
108
+ UpdatesTimer . Enabled = true ;
109
+
73
110
// Запуск
74
111
this . ShowDialog ( ) ;
75
112
}
76
113
77
114
/// <summary>
78
115
/// Конструктор. Открывает указанную ссылку без запуска формы
79
116
/// </summary>
80
- /// <param name="Link">Ссылка для отображения</param>
117
+ /// <param name="Link">Ссылка для отображения (если null, запускается стандартная) </param>
81
118
public AboutForm ( string Link )
82
119
{
83
120
try
84
121
{
85
- Process . Start ( Link ) ;
122
+ if ( Link == null )
123
+ Process . Start ( DefaultGitLink + ProgramDescription . AssemblyMainName + GitUpdatesSublink ) ;
124
+ else
125
+ Process . Start ( Link ) ;
86
126
}
87
127
catch
88
128
{
@@ -137,5 +177,126 @@ private void UpdatesPageButton_Click (object sender, EventArgs e)
137
177
{
138
178
}
139
179
}
180
+
181
+ private void ADP_Click ( object sender , EventArgs e )
182
+ {
183
+ try
184
+ {
185
+ Process . Start ( "https://vk.com/@rdaaow_fupl-adp" ) ;
186
+ }
187
+ catch
188
+ {
189
+ }
190
+ }
191
+
192
+ // Метод-исполнитель проверки обновлений
193
+ private void UpdatesChecker ( object sender , DoWorkEventArgs e )
194
+ {
195
+ // Настройка безопасности соединения
196
+ ServicePointManager . SecurityProtocol = ( SecurityProtocolType ) 0xFC0 ;
197
+ // Принудительно открывает TLS1.0, TLS1.1 и TLS1.2; блокирует SSL3
198
+
199
+ // Запрос обновлений пакета
200
+ HttpWebRequest rq = ( HttpWebRequest ) WebRequest . Create ( projectLink ) ;
201
+ rq . Method = "GET" ;
202
+ rq . KeepAlive = false ;
203
+ rq . Timeout = 10000 ;
204
+
205
+ // Отправка запроса
206
+ HttpWebResponse resp = null ;
207
+ string html = "" ;
208
+ try
209
+ {
210
+ resp = ( HttpWebResponse ) rq . GetResponse ( ) ;
211
+ }
212
+ catch
213
+ {
214
+ goto htmlError ;
215
+ }
216
+
217
+ // Чтение ответа
218
+ StreamReader SR = new StreamReader ( resp . GetResponseStream ( ) ) ;
219
+ html = SR . ReadToEnd ( ) ;
220
+ SR . Close ( ) ;
221
+ resp . Close ( ) ;
222
+
223
+ // Разбор ответа (извлечение версий и PCC)
224
+ string version = "" ;
225
+ string [ ] htmlMarkers = { "</a>" + ProgramDescription . AssemblyMainName , "</h1>" } ;
226
+
227
+ int i = html . IndexOf ( htmlMarkers [ 0 ] ) ;
228
+ if ( i < 0 )
229
+ goto htmlError ;
230
+
231
+ i += htmlMarkers [ 0 ] . Length ;
232
+
233
+ int j = html . IndexOf ( htmlMarkers [ 1 ] , i ) ;
234
+ if ( ( j < 0 ) || ( j <= i ) )
235
+ goto htmlError ;
236
+
237
+ version = html . Substring ( i , j - i ) . Trim ( ) ;
238
+
239
+ // Отображение результата
240
+ switch ( al )
241
+ {
242
+ case SupportedLanguages . ru_ru :
243
+ if ( ProgramDescription . AssemblyTitle . EndsWith ( version ) )
244
+ updatesMessage = "обновлений нет" ;
245
+ else
246
+ updatesMessage = "доступна " + version ;
247
+ break ;
248
+
249
+ default : // en_us
250
+ if ( ProgramDescription . AssemblyTitle . EndsWith ( version ) )
251
+ updatesMessage = "no updates" ;
252
+ else
253
+ updatesMessage = version + " available" ;
254
+ break ;
255
+ }
256
+
257
+
258
+ e . Result = 0 ;
259
+ return ;
260
+
261
+ // Есть проблема при загрузке страницы. Отмена
262
+ htmlError :
263
+ switch ( al )
264
+ {
265
+ case SupportedLanguages . ru_ru :
266
+ updatesMessage = "недоступны" ;
267
+ break ;
268
+
269
+ default : // en_us
270
+ updatesMessage = "unavailable" ;
271
+ break ;
272
+ }
273
+
274
+ e . Result = - 2 ;
275
+ return ;
276
+ }
277
+
278
+ // Контроль сообщения об обновлении
279
+ private void UpdatesTimer_Tick ( object sender , EventArgs e )
280
+ {
281
+ if ( updatesMessage != "" )
282
+ {
283
+ if ( AvailableUpdatesLabel . Text == "" )
284
+ {
285
+ AvailableUpdatesLabel . Text = updatesMessage ;
286
+ if ( ! updatesMessage . Contains ( "." ) )
287
+ {
288
+ UpdatesTimer . Enabled = false ;
289
+ }
290
+ else
291
+ {
292
+ UpdatesTimer . Interval = 1000 ;
293
+ }
294
+ }
295
+ else
296
+ {
297
+ AvailableUpdatesLabel . Text = "" ;
298
+ }
299
+ }
300
+ }
140
301
}
141
302
}
0 commit comments