Exemplo n.º 1
0
        private bool ParseCppProject(ref string line, VisualStudioVersion version, string solutionDirectory, SolutionConfigManager configManager)
        {
            if (!line.StartsWith("Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\")"))        // Guid for C++ projects
            {
                return(false);
            }
            if (version == VisualStudioVersion.VSUnknown)
            {
                throw new InvalidDataException("Solution file is corrupt. Found C++ project section before solution file format information.");
            }

            string extension      = version >= VisualStudioVersion.VS2010 ? ".vcxproj" : ".vcproj";
            int    extensionIndex = line.IndexOf(extension, System.StringComparison.Ordinal);

            if (extensionIndex <= 0)
            {
                throw new InvalidDataException("Solution file is corrupt. Found C++ project without project fileName.");
            }
            int projectFileNameIndex = line.LastIndexOf('"', extensionIndex) + 1;

            if (projectFileNameIndex <= 0)
            {
                throw new InvalidDataException("Solution file is corrupt. Found C++ project without project fileName.");
            }

            string projectFileName = line.Substring(projectFileNameIndex, extensionIndex - projectFileNameIndex) + extension;
            string projectGuid     = line.Substring(extensionIndex + extension.Length + "\", \"".Length, GuidPlaceholder.Length);

            if (projectGuid.Length != GuidPlaceholder.Length)
            {
                throw new InvalidDataException("Solution file is corrupt. Couldn't correctly parse C++ project GUID.");
            }

            string destProjectFileName = _settings.ModifyFileName(projectFileName);

            line = line.Substring(0, projectFileNameIndex) + destProjectFileName + line.Substring(extensionIndex + extension.Length);

            configManager.AddProject(Path.GetFullPath(Path.Combine(solutionDirectory, projectFileName)), projectGuid);

            return(true);
        }