@@ -54,12 +54,11 @@ public static class GitHubUpdateManager {
54
54
public static async Task PrepareUpdate ( ) {
55
55
try {
56
56
// To prepare the update, we just need to back up our files
57
- string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
58
- string backupFolder = Path . Combine ( ourFolder , ".." , "backup" ) ;
57
+ string backupFolder = Path . Combine ( AppContext . BaseDirectory , ".." , "backup" ) ;
59
58
await DeleteFolderRetry ( backupFolder ) ;
60
59
61
60
Directory . CreateDirectory ( backupFolder ) ;
62
- FileSystem . CopyDirectory ( ourFolder , backupFolder ) ;
61
+ FileSystem . CopyDirectory ( AppContext . BaseDirectory , backupFolder ) ;
63
62
}
64
63
catch ( Exception ex ) {
65
64
Log . Error ( ex ) ;
@@ -72,16 +71,15 @@ public static async Task PrepareUpdate() {
72
71
public static void ExitApplicationToUpdate ( ) {
73
72
try {
74
73
// Since we have a backup folder from PrepareUpdate() we can just run the backup executable
75
- string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
76
- string backupFolder = Path . Combine ( ourFolder , ".." , "backup" ) ;
74
+ string backupFolder = Path . Combine ( AppContext . BaseDirectory , ".." , "backup" ) ;
77
75
if ( ! Directory . Exists ( backupFolder ) ) {
78
76
return ;
79
77
}
80
78
81
79
string ourExecutable = $ "{ AppDomain . CurrentDomain . FriendlyName } .exe";
82
80
83
81
// we must pass the installation folder to the executable so it knows where to install
84
- Process . Start ( Path . Combine ( backupFolder , ourExecutable ) , $ "--update \" { ourFolder } \" ") ;
82
+ Process . Start ( Path . Combine ( backupFolder , ourExecutable ) , $ "--update \" { AppContext . BaseDirectory } \" ") ;
85
83
Environment . Exit ( 0 ) ;
86
84
}
87
85
catch ( Exception ex ) {
@@ -99,8 +97,7 @@ public static async Task PerformUpdateAndRestart(string owner, string repo, stri
99
97
await DeleteFolderContentsRetry ( installFolder ) ;
100
98
101
99
// Get the latest version of the application from GitHub.
102
- string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
103
- string zipLocation = Path . Combine ( ourFolder , assetName ) ;
100
+ string zipLocation = Path . Combine ( AppContext . BaseDirectory , assetName ) ;
104
101
GithubLatestReleaseJson ? latestVersion = await GetLatestVersion ( owner , repo ) ;
105
102
using ( var client = new HttpClient ( ) ) {
106
103
using HttpResponseMessage response = await client . GetAsync ( $ "https://github.com/{ owner } /{ repo } /releases/download/{ latestVersion ? . name } /{ assetName } ") ;
@@ -127,8 +124,7 @@ public static async Task PerformUpdateAndRestart(string owner, string repo, stri
127
124
/// Cleans up the previous update's files.
128
125
/// </summary>
129
126
public static async Task CleanupUpdate ( ) {
130
- string ourFolder = Path . GetDirectoryName ( typeof ( GitHubUpdateManager ) . Assembly . Location ) ?? "" ;
131
- string backupFolder = Path . Combine ( ourFolder , ".." , "backup" ) ;
127
+ string backupFolder = Path . Combine ( AppContext . BaseDirectory , ".." , "backup" ) ;
132
128
133
129
await DeleteFolderRetry ( backupFolder ) ;
134
130
}
0 commit comments