| 59 | } |
| 60 | |
| 61 | sp<Form> Form::loadForm(const UString &path) |
| 62 | { |
| 63 | auto file = fw().data->fs.open(path); |
| 64 | if (!file) |
| 65 | { |
| 66 | LogWarning("Failed to open form file \"%s\"", path); |
| 67 | return nullptr; |
| 68 | } |
| 69 | auto data = file.readAll(); |
| 70 | if (!data) |
| 71 | { |
| 72 | LogWarning("Failed to read form data from \"%s\"", path); |
| 73 | return nullptr; |
| 74 | } |
| 75 | pugi::xml_document doc; |
| 76 | auto result = doc.load_buffer(data.get(), file.size()); |
| 77 | if (!result) |
| 78 | { |
| 79 | LogWarning("Failed to parse form file at \"%s\" - \"%s\" at \"%llu\"", path, |
| 80 | result.description(), (unsigned long long)result.offset); |
| 81 | return nullptr; |
| 82 | } |
| 83 | |
| 84 | auto node = doc.child("openapoc"); |
| 85 | if (!node) |
| 86 | { |
| 87 | LogWarning("No root \"openapoc\" root element in form file \"%s\"", path); |
| 88 | return nullptr; |
| 89 | } |
| 90 | auto child = node.child("form"); |
| 91 | if (!child) |
| 92 | { |
| 93 | LogWarning("No child node of \"form\" in form file \"%s\"", path); |
| 94 | return nullptr; |
| 95 | } |
| 96 | auto form = mksp<Form>(); |
| 97 | form->readFormStyle(&child); |
| 98 | return form; |
| 99 | } |
| 100 | |
| 101 | }; // namespace OpenApoc |
nothing calls this directly
no test coverage detected