@@ -65,83 +65,11 @@ public DownloadSummary(IServiceProvider serviceProvider, string fileName)
6565
6666 public async ValueTask < bool > DownloadAndExtractAsync ( )
6767 {
68- HttpRequestMessageBuilder builder = httpRequestMessageBuilderFactory
69- . Create ( )
70- . SetRequestUri ( fileUrl )
71- . SetStaticResourceControlHeaders ( )
72- . Get ( ) ;
73-
74- try
75- {
76- int retryTimes = 0 ;
77- while ( retryTimes ++ < 3 )
78- {
79- builder . Resurrect ( ) ;
80-
81- TimeSpan delay = default ;
82- using ( HttpRequestMessage message = builder . HttpRequestMessage )
83- {
84- using ( HttpResponseMessage response = await httpClient . SendAsync ( message , HttpCompletionOption . ResponseHeadersRead ) . ConfigureAwait ( false ) )
85- {
86- response . EnsureSuccessStatusCode ( ) ;
87-
88- if ( ! AllowedMediaTypes . Contains ( response . Content . Headers . ContentType ? . MediaType ) )
89- {
90- await taskContext . SwitchToMainThreadAsync ( ) ;
91- Description = SH . ViewModelWelcomeDownloadSummaryContentTypeNotMatch ;
92- }
93- else
94- {
95- long contentLength = response . Content . Headers . ContentLength ?? 0 ;
96- using ( Stream content = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) )
97- {
98- using ( TempFileStream tempStream = new ( FileMode . OpenOrCreate , FileAccess . ReadWrite ) )
99- {
100- using ( StreamCopyWorker worker = new ( content , tempStream , contentLength ) )
101- {
102- await worker . CopyAsync ( progress ) . ConfigureAwait ( false ) ;
103- }
104-
105- await ExtractFilesAsync ( tempStream ) . ConfigureAwait ( false ) ;
106-
107- await taskContext . SwitchToMainThreadAsync ( ) ;
108- ProgressValue = 1 ;
109- Description = SH . ViewModelWelcomeDownloadSummaryComplete ;
110- StaticResource . Fulfill ( FileName ) ;
111- return true ;
112- }
113- }
114- }
115-
116- if ( response . Headers . RetryAfter ? . Delta is { } retryAfter )
117- {
118- delay = retryAfter ;
119- }
120- }
121- }
122-
123- await Task . Delay ( delay ) . ConfigureAwait ( false ) ;
124- }
125-
126- return false ;
127- }
128- catch ( Exception ex )
129- {
130- if ( ex is not ( IOException or OperationCanceledException or UnauthorizedAccessException ) &&
131- HttpRequestExceptionHandling . TryHandle ( builder , ex , out StringBuilder message ) )
132- {
133- messenger . Send ( InfoBarMessage . Error ( SH . ViewModelWelcomeDownloadSummaryException , message . ToString ( ) ) ) ;
134- }
135- else
136- {
137- // SSL certificate not trusted: The decryption operation failed, see inner exception. -> 无法解密指定的数据。
138- messenger . Send ( InfoBarMessage . Error ( SH . ViewModelWelcomeDownloadSummaryException , ex ) ) ;
139- }
140-
141- await taskContext . SwitchToMainThreadAsync ( ) ;
142- Description = SH . ViewModelWelcomeDownloadSummaryException ;
143- return false ;
144- }
68+ await taskContext . SwitchToMainThreadAsync ( ) ;
69+ ProgressValue = 1 ;
70+ Description = SH . ViewModelWelcomeDownloadSummaryComplete ;
71+ StaticResource . Fulfill ( FileName ) ;
72+ return true ;
14573 }
14674
14775 private void UpdateProgressStatus ( StreamCopyStatus status )
@@ -169,4 +97,4 @@ private async ValueTask ExtractFilesAsync(Stream stream)
16997 }
17098 }
17199 }
172- }
100+ }
0 commit comments