@@ -197,7 +197,7 @@ private async Task DownloadModelAsync(string url, string fileName, CancellationT
197197 }
198198 }
199199
200- private async Task DownloadWithProgressAsync ( HttpResponseMessage response , string filePath , string fileName , CancellationToken cancellationToken )
200+ private static async Task DownloadWithProgressAsync ( HttpResponseMessage response , string filePath , string fileName , CancellationToken cancellationToken )
201201 {
202202 var totalBytes = response . Content . Headers . ContentLength ;
203203 var totalBytesRead = 0L ;
@@ -215,10 +215,13 @@ private async Task DownloadWithProgressAsync(HttpResponseMessage response, strin
215215
216216 while ( true )
217217 {
218- var bytesRead = await contentStream . ReadAsync ( buffer , 0 , buffer . Length , cancellationToken ) ;
219- if ( bytesRead == 0 ) break ;
218+ var bytesRead = await contentStream . ReadAsync ( buffer , cancellationToken ) ;
219+ if ( bytesRead == 0 )
220+ {
221+ break ;
222+ }
220223
221- await fileStream . WriteAsync ( buffer , 0 , bytesRead , cancellationToken ) ;
224+ await fileStream . WriteAsync ( buffer . AsMemory ( 0 , bytesRead ) , cancellationToken ) ;
222225 totalBytesRead += bytesRead ;
223226
224227 if ( ShouldUpdateProgress ( progressStopwatch ) )
@@ -317,7 +320,7 @@ private static void ShowProgress(long totalBytesRead, long? totalBytes, Stopwatc
317320 $ "Speed: { FormatBytes ( ( long ) speed ) } /s ETA: { eta : hh\\:mm\\:ss} ") ;
318321
319322 var ( leftAfter , topAfter ) = Console . GetCursorPosition ( ) ;
320- int lengthDifference = leftBefore - leftAfter + ( topBefore - topAfter ) * Console . WindowWidth ;
323+ int lengthDifference = leftBefore - leftAfter + ( ( topBefore - topAfter ) * Console . WindowWidth ) ;
321324 while ( lengthDifference > 0 )
322325 {
323326 Console . Write ( ' ' ) ;
@@ -345,7 +348,10 @@ private static void ShowFinalProgress(long totalBytesRead, Stopwatch totalStopwa
345348
346349 private static string FormatBytes ( long bytes )
347350 {
348- if ( bytes == 0 ) return "0 Bytes" ;
351+ if ( bytes == 0 )
352+ {
353+ return "0 Bytes" ;
354+ }
349355
350356 const int scale = 1024 ;
351357 string [ ] orders = [ "GB" , "MB" , "KB" , "Bytes" ] ;
@@ -354,14 +360,17 @@ private static string FormatBytes(long bytes)
354360 foreach ( var order in orders )
355361 {
356362 if ( bytes >= max )
363+ {
357364 return $ "{ decimal . Divide ( bytes , max ) : ##.##} { order } ";
365+ }
366+
358367 max /= scale ;
359368 }
360369
361370 return "0 Bytes" ;
362371 }
363372
364- private string ResolvePath ( string ? settingsModelsPath ) =>
373+ private static string ResolvePath ( string ? settingsModelsPath ) =>
365374 settingsModelsPath
366375 ?? Environment . GetEnvironmentVariable ( "MaIN_ModelsPath" )
367376 ?? throw new ModelsPathNotFoundException ( ) ;
0 commit comments