@@ -18,12 +18,36 @@ public static async Task<Version> GetRemoteVersion(Uri address)
1818 return new Version ( text ) ;
1919 }
2020
21- public static async Task DownloadUpdater ( Uri address , string updaterDirectory , string zipFileName )
21+ public static async Task DownloadUpdater ( Uri address , string updaterDirectory , string zipFileName ,
22+ Action < DownloadProgressChangedEventArgs > eventHandler )
2223 {
2324 Directory . CreateDirectory ( updaterDirectory ) ;
2425
26+ var sequence = new Sequence ( ) ;
27+ var previousEventTimestamp = 0 ;
28+
2529 using ( var webClient = new WebClient ( ) )
30+ {
31+ webClient . DownloadProgressChanged += ( sender , args ) =>
32+ {
33+ if ( sequence . Next ( ) == 0 )
34+ {
35+ previousEventTimestamp = UniversalTime . GetTickCount ( ) ;
36+ eventHandler ( args ) ;
37+ }
38+ else
39+ {
40+ var current = UniversalTime . GetTickCount ( ) ;
41+ var elapsed = current - previousEventTimestamp ;
42+ if ( elapsed >= 1000 )
43+ {
44+ previousEventTimestamp = current ;
45+ eventHandler ( args ) ;
46+ }
47+ }
48+ } ;
2649 await webClient . DownloadFileTaskAsync ( address , zipFileName ) ;
50+ }
2751 }
2852
2953 public static void ExtractZip ( string zipFileName , string updaterDirectory )
@@ -34,10 +58,7 @@ public static void ExtractZip(string zipFileName, string updaterDirectory)
3458
3559 public static void StartUpdater ( string updaterExeFileName )
3660 {
37- var workingDirectory = Path . GetDirectoryName ( updaterExeFileName ) ;
38-
3961 var processStartInfo = new ProcessStartInfo ( ) ;
40- processStartInfo . WorkingDirectory = workingDirectory ;
4162 processStartInfo . FileName = updaterExeFileName ;
4263 processStartInfo . Arguments = $ "{ Quote ( Environment . CurrentDirectory ) } ";
4364 Process . Start ( processStartInfo ) ;
0 commit comments