| 960 | } |
| 961 | } |
| 962 | void DataImpl::readAliasFile(const UString &path) |
| 963 | { |
| 964 | LogInfo("Reading aliases from \"%s\"", path); |
| 965 | |
| 966 | auto file = this->fs.open(path); |
| 967 | if (!file) |
| 968 | { |
| 969 | LogWarning("Failed to open alias file \"%s\"", path); |
| 970 | return; |
| 971 | } |
| 972 | |
| 973 | auto data = file.readAll(); |
| 974 | if (!data) |
| 975 | { |
| 976 | LogWarning("Failed to read data from alias file \"%s\"", path); |
| 977 | return; |
| 978 | } |
| 979 | |
| 980 | pugi::xml_document doc; |
| 981 | auto parseResult = doc.load_buffer(data.get(), file.size()); |
| 982 | if (!parseResult) |
| 983 | { |
| 984 | LogWarning("Failed to parse alias file at \"%s\" - \"%s\" at \"%llu\"", path, |
| 985 | parseResult.description(), (unsigned long long)parseResult.offset); |
| 986 | return; |
| 987 | } |
| 988 | auto openapocNode = doc.child("openapoc"); |
| 989 | if (!openapocNode) |
| 990 | { |
| 991 | LogWarning("Failed to find \"openapoc\" root node in alias file at \"%s\"", path); |
| 992 | return; |
| 993 | } |
| 994 | for (auto aliasNode = openapocNode.child("alias"); aliasNode; |
| 995 | aliasNode = aliasNode.next_sibling("alias")) |
| 996 | { |
| 997 | UString name = aliasNode.attribute("id").value(); |
| 998 | if (name.empty()) |
| 999 | { |
| 1000 | LogWarning("Alias with missing 'id' attribute in \"%s\"", path); |
| 1001 | continue; |
| 1002 | } |
| 1003 | UString type = aliasNode.attribute("type").value(); |
| 1004 | if (type.empty()) |
| 1005 | { |
| 1006 | LogWarning("Alias \"%s\" with missing 'type' attribute in \"%s\"", name, path); |
| 1007 | continue; |
| 1008 | } |
| 1009 | UString value = aliasNode.text().get(); |
| 1010 | if (value.empty()) |
| 1011 | { |
| 1012 | LogWarning("Alias \"%s\" with missing value in \"%s\"", name, path); |
| 1013 | continue; |
| 1014 | } |
| 1015 | if (type == "sample") |
| 1016 | { |
| 1017 | this->addSampleAlias(name, value); |
| 1018 | } |
| 1019 | else if (type == "music") |
no test coverage detected