本文整理汇总了C++中CAddonDatabase::GetAvailableVersions方法的典型用法代码示例。如果您正苦于以下问题:C++ CAddonDatabase::GetAvailableVersions方法的具体用法?C++ CAddonDatabase::GetAvailableVersions怎么用?C++ CAddonDatabase::GetAvailableVersions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAddonDatabase
的用法示例。
在下文中一共展示了CAddonDatabase::GetAvailableVersions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnInstall
void CGUIDialogAddonInfo::OnInstall()
{
if (!g_passwordManager.CheckMenuLock(WINDOW_ADDON_BROWSER))
return;
if (m_localAddon || !m_item->HasAddonInfo())
return;
std::string addonId = m_item->GetAddonInfo()->ID();
std::vector<std::pair<AddonVersion, std::string>> versions;
CAddonDatabase database;
if (!database.Open() || !database.GetAvailableVersions(addonId, versions) || versions.empty())
{
CLog::Log(LOGERROR, "ADDON: no available versions of %s", addonId.c_str());
return;
}
int i = versions.size() == 1 ? 0 : AskForVersion(versions);
if (i != -1)
{
Close();
CAddonInstaller::GetInstance().Install(addonId, versions[i].first, versions[i].second);
}
}
示例2: OnUpdate
void CGUIDialogAddonInfo::OnUpdate()
{
if (!m_localAddon)
return;
std::vector<std::pair<AddonVersion, std::string>> versions;
CAddonDatabase database;
database.Open();
database.GetAvailableVersions(m_localAddon->ID(), versions);
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));
}
}
}
}
}
if (versions.empty())
CGUIDialogOK::ShowAndGetInput(CVariant{21341}, CVariant{21342});
else
{
int i = AskForVersion(versions);
if (i != -1)
{
Close();
//turn auto updating off if downgrading
if (m_localAddon->Version() > versions[i].first)
CAddonMgr::GetInstance().AddToUpdateBlacklist(m_localAddon->ID());
if (versions[i].second == LOCAL_CACHE)
CAddonInstaller::GetInstance().InstallFromZip(StringUtils::Format(
"special://home/addons/packages/%s-%s.zip", m_localAddon->ID().c_str(),
versions[i].first.asString().c_str()));
else
CAddonInstaller::GetInstance().Install(m_localAddon->ID(), versions[i].first, versions[i].second);
}
}
}
示例3: GetRepoForAddon
bool CAddonInstaller::GetRepoForAddon(const std::string& addonId, RepositoryPtr& repoPtr)
{
CAddonDatabase database;
if (!database.Open())
return false;
std::vector<std::pair<ADDON::AddonVersion, std::string>> versions;
if (!database.GetAvailableVersions(addonId, versions) || versions.empty())
return false;
auto repoId = std::min_element(versions.begin(), versions.end())->second;
AddonPtr tmp;
if (!CAddonMgr::GetInstance().GetAddon(repoId, tmp, ADDON_REPOSITORY))
return false;
repoPtr = std::static_pointer_cast<CRepository>(tmp);
return true;
}
示例4: OnUpdate
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));
}
}
}
}
}
if (versions.empty())
{
CGUIDialogOK::ShowAndGetInput(CVariant{21341}, CVariant{21342});
return;
}
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());
//turn auto updating off if downgrading
if (selected.first < m_localAddon->Version())
CAddonMgr::GetInstance().AddToUpdateBlacklist(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);
}
}