From 1b892dcf49d64f5ae6cc4f270c4e504d05c506b9 Mon Sep 17 00:00:00 2001 From: David Sarno Date: Fri, 8 Aug 2025 08:32:20 -0700 Subject: [PATCH] fix(ports): write both hashed and legacy port files; compare project paths case-insensitively to prevent sticky-port drift across reloads --- UnityMcpBridge/Editor/Helpers/PortManager.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/UnityMcpBridge/Editor/Helpers/PortManager.cs b/UnityMcpBridge/Editor/Helpers/PortManager.cs index 900cbd9..9e12e7a 100644 --- a/UnityMcpBridge/Editor/Helpers/PortManager.cs +++ b/UnityMcpBridge/Editor/Helpers/PortManager.cs @@ -38,7 +38,7 @@ namespace UnityMcpBridge.Editor.Helpers var storedConfig = GetStoredPortConfig(); if (storedConfig != null && storedConfig.unity_port > 0 && - storedConfig.project_path == Application.dataPath && + string.Equals(storedConfig.project_path ?? string.Empty, Application.dataPath ?? string.Empty, StringComparison.OrdinalIgnoreCase) && IsPortAvailable(storedConfig.unity_port)) { Debug.Log($"Using stored port {storedConfig.unity_port} for current project"); @@ -196,7 +196,11 @@ namespace UnityMcpBridge.Editor.Helpers string registryFile = GetRegistryFilePath(); string json = JsonConvert.SerializeObject(portConfig, Formatting.Indented); + // Write to hashed, project-scoped file File.WriteAllText(registryFile, json); + // Also write to legacy stable filename to avoid hash/case drift across reloads + string legacy = Path.Combine(GetRegistryDirectory(), RegistryFileName); + File.WriteAllText(legacy, json); Debug.Log($"Saved port {port} to storage"); }