@@ -48,7 +48,7 @@ public static async Task PrepareUpdate() {
48
48
// To prepare the update, we just need to back up our files
49
49
string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
50
50
string backupFolder = Path . Combine ( ourFolder , ".." , "backup" ) ;
51
- await DeleteRetry ( backupFolder ) ;
51
+ await DeleteFolderRetry ( backupFolder ) ;
52
52
53
53
Directory . CreateDirectory ( backupFolder ) ;
54
54
FileSystem . CopyDirectory ( ourFolder , backupFolder ) ;
@@ -78,7 +78,7 @@ public static void ExitApplicationToUpdate() {
78
78
/// </summary>
79
79
public static async Task PerformUpdateAndRestart ( string owner , string repo , string installFolder , string assetName ) {
80
80
// Delete the old install folder.
81
- await DeleteRetry ( installFolder ) ;
81
+ await DeleteFolderContentsRetry ( installFolder ) ;
82
82
83
83
// Get the latest version of the application from GitHub.
84
84
string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
@@ -96,7 +96,7 @@ public static async Task PerformUpdateAndRestart(string owner, string repo, stri
96
96
97
97
// Run the new version of the application.
98
98
Process . Start ( Path . Combine ( installFolder , $ "{ AppDomain . CurrentDomain . FriendlyName } .exe") , "--justUpdated" ) ;
99
-
99
+
100
100
// Close this version of the application.
101
101
Environment . Exit ( 0 ) ;
102
102
}
@@ -108,20 +108,38 @@ public static async Task CleanupUpdate() {
108
108
string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
109
109
string backupFolder = Path . Combine ( ourFolder , ".." , "backup" ) ;
110
110
111
- await DeleteRetry ( backupFolder ) ;
111
+ await DeleteFolderRetry ( backupFolder ) ;
112
112
}
113
113
114
114
/// <summary>
115
- /// Retries deleting a folder multiple times.
115
+ /// Retries deleting a folder multiple times.
116
116
/// </summary>
117
117
/// <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 ( ( ) => {
120
120
if ( Directory . Exists ( folder ) ) {
121
121
Directory . Delete ( folder , true ) ;
122
122
}
123
123
124
124
return Task . FromResult ( true ) ;
125
125
} , 30 , waitTime : TimeSpan . FromSeconds ( 1 ) ) ;
126
126
}
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
+ }
127
145
}
0 commit comments