コード例 #1
0
        private FileInfo RunQmake(FileInfo mainInfo, string ext, bool recursive, VersionInformation vi)
        {
            var name = mainInfo.Name.Remove(mainInfo.Name.IndexOf('.'));

            var VCInfo = new FileInfo(mainInfo.DirectoryName + "\\" + name + ext);

            if (!VCInfo.Exists || DialogResult.Yes == MessageBox.Show(SR.GetString("ExportProject_ProjectExistsRegenerateOrReuse", VCInfo.Name),
                                                                      SR.GetString("ProjectExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Messages.PaneMessage(dteObject, "--- (Import): Generating new project of " + mainInfo.Name + " file");

                var waitDialog = WaitDialog.Start(
                    "Open Qt Project File",
                    "Generating Visual Studio project...",
                    null, null, 2, false, true);

                var qmake    = new QMakeImport(vi, mainInfo.FullName, recursive, dteObject);
                int exitCode = qmake.Run(setVCVars: true);
                waitDialog.Stop();

                if (exitCode == 0)
                {
                    return(VCInfo);
                }
            }

            return(null);
        }
コード例 #2
0
 public QMakeImport(
     VersionInformation qtVersion,
     string proFilePath,
     bool recursiveRun = false,
     EnvDTE.DTE dte    = null)
     : base(qtVersion, dte)
 {
     ProFile        = proFilePath;
     TemplatePrefix = "vc";
     if (recursiveRun)
     {
         Recursive = true;
     }
     else
     {
         OutputFile = Path.ChangeExtension(proFilePath, ".vcxproj");
     }
     Vars = new Dictionary <string, string>
     {
         { "QMAKE_INCDIR_QT", @"$(QTDIR)\include" },
         { "QMAKE_LIBDIR", @"$(QTDIR)\lib" },
         { "QMAKE_MOC", @"$(QTDIR)\bin\moc.exe" },
         { "QMAKE_QMAKE", @"$(QTDIR)\bin\qmake.exe" },
     };
 }
コード例 #3
0
        public QMakeConf(VersionInformation versionInfo)
        {
            Entries            = new Hashtable();
            QMakeSpecDirectory = Path.Combine(versionInfo.qtDir, "mkspecs", "default");
            var qmakeConf = Path.Combine(QMakeSpecDirectory, "qmake.conf");

            // Starting from Qt5 beta2 there is no more "\\mkspecs\\default" folder available
            // To find location of "qmake.conf" there is a need to run "qmake -query" command
            // This is what happens below.
            if (!File.Exists(qmakeConf))
            {
                var qmakeQuery   = new QMakeQuery(versionInfo);
                var qmakespecDir = qmakeQuery.query("QMAKE_XSPEC");

                if (qmakeQuery.ErrorValue == 0 && !string.IsNullOrEmpty(qmakespecDir))
                {
                    QMakeSpecDirectory = Path.Combine(versionInfo.qtDir, "mkspecs", qmakespecDir);
                    qmakeConf          = Path.Combine(QMakeSpecDirectory, "qmake.conf");
                }

                if (qmakeQuery.ErrorValue != 0 || !File.Exists(qmakeConf))
                {
                    throw new QtVSException("qmake.conf expected at " + qmakeConf + " not found");
                }
            }

            ParseFile(qmakeConf);
        }
コード例 #4
0
ファイル: ProjectImporter.cs プロジェクト: phlebos/vstools
        private FileInfo RunQmake(FileInfo mainInfo, string ext, bool recursive, VersionInformation vi)
        {
            var name = mainInfo.Name.Remove(mainInfo.Name.IndexOf('.'));

            var VCInfo = new FileInfo(mainInfo.DirectoryName + "\\" + name + ext);

            if (!VCInfo.Exists || DialogResult.Yes == MessageBox.Show(SR.GetString("ExportProject_ProjectExistsRegenerateOrReuse", VCInfo.Name),
                                                                      SR.GetString("ProjectExists"), MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Messages.PaneMessage(dteObject, "--- (Import): Generating new project of " + mainInfo.Name + " file");

                var dialog = new InfoDialog(mainInfo.Name);
                var qmake  = new QMake(dteObject, mainInfo.FullName, recursive, vi);

                qmake.CloseEvent           += dialog.CloseEventHandler;
                qmake.PaneMessageDataEvent += PaneMessageDataReceived;

                var qmakeThread = new System.Threading.Thread(qmake.RunQMake);
                qmakeThread.Start();
                dialog.ShowDialog();
                qmakeThread.Join();

                if (qmake.ErrorValue == 0)
                {
                    return(VCInfo);
                }
            }

            return(null);
        }
コード例 #5
0
ファイル: QtVersionManager.cs プロジェクト: freall/vstools
        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);
        }
コード例 #6
0
ファイル: ProjectImporter.cs プロジェクト: jmd/vstools
        private void ImportQMakeProject(FileInfo projectFile, VersionInformation vi)
        {
            var xmlProject = MsBuildProject.Load(projectFile.FullName);
            var qtDir      = ParseQtDirFromFileContent(xmlProject.ProjectXml, vi);

            if (!string.IsNullOrEmpty(qtDir))
            {
                xmlProject.ReplacePath(qtDir, "$(QTDIR)\\");
                // qmake tends to write relative and absolute paths into the .vcxproj file
                if (!Path.IsPathRooted(qtDir)) // if the project is on the same drive as Qt.
                {
                    xmlProject.ReplacePath(vi.qtDir + '\\', "$(QTDIR)\\");
                }
            }
            else
            {
                Messages.PaneMessage(dteObject, SR.GetString("ImportProject_CannotFindQtDirectory", projectFile.Name));
            }
            xmlProject.ReplacePath(projectFile.DirectoryName, ".");
            xmlProject.AddQtMsBuildReferences();
            xmlProject.ConvertCustomBuildToQtMsBuild();
            xmlProject.EnableMultiProcessorCompilation();
#if (VS2017 || VS2015)
            string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion();
            if (!string.IsNullOrEmpty(versionWin10SDK))
            {
                xmlProject.SetDefaultWindowsSDKVersion(versionWin10SDK);
            }
#endif
            xmlProject.Save();
        }
コード例 #7
0
ファイル: VersionInformation.cs プロジェクト: freall/vstools
        public static VersionInformation Get(string qtDir)
        {
            qtDir = qtDir ?? Environment.GetEnvironmentVariable("QTDIR");
            if (qtDir == null)
            {
                return(null);
            }

            try {
                qtDir = new FileInfo(qtDir).FullName.ToUpperInvariant();
            } catch {
                return(null);
            }
            var versionInfo = _cache[qtDir] as VersionInformation;

            if (versionInfo == null)
            {
                versionInfo = new VersionInformation(qtDir);
                _cache.Add(qtDir, versionInfo);
            }
            else if (versionInfo.qtDir == null)
            {
                versionInfo   = new VersionInformation(qtDir);
                _cache[qtDir] = versionInfo;
            }
            return(versionInfo);
        }
コード例 #8
0
ファイル: QMake.cs プロジェクト: phlebos/vstools
 public QMake(EnvDTE.DTE dte, string fileName, bool recursiveRun, VersionInformation vi)
 {
     dteObject            = dte;
     file                 = fileName;
     recursive            = recursiveRun;
     qtVersionInformation = vi;
 }
コード例 #9
0
        private void ReplaceQtDirInProject(FileInfo projectFile, VersionInformation vi)
        {
            var sr      = projectFile.OpenText();
            var content = sr.ReadToEnd();

            sr.Close();

            var qtDir = ParseQtDirFromFileContent(content, vi);

            if (!string.IsNullOrEmpty(qtDir))
            {
                content = content.Replace(qtDir, "$(QTDIR)\\", StringComparison.OrdinalIgnoreCase);
                // qmake tends to write relative and absolute paths into the .vcxproj file
                if (!Path.IsPathRooted(qtDir)) // if the project is on the same drive as Qt.
                {
                    content = content.Replace(vi.qtDir + '\\', "$(QTDIR)\\", StringComparison.OrdinalIgnoreCase);
                }
                var sw = projectFile.CreateText();
                sw.Write(content);
                sw.Flush();
                sw.Close();
            }
            else
            {
                Messages.PaneMessage(dteObject, SR.GetString("ImportProject_CannotFindQtDirectory", projectFile.Name));
            }
        }
コード例 #10
0
ファイル: ProjectImporter.cs プロジェクト: phlebos/vstools
 private static bool CheckQtVersion(VersionInformation vi)
 {
     if (!vi.qt5Version)
     {
         Messages.DisplayWarningMessage(SR.GetString("ExportProject_EditProjectFileManually"));
         return(false);
     }
     return(true);
 }
コード例 #11
0
ファイル: ProjectImporter.cs プロジェクト: phlebos/vstools
        private void ImportQMakeSolution(FileInfo solutionFile, VersionInformation vi)
        {
            var projects = ParseProjectsFromSolution(solutionFile);

            foreach (var project in projects)
            {
                var projectInfo = new FileInfo(project);
                ImportQMakeProject(projectInfo, vi);
            }
        }
コード例 #12
0
        private void ReplaceAbsoluteQtDirInSolution(FileInfo solutionFile, VersionInformation vi)
        {
            var projects = ParseProjectsFromSolution(solutionFile);

            foreach (var project in projects)
            {
                var projectInfo = new FileInfo(project);
                ReplaceQtDirInProject(projectInfo, vi);
            }
        }
コード例 #13
0
ファイル: QMakeConf.cs プロジェクト: freall/vstools
        public QMakeConf(VersionInformation versionInfo, QMakeQuery qmakeQuery = null)
        {
            Entries            = new Hashtable();
            QMakeSpecDirectory = Path.Combine(versionInfo.qtDir, "mkspecs", "default");
            var qmakeConf = Path.Combine(QMakeSpecDirectory, "qmake.conf");

            // Starting from Qt5 beta2 there is no more "\\mkspecs\\default" folder available
            // To find location of "qmake.conf" there is a need to run "qmake -query" command
            // This is what happens below.
            if (!File.Exists(qmakeConf))
            {
                if (qmakeQuery == null)
                {
                    qmakeQuery = new QMakeQuery(versionInfo);
                }

                string qtPrefix = qmakeQuery["QT_INSTALL_PREFIX"];
                if (string.IsNullOrEmpty(qtPrefix))
                {
                    throw new QtVSException("qmake error: no value for QT_INSTALL_PREFIX");
                }

                string qtArchData = qmakeQuery["QT_INSTALL_ARCHDATA"];
                if (string.IsNullOrEmpty(qtArchData))
                {
                    throw new QtVSException("qmake error: no value for QT_INSTALL_ARCHDATA");
                }

                string qmakeXSpec = qmakeQuery["QMAKE_XSPEC"];
                if (string.IsNullOrEmpty(qtArchData))
                {
                    throw new QtVSException("qmake error: no value for QMAKE_XSPEC");
                }

                qmakeConf = Path.Combine(qtPrefix, qtArchData, "mkspecs", qmakeXSpec, "qmake.conf");

                if (!File.Exists(qmakeConf))
                {
                    throw new QtVSException("qmake.conf expected at " + qmakeConf + " not found");
                }
            }

            ParseFile(qmakeConf);
        }
コード例 #14
0
        private void ImportQMakeProject(FileInfo projectFile, VersionInformation vi)
        {
            var xmlProject = MsBuildProject.Load(projectFile.FullName);

            xmlProject.ReplacePath(vi.qtDir, "$(QTDIR)");
            xmlProject.ReplacePath(projectFile.DirectoryName, ".");

            bool ok = xmlProject.AddQtMsBuildReferences();

            if (ok)
            {
                ok = xmlProject.ConvertCustomBuildToQtMsBuild();
            }
            if (ok)
            {
                ok = xmlProject.EnableMultiProcessorCompilation();
            }
#if (VS2019 || VS2017 || VS2015)
            if (ok)
            {
                string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion();
                if (!string.IsNullOrEmpty(versionWin10SDK))
                {
                    ok = xmlProject.SetDefaultWindowsSDKVersion(versionWin10SDK);
                }
            }
#endif
            if (ok)
            {
                ok = xmlProject.UpdateProjectFormatVersion();
            }

            if (!ok)
            {
                Messages.PaneMessage(dteObject,
                                     SR.GetString("ImportProject_CannotConvertProject", projectFile.Name));
            }
            xmlProject.Save();

            // Initialize Qt variables
            xmlProject.BuildTarget("QtVarsDesignTime");
        }
コード例 #15
0
ファイル: ProjectImporter.cs プロジェクト: phlebos/vstools
        private static string ParseQtDirFromFileContent(string vcFileContent, VersionInformation vi)
        {
            // Starting with Qt5 beta2 the "\\mkspecs\\default" folder is not available anymore,
            var mkspecs = "mkspecs\\"; // try to use the spec we run qmake with.
            var index   = vi.QMakeSpecDirectory.IndexOf(mkspecs, StringComparison.OrdinalIgnoreCase);

            if (!string.IsNullOrEmpty(vi.QMakeSpecDirectory) && index >= 0)
            {
                mkspecs = vi.QMakeSpecDirectory.Substring(index);
            }

            var uicQtDir    = FindQtDirFromExtension(vcFileContent, "bin\\uic.exe");
            var rccQtDir    = FindQtDirFromExtension(vcFileContent, "bin\\rcc.exe");
            var mkspecQtDir = FindQtDirFromExtension(vcFileContent, mkspecs);

            if (!string.IsNullOrEmpty(mkspecQtDir))
            {
                if (!string.IsNullOrEmpty(uicQtDir) && uicQtDir.ToLower() != mkspecQtDir.ToLower())
                {
                    return("");
                }
                if (!string.IsNullOrEmpty(rccQtDir) && rccQtDir.ToLower() != mkspecQtDir.ToLower())
                {
                    return("");
                }
                return(mkspecQtDir);
            }
            if (!string.IsNullOrEmpty(uicQtDir))
            {
                if (!string.IsNullOrEmpty(rccQtDir) && rccQtDir.ToLower() != uicQtDir.ToLower())
                {
                    return("");
                }
                return(uicQtDir);
            }
            if (!string.IsNullOrEmpty(rccQtDir))
            {
                return(rccQtDir);
            }
            return(string.Empty);
        }
コード例 #16
0
 public QMake(VersionInformation qtVersion, EnvDTE.DTE dte = null)
 {
     Debug.Assert(qtVersion != null);
     QtVersion = qtVersion;
     Dte       = dte ?? VsServiceProvider.GetService <EnvDTE.DTE>();
 }
コード例 #17
0
 public List <string> GetLibs(bool isDebugCfg, VersionInformation vi)
 {
     return(GetLibs(isDebugCfg, vi.IsStaticBuild(), vi.LibInfix()));
 }
コード例 #18
0
ファイル: QMakeQuery.cs プロジェクト: freall/vstools
 public QMakeQuery(VersionInformation vi) : base(vi)
 {
 }
コード例 #19
0
ファイル: QtVersionManager.cs プロジェクト: wencan002/vstools
        /// <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);
        }
コード例 #20
0
ファイル: QMakeQuery.cs プロジェクト: wencan002/vstools
 public QMakeQuery(VersionInformation vi)
     : base(null, string.Empty, false, vi)
 {
     qtVersionInformation = vi;
 }