1 // SuperTux - Add-on Manager
2 // Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.de>
3 // 2014 Ingo Ruhnke <grumbel@gmail.com>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef HEADER_SUPERTUX_ADDON_ADDON_MANAGER_HPP
19 #define HEADER_SUPERTUX_ADDON_ADDON_MANAGER_HPP
26 #include "addon/downloader.hpp"
27 #include "supertux/gameconfig.hpp"
28 #include "util/currenton.hpp"
29 #include "util/reader_fwd.hpp"
30 #include "util/writer_fwd.hpp"
33 class AddonRepository;
35 using TransferStatusPtr = std::shared_ptr<TransferStatus>;
37 typedef std::string AddonId;
39 /** Checks for, installs and removes Add-ons */
40 class AddonManager : public Currenton<AddonManager>
43 using AddonList = std::vector<std::unique_ptr<Addon> >;
45 Downloader m_downloader;
46 std::string m_addon_directory;
47 std::string m_repository_url;
48 std::vector<Config::Addon>& m_addon_config;
50 AddonList m_installed_addons;
51 AddonList m_repository_addons;
53 bool m_has_been_updated;
55 TransferStatusPtr m_transfer_status;
58 AddonManager(const std::string& addon_directory,
59 std::vector<Config::Addon>& addon_config);
62 bool has_online_support() const;
63 bool has_been_updated() const;
65 TransferStatusPtr request_check_online();
67 std::vector<AddonId> get_repository_addons() const;
68 std::vector<AddonId> get_installed_addons() const;
70 Addon& get_repository_addon(const AddonId& addon);
71 Addon& get_installed_addon(const AddonId& addon);
73 TransferStatusPtr request_install_addon(const AddonId& addon_id);
74 void install_addon(const AddonId& addon_id);
75 void uninstall_addon(const AddonId& addon_id);
77 void enable_addon(const AddonId& addon_id);
78 void disable_addon(const AddonId& addon_id);
83 std::vector<std::string> scan_for_archives() const;
84 void add_installed_addons();
85 AddonList parse_addon_infos(const std::string& filename) const;
87 /** add \a archive, given as physfs path, to the list of installed
89 void add_installed_archive(const std::string& archive, const std::string& md5);
91 /** search for an .nfo file in the top level directory that
92 originates from \a archive, \a archive is a OS path */
93 std::string scan_for_info(const std::string& archive) const;
96 AddonManager(const AddonManager&) = delete;
97 AddonManager& operator=(const AddonManager&) = delete;