/** Removes all files froma login. * \param addon The addon to be removed. * \return True if uninstallation was successful. */ bool AddonsManager::uninstall(const Addon &addon) { std::cout << "[addons] Uninstalling <" << core::stringc(addon.getName()).c_str() << ">\n"; // addon is a const reference, and to avoid removing the const, we // find the proper index again to modify the installed state int index = getAddonIndex(addon.getId()); assert(index>=0 && index < (int)m_addons_list.getData().size()); m_addons_list.getData()[index].setInstalled(false); //remove the addons directory bool error = false; // if the user deleted the data directory for an add-on with // filesystem tools, removeTrack/removeKart will trigger an assert // because the kart/track was never added in the first place if (file_manager->fileExists(addon.getDataDir())) { error = !file_manager->removeDirectory(addon.getDataDir()); if(addon.getType()=="kart") { kart_properties_manager->removeKart(addon.getId()); } else if(addon.getType()=="track" || addon.getType()=="arena") { track_manager->removeTrack(addon.getId()); } } saveInstalled(); return !error; } // uninstall
/** Removes all files froma login. * \param addon The addon to be removed. * \return True if uninstallation was successful. */ bool AddonsManager::uninstall(const Addon &addon) { std::cout << "[addons] Uninstalling <" << core::stringc(addon.getName()).c_str() << ">\n"; // addon is a const reference, and to avoid removing the const, we // find the proper index again to modify the installed state int index = getAddonIndex(addon.getId()); assert(index>=0 && index < (int)m_addons_list.getData().size()); m_addons_list.getData()[index].setInstalled(false); //remove the addons directory bool error = !file_manager->removeDirectory(addon.getDataDir()); if(addon.getType()=="kart") { kart_properties_manager->removeKart(addon.getId()); } else if(addon.getType()=="track" || addon.getType()=="arena") { track_manager->removeTrack(addon.getId()); } saveInstalled(); return !error; } // uninstall
/** Installs or updates (i.e. = install on top of an existing installation) an * addon. It checks for the directories and then unzips the file (which must * already have been downloaded). * \param addon Addon data for the addon to install. * \return true if installation was successful. */ bool AddonsManager::install(const Addon &addon) { bool success=true; const std::string &id = addon.getId(); file_manager->checkAndCreateDirForAddons(id, addon.getTypeDirectory()); //extract the zip in the addons folder called like the addons name std::string base_name = StringUtils::getBasename(addon.getZipFileName()); std::string from = file_manager->getAddonsFile("tmp/"+base_name); std::string to = addon.getDataDir(); success = extract_zip(from, to); if (!success) { // TODO: show a message in the interface std::cerr << "[addons] Failed to unzip '" << from << "' to '" << to << "'\n"; std::cerr << "[addons] Zip file will not be removed.\n"; return false; } if(!file_manager->removeFile(from)) { std::cerr << "[addons] Problems removing temporary file '" << from << "'.\n"; } int index = getAddonIndex(addon.getId()); assert(index>=0 && index < (int)m_addons_list.getData().size()); m_addons_list.getData()[index].setInstalled(true); if(addon.getType()=="kart") { // We have to remove the mesh of the kart since otherwise it remains // cashed (if a kart is updated), and will therefore be found again // when reloading the karts. This is important on one hand since we // reload all karts (this function is easily available) and existing // karts will not reload their meshes. const KartProperties *prop = kart_properties_manager->getKart(addon.getId()); // If the model already exist, first remove the old kart if(prop) kart_properties_manager->removeKart(addon.getId()); kart_properties_manager->loadKart(addon.getDataDir()); } else if (addon.getType()=="track" || addon.getType()=="arena") { Track *track = track_manager->getTrack(addon.getId()); if(track) track_manager->removeTrack(addon.getId()); track_manager->loadTrack(addon.getDataDir()); } saveInstalled(); return true; } // install