8
8
using System ;
9
9
using System . Collections . Generic ;
10
10
using System . IO ;
11
- using System . Linq ;
12
11
using System . Net . Http ;
13
12
using System . Reflection ;
14
13
using System . Threading . Tasks ;
@@ -64,12 +63,17 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
64
63
}
65
64
else
66
65
{
67
- currentVersion = currentVersion . Substring ( 0 , currentVersion . IndexOf ( "+" ) < 0 ? currentVersion . Length : currentVersion . IndexOf ( "+" ) ) ;
66
+ currentVersion = currentVersion . Substring (
67
+ 0 ,
68
+ currentVersion . IndexOf ( "+" ) < 0 ? currentVersion . Length : currentVersion . IndexOf ( "+" ) ) ;
68
69
}
69
70
70
71
Version version = Version . Parse ( currentVersion ) ;
71
72
72
- string nanoClrDllLocation = Path . Combine ( Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) , "NanoCLR" , "nanoFramework.nanoCLR.dll" ) ;
73
+ string nanoClrDllLocation = Path . Combine (
74
+ Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ,
75
+ "NanoCLR" ,
76
+ "nanoFramework.nanoCLR.dll" ) ;
73
77
74
78
_httpClient . BaseAddress = new Uri ( _cloudSmithApiUrl ) ;
75
79
_httpClient . DefaultRequestHeaders . Add ( "Accept" , "*/*" ) ;
@@ -86,24 +90,24 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
86
90
87
91
var packageInfo = JsonConvert . DeserializeObject < List < CloudsmithPackageInfo > > ( responseBody ) ;
88
92
89
- if ( packageInfo . Count ( ) != 1 )
93
+ if ( packageInfo . Count != 1 )
90
94
{
91
95
Console . WriteLine ( $ "Error parsing latest nanoCLR version.") ;
92
96
return ExitCode . E9005 ;
93
97
}
94
98
else
95
99
{
96
- Version latestFwVersion = Version . Parse ( packageInfo . ElementAt ( 0 ) . Version ) ;
100
+ Version latestFwVersion = Version . Parse ( packageInfo [ 0 ] . Version ) ;
97
101
98
102
if ( latestFwVersion < version )
99
103
{
100
- Console . WriteLine ( $ "Current version { version } lower than available version { packageInfo . ElementAt ( 0 ) . Version } ") ;
104
+ Console . WriteLine ( $ "Current version { version } lower than available version { packageInfo [ 0 ] . Version } ") ;
101
105
}
102
106
else if ( latestFwVersion > version
103
107
|| ( ! string . IsNullOrEmpty ( targetVersion )
104
108
&& ( Version . Parse ( targetVersion ) > Version . Parse ( currentVersion ) ) ) )
105
109
{
106
- response = await _httpClient . GetAsync ( packageInfo . ElementAt ( 0 ) . DownloadUrl ) ;
110
+ response = await _httpClient . GetAsync ( packageInfo [ 0 ] . DownloadUrl ) ;
107
111
response . EnsureSuccessStatusCode ( ) ;
108
112
109
113
// need to unload the DLL before updating it
@@ -113,15 +117,15 @@ private static async Task<ExitCode> UpdateNanoCLRAsync(
113
117
await using var fs = File . OpenWrite ( nanoClrDllLocation ) ;
114
118
115
119
ms . Seek ( 0 , SeekOrigin . Begin ) ;
116
- ms . CopyTo ( fs ) ;
120
+ await ms . CopyToAsync ( fs ) ;
117
121
118
- fs . Flush ( ) ;
122
+ await fs . FlushAsync ( ) ;
119
123
120
- Console . WriteLine ( $ "Updated to v{ packageInfo . ElementAt ( 0 ) . Version } ") ;
124
+ Console . WriteLine ( $ "Updated to v{ packageInfo [ 0 ] . Version } ") ;
121
125
}
122
126
else
123
127
{
124
- Console . WriteLine ( $ "Already at v{ packageInfo . ElementAt ( 0 ) . Version } ") ;
128
+ Console . WriteLine ( $ "Already at v{ packageInfo [ 0 ] . Version } ") ;
125
129
}
126
130
127
131
return ExitCode . OK ;
0 commit comments