Beispiel #1
0
        static bool ConvertProject(string pathToProject)
        {
            var  xmlProject = MsBuildProject.Load(pathToProject);
            bool ok         = (xmlProject != null);

            if (ok)
            {
                ok = xmlProject.AddQtMsBuildReferences();
            }
            if (ok)
            {
                ok = xmlProject.ConvertCustomBuildToQtMsBuild();
            }
            if (ok)
            {
                ok = xmlProject.EnableMultiProcessorCompilation();
            }
            if (ok)
            {
                ok = xmlProject.UpdateProjectFormatVersion();
            }
            if (ok)
            {
                ok = xmlProject.Save();
            }

            // Initialize Qt variables
            if (ok)
            {
                xmlProject.BuildTarget("QtVarsDesignTime");
            }
            return(ok);
        }
        public override void AddProjectToSolution(string projectFullPath)
        {
            var msbuildProj  = MsBuildProject.Load(projectFullPath);
            var solutionFile = MSBuildSolution.Create(SolutionPath);

            solutionFile.AddProjectToSolution(msbuildProj.Name, msbuildProj.Guid);
        }
        public override void AddItems(params string[] itemsFullPath)
        {
            if (itemsFullPath == null || itemsFullPath.Length == 0)
            {
                return;
            }

            var projectFileName = FindProject(GenContext.Current.OutputPath);

            if (string.IsNullOrEmpty(projectFileName))
            {
                throw new Exception($"There is not project file in {GenContext.Current.OutputPath}");
            }

            var msbuildProj = MsBuildProject.Load(projectFileName);

            if (msbuildProj != null)
            {
                foreach (var item in itemsFullPath)
                {
                    msbuildProj.AddItem(item);
                }

                msbuildProj.Save();
            }
        }
Beispiel #4
0
        public override string GetActiveProjectGuid()
        {
            var projectFileName = FindProject(GenContext.Current.ProjectPath);

            if (string.IsNullOrEmpty(projectFileName))
            {
                throw new Exception($"There is not project file in {GenContext.Current.ProjectPath}");
            }

            var msbuildProj = MsBuildProject.Load(projectFileName);

            return(msbuildProj.Guid);
        }
Beispiel #5
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 (ok)
            {
                string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion();
                if (!string.IsNullOrEmpty(versionWin10SDK))
                {
                    ok = xmlProject.SetDefaultWindowsSDKVersion(versionWin10SDK);
                }
            }
            if (ok)
            {
                ok = xmlProject.UpdateProjectFormatVersion();
            }

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

            // Initialize Qt variables
            xmlProject.BuildTarget("QtVarsDesignTime");
        }
Beispiel #6
0
        static bool ConvertProject(string pathToProject)
        {
            var  xmlProject = MsBuildProject.Load(pathToProject);
            bool ok         = (xmlProject != null);

            if (ok)
            {
                ok = xmlProject.AddQtMsBuildReferences();
            }
            if (ok)
            {
                ok = xmlProject.ConvertCustomBuildToQtMsBuild();
            }
            if (ok)
            {
                ok = xmlProject.EnableMultiProcessorCompilation();
            }
            if (ok)
            {
                ok = xmlProject.Save();
            }
            return(ok);
        }
