| | |
| | | /****************************************************************************
|
| | | **
|
| | | ** Copyright (C) 2016 The Qt Company Ltd.
|
| | | ** Copyright (C) 2022 The Qt Company Ltd.
|
| | | ** Contact: https://www.qt.io/licensing/
|
| | | **
|
| | | ** This file is part of the Qt VS Tools.
|
| | |
| | | **
|
| | | ****************************************************************************/
|
| | |
|
| | | using EnvDTE;
|
| | | using EnvDTE80;
|
| | | using Microsoft.VisualStudio.VCProjectEngine;
|
| | | using System;
|
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using System.IO;
|
| | | using System.Text.RegularExpressions;
|
| | | using System.Windows.Forms;
|
| | | using Microsoft.VisualStudio.Shell;
|
| | | using Microsoft.VisualStudio.VCProjectEngine;
|
| | | using EnvDTE;
|
| | | using EnvDTE80;
|
| | |
|
| | | namespace QtVsTools.Core
|
| | | {
|
| | |
| | | /// </summary>
|
| | | public class ProjectExporter
|
| | | {
|
| | | private DTE dteObject;
|
| | | private readonly DTE dteObject;
|
| | |
|
| | | public ProjectExporter(DTE dte)
|
| | | {
|
| | |
| | |
|
| | | private ProSolution CreateProFileSolution(Solution sln)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | ProFileContent content;
|
| | | var prosln = new ProSolution(sln);
|
| | |
|
| | | foreach (var proj in HelperFunctions.ProjectsInSolution(sln.DTE)) {
|
| | | try {
|
| | | // only add qt projects
|
| | | if (HelperFunctions.IsQtProject(proj)) {
|
| | | if (HelperFunctions.IsVsToolsProject(proj)) {
|
| | | content = CreateProFileContent(proj);
|
| | | prosln.ProFiles.Add(content);
|
| | | } else if (proj.Kind == ProjectKinds.vsProjectKindSolutionFolder) {
|
| | |
| | |
|
| | | private void addProjectsInFolder(Project solutionFolder, ProSolution sln)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | foreach (ProjectItem pi in solutionFolder.ProjectItems) {
|
| | | var containedProject = pi.Object as Project;
|
| | | if (HelperFunctions.IsQtProject(containedProject)) {
|
| | | if (HelperFunctions.IsVsToolsProject(containedProject)) {
|
| | | var content = CreateProFileContent(containedProject);
|
| | | sln.ProFiles.Add(content);
|
| | | } else if (containedProject.Kind == ProjectKinds.vsProjectKindSolutionFolder) {
|
| | |
| | |
|
| | | private static ProFileContent CreateProFileContent(Project project)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | ProFileOption option;
|
| | | var qtPro = QtProject.Create(project);
|
| | | var content = new ProFileContent(qtPro.VCProject);
|
| | |
| | | if (config.ConfigurationType == ConfigurationTypes.typeStaticLibrary)
|
| | | option.List.Add("staticlib");
|
| | | if (linker != null) {
|
| | | var linkerRule = linker as IVCRulePropertyStorage;
|
| | | var generateDebugInformation = (linkerRule != null) ?
|
| | | var generateDebugInformation = (linker is IVCRulePropertyStorage linkerRule) ?
|
| | | linkerRule.GetUnevaluatedPropertyValue("GenerateDebugInformation") : null;
|
| | | if (generateDebugInformation != "false")
|
| | | option.List.Add("debug");
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | if (qtPro.IsDesignerPluginProject()) {
|
| | | option.List.Add("designer");
|
| | | var legacyDesigner = Legacy.QtProject.IsDesignerPluginProject(qtPro);
|
| | | var plugin = legacyDesigner | Core.QtProject.IsQtPlugin(qtPro);
|
| | | if (plugin)
|
| | | option.List.Add("plugin");
|
| | | }
|
| | | if (legacyDesigner)
|
| | | option.List.Add("designer");
|
| | |
|
| | | // add defines
|
| | | option = new ProFileOption("DEFINES");
|
| | |
| | | option.List.Add(project.Name + ".rc");
|
| | | }
|
| | |
|
| | | if (qtPro.IsDesignerPluginProject()) {
|
| | | if (plugin) {
|
| | | option = new ProFileOption("target.path");
|
| | | option.ShortComment = "Install the plugin in the designer plugins directory.";
|
| | | if (legacyDesigner)
|
| | | option.ShortComment = "Installs the plugin in the designer plugins directory.";
|
| | | else
|
| | | option.ShortComment = "Installs the plugin in the plugins directory.";
|
| | | option.IncludeComment = true;
|
| | | option.AssignSymbol = ProFileOption.AssignType.AT_Equals;
|
| | | option.List.Add("$$[QT_INSTALL_PLUGINS]/designer");
|
| | | if (legacyDesigner)
|
| | | option.List.Add("$$[QT_INSTALL_PLUGINS]/designer");
|
| | | else
|
| | | option.List.Add("$$[QT_INSTALL_PLUGINS]");
|
| | | content.Options.Add(option);
|
| | |
|
| | | option = new ProFileOption("INSTALLS");
|
| | |
| | |
|
| | | private static ProFileContent CreatePriFileContent(Project project, string priFileDirectory)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | ProFileOption option;
|
| | | var qtPro = QtProject.Create(project);
|
| | | var content = new ProFileContent(qtPro.VCProject);
|
| | |
| | |
|
| | | private static void AddIncludePaths(Project project, ProFileOption option, string includePaths)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | if (QtProject.GetFormatVersion(project) >= Resources.qtMinFormatVersion_ClProperties)
|
| | | return;
|
| | |
|
| | |
| | | if (!d.StartsWith("$(qtdir)\\include", StringComparison.OrdinalIgnoreCase) &&
|
| | | !d.StartsWith(qtDir + "\\include", StringComparison.OrdinalIgnoreCase) &&
|
| | | !d.EndsWith("win32-msvc2005", StringComparison.OrdinalIgnoreCase)) {
|
| | |
|
| | | var vcConfig = project.ConfigurationManager.ActiveConfiguration.Object
|
| | | as VCConfiguration;
|
| | | if (vcConfig != null)
|
| | | if (project.ConfigurationManager.ActiveConfiguration.Object is VCConfiguration vcConfig)
|
| | | HelperFunctions.ExpandString(ref d, vcConfig);
|
| | | if (HelperFunctions.IsAbsoluteFilePath(d))
|
| | | d = HelperFunctions.GetRelativePath(project.FullName, d);
|
| | |
| | | qtDir = Environment.GetEnvironmentVariable("QTDIR");
|
| | | if (qtDir == null)
|
| | | qtDir = "";
|
| | |
|
| | | qtDir = HelperFunctions.NormalizeRelativeFilePath(qtDir);
|
| | |
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | if (paths != null) {
|
| | | foreach (var s in paths.Split(';', ',')) {
|
| | |
| | |
|
| | | private static void AddModules(QtProject qtPrj, ProFileOption optionQT, ProFileOption optionCONFIG)
|
| | | {
|
| | | foreach (var module in QtModules.Instance.GetAvailableModules()) {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | var vm = QtVersionManager.The();
|
| | | var versionInfo = vm.GetVersionInfo(qtPrj.Project);
|
| | | if (versionInfo == null)
|
| | | versionInfo = vm.GetVersionInfo(vm.GetDefaultVersion());
|
| | |
|
| | | foreach (var module in QtModules.Instance.GetAvailableModules(versionInfo.qtMajor)) {
|
| | | if (!qtPrj.HasModule(module.Id))
|
| | | continue;
|
| | |
|
| | |
| | |
|
| | | private void WriteProSolution(ProSolution prosln, bool openFile)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | var sln = prosln.ProjectSolution;
|
| | | if (string.IsNullOrEmpty(sln.FileName))
|
| | | return;
|
| | |
| | |
|
| | | private void WriteProFile(ProFileContent content, string proFile, string priFileToInclude, bool openFile)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | StreamWriter sw;
|
| | | if (File.Exists(proFile)) {
|
| | | if (MessageBox.Show(SR.GetString("ExportProject_ExistsOverwriteQuestion", proFile),
|
| | |
| | | WriteProFileOptions(sw, content.Options);
|
| | | }
|
| | |
|
| | | // open the file in vs
|
| | | if (openFile)
|
| | | if (openFile) // open the file in vs
|
| | | dteObject.OpenFile(Constants.vsViewKindTextView, proFile).Activate();
|
| | | }
|
| | |
|
| | |
| | | public static void SyncIncludeFiles(VCProject vcproj, List<string> priFiles,
|
| | | List<string> projFiles, DTE dte, bool flat, FakeFilter fakeFilter)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | var cmpPriFiles = new List<string>(priFiles.Count);
|
| | | foreach (var s in priFiles)
|
| | | cmpPriFiles.Add(HelperFunctions.NormalizeFilePath(s).ToLower());
|
| | |
| | |
|
| | | public void ExportToProFile()
|
| | | {
|
| | | var expDlg = new ExportProjectDialog();
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | var sln = dteObject.Solution;
|
| | | var prosln = CreateProFileSolution(sln);
|
| | |
| | | return;
|
| | | }
|
| | |
|
| | | var expDlg = new ExportProjectDialog();
|
| | | expDlg.ProFileSolution = prosln;
|
| | | expDlg.StartPosition = FormStartPosition.CenterParent;
|
| | | var ww = new MainWinWrapper(dteObject);
|
| | |
| | |
|
| | | public string ExportToPriFile(Project proj)
|
| | | {
|
| | | VCProject vcproj;
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | if (HelperFunctions.IsQtProject(proj)) {
|
| | | VCProject vcproj;
|
| | | if (HelperFunctions.IsVsToolsProject(proj)) {
|
| | | try {
|
| | | vcproj = (VCProject)proj.Object;
|
| | | } catch (Exception e) {
|
| | |
| | |
|
| | | public void ExportToPriFile(Project proj, string fileName)
|
| | | {
|
| | | var priFile = new FileInfo(fileName);
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | var priFile = new FileInfo(fileName);
|
| | | var content = CreatePriFileContent(proj, priFile.DirectoryName);
|
| | | WritePriFile(content, priFile.FullName);
|
| | | }
|