Skip to content

Commit a8f2e88

Browse files
authored
Merge pull request #3670 from Nexus-Mods/fix-3668
Fixed: Unrecognised AppImage environment variable after handler fix.
2 parents d170f5e + 314c185 commit a8f2e88

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

src/NexusMods.CrossPlatform/Process/AOSInterop.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,15 @@ public virtual Task OpenFileInDirectory(AbsolutePath filePath, bool logOutput =
8686
}
8787

8888
/// <inheritdoc />
89-
public virtual AbsolutePath GetOwnExe()
89+
public virtual AbsolutePath GetOwnExe() => FileSystem.Shared.FromUnsanitizedFullPath(GetOwnExeUnsanitized());
90+
91+
/// <inheritdoc />
92+
public virtual string GetOwnExeUnsanitized()
9093
{
9194
var processPath = Environment.ProcessPath;
9295
Debug.Assert(processPath is not null);
9396

94-
return FileSystem.Shared.FromUnsanitizedFullPath(processPath);
97+
return processPath;
9598
}
9699

97100
/// <inheritdoc />

src/NexusMods.CrossPlatform/Process/IOSInterop.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public interface IOSInterop
3939
/// </summary>
4040
AbsolutePath GetOwnExe();
4141

42+
/// <summary>
43+
/// Get the path to the current executable as an unsanitized string.
44+
/// This preserves the original path without conversion through the paths library.
45+
/// </summary>
46+
/// <remarks>
47+
/// Do not use in production *unless you have a very good reason to do so*.
48+
/// This API exists to resolve an edge case with protocol registration on Linux,
49+
/// https://github.com/Nexus-Mods/NexusMods.Paths/issues/71
50+
/// </remarks>
51+
string GetOwnExeUnsanitized();
52+
4253
/// <summary>
4354
/// Gets all file system mounts.
4455
/// </summary>

src/NexusMods.CrossPlatform/Process/OSInteropLinux.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ private async ValueTask<OpenUriPortal> GetPortal()
6969
protected override Command CreateCommand(Uri uri) => throw new UnreachableException("Should never be called");
7070

7171
/// <inheritdoc />
72-
public override AbsolutePath GetOwnExe()
72+
public override string GetOwnExeUnsanitized()
7373
{
7474
// https://docs.appimage.org/packaging-guide/environment-variables.html#type-2-appimage-runtime
7575
// APPIMAGE: (Absolute) path to AppImage file (with symlinks resolved)
7676
var appImagePath = Environment.GetEnvironmentVariable("APPIMAGE", EnvironmentVariableTarget.Process);
77-
if (appImagePath is null) return base.GetOwnExe();
77+
if (appImagePath is not null) return appImagePath;
7878

79-
return _fileSystem.FromUnsanitizedFullPath(appImagePath);
79+
return base.GetOwnExeUnsanitized();
8080
}
8181

8282
/// <inheritdoc />

src/NexusMods.CrossPlatform/ProtocolRegistration/ProtocolRegistrationLinux.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,6 @@ private async Task CreateDesktopFile(AbsolutePath applicationsDirectory, Cancell
118118

119119
var text = await sr.ReadToEndAsync(cancellationToken);
120120

121-
// Note(sewer): For `processPath` we're temporarily using `_osInterop.GetOwnExe()` because
122-
// paths library will replace backslashes in folder names with forward slashes.
123-
// Backslashes are valid on Linux (& macOS), so we're avoiding
124-
// breaking the App here.
125-
// https://github.com/Nexus-Mods/NexusMods.Paths/issues/71
126-
127121
// Note(sewer): xdg-utils has issues with the 'generic' fallback for `.desktop` files
128122
// which will be used in non-mainstream DEs like Hyprland, Sway, i3, etc.
129123
// We'll use a hack to work around this.
@@ -146,7 +140,13 @@ private async Task CreateDesktopFile(AbsolutePath applicationsDirectory, Cancell
146140
// I also added an extra 'safety' rule:
147141
// - The wrapper will only be used if the path requires escaping.
148142
// - IF Path requires escaping AND `XDG_DATA_HOME` needs escaping, we log a warning.
149-
var processPath = Environment.ProcessPath!;
143+
144+
// Note(sewer): We use GetOwnExeUnsanitized() instead of GetOwnExe()
145+
// because the backslashes \ are unfortunately valid filename
146+
// characters on Linux. The Paths library converts \ to /
147+
// which breaks the path, so we must avoid this.
148+
// https://github.com/Nexus-Mods/NexusMods.Paths/issues/71
149+
var processPath = _osInterop.GetOwnExeUnsanitized();
150150
var wrapperScriptPath = await CreateWrapperScriptIfNeeded(applicationsDirectory, processPath, cancellationToken);
151151

152152
text = text.Replace(ExecuteParameterPlaceholder, wrapperScriptPath.ToString());

0 commit comments

Comments
 (0)