| 280 | } |
| 281 | |
| 282 | RootNodePtr MapResource::loadMapNode() |
| 283 | { |
| 284 | RootNodePtr rootNode; |
| 285 | |
| 286 | // Open a stream - will throw on failure |
| 287 | auto stream = openMapfileStream(); |
| 288 | |
| 289 | if (!stream || !stream->isOpen()) |
| 290 | { |
| 291 | throw OperationException(_("Could not open map stream")); |
| 292 | } |
| 293 | |
| 294 | try |
| 295 | { |
| 296 | // Get the mapformat |
| 297 | auto format = algorithm::determineMapFormat(stream->getStream(), _extension); |
| 298 | |
| 299 | if (!format) |
| 300 | { |
| 301 | throw OperationException(_("Could not determine map format")); |
| 302 | } |
| 303 | |
| 304 | // Instantiate a loader to process the map file stream |
| 305 | MapResourceLoader loader(stream->getStream(), *format); |
| 306 | |
| 307 | // Load the root from the primary stream (throws on failure or cancel) |
| 308 | rootNode = loader.load(); |
| 309 | |
| 310 | if (rootNode) |
| 311 | { |
| 312 | rootNode->setName(_name); |
| 313 | } |
| 314 | |
| 315 | // Check if an info file is supported by this map format |
| 316 | if (format->allowInfoFileCreation()) |
| 317 | { |
| 318 | auto infoFileStream = openInfofileStream(); |
| 319 | |
| 320 | if (infoFileStream && infoFileStream->isOpen()) |
| 321 | { |
| 322 | loader.loadInfoFile(infoFileStream->getStream(), rootNode); |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | refreshLastModifiedTime(); |
| 327 | } |
| 328 | catch (const OperationException& ex) |
| 329 | { |
| 330 | // Re-throw the exception, prepending the map file path to the message (if not cancelled) |
| 331 | throw ex.operationCancelled() ? ex : |
| 332 | OperationException(fmt::format(_("Failure reading map file:\n{0}\n\n{1}"), getAbsoluteResourcePath(), ex.what())); |
| 333 | } |
| 334 | |
| 335 | return rootNode; |
| 336 | } |
| 337 | |
| 338 | stream::MapResourceStream::Ptr MapResource::openFileStream(const std::string& path) |
| 339 | { |
nothing calls this directly
no test coverage detected