@@ -27,6 +27,8 @@ public partial class Operate : Form
27
27
ZipArchive archive ;
28
28
IReader reader ;
29
29
30
+ List < string > extractedFiles = new List < string > ( ) ;
31
+
30
32
long byteProgress = 0 ;
31
33
long byteTotal = 0 ;
32
34
@@ -166,6 +168,8 @@ private void ExtractComponents()
166
168
writer . WriteLine ( string . Join ( " " , header ) ) ;
167
169
}
168
170
171
+ extractedFiles . Add ( infoFile ) ;
172
+
169
173
if ( workingComponent . Size == 0 ) return ;
170
174
171
175
using ( archive = ZipArchive . Open ( stream ) )
@@ -187,6 +191,8 @@ private void ExtractComponents()
187
191
ExtractFullPath = true , Overwrite = true , PreserveFileTime = true
188
192
} ) ;
189
193
194
+ extractedFiles . Add ( Path . Combine ( destPath , reader . Entry . Key . Replace ( '/' , '\\ ' ) ) ) ;
195
+
190
196
using ( TextWriter writer = File . AppendText ( infoFile ) )
191
197
{
192
198
writer . WriteLine ( Path . Combine ( workingComponent . Path , reader . Entry . Key ) . Replace ( "/" , @"\" ) ) ;
@@ -276,12 +282,23 @@ await Task.Run(() =>
276
282
277
283
if ( Directory . Exists ( FPM . Main . DestinationPath . Text ) )
278
284
{
279
- foreach ( string file in Directory . EnumerateFiles ( FPM . Main . DestinationPath . Text ) )
285
+ foreach ( string file in extractedFiles )
280
286
{
281
287
try { File . Delete ( file ) ; } catch { }
282
- }
283
288
284
- 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
+ }
285
302
}
286
303
} ) ;
287
304
0 commit comments