Skip to content

Commit c91382b

Browse files
committed
fix: handle windows deeplink when build profile executable name differs from product name
1 parent 2c2a32e commit c91382b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Packages/Passport/Runtime/Scripts/Private/Helpers/WindowsDeepLink.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
using System;
33
using System.IO;
44
using System.Runtime.InteropServices;
5+
using System.Diagnostics;
6+
#if UNITY_EDITOR
7+
using UnityEditor;
8+
#endif
59
using UnityEditor;
610
using UnityEngine;
711
using Immutable.Passport.Core.Logging;
12+
using Debug = UnityEngine.Debug;
813

914
#nullable enable
1015
namespace Immutable.Passport.Helpers
@@ -173,7 +178,7 @@ private static void CreateCommandScript(string protocolName)
173178
// Store deeplink URI in registry
174179
$"REG ADD \"HKCU\\Software\\Classes\\{protocolName}\" /v \"{REGISTRY_DEEP_LINK_NAME}\" /t REG_SZ /d %1 /f >nul 2>&1",
175180
// Check if game is already running
176-
$"tasklist /FI \"IMAGENAME eq {gameExeName}\" 2>NUL | find /I \"{gameExeName}\" >NUL",
181+
$"tasklist /FI \"IMAGENAME eq {gameExeName}\" >nul 2>&1",
177182
"if %ERRORLEVEL%==0 (",
178183
// Bring existing game window to foreground
179184
" powershell -NoProfile -ExecutionPolicy Bypass -Command ^",
@@ -264,11 +269,17 @@ private static void RegisterProtocol(string protocolName)
264269
RegCloseKey(commandKey);
265270
RegCloseKey(hKey);
266271
}
267-
272+
268273
private static string GetGameExecutablePath(string suffix)
269274
{
270-
var exeName = Application.productName + suffix;
271-
return Path.Combine(Application.persistentDataPath, exeName).Replace("/", "\\");
275+
#if !UNITY_EDITOR_WIN
276+
if (suffix == ".exe")
277+
{
278+
return System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName.Replace("/", "\\");
279+
}
280+
#endif
281+
var fileName = Application.productName + suffix;
282+
return Path.Combine(Application.persistentDataPath, fileName).Replace("/", "\\");
272283
}
273284

274285
private void OnApplicationFocus(bool hasFocus)

0 commit comments

Comments
 (0)