Skip to content

Commit 0d16276

Browse files
bug: fixing issue with compiling as a single file application
You cannot refer to a base folder in the way we were when you compile as a single file application. The reason being that there is no assembly because it lives inside the exe so it returns an empty string at all times.
1 parent 56b2694 commit 0d16276

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/Nullinside.Api.Common/Desktop/GitHubUpdateManager.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)