@@ -130,8 +130,6 @@ private async void Operation_Load(object sender, EventArgs e)
130130 await Task . Run ( ApplyComponents ) ;
131131 }
132132
133- await Task . Run ( DeleteTempDirectory ) ;
134-
135133 TaskbarManager . Instance . SetProgressState ( TaskbarProgressBarState . NoProgress , FPM . Main . Handle ) ;
136134
137135 if ( FPM . AutoDownload . Count == 0 ) FPM . SyncManager ( ) ;
@@ -292,6 +290,23 @@ private void RemoveComponents()
292290
293291 private void ApplyComponents ( )
294292 {
293+ void MoveDelete ( string source , string dest )
294+ {
295+ try
296+ {
297+ File . Move ( source , dest ) ;
298+ FPM . DeleteFileAndDirectories ( source ) ;
299+ }
300+ catch
301+ {
302+ MessageBox . Show (
303+ "Failed to move the following file:\n " + source + "\n \n " +
304+ "You will have to move it manually from the Temp folder." ,
305+ "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error
306+ ) ;
307+ }
308+ }
309+
295310 string tempPath = Path . Combine ( FPM . SourcePath , "Temp" ) ;
296311 string tempInfoFile = Path . Combine ( tempPath , "Components" , workingComponent . ID ) ;
297312 string [ ] infoText = File . ReadLines ( tempInfoFile ) . Skip ( 1 ) . ToArray ( ) ;
@@ -302,25 +317,11 @@ private void ApplyComponents()
302317 string destFile = Path . Combine ( FPM . SourcePath , file ) ;
303318
304319 Directory . CreateDirectory ( Path . GetDirectoryName ( destFile ) ) ;
305- try { File . Move ( tempFile , destFile ) ; } catch { }
306- }
307-
308- try { File . Move ( tempInfoFile , workingComponent . InfoFile ) ; } catch { }
309- }
310-
311- public static void DeleteTempDirectory ( )
312- {
313- string tempPath = Path . Combine ( FPM . SourcePath , "Temp" ) ;
314320
315- if ( Directory . Exists ( tempPath ) )
316- {
317- foreach ( string tempFile in Directory . EnumerateFiles ( tempPath ) )
318- {
319- try { File . Delete ( tempFile ) ; } catch { }
320- }
321-
322- try { Directory . Delete ( tempPath , true ) ; } catch { }
321+ MoveDelete ( tempFile , destFile ) ;
323322 }
323+
324+ MoveDelete ( tempInfoFile , workingComponent . InfoFile ) ;
324325 }
325326
326327 private async void CancelButton_Click ( object sender , EventArgs e )
@@ -337,7 +338,17 @@ await Task.Run(() =>
337338 {
338339 while ( cancelStatus != 2 ) { }
339340
340- DeleteTempDirectory ( ) ;
341+ string tempPath = Path . Combine ( FPM . SourcePath , "Temp" ) ;
342+
343+ if ( Directory . Exists ( tempPath ) )
344+ {
345+ foreach ( string tempFile in Directory . EnumerateFiles ( tempPath ) )
346+ {
347+ try { File . Delete ( tempFile ) ; } catch { }
348+ }
349+
350+ try { Directory . Delete ( tempPath , true ) ; } catch { }
351+ }
341352 } ) ;
342353
343354 TaskbarManager . Instance . SetProgressState ( TaskbarProgressBarState . NoProgress , FPM . Main . Handle ) ;
0 commit comments