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