| 844 | } |
| 845 | |
| 846 | void RemoteBCL::onDownloadComplete() { |
| 847 | const auto src = m_downloadFile->fileName(); |
| 848 | std::string componentType; |
| 849 | |
| 850 | // Extract the files to a temp location |
| 851 | openstudio::path tempDest = openstudio::filesystem::temp_directory_path() / toPath(m_downloadUid + '/'); |
| 852 | |
| 853 | if (openstudio::filesystem::is_directory(tempDest)) { |
| 854 | removeDirectory(tempDest); |
| 855 | } |
| 856 | openstudio::filesystem::create_directories(tempDest); |
| 857 | |
| 858 | std::vector<openstudio::path> createdFiles; |
| 859 | try { |
| 860 | openstudio::UnzipFile uf(src); |
| 861 | createdFiles = uf.extractAllFiles(tempDest); |
| 862 | } catch (const std::exception& e) { |
| 863 | LOG(Error, "Cannot unzip file: " << e.what()); |
| 864 | } |
| 865 | openstudio::filesystem::remove(src); |
| 866 | |
| 867 | // search for component.xml or measure.xml file |
| 868 | boost::optional<openstudio::path> xmlPath; |
| 869 | |
| 870 | for (const auto& path : createdFiles) { |
| 871 | if (path.filename() == toPath("component.xml")) { |
| 872 | componentType = "component"; |
| 873 | m_lastComponentDownload.reset(); |
| 874 | xmlPath = path; |
| 875 | break; |
| 876 | } else if (path.filename() == toPath("measure.xml")) { |
| 877 | componentType = "measure"; |
| 878 | m_lastMeasureDownload.reset(); |
| 879 | xmlPath = path; |
| 880 | break; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | if (xmlPath) { |
| 885 | // cppcheck-suppress shadowVariable |
| 886 | path src = xmlPath->parent_path(); |
| 887 | path dest = src.parent_path(); |
| 888 | openstudio::filesystem::remove(dest / toPath("DISCLAIMER.txt")); |
| 889 | openstudio::filesystem::remove(dest / toPath("README.txt")); |
| 890 | openstudio::filesystem::remove(dest / toPath("output.xml")); |
| 891 | copyDirectory(src, dest); |
| 892 | removeDirectory(src); |
| 893 | |
| 894 | if (componentType == "component") { |
| 895 | path componentXmlPath = dest / toPath("component.xml"); |
| 896 | // open the component to figure out uid and vid |
| 897 | BCLComponent component(toString(componentXmlPath.parent_path())); |
| 898 | std::string uid = component.uid(); |
| 899 | std::string versionId = component.versionId(); |
| 900 | |
| 901 | // check if component has proper uid and vid |
| 902 | if (!uid.empty() && !versionId.empty()) { |
| 903 | dest = LocalBCL::instance().libraryPath() / uid / versionId; |
nothing calls this directly
no test coverage detected