private static List <UnityInstallationInfo> GetPossibleInstallationInfos()
        {
            var installations = GetPossibleApplicationPaths();

            return(installations.Select(path =>
            {
                var version = UnityVersion.GetVersionByAppPath(path);
                return new UnityInstallationInfo(version, path);
            }).ToList());
        }
示例#2
0
        public static UnityInstallationInfo GetApplicationInfo(Version version, UnityVersion unityVersion)
        {
            var possible            = GetPossibleInstallationInfos().ToArray();
            var possibleWithVersion = possible.Where(a => a.Version != null).ToList();

            // fast check is we have a best choice
            var bestChoice = TryGetBestChoice(version, possibleWithVersion);

            if (bestChoice != null)
            {
                return(bestChoice);
            }

            // best choice not found by version - try version by path then
            var pathForSolution  = unityVersion.GetActualAppPathForSolution();
            var versionByAppPath = UnityVersion.GetVersionByAppPath(pathForSolution);

            if (versionByAppPath != null)
            {
                possibleWithVersion.Add(new UnityInstallationInfo(versionByAppPath, pathForSolution));
            }

            // check best choice again, since newly added version may be best one
            bestChoice = TryGetBestChoice(version, possibleWithVersion);
            if (bestChoice != null)
            {
                return(bestChoice);
            }

            var choice1 = possibleWithVersion.Where(a =>
                                                    a.Version.Major == version.Major && a.Version.Minor == version.Minor &&
                                                    a.Version.Build == version.Build).OrderBy(b => b.Version).LastOrDefault();

            if (choice1 != null)
            {
                return(choice1);
            }
            var choice2 = possibleWithVersion.Where(a =>
                                                    a.Version.Major == version.Major && a.Version.Minor == version.Minor).OrderBy(b => b.Version).LastOrDefault();

            if (choice2 != null)
            {
                return(choice2);
            }
            var choice3 = possibleWithVersion.Where(a => a.Version.Major == version.Major)
                          .OrderBy(b => b.Version).LastOrDefault();

            if (choice3 != null)
            {
                return(choice3);
            }
            var choice4 = possibleWithVersion
                          .OrderBy(b => b.Version).LastOrDefault();

            if (choice4 != null)
            {
                return(choice4);
            }

            var worstChoice = possible.LastOrDefault();

            return(worstChoice);
        }