aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2022-07-11 14:36:14 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2022-07-26 10:47:18 +0000
commit633f609f1025fa530858ce8e6e5af5a719eca071 (patch)
tree8bfb13d2b937d36cca1bcdf6f382e429dcb19618
parenta93bf4a5aa619a9679d4fc2dd90951369b071f8d (diff)
Rename IsProjectInSolution to ProjectFromSolution
Since the return value has to be checked anyway, lets return the project and check for null instead of bool. Helps simplifying the implementation of ProjectImporter::ImportProject(). Change-Id: I8114aa59d058f7dbe2004f01dadcee6082538cec Reviewed-by: Miguel Costa <miguel.costa@qt.io>
-rw-r--r--QtVsTools.Core/HelperFunctions.cs10
-rw-r--r--QtVsTools.Core/ProjectImporter.cs14
2 files changed, 9 insertions, 15 deletions
diff --git a/QtVsTools.Core/HelperFunctions.cs b/QtVsTools.Core/HelperFunctions.cs
index 68f658df..cf8894a2 100644
--- a/QtVsTools.Core/HelperFunctions.cs
+++ b/QtVsTools.Core/HelperFunctions.cs
@@ -179,16 +179,16 @@ namespace QtVsTools.Core
}
}
- public static bool IsProjectInSolution(DTE dteObject, string fullName)
+ public static Project ProjectFromSolution(DTE dteObject, string fullName)
{
ThreadHelper.ThrowIfNotOnUIThread();
- var fi = new FileInfo(fullName);
+ fullName = new FileInfo(fullName).FullName;
foreach (var p in ProjectsInSolution(dteObject)) {
- if (p.FullName.ToLower() == fi.FullName.ToLower())
- return true;
+ if (p.FullName.Equals(fullName, StringComparison.OrdinalIgnoreCase))
+ return p;
}
- return false;
+ return null;
}
/// <summary>
diff --git a/QtVsTools.Core/ProjectImporter.cs b/QtVsTools.Core/ProjectImporter.cs
index eca8f684..8ae7c092 100644
--- a/QtVsTools.Core/ProjectImporter.cs
+++ b/QtVsTools.Core/ProjectImporter.cs
@@ -31,7 +31,6 @@ using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell;
-using Microsoft.VisualStudio.VCProjectEngine;
using EnvDTE;
namespace QtVsTools.Core
@@ -123,9 +122,11 @@ namespace QtVsTools.Core
try {
if (CheckQtVersion(versionInfo)) {
// no need to add the project again if it's already there...
- if (!HelperFunctions.IsProjectInSolution(dteObject, VCInfo.FullName)) {
+ var fullName = VCInfo.FullName;
+ var pro = HelperFunctions.ProjectFromSolution(dteObject, fullName);
+ if (pro == null) {
try {
- dteObject.Solution.AddFromFile(VCInfo.FullName, false);
+ pro = dteObject.Solution.AddFromFile(fullName, false);
} catch (Exception /*exception*/) {
Messages.Print("--- (Import): Generated project could not be loaded.");
Messages.Print("--- (Import): Please look in the output above for errors and warnings.");
@@ -136,13 +137,6 @@ namespace QtVsTools.Core
Messages.Print("Project already in Solution");
}
- Project pro = null;
- foreach (var p in HelperFunctions.ProjectsInSolution(dteObject)) {
- if (p.FullName.ToLower() == VCInfo.FullName.ToLower()) {
- pro = p;
- break;
- }
- }
if (pro != null) {
var qtPro = QtProject.Create(pro);
qtPro.SetQtEnvironment();