|
2 | 2 | using System; |
3 | 3 | using System.IO; |
4 | 4 | using System.Runtime.InteropServices; |
| 5 | +using System.Diagnostics; |
| 6 | +#if UNITY_EDITOR |
| 7 | +using UnityEditor; |
| 8 | +#endif |
5 | 9 | using UnityEditor; |
6 | 10 | using UnityEngine; |
7 | 11 | using Immutable.Passport.Core.Logging; |
| 12 | +using Debug = UnityEngine.Debug; |
8 | 13 |
|
9 | 14 | #nullable enable |
10 | 15 | namespace Immutable.Passport.Helpers |
@@ -173,7 +178,7 @@ private static void CreateCommandScript(string protocolName) |
173 | 178 | // Store deeplink URI in registry |
174 | 179 | $"REG ADD \"HKCU\\Software\\Classes\\{protocolName}\" /v \"{REGISTRY_DEEP_LINK_NAME}\" /t REG_SZ /d %1 /f >nul 2>&1", |
175 | 180 | // 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", |
177 | 182 | "if %ERRORLEVEL%==0 (", |
178 | 183 | // Bring existing game window to foreground |
179 | 184 | " powershell -NoProfile -ExecutionPolicy Bypass -Command ^", |
@@ -264,11 +269,17 @@ private static void RegisterProtocol(string protocolName) |
264 | 269 | RegCloseKey(commandKey); |
265 | 270 | RegCloseKey(hKey); |
266 | 271 | } |
267 | | - |
| 272 | + |
268 | 273 | private static string GetGameExecutablePath(string suffix) |
269 | 274 | { |
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("/", "\\"); |
272 | 283 | } |
273 | 284 |
|
274 | 285 | private void OnApplicationFocus(bool hasFocus) |
|
0 commit comments