Skip to content

Commit 48c1b7a

Browse files
committed
fix(installer): use Application.platform for OS detection; add canonical root logs; fallback to RuntimeInformation
1 parent 86b4dc1 commit 48c1b7a

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

UnityMcpBridge/Editor/Helpers/ServerInstaller.cs

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,35 +123,57 @@ public static string GetServerPath()
123123
/// </summary>
124124
private static string GetSaveLocation()
125125
{
126+
// Prefer Unity's platform to avoid RuntimeInformation quirks under Mono/macOS
127+
try
128+
{
129+
if (Application.platform == RuntimePlatform.OSXEditor)
130+
{
131+
string home = Environment.GetFolderPath(Environment.SpecialFolder.Personal) ?? string.Empty;
132+
string appSupport = Path.Combine(home, "Library", "Application Support");
133+
string path = Path.Combine(appSupport, RootFolder);
134+
McpLog.Info($"Resolved canonical install root (macOS): {path}", always: false);
135+
return path;
136+
}
137+
if (Application.platform == RuntimePlatform.WindowsEditor)
138+
{
139+
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
140+
?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, "AppData", "Local");
141+
string path = Path.Combine(localAppData, RootFolder);
142+
McpLog.Info($"Resolved canonical install root (Windows): {path}", always: false);
143+
return path;
144+
}
145+
if (Application.platform == RuntimePlatform.LinuxEditor)
146+
{
147+
var xdg = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
148+
if (string.IsNullOrEmpty(xdg))
149+
{
150+
xdg = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, ".local", "share");
151+
}
152+
string path = Path.Combine(xdg, RootFolder);
153+
McpLog.Info($"Resolved canonical install root (Linux): {path}", always: false);
154+
return path;
155+
}
156+
}
157+
catch { }
158+
159+
// Fallback to RuntimeInformation if Application.platform is unavailable
160+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
161+
{
162+
string home = Environment.GetFolderPath(Environment.SpecialFolder.Personal) ?? string.Empty;
163+
return Path.Combine(home, "Library", "Application Support", RootFolder);
164+
}
126165
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
127166
{
128-
// Use per-user LocalApplicationData for canonical install location
129167
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
130168
?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, "AppData", "Local");
131169
return Path.Combine(localAppData, RootFolder);
132170
}
133-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
171+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
134172
{
135173
var xdg = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
136-
if (string.IsNullOrEmpty(xdg))
137-
{
138-
xdg = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty,
139-
".local", "share");
140-
}
174+
if (string.IsNullOrEmpty(xdg)) xdg = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, ".local", "share");
141175
return Path.Combine(xdg, RootFolder);
142176
}
143-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
144-
{
145-
// On macOS, use LocalApplicationData (~/Library/Application Support)
146-
var localAppSupport = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
147-
if (string.IsNullOrEmpty(localAppSupport))
148-
{
149-
// Fallback: construct from $HOME
150-
var home = Environment.GetFolderPath(Environment.SpecialFolder.Personal) ?? string.Empty;
151-
localAppSupport = Path.Combine(home, "Library", "Application Support");
152-
}
153-
return Path.Combine(localAppSupport, RootFolder);
154-
}
155177
throw new Exception("Unsupported operating system.");
156178
}
157179

0 commit comments

Comments
 (0)