private void addProjectsInFolder(EnvDTE.Project solutionFolder, ProSolution sln)
 {
     foreach (ProjectItem pi in solutionFolder.ProjectItems)
     {
         Project containedProject = pi.Object as Project;
         if (HelperFunctions.IsQt5Project(containedProject))
         {
             ProFileContent content = CreateProFileContent(containedProject);
             sln.ProFiles.Add(content);
         }
         else if (containedProject.Kind == ProjectKinds.vsProjectKindSolutionFolder)
         {
             addProjectsInFolder(containedProject, sln);
         }
     }
 }
        private ProSolution CreateProFileSolution(EnvDTE.Solution sln)
        {
            ProFileContent content;
            ProSolution prosln = new ProSolution(sln);

            foreach (EnvDTE.Project proj in HelperFunctions.ProjectsInSolution(sln.DTE))
            {
                try
                {
                    // only add qt projects
                    if (HelperFunctions.IsQt5Project(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 WriteProSolution(ProSolution prosln, bool openFile)
        {
            EnvDTE.Solution sln = prosln.ProjectSolution;
            if (string.IsNullOrEmpty(sln.FileName))
                return;

            FileInfo fi = new FileInfo(sln.FullName);
            DirectoryInfo slnDir = fi.Directory;
            bool 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;
                string slnName = HelperFunctions.RemoveFileNameExtension(fi);
                string 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 (System.Exception e)
                {
                    Messages.DisplayErrorMessage(e);
                    return;
                }

                ProFileContent content = new ProFileContent(null);

                ProFileOption 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 (ProFileContent profile in prosln.ProFiles)
                {
                    FileInfo fiProject = new FileInfo(profile.Project.ProjectFile);
                    string 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 (int i=0; i<content.Options.Count; i++)
                    {
                        WriteProFileOption(sw, (ProFileOption)content.Options[i]);
                    }
                }

                if (openFile)
                    dteObject.OpenFile(EnvDTE.Constants.vsViewKindTextView, slnFileName).Activate();
            }
        }