1
+ using System . Diagnostics ;
1
2
using System . IO ;
3
+ using System . Net ;
2
4
using System . Threading ;
3
5
using System . Windows . Forms ;
4
6
@@ -30,12 +32,13 @@ public RAIntegrationDownloaderForm(string url)
30
32
private bool _exiting = false ;
31
33
private bool _succeeded = false ;
32
34
private bool _failed = false ;
33
- private Thread _thread ;
35
+
36
+ private Thread /*?*/ _thread = null ;
34
37
35
38
public bool DownloadSucceeded ( )
36
39
{
37
40
// block until the thread dies
38
- while ( _thread ? . IsAlive ?? false )
41
+ while ( _thread is { IsAlive : true } )
39
42
{
40
43
Thread . Sleep ( 1 ) ;
41
44
}
@@ -57,23 +60,15 @@ private void Download()
57
60
{
58
61
using ( var evt = new ManualResetEvent ( false ) )
59
62
{
60
- using var client = new System . Net . WebClient ( ) ;
61
- System . Net . ServicePointManager . SecurityProtocol = System . Net . SecurityProtocolType . Tls12 ;
63
+ using var client = new WebClient ( ) ;
64
+ ServicePointManager . SecurityProtocol = SecurityProtocolType . Tls12 ;
62
65
client . DownloadFileAsync ( new Uri ( _url ) , fn ) ;
63
- client . DownloadProgressChanged += ( object sender , System . Net . DownloadProgressChangedEventArgs e ) =>
64
- {
65
- _pct = e . ProgressPercentage ;
66
- } ;
67
- client . DownloadFileCompleted += ( object sender , System . ComponentModel . AsyncCompletedEventArgs e ) =>
68
- {
69
- //we don't really need a status. we'll just try to unzip it when it's done
70
- evt . Set ( ) ;
71
- } ;
66
+ client . DownloadProgressChanged += ( _ , progressArgs ) => _pct = progressArgs . ProgressPercentage ;
67
+ client . DownloadFileCompleted += ( _ , _ ) => evt . Set ( ) ; // we don't really need a status, we'll just try to unzip it when it's done
72
68
73
- for ( ; ; )
69
+ while ( true )
74
70
{
75
- if ( evt . WaitOne ( 10 ) )
76
- break ;
71
+ if ( evt . WaitOne ( 10 ) ) break ;
77
72
78
73
//if the gui thread ordered an exit, cancel the download and wait for it to acknowledge
79
74
if ( _exiting )
@@ -85,20 +80,18 @@ private void Download()
85
80
}
86
81
}
87
82
88
- // throw new Exception("test of download failure");
83
+ // throw new Exception("test of download failure");
89
84
90
85
//if we were ordered to exit, bail without wasting any more time
91
- if ( _exiting )
92
- return ;
86
+ if ( _exiting ) return ;
93
87
94
88
//try acquiring file
95
89
using ( var dll = new HawkFile ( fn ) )
96
90
{
97
91
var data = dll ! . ReadAllBytes ( ) ;
98
92
99
93
//last chance. exiting, don't dump the new RAIntegration file
100
- if ( _exiting )
101
- return ;
94
+ if ( _exiting ) return ;
102
95
103
96
DirectoryInfo parentDir = new ( Path . GetDirectoryName ( _path ) ! ) ;
104
97
if ( ! parentDir . Exists ) parentDir . Create ( ) ;
@@ -114,8 +107,14 @@ private void Download()
114
107
}
115
108
finally
116
109
{
117
- try { File . Delete ( fn ) ; }
118
- catch { }
110
+ try
111
+ {
112
+ File . Delete ( fn ) ;
113
+ }
114
+ catch
115
+ {
116
+ // ignore
117
+ }
119
118
}
120
119
}
121
120
@@ -145,8 +144,7 @@ protected override void OnClosed(EventArgs e)
145
144
private void timer1_Tick ( object sender , EventArgs e )
146
145
{
147
146
//if it's done, close the window. the user will be smart enough to reopen it
148
- if ( _succeeded )
149
- Close ( ) ;
147
+ if ( _succeeded ) Close ( ) ;
150
148
if ( _failed )
151
149
{
152
150
_failed = false ;
@@ -159,8 +157,7 @@ private void timer1_Tick(object sender, EventArgs e)
159
157
160
158
private void linkLabel1_LinkClicked ( object sender , LinkLabelLinkClickedEventArgs e )
161
159
{
162
- System . Diagnostics . Process . Start ( _url ) ;
160
+ Process . Start ( _url ) ;
163
161
}
164
162
}
165
163
}
166
-
0 commit comments