void CGUIDialogAddonInfo::OnRollback() { CGUIDialogContextMenu* dlg = (CGUIDialogContextMenu*)g_windowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU); CAddonDatabase database; database.Open(); CContextButtons buttons; for (unsigned int i=0;i<m_rollbackVersions.size();++i) { CStdString label(m_rollbackVersions[i]); if (m_rollbackVersions[i].Equals(m_localAddon->Version().c_str())) label += " "+g_localizeStrings.Get(24094); if (database.IsAddonBlacklisted(m_localAddon->ID(),label)) label += " "+g_localizeStrings.Get(24095); buttons.Add(i,label); } int choice; if ((choice=dlg->ShowAndGetChoice(buttons)) > -1) { // blacklist everything newer for (unsigned int j=choice+1;j<m_rollbackVersions.size();++j) database.BlacklistAddon(m_localAddon->ID(),m_rollbackVersions[j]); CStdString path = "special://home/addons/packages/"; path += m_localAddon->ID()+"-"+m_rollbackVersions[choice]+".zip"; // needed as cpluff won't downgrade if (!m_localAddon->IsType(ADDON_SERVICE)) //we will handle this for service addons in CAddonInstallJob::OnPostInstall CAddonMgr::Get().RemoveAddon(m_localAddon->ID()); CAddonInstaller::Get().InstallFromZip(path); database.RemoveAddonFromBlacklist(m_localAddon->ID(),m_rollbackVersions[choice]); Close(); } }
void CGUIDialogAddonInfo::OnRollback() { if (!g_passwordManager.CheckMenuLock(WINDOW_ADDON_BROWSER)) return; CGUIDialogContextMenu* dlg = (CGUIDialogContextMenu*)g_windowManager.GetWindow(WINDOW_DIALOG_CONTEXT_MENU); CAddonDatabase database; database.Open(); CContextButtons buttons; for (unsigned int i=0;i<m_rollbackVersions.size();++i) { std::string label(m_rollbackVersions[i]); if (m_rollbackVersions[i] == m_localAddon->Version().asString()) label += " "+g_localizeStrings.Get(24094); if (database.IsAddonBlacklisted(m_localAddon->ID(),label)) label += " "+g_localizeStrings.Get(24095); buttons.Add(i,label); } int choice; if ((choice=dlg->ShowAndGetChoice(buttons)) > -1) { // blacklist everything newer for (unsigned int j=choice+1;j<m_rollbackVersions.size();++j) database.BlacklistAddon(m_localAddon->ID(),m_rollbackVersions[j]); std::string path = "special://home/addons/packages/"; path += m_localAddon->ID()+"-"+m_rollbackVersions[choice]+".zip"; //FIXME: this is probably broken // needed as cpluff won't downgrade CAddonInstaller::GetInstance().InstallFromZip(path); database.RemoveAddonFromBlacklist(m_localAddon->ID(),m_rollbackVersions[choice]); Close(); } }
void CGUIDialogAddonInfo::OnUpdate() { if (!m_localAddon) return; CAddonDatabase database; if (!database.Open()) return; std::vector<std::pair<AddonVersion, std::string>> versions; if (!database.GetAvailableVersions(m_localAddon->ID(), versions)) return; CFileItemList items; if (XFILE::CDirectory::GetDirectory("special://home/addons/packages/", items, ".zip", DIR_FLAG_NO_FILE_DIRS)) { for (int i = 0; i < items.Size(); ++i) { std::string packageId; std::string versionString; if (AddonVersion::SplitFileName(packageId, versionString, items[i]->GetLabel())) { if (packageId == m_localAddon->ID()) { std::string hash; std::string path(items[i]->GetPath()); if (database.GetPackageHash(m_localAddon->ID(), items[i]->GetPath(), hash)) { std::string md5 = CUtil::GetFileMD5(path); if (md5 == hash) versions.push_back(std::make_pair(AddonVersion(versionString), LOCAL_CACHE)); } } } } } auto* dialog = static_cast<CGUIDialogSelect*>(g_windowManager.GetWindow(WINDOW_DIALOG_SELECT)); dialog->Reset(); dialog->SetHeading(CVariant{21338}); dialog->SetUseDetails(true); std::stable_sort(versions.begin(), versions.end(), CompareVersion); for (const auto& versionInfo : versions) { CFileItem item(StringUtils::Format(g_localizeStrings.Get(21339).c_str(), versionInfo.first.asString().c_str())); if (versionInfo.first == m_localAddon->Version()) item.Select(true); AddonPtr repo; if (versionInfo.second == LOCAL_CACHE) { item.SetProperty("Addon.Summary", g_localizeStrings.Get(24095)); item.SetIconImage("DefaultAddonRepository.png"); dialog->Add(item); } else if (CAddonMgr::GetInstance().GetAddon(versionInfo.second, repo, ADDON_REPOSITORY)) { item.SetProperty("Addon.Summary", repo->Name()); item.SetIconImage(repo->Icon()); dialog->Add(item); } } dialog->Open(); if (dialog->IsConfirmed()) { Close(); auto selected = versions.at(dialog->GetSelectedLabel()); //add or remove from blacklist to toggle auto updating. if downgrading //turn off, if upgrading to latest turn it back on if (selected.first < m_localAddon->Version()) database.BlacklistAddon(m_localAddon->ID()); if (selected.first == versions.at(0).first) database.RemoveAddonFromBlacklist(m_localAddon->ID()); if (selected.second == LOCAL_CACHE) CAddonInstaller::GetInstance().InstallFromZip(StringUtils::Format("special://home/addons/packages/%s-%s.zip", m_localAddon->ID().c_str(), selected.first.asString().c_str())); else CAddonInstaller::GetInstance().Install(m_addon->ID(), selected.first, selected.second); } }