| 434 | } |
| 435 | |
| 436 | void Base::XMLReader::readFiles(zipios::ZipInputStream& zipstream) const |
| 437 | { |
| 438 | // It's possible that not all objects inside the document could be created, e.g. if a module |
| 439 | // is missing that would know these object types. So, there may be data files inside the zip |
| 440 | // file that cannot be read. We simply ignore these files. |
| 441 | // On the other hand, however, it could happen that a file should be read that is not part of |
| 442 | // the zip file. This happens e.g. if a document is written without GUI up but is read with GUI |
| 443 | // up. In this case the associated GUI document asks for its file which is not part of the ZIP |
| 444 | // file, then. |
| 445 | // In either case it's guaranteed that the order of the files is kept. |
| 446 | zipios::ConstEntryPointer entry; |
| 447 | try { |
| 448 | entry = zipstream.getNextEntry(); |
| 449 | } |
| 450 | catch (const std::exception&) { |
| 451 | // There is no further file at all. This can happen if the |
| 452 | // project file was created without GUI |
| 453 | return; |
| 454 | } |
| 455 | std::vector<FileEntry>::const_iterator it = FileList.begin(); |
| 456 | Base::SequencerLauncher seq("Importing project files...", FileList.size()); |
| 457 | while (entry->isValid() && it != FileList.end()) { |
| 458 | std::vector<FileEntry>::const_iterator jt = it; |
| 459 | // Check if the current entry is registered, otherwise check the next registered files as |
| 460 | // soon as both file names match |
| 461 | while (jt != FileList.end() && entry->getName() != jt->FileName) { |
| 462 | ++jt; |
| 463 | } |
| 464 | // If this condition is true both file names match and we can read-in the data, otherwise |
| 465 | // no file name for the current entry in the zip was registered. |
| 466 | if (jt != FileList.end()) { |
| 467 | try { |
| 468 | Base::Reader reader(zipstream, jt->FileName, FileVersion); |
| 469 | jt->Object->RestoreDocFile(reader); |
| 470 | if (reader.getLocalReader()) { |
| 471 | reader.getLocalReader()->readFiles(zipstream); |
| 472 | } |
| 473 | } |
| 474 | catch (...) { |
| 475 | // For any exception we just continue with the next file. |
| 476 | // It doesn't matter if the last reader has read more or |
| 477 | // less data than the file size would allow. |
| 478 | // All what we need to do is to notify the user about the |
| 479 | // failure. |
| 480 | if (entry->getSize() == 0) { |
| 481 | Base::Console().log("Skipped empty embedded file: %s\n", entry->toString().c_str()); |
| 482 | } |
| 483 | else { |
| 484 | Base::Console().error( |
| 485 | "Reading failed from embedded file: %s\n", |
| 486 | entry->toString().c_str() |
| 487 | ); |
| 488 | FailedFiles.push_back(jt->FileName); |
| 489 | } |
| 490 | } |
| 491 | // Go to the next registered file name |
| 492 | it = jt + 1; |
| 493 | } |
no test coverage detected