fix(installer): use Application.platform for OS detection; add canonical root logs; fallback to RuntimeInformation
parent
86b4dc14bc
commit
48c1b7a51e
|
|
@ -123,35 +123,57 @@ namespace MCPForUnity.Editor.Helpers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static string GetSaveLocation()
|
private static string GetSaveLocation()
|
||||||
{
|
{
|
||||||
|
// Prefer Unity's platform to avoid RuntimeInformation quirks under Mono/macOS
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Application.platform == RuntimePlatform.OSXEditor)
|
||||||
|
{
|
||||||
|
string home = Environment.GetFolderPath(Environment.SpecialFolder.Personal) ?? string.Empty;
|
||||||
|
string appSupport = Path.Combine(home, "Library", "Application Support");
|
||||||
|
string path = Path.Combine(appSupport, RootFolder);
|
||||||
|
McpLog.Info($"Resolved canonical install root (macOS): {path}", always: false);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
if (Application.platform == RuntimePlatform.WindowsEditor)
|
||||||
|
{
|
||||||
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||||
|
?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, "AppData", "Local");
|
||||||
|
string path = Path.Combine(localAppData, RootFolder);
|
||||||
|
McpLog.Info($"Resolved canonical install root (Windows): {path}", always: false);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
if (Application.platform == RuntimePlatform.LinuxEditor)
|
||||||
|
{
|
||||||
|
var xdg = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||||
|
if (string.IsNullOrEmpty(xdg))
|
||||||
|
{
|
||||||
|
xdg = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, ".local", "share");
|
||||||
|
}
|
||||||
|
string path = Path.Combine(xdg, RootFolder);
|
||||||
|
McpLog.Info($"Resolved canonical install root (Linux): {path}", always: false);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
// Fallback to RuntimeInformation if Application.platform is unavailable
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
string home = Environment.GetFolderPath(Environment.SpecialFolder.Personal) ?? string.Empty;
|
||||||
|
return Path.Combine(home, "Library", "Application Support", RootFolder);
|
||||||
|
}
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
// Use per-user LocalApplicationData for canonical install location
|
|
||||||
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||||
?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, "AppData", "Local");
|
?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, "AppData", "Local");
|
||||||
return Path.Combine(localAppData, RootFolder);
|
return Path.Combine(localAppData, RootFolder);
|
||||||
}
|
}
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
{
|
{
|
||||||
var xdg = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
var xdg = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
|
||||||
if (string.IsNullOrEmpty(xdg))
|
if (string.IsNullOrEmpty(xdg)) xdg = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty, ".local", "share");
|
||||||
{
|
|
||||||
xdg = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? string.Empty,
|
|
||||||
".local", "share");
|
|
||||||
}
|
|
||||||
return Path.Combine(xdg, RootFolder);
|
return Path.Combine(xdg, RootFolder);
|
||||||
}
|
}
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
|
||||||
{
|
|
||||||
// On macOS, use LocalApplicationData (~/Library/Application Support)
|
|
||||||
var localAppSupport = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
||||||
if (string.IsNullOrEmpty(localAppSupport))
|
|
||||||
{
|
|
||||||
// Fallback: construct from $HOME
|
|
||||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.Personal) ?? string.Empty;
|
|
||||||
localAppSupport = Path.Combine(home, "Library", "Application Support");
|
|
||||||
}
|
|
||||||
return Path.Combine(localAppSupport, RootFolder);
|
|
||||||
}
|
|
||||||
throw new Exception("Unsupported operating system.");
|
throw new Exception("Unsupported operating system.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue