コード例 #1
0
ファイル: versions.cpp プロジェクト: MAPJe71/libyuni
	void List::loadFromPath(const String& folder)
	{
		String path;
		IO::Canonicalize(path, folder);
		if (pOptDebug)
			std::cout << "[yuni-config][debug] :: reading `" << path << "`" << std::endl;

		VersionInfo::Settings info;
		info.mapping = mappingStandard;

		String s;
		s << path << SEP << "yuni.version";
		if (not IO::File::Exists(s))
		{
			s.clear() << path << SEP << "include" << SEP << "yuni" << SEP << "yuni.version";
			if (not IO::File::Exists(s))
			{
				info.mapping = mappingSVNSources;
				s.clear() << path << SEP << "src" << SEP << "yuni" << SEP << "yuni.version";
				if (not IO::File::Exists(s))
                {
					if (pOptDebug)
						std::cout << "[yuni-config][debug] :: " << s << " not found" << std::endl;
					return;
                }
			}
		}

		IO::File::Stream file;
		if (file.open(s))
		{
			String key;
			String value;

			Version version;

			// A buffer. The given capacity will be the maximum length for a single line
			Clob buffer;
			buffer.reserve(8000);
			while (file.readline(buffer))
			{
				buffer.extractKeyValue(key, value);

				if (key.empty() || key == "[")
					continue;
				if (key == "version.hi")
					version.hi = value.to<unsigned int>();
				if (key == "version.lo")
					version.lo = value.to<unsigned int>();
				if (key == "version.rev")
					version.revision = value.to<unsigned int>();
				if (key == "version.target")
					info.compilationMode = value;
				if (key == "modules.available")
					value.split(info.modules, ";\"', \t", false);
				if (key == "support.opengl")
					info.supportOpenGL = value.to<bool>();
				if (key == "support.directx")
					info.supportDirectX = value.to<bool>();
				if (key == "redirect")
					loadFromPath(value);
				if (key == "path.include")
				{
					if (not value.empty())
						info.includePath.push_back(value);
				}
				if (key == "path.lib")
				{
					if (not value.empty())
						info.libPath.push_back(value);
				}
			}

			if (not version.null() and not info.modules.empty())
			{
				info.path = path;
				info.compiler = pCompiler;
				pList[version] = info;

				if (pOptDebug)
				{
					std::cout << "[yuni-config][debug]  - found installation `" << path
						<< "` (" << version << ")" << std::endl;
				}
			}
			else
			{
				std::cerr << "error: " << s << ": invalid file";
				if (version.null())
					std::cerr << " (invalid version)" << std::endl;
				else if (info.modules.empty())
					std::cerr << " (no module)" << std::endl;
			}
		}
	}