@@ -27,6 +27,8 @@ public partial class Operate : Form
2727 ZipArchive archive ;
2828 IReader reader ;
2929
30+ List < string > extractedFiles = new List < string > ( ) ;
31+
3032 long byteProgress = 0 ;
3133 long byteTotal = 0 ;
3234
@@ -61,10 +63,19 @@ private async void Operation_Load(object sender, EventArgs e)
6163 {
6264 stream = new MemoryStream ( await client . DownloadDataTaskAsync ( new Uri ( component . URL ) ) ) ;
6365 }
64- catch ( WebException ex ) when ( ex . Status == WebExceptionStatus . RequestCanceled )
66+ catch ( WebException ex )
6567 {
66- client . Dispose ( ) ;
68+ if ( ex . Status != WebExceptionStatus . RequestCanceled )
69+ {
70+ MessageBox . Show (
71+ $ "The { workingComponent . Title } component failed to download.\n \n " +
72+ "If this issue persists, please let us know as soon as possible." ,
73+ "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error
74+ ) ;
75+ }
76+
6777 cancelStatus = 2 ;
78+ CancelButton . PerformClick ( ) ;
6879 return ;
6980 }
7081 }
@@ -157,6 +168,8 @@ private void ExtractComponents()
157168 writer . WriteLine ( string . Join ( " " , header ) ) ;
158169 }
159170
171+ extractedFiles . Add ( infoFile ) ;
172+
160173 if ( workingComponent . Size == 0 ) return ;
161174
162175 using ( archive = ZipArchive . Open ( stream ) )
@@ -178,6 +191,8 @@ private void ExtractComponents()
178191 ExtractFullPath = true , Overwrite = true , PreserveFileTime = true
179192 } ) ;
180193
194+ extractedFiles . Add ( Path . Combine ( destPath , reader . Entry . Key . Replace ( '/' , '\\ ' ) ) ) ;
195+
181196 using ( TextWriter writer = File . AppendText ( infoFile ) )
182197 {
183198 writer . WriteLine ( Path . Combine ( workingComponent . Path , reader . Entry . Key ) . Replace ( "/" , @"\" ) ) ;
@@ -253,7 +268,7 @@ await Task.Run(() =>
253268
254269 private async void CancelButton_Click ( object sender , EventArgs e )
255270 {
256- cancelStatus = 1 ;
271+ if ( cancelStatus < 1 ) cancelStatus = 1 ;
257272
258273 CancelButton . Enabled = false ;
259274 ProgressLabel . Invoke ( ( MethodInvoker ) delegate
@@ -267,12 +282,23 @@ await Task.Run(() =>
267282
268283 if ( Directory . Exists ( FPM . Main . DestinationPath . Text ) )
269284 {
270- foreach ( string file in Directory . EnumerateFiles ( FPM . Main . DestinationPath . Text ) )
285+ foreach ( string file in extractedFiles )
271286 {
272287 try { File . Delete ( file ) ; } catch { }
273- }
274288
275- try { Directory . Delete ( FPM . Main . DestinationPath . Text , true ) ; } catch { }
289+ string folder = Path . GetDirectoryName ( file ) ;
290+
291+ while ( folder != Directory . GetParent ( FPM . Main . DestinationPath . Text ) . ToString ( ) )
292+ {
293+ if ( Directory . Exists ( folder ) && ! Directory . EnumerateFiles ( folder , "*" , SearchOption . AllDirectories ) . Any ( ) )
294+ {
295+ try { Directory . Delete ( folder , true ) ; } catch { }
296+ }
297+ else break ;
298+
299+ folder = Directory . GetParent ( folder ) . ToString ( ) ;
300+ }
301+ }
276302 }
277303 } ) ;
278304
0 commit comments