Beispiel #7
0
        public void RunStarted(object automation, Dictionary <string, string> replacements,
                               WizardRunKind runKind, object[] customParams)
        {
            var serviceProvider = new ServiceProvider(automation as IServiceProvider);
            var iVsUIShell      = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;

            iVsUIShell.EnableModeless(0);

            try {
                System.IntPtr hwnd;
                iVsUIShell.GetDialogOwnerHwnd(out hwnd);

                try {
                    var className = replacements["$safeprojectname$"];
                    className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty);
                    className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty);
                    var result = new ClassNameValidationRule().Validate(className, null);
                    if (result != ValidationResult.ValidResult)
                    {
                        className = @"QtGuiApplication";
                    }

                    data.ClassName       = className;
                    data.BaseClass       = @"QMainWindow";
                    data.ClassHeaderFile = className + @".h";
                    data.ClassSourceFile = className + @".cpp";
                    data.UiFile          = data.ClassName + @".ui";
                    data.QrcFile         = data.ClassName + @".qrc";

                    var wizard = new WizardWindow(new List <WizardPage> {
                        new IntroPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt GUI Application Wizard",
                            Message = @"This wizard generates a Qt GUI application project. The "
                                      + @"application derives from QApplication and includes an empty "
                                      + @"widget." + System.Environment.NewLine
                                      + System.Environment.NewLine + "To continue, click Next.",
                            PreviousButtonEnabled = false,
                            NextButtonEnabled     = true,
                            FinishButtonEnabled   = false,
                            CancelButtonEnabled   = true
                        },
                        new ModulePage {
                            Data    = data,
                            Header  = @"Welcome to the Qt GUI Application Wizard",
                            Message = @"Select the modules you want to include in your project. The "
                                      + @"recommended modules for this project are selected by default.",
                            PreviousButtonEnabled = true,
                            NextButtonEnabled     = true,
                            FinishButtonEnabled   = false,
                            CancelButtonEnabled   = true
                        },
                        new GuiPage {
                            Data    = data,
                            Header  = @"Welcome to the Qt GUI Application Wizard",
                            Message = @"This wizard generates a Qt GUI application project. The "
                                      + @"application derives from QApplication and includes an empty "
                                      + @"widget.",
                            PreviousButtonEnabled = true,
                            NextButtonEnabled     = false,
                            FinishButtonEnabled   = data.DefaultModules.All(QtModuleInfo.IsInstalled),
                            CancelButtonEnabled   = true
                        }
                    })
                    {
                        Title = @"Qt GUI Application Wizard"
                    };
                    WindowHelper.ShowModal(wizard, hwnd);
                    if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value)
                    {
                        throw new System.Exception("Unexpected wizard return value.");
                    }
                } catch (QtVSException exception) {
                    Messages.DisplayErrorMessage(exception.Message);
                    throw; // re-throw, but keep the original exception stack intact
                }

                var version = (automation as DTE).Version;
                replacements["$ToolsVersion$"] = version;

                var vm = QtVersionManager.The();
                var vi = VersionInformation.Get(vm.GetInstallPath(vm.GetDefaultVersion()));
                replacements["$Platform$"] = vi.GetVSPlatformName();

                replacements["$Keyword$"]         = Resources.qtProjectKeyword;
                replacements["$ProjectGuid$"]     = @"{B12702AD-ABFB-343A-A199-8E24837244A3}";
                replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version);

                replacements["$classname$"]      = data.ClassName;
                replacements["$baseclass$"]      = data.BaseClass;
                replacements["$sourcefilename$"] = data.ClassSourceFile;
                replacements["$headerfilename$"] = data.ClassHeaderFile;
                replacements["$uifilename$"]     = data.UiFile;

                replacements["$precompiledheader$"]      = string.Empty;
                replacements["$precompiledsource$"]      = string.Empty;
                replacements["$DefaultApplicationIcon$"] = string.Empty;
                replacements["$centralwidget$"]          = string.Empty;

                var strHeaderInclude = data.ClassHeaderFile;
                if (data.UsePrecompiledHeader)
                {
                    strHeaderInclude = "stdafx.h\"\r\n#include \"" + data.ClassHeaderFile;
                    replacements["$precompiledheader$"] = "<None Include=\"stdafx.h\" />";
                    replacements["$precompiledsource$"] = "<None Include=\"stdafx.cpp\" />";
                }

                replacements["$include$"] = strHeaderInclude;
                replacements["$ui_hdr$"]  = "ui_" + Path.GetFileNameWithoutExtension(data.UiFile)
                                            + ".h";
                replacements["$qrcfilename$"] = data.QrcFile;

                if (data.BaseClass == "QMainWindow")
                {
                    replacements["$centralwidget$"] =
                        "\r\n  <widget class=\"QMenuBar\" name=\"menuBar\" />"
                        + "\r\n  <widget class=\"QToolBar\" name=\"mainToolBar\" />"
                        + "\r\n  <widget class=\"QWidget\" name=\"centralWidget\" />"
                        + "\r\n  <widget class=\"QStatusBar\" name=\"statusBar\" />";
                }

                if (data.AddDefaultAppIcon)
                {
                    replacements["$DefaultApplicationIcon$"] = "<None Include=\"gui.ico\" />";
                }

                if (vi.isWinRT())
                {
                    replacements["$QtWinRT$"] = "true";

                    var projDir = replacements["$destinationdirectory$"];

                    var qmakeTmpDir = Path.Combine(projDir, "qmake_tmp");
                    Directory.CreateDirectory(qmakeTmpDir);

                    var dummyPro = Path.Combine(qmakeTmpDir,
                                                string.Format("{0}.pro", replacements["$projectname$"]));
                    File.WriteAllText(dummyPro, "SOURCES = main.cpp\r\n");

                    var qmake = new QMake(null, dummyPro, false, vi);
                    qmake.RunQMake();

                    var assetsDir = Path.Combine(qmakeTmpDir, "assets");
                    if (Directory.Exists(assetsDir))
                    {
                        Directory.Move(assetsDir, Path.Combine(projDir, "assets"));
                    }

                    var manifestFile = Path.Combine(qmakeTmpDir, "Package.appxmanifest");
                    if (File.Exists(manifestFile))
                    {
                        File.Move(manifestFile, Path.Combine(projDir, "Package.appxmanifest"));
                    }

                    var projFile = Path.Combine(qmakeTmpDir,
                                                string.Format("{0}.vcxproj", replacements["$projectname$"]));

                    var proj = MsBuildProject.Load(projFile);
                    replacements["$MinimumVisualStudioVersion$"] =
                        proj.GetProperty("MinimumVisualStudioVersion");
                    replacements["$ApplicationTypeRevision$"] =
                        proj.GetProperty("ApplicationTypeRevision");
                    replacements["$WindowsTargetPlatformVersion$"] =
                        proj.GetProperty("WindowsTargetPlatformVersion");
                    replacements["$isSet_WindowsTargetPlatformVersion$"] = "true";
                    replacements["$WindowsTargetPlatformMinVersion$"]    =
                        proj.GetProperty("WindowsTargetPlatformMinVersion");
                    replacements["$Link_TargetMachine$"] =
                        proj.GetProperty("Link", "TargetMachine");

                    Directory.Delete(qmakeTmpDir, true);
                }
