Removed AddonManager::InstallRequest, the data can be hold in the lambda capture...
[supertux.git] / src / addon / addon_manager.hpp
index 0b4889a..92b38e5 100644 (file)
@@ -1,12 +1,11 @@
-//  $Id$
-//
 //  SuperTux - Add-on Manager
 //  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.de>
+//                2014 Ingo Ruhnke <grumbel@gmail.com>
 //
-//  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
-//  of the License, or (at your option) any later version.
+//  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 3 of the License, 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
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-//  02111-1307, USA.
-//
-#ifndef ADDON_MANAGER_H
-#define ADDON_MANAGER_H
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_ADDON_ADDON_MANAGER_HPP
+#define HEADER_SUPERTUX_ADDON_ADDON_MANAGER_HPP
 
+#include <functional>
+#include <memory>
 #include <string>
 #include <vector>
-namespace lisp {
-class Lisp;
-class Writer;
-}
+
+#include "addon/downloader.hpp"
+#include "supertux/gameconfig.hpp"
+#include "util/currenton.hpp"
+#include "util/reader_fwd.hpp"
+#include "util/writer_fwd.hpp"
 
 class Addon;
+class AddonRepository;
+class TransferStatus;
+using TransferStatusPtr = std::shared_ptr<TransferStatus>;
+
+typedef std::string AddonId;
 
-/**
- * Checks for, installs and removes Add-ons
- */
-class AddonManager
+/** Checks for, installs and removes Add-ons */
+class AddonManager : public Currenton<AddonManager>
 {
+private:
+  using AddonList = std::vector<std::unique_ptr<Addon> >;
+
+  Downloader m_downloader;
+  std::string m_addon_directory;
+  std::string m_repository_url;
+  std::vector<Config::Addon>& m_addon_config;
+
+  AddonList m_installed_addons;
+  AddonList m_repository_addons;
+
+  bool m_has_been_updated;
+
+  TransferStatusPtr m_transfer_status;
+
 public:
-  /**
-   * returns a list of installed Add-ons
-   */
-  std::vector<Addon*> get_addons();
-
-  /**
-   * downloads list of available Add-ons
-   */
+  AddonManager(const std::string& addon_directory,
+               std::vector<Config::Addon>& addon_config);
+  ~AddonManager();
+
+  bool has_online_support() const;
+  bool has_been_updated() const;
   void check_online();
+  TransferStatusPtr request_check_online();
 
-  /**
-   * Download and install Add-on
-   */
-  void install(Addon* addon);
-
-  /**
-   * Physically delete Add-on
-   */
-  void remove(Addon* addon);
-
-  /**
-   * Unload Add-on and mark as not to be loaded automatically
-   */
-  void disable(Addon* addon);
-
-  /**
-   * Load Add-on and mark as to be loaded automatically
-   */
-  void enable(Addon* addon);
-
-  /**
-   * Remove Add-on from search path
-   */
-  void unload(Addon* addon);
-
-  /**
-   * Add Add-on to search path
-   */
-  void load(Addon* addon);
-
-  /**
-   * Loads all enabled Add-ons, i.e. adds them to the search path
-   */
-  void load_addons();
-
-  /**
-   * Returns the shared AddonManager instance
-   */
-  static AddonManager& get_instance();
-
-  /**
-   * Write AddonManager configuration to Lisp
-   */
-  void write_config(lisp::Writer& writer);
-
-  /**
-   * Read AddonManager configuration from Lisp
-   */
-  void read_config(const lisp::Lisp& lisp);
-
-protected:
-  std::vector<Addon*> addons;
-  std::vector<std::string> ignored_addon_filenames;
-
-  AddonManager();
-  ~AddonManager();
+  std::vector<AddonId> get_repository_addons() const;
+  std::vector<AddonId> get_installed_addons() const;
+
+  Addon& get_repository_addon(const AddonId& addon);
+  Addon& get_installed_addon(const AddonId& addon);
+
+  TransferStatusPtr request_install_addon(const AddonId& addon_id);
+  void abort_install();
+  void install_addon(const AddonId& addon_id);
+  void uninstall_addon(const AddonId& addon_id);
+
+  void enable_addon(const AddonId& addon_id);
+  void disable_addon(const AddonId& addon_id);
+
+  void update();
+
+private:
+  std::vector<std::string> scan_for_archives() const;
+  void add_installed_addons();
+  AddonList parse_addon_infos(const std::string& filename) const;
+
+  /** add \a archive, given as physfs path, to the list of installed
+      archives */
+  void add_installed_archive(const std::string& archive, const std::string& md5);
+
+  /** search for an .nfo file in the top level directory that
+      originates from \a archive, \a archive is a OS path */
+  std::string scan_for_info(const std::string& archive) const;
+
+private:
+  AddonManager(const AddonManager&) = delete;
+  AddonManager& operator=(const AddonManager&) = delete;
 };
 
 #endif
+
+/* EOF */