Permalink
Browse files

added: addon repository class

git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@29225 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
  • Loading branch information...
1 parent 8a457f5 commit 606248f55785d83eb4412fdeae674b350699c9c3 spiff_ committed Apr 13, 2010
@@ -2114,6 +2114,7 @@
<string id="24008">Screensaver</string>
<string id="24009">Script</string>
<string id="24010">Visualization</string>
+ <string id="24011">Add-on repository</string>
<string id="24020">Configure Add-on</string>
<string id="24021">Disable Add-on</string>
View
@@ -137,6 +137,12 @@ const CStdString TranslateType(const ADDON::TYPE &type, bool pretty/*=false*/)
return g_localizeStrings.Get(24009);
return "script";
}
+ case ADDON::ADDON_REPOSITORY:
+ {
+ if (pretty)
+ return g_localizeStrings.Get(24011);
+ return "addon-repository";
+ }
default:
{
return "";
@@ -154,6 +160,7 @@ const ADDON::TYPE TranslateType(const CStdString &string)
else if (string.Equals("visualization-library")) return ADDON_VIZ_LIBRARY;
else if (string.Equals("plugin")) return ADDON_PLUGIN;
else if (string.Equals("script")) return ADDON_SCRIPT;
+ else if (string.Equals("addon-repository")) return ADDON_REPOSITORY;
else return ADDON_UNKNOWN;
}
@@ -40,7 +40,7 @@
//#ifdef HAS_SCRAPERS
#include "Scraper.h"
//#endif
-
+#include "Repository.h"
using namespace std;
@@ -659,6 +659,8 @@ AddonPtr CAddonMgr::AddonFromProps(AddonProps& addonProps)
case ADDON_SCRAPER_LIBRARY:
case ADDON_VIZ_LIBRARY:
return AddonPtr(new CAddonLibrary(addonProps));
+ case ADDON_REPOSITORY:
+ return AddonPtr(new CRepository(addonProps));
default:
break;
}
View
@@ -53,6 +53,7 @@ namespace ADDON
ADDON_SCRAPER,
ADDON_SCREENSAVER,
ADDON_PLUGIN,
+ ADDON_REPOSITORY,
ADDON_VIZ_LIBRARY, // add noninstallable after this and installable before
ADDON_SCRAPER_LIBRARY
} TYPE;
View
@@ -6,7 +6,8 @@ SRCS=Addon.cpp \
ScreenSaver.cpp \
Scraper.cpp \
Visualisation.cpp \
- fft.cpp
+ fft.cpp \
+ Repository.cpp \
LIB=addons.a
View
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2005-2010 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "Repository.h"
+#include "tinyXML/tinyxml.h"
+#include "FileSystem/File.h"
+#include "XMLUtils.h"
+#include "AddonDatabase.h"
+#include "Application.h"
+#include "Settings.h"
+#include "FileItem.h"
+#include "utils/JobManager.h"
+#include "utils/FileOperationJob.h"
+#include "GUIWindowManager.h"
+#include "GUIWindowAddonBrowser.h"
+
+using namespace XFILE;
+using namespace ADDON;
+
+AddonPtr CRepository::Clone(const AddonPtr &self) const
+{
+ CRepository* result = new CRepository(*this, self);
+ result->m_name = m_name;
+ result->m_info = m_info;
+ result->m_checksum = m_checksum;
+ result->m_datadir = m_datadir;
+ return AddonPtr(result);
+}
+
+CRepository::CRepository(const AddonProps& props) :
+ CAddon(props)
+{
+ LoadFromXML(Path()+LibName());
+ SetUpdated(CDateTime::GetCurrentDateTime()-CDateTimeSpan(0,12,0,0));
+}
+
+CRepository::CRepository(const CRepository &rhs, const AddonPtr &self)
+ : CAddon(rhs, self)
+{
+}
+
+CRepository::~CRepository()
+{
+}
+
+bool CRepository::LoadFromXML(const CStdString& xml)
+{
+ CSingleLock lock(m_critSection);
+ TiXmlDocument doc;
+ doc.LoadFile(xml);
+ if (!doc.RootElement())
+ return false;
+
+ XMLUtils::GetString(doc.RootElement(),"name", m_name);
+ XMLUtils::GetString(doc.RootElement(),"info", m_info);
+ XMLUtils::GetString(doc.RootElement(),"checksum", m_checksum);
+ XMLUtils::GetString(doc.RootElement(),"datadir", m_datadir);
+
+ return true;
+}
+
+CStdString CRepository::Checksum()
+{
+ CSingleLock lock(m_critSection);
+ CFile file;
+ file.Open(m_checksum);
+ CStdString checksum;
+ char* temp = new char[file.GetLength()+1];
+ if (temp)
+ {
+ file.Read(temp,file.GetLength());
+ temp[file.GetLength()] = 0;
+ checksum = temp;
+ delete[] temp;
+ }
+
+ return checksum;
+}
+
+VECADDONS CRepository::Parse()
+{
+ CSingleLock lock(m_critSection);
+
+ VECADDONS result;
+
+ TiXmlDocument doc;
+ doc.LoadFile(m_info);
+ if (doc.RootElement())
+ {
+ TiXmlElement* element = doc.FirstChildElement("addoninfo");
+ while (element)
+ {
+ AddonPtr addon;
+ if (CAddonMgr::AddonFromInfoXML(element,addon,m_info))
+ {
+ CUtil::GetDirectory(m_info,addon->Props().path);
+ addon->Props().path = CUtil::AddFileToFolder(m_datadir,addon->ID()+"-"+addon->Version().str+".zip");
+ addon->Props().icon = CUtil::AddFileToFolder(m_datadir,addon->ID()+".tbn");
+ result.push_back(addon);
+ }
+ element = element->NextSiblingElement("addoninfo");
+ }
+ }
+
+ return result;
+}
+
+CDateTime CRepository::LastUpdate()
+{
+ CSingleLock lock(m_critSection);
+ CAddonDatabase database;
+ database.Open();
+ CStdString date;
+ CDateTime datetime = CDateTime::GetCurrentDateTime();
+ if (database.GetRepoTimestamp(ID(),date) > -1)
+ datetime.SetFromDBDate(date);
+
+ return datetime;
+}
+
+void CRepository::SetUpdated(const CDateTime& time)
+{
+ CSingleLock lock(m_critSection);
+ CAddonDatabase database;
+ database.Open();
+ database.SetRepoTimestamp(ID(),time.GetAsDBDateTime());
+}
+
+CRepositoryUpdateJob::CRepositoryUpdateJob(RepositoryPtr& repo)
+{
+ m_repo = boost::dynamic_pointer_cast<CRepository>(repo->Clone(repo));
+}
+
+bool CRepositoryUpdateJob::DoWork()
+{
+ VECADDONS addons = GrabAddons(m_repo,true);
+ if (addons.empty())
+ return false;
+
+ // check for updates
+ for (unsigned int i=0;i<addons.size();++i)
+ {
+ AddonPtr addon;
+ if (CAddonMgr::Get()->GetAddon(addons[i]->ID(),addon) &&
+ addons[i]->Version() > addon->Version())
+ {
+ if (g_settings.m_bAddonAutoUpdate || addon->Type() >= ADDON_VIZ_LIBRARY)
+ {
+ CGUIWindowAddonBrowser::AddJob(addons[i]->Path());
+ }
+ else
+ {
+ g_application.m_guiDialogKaiToast.QueueNotification(CGUIDialogKaiToast::Info,
+ g_localizeStrings.Get(24061),
+ addon->Name());
+ }
+ }
+ }
+
+ return true;
+}
+
+VECADDONS CRepositoryUpdateJob::GrabAddons(RepositoryPtr& repo,
+ bool check)
+{
+ CAddonDatabase database;
+ database.Open();
+ CStdString checksum, timestamp;
+ CDateTime time = CDateTime::GetCurrentDateTime();
+ if (database.GetRepoTimestamp(repo->ID(),timestamp))
+ time.SetFromDBDate(timestamp);
+ int idRepo = database.GetRepoChecksum(repo->ID(),checksum);
+ CStdString reposum=checksum;
+ if (check)
+ reposum = repo->Checksum();
+ VECADDONS addons;
+ if (idRepo == -1 || !checksum.Equals(reposum))
+ {
+ addons = repo->Parse();
+ database.AddRepository(repo->ID(),addons,reposum);
+ }
+ else
+ {
+ database.GetRepository(repo->ID(),addons);
+ database.SetRepoTimestamp(repo->ID(),CDateTime::GetCurrentDateTime().GetAsDBDateTime());
+ }
+
+ return addons;
+}
+
View
@@ -0,0 +1,68 @@
+#pragma once
+/*
+ * Copyright (C) 2005-2010 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include "Addon.h"
+#include "AddonManager.h"
+#include "DateTime.h"
+#include "URL.h"
+#include "utils/Job.h"
+#include "utils/CriticalSection.h"
+#include "utils/SingleLock.h"
+
+namespace ADDON
+{
+ class CRepository;
+ typedef boost::shared_ptr<CRepository> RepositoryPtr;
+ class CRepository : public CAddon
+ {
+ public:
+ AddonPtr Clone(const AddonPtr &self) const;
+ CRepository(const AddonProps& props);
+ virtual ~CRepository();
+
+ bool LoadFromXML(const CStdString& xml);
+ CStdString Checksum();
+ VECADDONS Parse();
+ CDateTime LastUpdate();
+ void SetUpdated(const CDateTime& time);
+ private:
+ CRepository(const CRepository&, const AddonPtr&);
+ CStdString m_name;
+ CStdString m_info;
+ CStdString m_checksum;
+ CStdString m_datadir;
+ CCriticalSection m_critSection;
+ };
+
+ class CRepositoryUpdateJob : public CJob
+ {
+ public:
+ CRepositoryUpdateJob(RepositoryPtr& repo);
+ virtual ~CRepositoryUpdateJob() {}
+
+ virtual bool DoWork();
+ static VECADDONS GrabAddons(RepositoryPtr& repo, bool check);
+
+ RepositoryPtr m_repo;
+ };
+}
+

0 comments on commit 606248f

Please sign in to comment.