From 7dd6d5ce085802395f67525c315534c2664e5bbb Mon Sep 17 00:00:00 2001 From: Anssi Hannula Date: Sun, 10 Oct 2010 20:01:39 +0300 Subject: [PATCH 2/7] changed: split addon installation failure reporting out of CheckHash() Split two functions out of CheckHash(): CGUIWindowAddonBrowser::ReportInstallError() CGUIWindowAddonBrowser::ReportInstallErrorZip() The former will take an addon id and fallback string, and the latter takes a zip filename. The latter function calls the former. This will allow the reporting of other failures to use the same code. --- xbmc/GUIWindowAddonBrowser.cpp | 44 +++++++++++++++++++++++++-------------- xbmc/GUIWindowAddonBrowser.h | 11 ++++++++++ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/xbmc/GUIWindowAddonBrowser.cpp b/xbmc/GUIWindowAddonBrowser.cpp index 48ccea2..b6cbc25 100644 --- a/xbmc/GUIWindowAddonBrowser.cpp +++ b/xbmc/GUIWindowAddonBrowser.cpp @@ -251,6 +251,33 @@ bool CGUIWindowAddonBrowser::OnClick(int iItem) return CGUIMediaWindow::OnClick(iItem); } +void CGUIWindowAddonBrowser::ReportInstallError(const CStdString& addonID, + const CStdString& fileName) +{ + AddonPtr addon; + CAddonDatabase database; + database.Open(); + database.GetAddon(addonID, addon); + if (addon) + { + AddonPtr addon2; + CAddonMgr::Get().GetAddon(addonID, addon2); + g_application.m_guiDialogKaiToast.QueueNotification( + addon->Icon(), + addon->Name(), + g_localizeStrings.Get(addon2 ? 113 : 114), + TOAST_DISPLAY_TIME, false); + } +} + +void CGUIWindowAddonBrowser::ReportInstallErrorZip(const CStdString& zipName) +{ + CStdStringArray arr; + // FIXME: this doesn't work if addon id contains dashes + StringUtils::SplitString(zipName, "-", arr); + ReportInstallError(arr[0], zipName); +} + bool CGUIWindowAddonBrowser::CheckHash(const CStdString& zipFile, const CStdString& hash) { @@ -261,22 +288,7 @@ bool CGUIWindowAddonBrowser::CheckHash(const CStdString& zipFile, if (!md5.Equals(hash)) { CFile::Delete(package); - CStdStringArray arr; - StringUtils::SplitString(zipFile,"-",arr); - AddonPtr addon; - CAddonDatabase database; - database.Open(); - database.GetAddon(arr[0],addon); - if (addon) - { - AddonPtr addon2; - CAddonMgr::Get().GetAddon(arr[0],addon2); - g_application.m_guiDialogKaiToast.QueueNotification( - addon->Icon(), - addon->Name(), - g_localizeStrings.Get(addon2 ? 113 : 114), - TOAST_DISPLAY_TIME, false); - } + ReportInstallErrorZip(zipFile); CLog::Log(LOGERROR,"MD5 mismatch after download %s", zipFile.c_str()); return false; } diff --git a/xbmc/GUIWindowAddonBrowser.h b/xbmc/GUIWindowAddonBrowser.h index 315e441..fc44656 100644 --- a/xbmc/GUIWindowAddonBrowser.h +++ b/xbmc/GUIWindowAddonBrowser.h @@ -88,6 +88,17 @@ protected: */ void SetItemLabel2(CFileItemPtr item); + /*! \brief Queue a notification for addon installation/update failure + \param addonID - addon id + \param fileName - filename which is shown in case the addon id is unknown + */ + void ReportInstallError(const CStdString& addonID, const CStdString& fileName); + + /*! \brief Queue a notification for addon installation/update failure when only zip filename is known + \param zipName - zip filename (will try to guess addon ID from it) + */ + void ReportInstallErrorZip(const CStdString& zipName); + /*! \brief Check the hash of a downloaded addon with the hash in the repository \param addonZip - filename of the zipped addon to check \param hash - correct hash of the file -- 1.7.3