#if (VS2017 || VS2015)
                else
                {
                    string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion();
                    if (!string.IsNullOrEmpty(versionWin10SDK))
                    {
                        replacements["$WindowsTargetPlatformVersion$"]       = versionWin10SDK;
                        replacements["$isSet_WindowsTargetPlatformVersion$"] = "true";
                    }
                }
#endif
            } catch {
                try {
                    Directory.Delete(replacements["$destinationdirectory$"]);
                    Directory.Delete(replacements["$solutiondirectory$"]);
                } catch { }

                iVsUIShell.EnableModeless(1);
                throw new WizardBackoutException();
            }

            iVsUIShell.EnableModeless(1);
        }
Beispiel #8
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);
            }
        }
Beispiel #9
0
        public static bool ProjectToQtMsBuild(EnvDTE.Project project, bool askConfirmation = true)
        {
            if (project == null)
            {
                return(ErrorMessage(string.Format(SR.GetString("ErrorConvertingProject"), "")));
            }
            var pathToProject = project.FullName;

            if (askConfirmation &&
                MessageBox.Show(
                    SR.GetString("ConvertConfirmation"),
                    SR.GetString("ConvertTitle"),
                    MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return(WarningMessage(SR.GetString("CancelConvertingProject")));
            }
            if (project.IsDirty)
            {
                if (askConfirmation &&
                    MessageBox.Show(SR.GetString("ConvertSaveConfirmation"), project.Name,
                                    MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return(WarningMessage(SR.GetString("CancelConvertingProject")));
                }
                try {
                    project.Save();
                } catch (Exception e) {
                    return(ErrorMessage(string.Format(SR.GetString("ErrorConvertingProject"),
                                                      string.Format("{0}\r\n{1}", project.Name, e.Message))));
                }
            }

            var serviceProvider = Vsix.Instance as IServiceProvider;

            if (serviceProvider == null)
            {
                return(ErrorMessage(
                           string.Format(SR.GetString("ErrorConvertingProject"), project.Name)));
            }
            var vcProject = project.Object as VCProject;

            if (vcProject == null)
            {
                return(ErrorMessage(
                           string.Format(SR.GetString("ErrorConvertingProject"), project.Name)));
            }
            var solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution4;

            if (solution == null)
            {
                return(ErrorMessage(
                           string.Format(SR.GetString("ErrorConvertingProject"), project.Name)));
            }
            var projectGuid = new Guid(vcProject.ProjectGUID);
            var projectName = project.Name;

            try {
                if (solution.UnloadProject(
                        ref projectGuid,
                        (uint)_VSProjectUnloadStatus.UNLOADSTATUS_LoadPendingIfNeeded)
                    != VSConstants.S_OK)
                {
                    return(ErrorMessage(
                               string.Format(SR.GetString("ErrorConvertingProject"), projectName)));
                }
            } catch (Exception e) {
                return(ErrorMessage(string.Format(SR.GetString("ErrorConvertingProject"),
                                                  string.Format("{0}\r\n{1}", projectName, e.Message))));
            }

            var  xmlProject = MsBuildProject.Load(pathToProject);
            bool ok         = (xmlProject != null);

            if (ok)
            {
                ok = xmlProject.AddQtMsBuildReferences();
            }
            if (ok)
            {
                ok = xmlProject.ConvertCustomBuildToQtMsBuild();
            }
            if (ok)
            {
                ok = xmlProject.EnableMultiProcessorCompilation();
            }
            if (ok)
            {
                ok = xmlProject.Save();
            }
            try {
                solution.ReloadProject(ref projectGuid);
            } catch (Exception e) {
                return(ErrorMessage(
                           string.Format(SR.GetString("ErrorConvertingProject"),
                                         string.Format("{0}\r\n{1}", projectName, e.Message))));
            }
            if (!ok)
            {
                return(ErrorMessage(
                           string.Format(SR.GetString("ErrorConvertingProject"), projectName)));
            }
            return(true);
        }