@@ -48,7 +48,7 @@ public static async Task PrepareUpdate() {
4848 // To prepare the update, we just need to back up our files
4949 string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
5050 string backupFolder = Path . Combine ( ourFolder , ".." , "backup" ) ;
51- await DeleteRetry ( backupFolder ) ;
51+ await DeleteFolderRetry ( backupFolder ) ;
5252
5353 Directory . CreateDirectory ( backupFolder ) ;
5454 FileSystem . CopyDirectory ( ourFolder , backupFolder ) ;
@@ -78,7 +78,7 @@ public static void ExitApplicationToUpdate() {
7878 /// </summary>
7979 public static async Task PerformUpdateAndRestart ( string owner , string repo , string installFolder , string assetName ) {
8080 // Delete the old install folder.
81- await DeleteRetry ( installFolder ) ;
81+ await DeleteFolderContentsRetry ( installFolder ) ;
8282
8383 // Get the latest version of the application from GitHub.
8484 string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
@@ -96,7 +96,7 @@ public static async Task PerformUpdateAndRestart(string owner, string repo, stri
9696
9797 // Run the new version of the application.
9898 Process . Start ( Path . Combine ( installFolder , $ "{ AppDomain . CurrentDomain . FriendlyName } .exe") , "--justUpdated" ) ;
99-
99+
100100 // Close this version of the application.
101101 Environment . Exit ( 0 ) ;
102102 }
@@ -108,20 +108,38 @@ public static async Task CleanupUpdate() {
108108 string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
109109 string backupFolder = Path . Combine ( ourFolder , ".." , "backup" ) ;
110110
111- await DeleteRetry ( backupFolder ) ;
111+ await DeleteFolderRetry ( backupFolder ) ;
112112 }
113113
114114 /// <summary>
115- /// Retries deleting a folder multiple times.
115+ /// Retries deleting a folder multiple times.
116116 /// </summary>
117117 /// <param name="folder">The folder to delete.</param>
118- private static async Task DeleteRetry ( string folder ) {
119- await Retry . Execute < bool > ( ( ) => {
118+ private static async Task DeleteFolderRetry ( string folder ) {
119+ await Retry . Execute ( ( ) => {
120120 if ( Directory . Exists ( folder ) ) {
121121 Directory . Delete ( folder , true ) ;
122122 }
123123
124124 return Task . FromResult ( true ) ;
125125 } , 30 , waitTime : TimeSpan . FromSeconds ( 1 ) ) ;
126126 }
127+
128+ /// <summary>
129+ /// Retries deleting the contents of a folder multiple times.
130+ /// </summary>
131+ /// <param name="folder">The folder to delete the contents of.</param>
132+ private static async Task DeleteFolderContentsRetry ( string folder ) {
133+ await Retry . Execute ( ( ) => {
134+ if ( ! Directory . Exists ( folder ) ) {
135+ return Task . FromResult ( true ) ;
136+ }
137+
138+ foreach ( string file in Directory . GetFiles ( folder ) ) {
139+ File . Delete ( file ) ;
140+ }
141+
142+ return Task . FromResult ( true ) ;
143+ } , 30 , waitTime : TimeSpan . FromSeconds ( 1 ) ) ;
144+ }
127145}
0 commit comments