@@ -529,27 +529,48 @@ bool ImportProject::importSlnx(const std::string& filename, const std::vector<st
529529 return false ;
530530 }
531531
532+ if (std::strcmp (rootnode->Name (), " Solution" ) != 0 ) {
533+ errors.emplace_back (" Invalid Visual Studio solution file format" );
534+ return false ;
535+ }
536+
532537 std::map<std::string, std::string, cppcheck::stricmp> variables;
533538 variables[" SolutionDir" ] = Path::simplifyPath (Path::getPathFromFilename (filename));
534539
535540 bool found = false ;
536541 std::vector<SharedItemsProject> sharedItemsProjects;
537542
543+ auto processProject = [&](const tinyxml2::XMLElement* projectNode) {
544+ const char * pathAttribute = projectNode->Attribute (" Path" );
545+ if (pathAttribute == nullptr )
546+ return ;
547+
548+ std::string vcxproj (pathAttribute);
549+ vcxproj = Path::toNativeSeparators (std::move (vcxproj));
550+
551+ if (Path::getFilenameExtensionInLowerCase (vcxproj) != " .vcxproj" )
552+ return ; // skip other project types
553+
554+ if (!Path::isAbsolute (vcxproj))
555+ vcxproj = variables[" SolutionDir" ] + vcxproj;
556+
557+ vcxproj = Path::fromNativeSeparators (std::move (vcxproj));
558+ if (!importVcxproj (vcxproj, variables, " " , fileFilters, sharedItemsProjects)) {
559+ errors.emplace_back (" failed to load '" + vcxproj + " ' from Visual Studio solution" );
560+ return ;
561+ }
562+ found = true ;
563+ };
564+
538565 for (const tinyxml2::XMLElement* node = rootnode->FirstChildElement (); node; node = node->NextSiblingElement ()) {
539566 const char * name = node->Name ();
540567 if (std::strcmp (name, " Project" ) == 0 ) {
541- const char * labelAttribute = node->Attribute (" Path" );
542- if (labelAttribute) {
543- std::string vcxproj (labelAttribute);
544- vcxproj = Path::toNativeSeparators (std::move (vcxproj));
545- if (!Path::isAbsolute (vcxproj))
546- vcxproj = variables[" SolutionDir" ] + vcxproj;
547- vcxproj = Path::fromNativeSeparators (std::move (vcxproj));
548- if (!importVcxproj (vcxproj, variables, " " , fileFilters, sharedItemsProjects)) {
549- errors.emplace_back (" failed to load '" + vcxproj + " ' from Visual Studio solution" );
550- return false ;
568+ processProject (node);
569+ } else if (std::strcmp (name, " Folder" ) == 0 ) {
570+ for (const tinyxml2::XMLElement* childNode = node->FirstChildElement (); childNode; childNode = childNode->NextSiblingElement ()) {
571+ if (std::strcmp (childNode->Name (), " Project" ) == 0 ) {
572+ processProject (childNode);
551573 }
552- found = true ;
553574 }
554575 }
555576 }
0 commit comments