void AddonManager::add_installed_addons() { auto archives = scan_for_archives(); for(const auto& archive : archives) { MD5 md5 = md5_from_file(archive); add_installed_archive(archive, md5.hex_digest()); } }
void AddonManager::install_addon(const AddonId& addon_id) { { // remove addon if it already exists auto it = std::find_if(m_installed_addons.begin(), m_installed_addons.end(), [&addon_id](const std::unique_ptr<Addon>& addon) { return addon->get_id() == addon_id; }); if (it != m_installed_addons.end()) { log_debug << "reinstalling addon " << addon_id << std::endl; if ((*it)->is_enabled()) { disable_addon((*it)->get_id()); } m_installed_addons.erase(it); } else { log_debug << "installing addon " << addon_id << std::endl; } } auto& repository_addon = get_repository_addon(addon_id); std::string install_filename = FileSystem::join(m_addon_directory, repository_addon.get_filename()); m_downloader.download(repository_addon.get_url(), install_filename); MD5 md5 = md5_from_file(install_filename); if (repository_addon.get_md5() != md5.hex_digest()) { if (PHYSFS_delete(install_filename.c_str()) == 0) { log_warning << "PHYSFS_delete failed: " << PHYSFS_getLastError() << std::endl; } throw std::runtime_error("Downloading Add-on failed: MD5 checksums differ"); } else { const char* realdir = PHYSFS_getRealDir(install_filename.c_str()); if (!realdir) { throw std::runtime_error("PHYSFS_getRealDir failed: " + install_filename); } else { add_installed_archive(install_filename, md5.hex_digest()); } } }
error image_get_digest(image_t *image, unsigned char digest[image_DIGESTSZ]) { if ((image->flags & image_FLAG_HAS_DIGEST) == 0) { md5_from_file(image->file_name, image->digest); image->flags |= image_FLAG_HAS_DIGEST; } memcpy(digest, image->digest, image_DIGESTSZ); return error_OK; }