| 115 | } |
| 116 | |
| 117 | void loadPlaylists() override |
| 118 | { |
| 119 | const std::map<PlayList, UString> playlistPaths = { |
| 120 | {PlayList::City, "playlists/city.xml"}, |
| 121 | {PlayList::Tactical, "playlists/tactical.xml"}, |
| 122 | {PlayList::Action, "playlists/action.xml"}, |
| 123 | {PlayList::Alien, "playlists/alien.xml"}, |
| 124 | |
| 125 | }; |
| 126 | |
| 127 | for (const auto &[playlist, path] : playlistPaths) |
| 128 | { |
| 129 | auto file = fw.data->fs.open(path); |
| 130 | if (!file) |
| 131 | { |
| 132 | LogWarning("Failed to open playlist file \"%s\"", path); |
| 133 | continue; |
| 134 | } |
| 135 | auto data = file.readAll(); |
| 136 | if (!data) |
| 137 | { |
| 138 | LogWarning("Failed to read playlist file \"%s\"", path); |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | pugi::xml_document doc; |
| 143 | auto result = doc.load_buffer(data.get(), file.size()); |
| 144 | if (!result) |
| 145 | { |
| 146 | LogWarning("Failed to parse playlist \"%s\" - \"%s\" at \"%llu\"", path, |
| 147 | result.description(), result.offset); |
| 148 | continue; |
| 149 | } |
| 150 | auto node = doc.child("openapoc_playlist"); |
| 151 | if (!node) |
| 152 | { |
| 153 | LogWarning("No root \"openapoc_playlist\" element in playlist file \"%s\"", path); |
| 154 | continue; |
| 155 | } |
| 156 | |
| 157 | for (auto child = node.first_child(); child; child = child.next_sibling()) |
| 158 | { |
| 159 | UString nodename = child.name(); |
| 160 | if (nodename == "playlist_entry") |
| 161 | { |
| 162 | UString entry = child.text().as_string(); |
| 163 | this->playlists[playlist].push_back(entry); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | this->playlistsLoaded = true; |
| 168 | } |
| 169 | }; |
| 170 | |
| 171 | } // namespace |