unity-mcp/MCPForUnity/Editor/Dependencies/DependencyManager.cs

148 lines
5.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using MCPForUnity.Editor.Dependencies.Models;
using MCPForUnity.Editor.Dependencies.PlatformDetectors;
using MCPForUnity.Editor.Helpers;
using UnityEditor;
using UnityEngine;
namespace MCPForUnity.Editor.Dependencies
{
/// <summary>
/// Main orchestrator for dependency validation and management
/// </summary>
public static class DependencyManager
{
private static readonly List<IPlatformDetector> _detectors = new List<IPlatformDetector>
{
new WindowsPlatformDetector(),
new MacOSPlatformDetector(),
new LinuxPlatformDetector()
};
private static IPlatformDetector _currentDetector;
/// <summary>
/// Get the platform detector for the current operating system
/// </summary>
public static IPlatformDetector GetCurrentPlatformDetector()
{
if (_currentDetector == null)
{
_currentDetector = _detectors.FirstOrDefault(d => d.CanDetect);
if (_currentDetector == null)
{
throw new PlatformNotSupportedException($"No detector available for current platform: {RuntimeInformation.OSDescription}");
}
}
return _currentDetector;
}
/// <summary>
/// Perform a comprehensive dependency check
/// </summary>
public static DependencyCheckResult CheckAllDependencies()
{
var result = new DependencyCheckResult();
try
{
var detector = GetCurrentPlatformDetector();
McpLog.Info($"Checking dependencies on {detector.PlatformName}...", always: false);
// Check Python
var pythonStatus = detector.DetectPython();
result.Dependencies.Add(pythonStatus);
// Check UV
var uvStatus = detector.DetectUV();
result.Dependencies.Add(uvStatus);
// Check MCP Server
var serverStatus = detector.DetectMCPServer();
result.Dependencies.Add(serverStatus);
// Generate summary and recommendations
result.GenerateSummary();
GenerateRecommendations(result, detector);
McpLog.Info($"Dependency check completed. System ready: {result.IsSystemReady}", always: false);
}
catch (Exception ex)
{
McpLog.Error($"Error during dependency check: {ex.Message}");
result.Summary = $"Dependency check failed: {ex.Message}";
result.IsSystemReady = false;
}
return result;
}
/// <summary>
/// Get installation recommendations for the current platform
/// </summary>
public static string GetInstallationRecommendations()
{
try
{
var detector = GetCurrentPlatformDetector();
return detector.GetInstallationRecommendations();
}
catch (Exception ex)
{
return $"Error getting installation recommendations: {ex.Message}";
}
}
/// <summary>
/// Get platform-specific installation URLs
/// </summary>
public static (string pythonUrl, string uvUrl) GetInstallationUrls()
{
try
{
var detector = GetCurrentPlatformDetector();
return (detector.GetPythonInstallUrl(), detector.GetUVInstallUrl());
}
catch
{
return ("https://python.org/downloads/", "https://docs.astral.sh/uv/getting-started/installation/");
}
}
private static void GenerateRecommendations(DependencyCheckResult result, IPlatformDetector detector)
{
var missing = result.GetMissingDependencies();
if (missing.Count == 0)
{
result.RecommendedActions.Add("All dependencies are available. You can start using MCP for Unity.");
return;
}
foreach (var dep in missing)
{
if (dep.Name == "Python")
{
feat: lower minimum Python requirement to 3.10+ (#362) * feat: lower minimum Python requirement to 3.10+ - Updated Python version requirement from 3.11+ to 3.10+ across all platform detectors - Added Python 3.10 to MacOS framework search paths for broader compatibility - Modified version validation logic to accept Python 3.10 or higher - Updated documentation and error messages to reflect new minimum Python version - Changed pyproject.toml requires-python field to ">=3.10" - Updated badges and requirements in README files to show Python 3.10 support * feat: add Python 3.10 and 3.11 to Windows path detection - Added Python 3.10 installation path to LocalApplicationData search locations - Added Python 3.10 and 3.11 paths to ProgramFiles search locations - Expanded Python version compatibility to support older installations while maintaining support for newer versions * feat: add Python 3.14 support and update path detection - Added Python 3.14 installation paths to Windows and macOS platform detectors - Removed legacy Python 3.9 paths from Windows path detection - Updated Windows installation recommendations to suggest Python 3.10 or higher - Added additional Python framework paths (3.10, 3.11) for macOS UV package manager detection - Extended UV executable path detection to include Python 3.14 locations on both platforms * Reduce size of README img * Revert "Reduce size of README img" This reverts commit 6fb99c7047bdef3610fb94dd3741c71c9e3ffcc1. * Adjust size in README to maintain quality but be smaller
2025-11-01 03:44:10 +08:00
result.RecommendedActions.Add($"Install Python 3.10+ from: {detector.GetPythonInstallUrl()}");
}
else if (dep.Name == "UV Package Manager")
{
result.RecommendedActions.Add($"Install UV package manager from: {detector.GetUVInstallUrl()}");
}
else if (dep.Name == "MCP Server")
{
result.RecommendedActions.Add("MCP Server will be installed automatically when needed.");
}
}
if (result.GetMissingRequired().Count > 0)
{
result.RecommendedActions.Add("Use the Setup Wizard (Window > MCP for Unity > Setup Wizard) for guided installation.");
}
}
}
}