| 100 | } |
| 101 | |
| 102 | void parseGamelist(SystemData* system) |
| 103 | { |
| 104 | std::string xmlpath = system->getGamelistPath(); |
| 105 | |
| 106 | if(xmlpath.empty()) |
| 107 | return; |
| 108 | |
| 109 | LOG(LogInfo) << "Parsing XML file \"" << xmlpath << "\"..."; |
| 110 | |
| 111 | pugi::xml_document doc; |
| 112 | pugi::xml_parse_result result = doc.load_file(xmlpath.c_str()); |
| 113 | |
| 114 | if(!result) |
| 115 | { |
| 116 | LOG(LogError) << "Error parsing XML file \"" << xmlpath << "\"!\n " << result.description(); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | pugi::xml_node root = doc.child(GameData::xmlTagGameList.c_str()); |
| 121 | if(!root) |
| 122 | { |
| 123 | LOG(LogError) << "Could not find <" << GameData::xmlTagGameList << "> node in gamelist \"" << xmlpath << "\"!"; |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | for(pugi::xml_node gameNode = root.child(GameData::xmlTagGame.c_str()); gameNode; gameNode = gameNode.next_sibling(GameData::xmlTagGame.c_str())) |
| 128 | { |
| 129 | pugi::xml_node pathNode = gameNode.child(GameData::xmlTagPath.c_str()); |
| 130 | if(!pathNode) |
| 131 | { |
| 132 | LOG(LogError) << "<" << GameData::xmlTagGame << "> node contains no <" << GameData::xmlTagPath << "> child!"; |
| 133 | continue; |
| 134 | } |
| 135 | |
| 136 | //convert path to generic directory seperators |
| 137 | boost::filesystem::path gamePath(pathNode.text().get()); |
| 138 | std::string path = gamePath.generic_string(); |
| 139 | |
| 140 | //expand "." |
| 141 | if(path[0] == '.') |
| 142 | { |
| 143 | path.erase(0, 1); |
| 144 | path.insert(0, system->getRootFolder()->getPath()); |
| 145 | } |
| 146 | |
| 147 | if(boost::filesystem::exists(path)) |
| 148 | { |
| 149 | GameData* game = searchFolderByPath(system->getRootFolder(), path); |
| 150 | |
| 151 | if(game == NULL) |
| 152 | game = createGameFromPath(path, system); |
| 153 | |
| 154 | //actually gather the information in the XML doc, then pass it to the game's set method |
| 155 | std::string newName, newDesc, newImage; |
| 156 | |
| 157 | if(gameNode.child(GameData::xmlTagName.c_str())) |
| 158 | { |
| 159 | game->setName(gameNode.child(GameData::xmlTagName.c_str()).text().get()); |
no test coverage detected