Пример #1
0
        private FileInfo RunQmake(FileInfo mainInfo, string ext, bool recursive, VersionInformation vi)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            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.Print("--- (Import): Generating new project of " + mainInfo.Name + " file");

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

                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
        private VersionInformation(string qtDirIn)
        {
            qtDir = qtDirIn;

            try {
                var qmakeQuery = new QMakeQuery(this);
                SetupPlatformSpecificData(qmakeQuery);

                // Find version number
                var strVersion = qmakeQuery["QT_VERSION"];
                if (!string.IsNullOrEmpty(strVersion))
                {
                    var versionParts = strVersion.Split('.');
                    if (versionParts.Length != 3)
                    {
                        qtDir = null;
                        return;
                    }
                    qtMajor = uint.Parse(versionParts[0]);
                    qtMinor = uint.Parse(versionParts[1]);
                    qtPatch = uint.Parse(versionParts[2]);
                }
                else
                {
                    var inF         = new StreamReader(Locate_qglobal_h());
                    var rgxpVersion = new Regex("#define\\s*QT_VERSION\\s*0x(?<number>\\d+)", RegexOptions.Multiline);
                    var contents    = inF.ReadToEnd();
                    inF.Close();
                    var matchObj = rgxpVersion.Match(contents);
                    if (!matchObj.Success)
                    {
                        qtDir = null;
                        return;
                    }

                    strVersion = matchObj.Groups[1].ToString();
                    var version = Convert.ToUInt32(strVersion, 16);
                    qtMajor = version >> 16;
                    qtMinor = (version >> 8) & 0xFF;
                    qtPatch = version & 0xFF;
                }

                try {
                    QtInstallDocs = qmakeQuery["QT_INSTALL_DOCS"];
                } catch { }
            } catch {
                qtDir = null;
                return;
            }

            // Get VS project settings
            try {
                var tempProData = new StringBuilder();
                tempProData.AppendLine("SOURCES = main.cpp");

                var modules = QtModules.Instance.GetAvailableModules()
                              .Where((QtModule mi) => mi.Selectable);

                foreach (QtModule mi in modules)
                {
                    tempProData.AppendLine(string.Format(
                                               "qtHaveModule({0}): HEADERS += {0}.h", mi.proVarQT));
                }

                var randomName = Path.GetRandomFileName();
                var tempDir    = Path.Combine(Path.GetTempPath(), randomName);
                Directory.CreateDirectory(tempDir);

                var tempPro = Path.Combine(tempDir, string.Format("{0}.pro", randomName));
                File.WriteAllText(tempPro, tempProData.ToString());

                var qmake = new QMakeImport(this, tempPro);
                qmake.DisableWarnings = true;
                qmake.Run(setVCVars: true);

                var tempVcxproj = Path.Combine(tempDir, string.Format("{0}.vcxproj", randomName));
                var msbuildProj = MsBuildProject.Load(tempVcxproj);

                Directory.Delete(tempDir, recursive: true);

                var availableModules = msbuildProj.GetItems("ClInclude")
                                       .Select((string s) => Path.GetFileNameWithoutExtension(s));

                _IsModuleAvailable = modules.ToDictionary(
                    (QtModule mi) => mi.proVarQT,
                    (QtModule mi) => availableModules.Contains(mi.proVarQT));

                VC_MinimumVisualStudioVersion =
                    msbuildProj.GetProperty("MinimumVisualStudioVersion");
                VC_ApplicationTypeRevision =
                    msbuildProj.GetProperty("ApplicationTypeRevision");
                VC_WindowsTargetPlatformVersion =
                    msbuildProj.GetProperty("WindowsTargetPlatformVersion");
                VC_WindowsTargetPlatformMinVersion =
                    msbuildProj.GetProperty("WindowsTargetPlatformMinVersion");
                VC_PlatformToolset =
                    msbuildProj.GetProperty("PlatformToolset");
                VC_Link_TargetMachine =
                    msbuildProj.GetProperty("Link", "TargetMachine");
            } catch (Exception e) {
                throw new QtVSException("Error reading VS project settings", e);
            }
        }