From a9452c7384ce48a56785df2397f9e3a441991afe Mon Sep 17 00:00:00 2001 From: VioletGiraffe Date: Tue, 19 Sep 2017 00:18:54 +0300 Subject: [PATCH] Fixed #156 --- CPPCheckPlugin/CPPCheckPluginPackage.cs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/CPPCheckPlugin/CPPCheckPluginPackage.cs b/CPPCheckPlugin/CPPCheckPluginPackage.cs index 7cda6c2..0458a8d 100644 --- a/CPPCheckPlugin/CPPCheckPluginPackage.cs +++ b/CPPCheckPlugin/CPPCheckPluginPackage.cs @@ -121,12 +121,11 @@ private static dynamic activeProject() foreach (dynamic o in activeProjects) { - dynamic project = o.Object; - if (!isVisualCppProject(project)) + if (!isVisualCppProject(o)) { return null; } - return project; + return o.Object; } return null; @@ -289,8 +288,8 @@ private void documentSaved(Document document) } try { - dynamic project = document.ProjectItem.ContainingProject.Object; - if (!isVisualCppProject(project)) + var kind = document.ProjectItem.ContainingProject.Kind; + if (!isVisualCppProject(document.ProjectItem.ContainingProject.Kind)) { return; } @@ -304,6 +303,7 @@ private void documentSaved(Document document) return; } + dynamic project = document.ProjectItem.ContainingProject.Object; SourceFile sourceForAnalysis = createSourceFile(document.FullName, currentConfig, project); if (sourceForAnalysis == null) return; @@ -428,7 +428,7 @@ private List getActiveSelections() project = selItem.Project; } - if (project == null || !isVisualCppProject(project.Object)) + if (project == null || !isVisualCppProject(project.Kind)) { continue; } @@ -524,13 +524,14 @@ private void checkSelections() private List getProjectFiles(Project p, Configuration currentConfig) { - dynamic project = p.Object; - if (!isVisualCppProject(project)) + if (!isVisualCppProject(p.Kind)) { System.Windows.MessageBox.Show("Only C++ projects can be checked."); return null; } + List files = new List(); + dynamic project = p.Object; dynamic projectFiles = project.Files; foreach (dynamic file in projectFiles) { @@ -641,7 +642,8 @@ private void runAnalysis(List configuredFiles, OutputWindowPane private static SourceFile createSourceFile(string filePath, Configuration targetConfig, dynamic project) { - Debug.Assert(isVisualCppProject((object)project)); + // TODO: + //Debug.Assert(isVisualCppProject((object)project)); try { var configurationName = targetConfig.ConfigurationName; @@ -680,9 +682,9 @@ private static SourceFile createSourceFile(string filePath, Configuration target } } - private static bool isVisualCppProject(object project) + private static bool isVisualCppProject(string kind) { - return implementsInterface(project, "Microsoft.VisualStudio.VCProjectEngine.VCProject"); + return kind.Equals("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"); } private static bool implementsInterface(object objectToCheck, String interfaceName)