@@ -54,12 +54,11 @@ public static class GitHubUpdateManager {
5454 public static async Task PrepareUpdate ( ) {
5555 try {
5656 // 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" ) ;
5958 await DeleteFolderRetry ( backupFolder ) ;
6059
6160 Directory . CreateDirectory ( backupFolder ) ;
62- FileSystem . CopyDirectory ( ourFolder , backupFolder ) ;
61+ FileSystem . CopyDirectory ( AppContext . BaseDirectory , backupFolder ) ;
6362 }
6463 catch ( Exception ex ) {
6564 Log . Error ( ex ) ;
@@ -72,16 +71,15 @@ public static async Task PrepareUpdate() {
7271 public static void ExitApplicationToUpdate ( ) {
7372 try {
7473 // 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" ) ;
7775 if ( ! Directory . Exists ( backupFolder ) ) {
7876 return ;
7977 }
8078
8179 string ourExecutable = $ "{ AppDomain . CurrentDomain . FriendlyName } .exe";
8280
8381 // 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 } \" ") ;
8583 Environment . Exit ( 0 ) ;
8684 }
8785 catch ( Exception ex ) {
@@ -99,8 +97,7 @@ public static async Task PerformUpdateAndRestart(string owner, string repo, stri
9997 await DeleteFolderContentsRetry ( installFolder ) ;
10098
10199 // 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 ) ;
104101 GithubLatestReleaseJson ? latestVersion = await GetLatestVersion ( owner , repo ) ;
105102 using ( var client = new HttpClient ( ) ) {
106103 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
127124 /// Cleans up the previous update's files.
128125 /// </summary>
129126 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" ) ;
132128
133129 await DeleteFolderRetry ( backupFolder ) ;
134130 }
0 commit comments