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)) { content = CreateProFileContent(proj); prosln.ProFiles.Add(content); } else if (proj.Kind == ProjectKinds.vsProjectKindSolutionFolder) { addProjectsInFolder(proj, prosln); } } catch { // Catch all exceptions. Try to add as many projects as possible. } } return(prosln); }
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)) { var content = CreateProFileContent(containedProject); sln.ProFiles.Add(content); } else if (containedProject.Kind == ProjectKinds.vsProjectKindSolutionFolder) { addProjectsInFolder(containedProject, sln); } } }
private void WriteProSolution(ProSolution prosln, bool openFile) { ThreadHelper.ThrowIfNotOnUIThread(); var sln = prosln.ProjectSolution; if (string.IsNullOrEmpty(sln.FileName)) { return; } var fi = new FileInfo(sln.FullName); var slnDir = fi.Directory; var createSlnFile = false; if ((slnDir != null) && (prosln.ProFiles.Count > 1)) { if (MessageBox.Show(SR.GetString("ExportProject_SolutionProFileBuildIn", slnDir.FullName), SR.GetString("ExportSolution"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { createSlnFile = true; } } if (createSlnFile) { StreamWriter sw; var slnName = HelperFunctions.RemoveFileNameExtension(fi); var slnFileName = slnDir.FullName + "\\" + slnName + ".pro"; if (File.Exists(slnFileName)) { if (MessageBox.Show(SR.GetString("ExportProject_ExistsOverwriteQuestion", slnFileName), SR.GetString("ExportSolution"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } } try { sw = new StreamWriter(File.Create(slnFileName)); } catch (Exception e) { Messages.DisplayErrorMessage(e); return; } var content = new ProFileContent(null); var option = new ProFileOption("TEMPLATE"); option.NewOption = null; // just one option... option.AssignSymbol = ProFileOption.AssignType.AT_Equals; content.Options.Add(option); option.List.Add("subdirs"); option = new ProFileOption("SUBDIRS"); option.ShortComment = "#Projects"; content.Options.Add(option); string proFullName, relativePath; char[] trimChars = { '\\' }; foreach (var profile in prosln.ProFiles) { var fiProject = new FileInfo(profile.Project.ProjectFile); var projectBaseName = HelperFunctions.RemoveFileNameExtension(fiProject); proFullName = profile.Project.ProjectDirectory + projectBaseName + ".pro"; relativePath = HelperFunctions.GetRelativePath(slnDir.FullName, proFullName); relativePath = relativePath.TrimEnd(trimChars); relativePath = HelperFunctions.ChangePathFormat(relativePath.Remove(0, 2)); option.List.Add(relativePath); } using (sw) { sw.WriteLine(Resources.exportSolutionHeader); for (var i = 0; i < content.Options.Count; i++) { WriteProFileOption(sw, content.Options[i]); } } if (openFile) { dteObject.OpenFile(Constants.vsViewKindTextView, slnFileName).Activate(); } } }