void SolutionEvents_ProjectAdded(Project project) { ThreadHelper.ThrowIfNotOnUIThread(); if (HelperFunctions.IsQMakeProject(project)) { InitializeVCProject(project); QtProjectTracker.Add(project); var vcpro = project.Object as VCProject; VCFilter filter = null; foreach (VCFilter f in vcpro.Filters as IVCCollection) { if (f.Name == Filters.HeaderFiles().Name) { filter = f; break; } } if (filter != null) { foreach (VCFile file in filter.Files as IVCCollection) { foreach (VCFileConfiguration config in file.FileConfigurations as IVCCollection) { var tool = new QtCustomBuildTool(config); var commandLine = tool.CommandLine; if (!string.IsNullOrEmpty(commandLine) && commandLine.Contains("moc.exe")) { var matches = Regex.Matches(commandLine, "[^ ^\n]+moc\\.(exe\"|exe)"); string qtDir; if (matches.Count != 1) { var vm = QtVersionManager.The(); qtDir = vm.GetInstallPath(vm.GetDefaultVersion()); } else { qtDir = matches[0].ToString().Trim('"'); qtDir = qtDir.Remove(qtDir.LastIndexOf('\\')); qtDir = qtDir.Remove(qtDir.LastIndexOf('\\')); } qtDir = qtDir.Replace("_(QTDIR)", "$(QTDIR)"); HelperFunctions.SetDebuggingEnvironment(project, "PATH=" + Path.Combine(qtDir, "bin") + ";$(PATH)", false, config.Name); } } } } QtProjectIntellisense.Refresh(project); } }
private static string GetDirectory(EnvDTE.Project project, string type) { ThreadHelper.ThrowIfNotOnUIThread(); // check for directory in following order: // - stored in project // - stored in cache // - retrieve from moc/uic steps // - globally defined default directory // - fallback on hardcoded directory if (project != null) { if (project.Globals.get_VariablePersists(type)) { return(HelperFunctions.NormalizeRelativeFilePath((string)project.Globals[type])); } try { if (type == Resources.mocDirKeyword && mocDirCache.Contains(project.FullName)) { return((string)mocDirCache[project.FullName]); } if (type == Resources.uicDirKeyword && uicDirCache.Contains(project.FullName)) { return((string)uicDirCache[project.FullName]); } if (type == Resources.rccDirKeyword && rccDirCache.Contains(project.FullName)) { return((string)rccDirCache[project.FullName]); } QtCustomBuildTool tool = null; string configName = null; string platformName = null; var vcpro = (VCProject)project.Object; foreach (VCFile vcfile in (IVCCollection)vcpro.Files) { var name = vcfile.Name; if ((type == Resources.mocDirKeyword && HelperFunctions.IsHeaderFile(name)) || (type == Resources.mocDirKeyword && HelperFunctions.IsMocFile(name)) || (type == Resources.uicDirKeyword && HelperFunctions.IsUicFile(name)) || (type == Resources.rccDirKeyword && HelperFunctions.IsQrcFile(name))) { foreach (VCFileConfiguration config in (IVCCollection)vcfile.FileConfigurations) { tool = new QtCustomBuildTool(config); configName = config.Name.Remove(config.Name.IndexOf('|')); var vcConfig = config.ProjectConfiguration as VCConfiguration; var platform = vcConfig.Platform as VCPlatform; platformName = platform.Name; if (tool != null && (tool.CommandLine.IndexOf("moc.exe", StringComparison.OrdinalIgnoreCase) != -1 || (tool.CommandLine.IndexOf("uic.exe", StringComparison.OrdinalIgnoreCase) != -1) || (tool.CommandLine.IndexOf("rcc.exe", StringComparison.OrdinalIgnoreCase) != -1))) { break; } tool = null; } if (tool != null) { break; } } } if (tool != null) { string dir = null; var lastindex = tool.Outputs.LastIndexOf('\\'); if (tool.Outputs.LastIndexOf('/') > lastindex) { lastindex = tool.Outputs.LastIndexOf('/'); } if (lastindex == -1) { dir = "."; } else { dir = tool.Outputs.Substring(0, lastindex); } dir = dir.Replace("\"", ""); if (type == Resources.mocDirKeyword) { int index; if ((index = dir.IndexOf(configName, StringComparison.OrdinalIgnoreCase)) != -1) { dir = dir.Replace(dir.Substring(index, configName.Length), "$(ConfigurationName)"); } if ((index = dir.IndexOf(platformName, StringComparison.OrdinalIgnoreCase)) != -1) { dir = dir.Replace(dir.Substring(index, platformName.Length), "$(PlatformName)"); } mocDirCache.Add(project.FullName, HelperFunctions.NormalizeRelativeFilePath(dir)); } else if (type == Resources.uicDirKeyword) { uicDirCache.Add(project.FullName, HelperFunctions.NormalizeRelativeFilePath(dir)); } else if (type == Resources.rccDirKeyword) { rccDirCache.Add(project.FullName, HelperFunctions.NormalizeRelativeFilePath(dir)); } cleanUpCache(project); return(HelperFunctions.NormalizeRelativeFilePath(dir)); } } catch { } } return(GetDirectory(type)); }