| 1 | //  SuperTux - Add-on Manager | 
|---|
| 2 | //  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.de> | 
|---|
| 3 | //                2014 Ingo Ruhnke <grumbel@gmail.com> | 
|---|
| 4 | // | 
|---|
| 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. | 
|---|
| 9 | // | 
|---|
| 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. | 
|---|
| 14 | // | 
|---|
| 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/>. | 
|---|
| 17 |  | 
|---|
| 18 | #ifndef HEADER_SUPERTUX_ADDON_ADDON_MANAGER_HPP | 
|---|
| 19 | #define | 
|---|
| 20 |  | 
|---|
| 21 | #include <memory> | 
|---|
| 22 | #include <string> | 
|---|
| 23 | #include <vector> | 
|---|
| 24 |  | 
|---|
| 25 | #include "addon/downloader.hpp" | 
|---|
| 26 | #include "supertux/gameconfig.hpp" | 
|---|
| 27 | #include "util/currenton.hpp" | 
|---|
| 28 |  | 
|---|
| 29 | class Addon; | 
|---|
| 30 | using TransferStatusPtr = std::shared_ptr<TransferStatus>; | 
|---|
| 31 |  | 
|---|
| 32 | typedef std::string AddonId; | 
|---|
| 33 |  | 
|---|
| 34 | /** Checks for, installs and removes Add-ons */ | 
|---|
| 35 | class AddonManager final : public Currenton<AddonManager> | 
|---|
| 36 | { | 
|---|
| 37 | public: | 
|---|
| 38 | using AddonList = std::vector<std::unique_ptr<Addon> >; | 
|---|
| 39 |  | 
|---|
| 40 | private: | 
|---|
| 41 | Downloader m_downloader; | 
|---|
| 42 | std::string m_addon_directory; | 
|---|
| 43 | std::string m_repository_url; | 
|---|
| 44 | std::vector<Config::Addon>& m_addon_config; | 
|---|
| 45 |  | 
|---|
| 46 | AddonList m_installed_addons; | 
|---|
| 47 | AddonList m_repository_addons; | 
|---|
| 48 |  | 
|---|
| 49 | bool m_has_been_updated; | 
|---|
| 50 |  | 
|---|
| 51 | TransferStatusPtr m_transfer_status; | 
|---|
| 52 |  | 
|---|
| 53 | public: | 
|---|
| 54 | AddonManager(const std::string& addon_directory, | 
|---|
| 55 | std::vector<Config::Addon>& addon_config); | 
|---|
| 56 | ~AddonManager(); | 
|---|
| 57 |  | 
|---|
| 58 | bool has_online_support() const; | 
|---|
| 59 | bool has_been_updated() const; | 
|---|
| 60 | void check_online(); | 
|---|
| 61 | TransferStatusPtr request_check_online(); | 
|---|
| 62 |  | 
|---|
| 63 | std::vector<AddonId> get_repository_addons() const; | 
|---|
| 64 | std::vector<AddonId> get_installed_addons() const; | 
|---|
| 65 |  | 
|---|
| 66 | Addon& get_repository_addon(const AddonId& addon) const; | 
|---|
| 67 | Addon& get_installed_addon(const AddonId& addon) const; | 
|---|
| 68 |  | 
|---|
| 69 | TransferStatusPtr request_install_addon(const AddonId& addon_id); | 
|---|
| 70 | void install_addon(const AddonId& addon_id); | 
|---|
| 71 | void uninstall_addon(const AddonId& addon_id); | 
|---|
| 72 |  | 
|---|
| 73 | void enable_addon(const AddonId& addon_id); | 
|---|
| 74 | void disable_addon(const AddonId& addon_id); | 
|---|
| 75 |  | 
|---|
| 76 | bool is_old_enabled_addon(const std::unique_ptr<Addon>& addon) const; | 
|---|
| 77 | bool is_old_addon_enabled() const; | 
|---|
| 78 | void disable_old_addons(); | 
|---|
| 79 | void mount_old_addons(); | 
|---|
| 80 | void unmount_old_addons(); | 
|---|
| 81 | bool is_from_old_addon(const std::string& filename) const; | 
|---|
| 82 | bool is_addon_installed(const std::string& id) const; | 
|---|
| 83 |  | 
|---|
| 84 | void update(); | 
|---|
| 85 | void check_for_langpack_updates(); | 
|---|
| 86 |  | 
|---|
| 87 | private: | 
|---|
| 88 | std::vector<std::string> scan_for_archives() const; | 
|---|
| 89 | void add_installed_addons(); | 
|---|
| 90 | AddonList parse_addon_infos(const std::string& filename) const; | 
|---|
| 91 |  | 
|---|
| 92 | /** add \a archive, given as physfs path, to the list of installed | 
|---|
| 93 | archives */ | 
|---|
| 94 | void add_installed_archive(const std::string& archive, const std::string& md5); | 
|---|
| 95 |  | 
|---|
| 96 | /** search for an .nfo file in the top level directory that | 
|---|
| 97 | originates from \a archive, \a archive is a OS path */ | 
|---|
| 98 | std::string scan_for_info(const std::string& archive) const; | 
|---|
| 99 |  | 
|---|
| 100 | private: | 
|---|
| 101 | AddonManager(const AddonManager&) = delete; | 
|---|
| 102 | AddonManager& operator=(const AddonManager&) = delete; | 
|---|
| 103 | }; | 
|---|
| 104 |  | 
|---|
| 105 | #endif | 
|---|
| 106 |  | 
|---|
| 107 | /* EOF */ | 
|---|
| 108 |  | 
|---|