/// <summary> /// Locate all installed version of Unity3D. /// Warning: This currently only works for Windows and has only been tested on Windows 10. /// </summary> /// <returns></returns> public static Dictionary <string, string> LocateUnityInstalls() { var programData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); if (!System.IO.Directory.Exists(programData)) { throw new Exception($"Failed to find any installed Unity3d versions. 'ProgramData' folder '{programData}' does not exist."); } var startMenuProgramsDirectory = System.IO.Path.Combine(programData, "Microsoft", "Windows", "Start Menu", "Programs"); if (!System.IO.Directory.Exists(startMenuProgramsDirectory)) { throw new Exception($"Failed to find any installed Unity3d versions. Start menu programs folder '{startMenuProgramsDirectory}' does not exist."); } var installs = new Dictionary <string, string>(); foreach (var unityFolder in System.IO.Directory.EnumerateDirectories(startMenuProgramsDirectory, "Unity*")) { var unityShortcut = System.IO.Path.Combine(unityFolder, "Unity.lnk"); if (!System.IO.File.Exists(unityShortcut)) { continue; } installs.Add(new System.IO.DirectoryInfo(unityFolder).Name, WindowsShortcut.GetShortcutTarget(unityShortcut)); } return(installs); }
/// <summary> /// Locate all installed version of Unity3D on Windows. /// </summary> /// <returns></returns> public static Dictionary <string, string> LocateUnityInstallsWindows() { var programData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); if (!System.IO.Directory.Exists(programData)) { throw new Exception($"Failed to find any installed Unity3d versions. 'ProgramData' folder '{programData}' does not exist."); } var startMenuProgramsDirectory = System.IO.Path.Combine(programData, "Microsoft", "Windows", "Start Menu", "Programs"); if (!System.IO.Directory.Exists(startMenuProgramsDirectory)) { throw new Exception($"Failed to find any installed Unity3d versions. Start menu programs folder '{startMenuProgramsDirectory}' does not exist."); } var installs = new Dictionary <string, string>(); foreach (var unityFolder in System.IO.Directory.EnumerateDirectories(startMenuProgramsDirectory, "Unity*")) { var unityShortcut = System.IO.Path.Combine(unityFolder, "Unity.lnk"); if (!System.IO.File.Exists(unityShortcut)) { continue; } string exePath = WindowsShortcut.GetShortcutTarget(unityShortcut); string version = ""; if (!TryGetUnityVersion(exePath, "Data", out version)) { var fileInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(exePath); version = fileInfo.ProductVersion; } if (!installs.ContainsKey(version)) { installs.Add(version, exePath); } } return(installs); }