fix(ports): write both hashed and legacy port files; compare project paths case-insensitively to prevent sticky-port drift across reloads

main
David Sarno 2025-08-08 08:32:20 -07:00
parent 85202d4ccb
commit 1b892dcf49
1 changed files with 5 additions and 1 deletions

View File

@ -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");
}