| 964 | } |
| 965 | |
| 966 | bool BCLMeasure::checkForUpdatesFiles() { |
| 967 | bool result = false; |
| 968 | |
| 969 | std::vector<BCLFileReference> filesToRemove; |
| 970 | std::vector<BCLFileReference> filesToAdd; |
| 971 | |
| 972 | // For all files we have on reference in the measure.xml |
| 973 | for (BCLFileReference& file : m_bclXML.files()) { |
| 974 | |
| 975 | openstudio::path filePath = file.path(); |
| 976 | // If the file has been deleted from disk, mark it for removal |
| 977 | if (!openstudio::filesystem::exists(filePath)) { |
| 978 | LOG(Info, filePath << " has been deleted"); |
| 979 | result = true; |
| 980 | // what if this is the measure.rb file? |
| 981 | filesToRemove.push_back(file); |
| 982 | |
| 983 | // Otherwise, if it's to be ignored |
| 984 | } else if (!isApprovedFile(filePath, m_directory)) { |
| 985 | // The only way this file could have been added to the XML is if the user had manually added it, |
| 986 | // or we have changed the rules in the source code. In either case, I think a log message is helpful... |
| 987 | // We filter for ALL allowed cases here, so that we catch all mistakes, eg any file that the user manually added that isn't one of the |
| 988 | // approved root files or under an approved subdirectory |
| 989 | LOG(Warn, filePath << " was present in your measure.xml but it is not an approved file and will be removed from tracking."); |
| 990 | result = true; |
| 991 | filesToRemove.push_back(file); |
| 992 | |
| 993 | // otherwise, compute new checksum, and if not the same: mark it for addition |
| 994 | } else if (file.checkForUpdate()) { |
| 995 | LOG(Info, filePath << " has been updated"); |
| 996 | result = true; |
| 997 | filesToAdd.push_back(file); |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | auto addWithUsageTypeIfNotExisting = [this, &filesToAdd](const openstudio::path& relativeFilePath, const std::string& usageType) -> bool { |
| 1002 | if (!m_bclXML.hasFile(m_directory / relativeFilePath)) { |
| 1003 | BCLFileReference fileref(m_directory, relativeFilePath, true); |
| 1004 | fileref.setUsageType(usageType); |
| 1005 | filesToAdd.push_back(fileref); |
| 1006 | return true; |
| 1007 | } else { |
| 1008 | return false; |
| 1009 | } |
| 1010 | }; |
| 1011 | |
| 1012 | // I could loop on all recursive_directory_files for the entire measureDir, |
| 1013 | // but this is likely faster by prefiltering on what has potential to be added |
| 1014 | for (const auto& [subFolderName, usageType] : approvedSubFolderToUsageMap) { |
| 1015 | openstudio::path approvedSubFolderAbsolutePath = m_directory / toPath(subFolderName); |
| 1016 | if (openstudio::filesystem::exists(approvedSubFolderAbsolutePath)) { |
| 1017 | |
| 1018 | for (auto it = openstudio::filesystem::recursive_directory_iterator(approvedSubFolderAbsolutePath); |
| 1019 | it != openstudio::filesystem::recursive_directory_iterator(); ++it) { |
| 1020 | const auto& absoluteFilePath = it->path(); |
| 1021 | |
| 1022 | if (openstudio::filesystem::is_directory(absoluteFilePath)) { |
| 1023 | const std::string name = absoluteFilePath.filename().string(); |