4
4
using System . Diagnostics ;
5
5
using System . Globalization ;
6
6
using System . Net . Http . Headers ;
7
+ using System . Net . Sockets ;
7
8
using System . Reflection ;
8
9
using System . Runtime . InteropServices ;
9
10
using System . Text ;
@@ -38,7 +39,7 @@ public partial class MainWindow : Form
38
39
private uint NtActualResolution = 0 ;
39
40
40
41
private readonly static bool emptyBuildVersion = Assembly . GetEntryAssembly ( ) . GetName ( ) . Version . Build == - 1 ;
41
- private readonly string ProgramVersion = emptyBuildVersion ? Assembly . GetEntryAssembly ( ) . GetName ( ) . Version . Build . ToString ( ) : "1.0.3.8 " ;
42
+ private readonly string ProgramVersion = emptyBuildVersion ? Assembly . GetEntryAssembly ( ) . GetName ( ) . Version . Build . ToString ( ) : "1.0.3.9 " ;
42
43
43
44
private static Dictionary < string , int > Logger = new ( ) ;
44
45
@@ -129,21 +130,44 @@ public MainWindow()
129
130
130
131
public string GetRequest ( string uri , bool jsonaccept )
131
132
{
132
- HttpClient client = new HttpClient ( ) ;
133
- client . BaseAddress = new Uri ( uri ) ;
133
+ HttpClient client = new ( ) ;
134
+ client . BaseAddress = new ( uri ) ;
135
+ client . Timeout = new ( 0 , 0 , 4 ) ;
134
136
135
137
if ( jsonaccept )
136
138
client . DefaultRequestHeaders
137
139
. Accept
138
140
. Add ( new MediaTypeWithQualityHeaderValue ( "application/json" ) ) ;
139
141
140
- var res = client . GetStringAsync ( uri ) . Result ;
142
+ string res = string . Empty ;
143
+
144
+ try
145
+ {
146
+ res = client . GetStringAsync ( uri ) . Result ;
147
+ }
148
+ catch ( AggregateException ex )
149
+ {
150
+ ex . Handle ( x =>
151
+ {
152
+ if ( x is HttpRequestException || x is SocketException )
153
+ {
154
+ return true ;
155
+ }
156
+
157
+ return false ;
158
+ } ) ;
159
+ }
160
+
141
161
return res ;
142
162
}
143
163
144
164
public void CheckForUpdates ( )
145
165
{
146
166
string json = GetRequest ( "https://github.com/TorniX0/OpenTimerResolution/releases/latest" , true ) ;
167
+
168
+ if ( json == string . Empty )
169
+ return ;
170
+
147
171
var obj = JObject . Parse ( json ) ;
148
172
string ver = obj [ "tag_name" ] . ToString ( ) ;
149
173
ver = ver . Substring ( 8 , ver . Length - 8 ) ;
@@ -218,7 +242,7 @@ private void stopButton_Click(object sender, EventArgs e)
218
242
return ;
219
243
220
244
var result = NtSetTimerResolution ( ( int ) ( float . Parse ( timerResolutionBox . Text ) * 10000f ) , false , out NtCurrentResolution ) ;
221
-
245
+
222
246
if ( result != NtStatus . Success )
223
247
{
224
248
MessageBox . Show ( $ "Error code: { result } ", "OpenTimerResolution" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
@@ -265,7 +289,7 @@ private void minimizeIcon_MouseClick(object sender, MouseEventArgs e)
265
289
this . ShowInTaskbar = true ;
266
290
this . Show ( ) ;
267
291
this . BringToFront ( ) ;
268
- this . WindowState = FormWindowState . Normal ;
292
+ this . WindowState = FormWindowState . Normal ;
269
293
}
270
294
271
295
private void quitStripMenu_Click ( object sender , EventArgs e )
@@ -475,4 +499,4 @@ private void updateConfigButton_Click(object sender, EventArgs e)
475
499
476
500
#endregion
477
501
}
478
- }
502
+ }
0 commit comments