More accurate flatpak info parser

This commit is contained in:
Patrick Nicolas
2024-11-07 19:41:35 +01:00
parent 7983745317
commit 8400a03fde
7 changed files with 20 additions and 8 deletions
+7 -2
View File
@@ -29,14 +29,19 @@ bool wivrn::is_flatpak()
return std::filesystem::exists(info_path);
}
std::optional<std::string> wivrn::flatpak_key(std::string key)
std::optional<std::string> wivrn::flatpak_key(std::string section, std::string key)
{
section = "[" + section + "]";
key += "=";
std::string line;
std::ifstream info(info_path);
bool in_section = false;
while (std::getline(info, line))
{
if (line.starts_with(key))
if (line.starts_with("["))
in_section = section == line;
if (in_section and line.starts_with(key))
return line.substr(key.size());
}
return {};