Пример #1
0
        public VersionInformation GetVersionInfo(string name)
        {
            if (name == "$(DefaultQtVersion)")
            {
                name = GetDefaultVersion();
            }
            if (name == null)
            {
                return(null);
            }
            if (versionCache == null)
            {
                versionCache = new Hashtable();
            }

            var vi = versionCache[name] as VersionInformation;

            if (vi == null)
            {
                var qtdir = GetInstallPath(name);
                versionCache[name] = vi = VersionInformation.Get(qtdir);
                if (vi != null)
                {
                    vi.name = name;
                }
            }
            return(vi);
        }
Пример #2
0
        /// <summary>
        /// Check if all Qt versions are valid and readable.
        /// </summary>
        /// Also sets the default Qt version to the newest version, if needed.
        /// <param name="errorMessage"></param>
        /// <returns>true, if we found an invalid version</returns>
        public bool HasInvalidVersions(out string errorMessage)
        {
            var validVersions   = new List <QtVersion>();
            var invalidVersions = new List <string>();

            foreach (var v in GetVersions())
            {
                if (v == "$(DefaultQtVersion)")
                {
                    continue;
                }
                try {
                    var vi        = VersionInformation.Get(GetInstallPath(v));
                    var qtVersion = new QtVersion();
                    qtVersion.name = v;
                    qtVersion.vi   = vi;
                    validVersions.Add(qtVersion);
                } catch (Exception) {
                    invalidVersions.Add(v);
                }
            }

            if (invalidVersions.Count > 0)
            {
                errorMessage = "These Qt version are inaccessible:\n";

                foreach (var invalidVersion in invalidVersions)
                {
                    errorMessage += invalidVersion + " in " + GetInstallPath(invalidVersion) + "\n";
                }
                errorMessage += "Make sure that you have read access to all files in your Qt directories.";

                // Is the default Qt version invalid?
                var isDefaultQtVersionInvalid = false;
                var defaultQtVersionName      = GetDefaultVersion();
                if (string.IsNullOrEmpty(defaultQtVersionName))
                {
                    isDefaultQtVersionInvalid = true;
                }
                else
                {
                    foreach (var name in invalidVersions)
                    {
                        if (name == defaultQtVersionName)
                        {
                            isDefaultQtVersionInvalid = true;
                            break;
                        }
                    }
                }

                // find the newest valid Qt version that can be used as default version
                if (isDefaultQtVersionInvalid && validVersions.Count > 0)
                {
                    QtVersion defaultQtVersion = null;
                    foreach (var v in validVersions)
                    {
                        if (defaultQtVersion == null)
                        {
                            defaultQtVersion = v;
                            continue;
                        }
                        if (defaultQtVersion.vi.qtMajor < v.vi.qtMajor ||
                            (defaultQtVersion.vi.qtMajor == v.vi.qtMajor && (defaultQtVersion.vi.qtMinor < v.vi.qtMinor ||
                                                                             (defaultQtVersion.vi.qtMinor == v.vi.qtMinor && defaultQtVersion.vi.qtPatch < v.vi.qtPatch))))
                        {
                            defaultQtVersion = v;
                        }
                    }
                    if (defaultQtVersion != null)
                    {
                        SaveDefaultVersion(defaultQtVersion.name);
                    }
                }

                return(true);
            }
            errorMessage = null;
            return(false);
        }