bool Settings::configFile(String::List& options, bool displayError) const { if (compiler.empty()) { if (displayError) std::cout << "Error: unknown compiler\n"; return false; } String out; out << this->path << SEP; switch (mapping) { case mappingSVNSources: out << "src" << SEP << "yuni" << SEP; break; case mappingStandard: // Nothing to do break; } out << "yuni.config." << this->compiler; if (not IO::File::Exists(out)) { if (displayError) std::cout << "Error: impossible to open the config file '" << out << "'\n"; return false; } options.clear(); IO::File::Stream file; if (file.open(out)) { CString<8192> buffer; while (file.readline(buffer)) options.push_back(buffer); } else { if (displayError) std::cout << "Error: Impossible to read '" << out << "'\n"; return false; } return true; }
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; } } }