supertux
addon_manager.hpp
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 HEADER_SUPERTUX_ADDON_ADDON_MANAGER_HPP
20 
21 #include <memory>
22 #include <string>
23 #include <map>
24 #include <vector>
25 
26 #include "addon/downloader.hpp"
27 #include "supertux/gameconfig.hpp"
28 #include "util/currenton.hpp"
29 
30 class Addon;
31 class AddonDependencyManager;
32 
33 typedef std::string AddonId;
34 
36 class AddonManager final : public Currenton<AddonManager>
37 {
38 public:
39  using AddonMap = std::map<AddonId, std::unique_ptr<Addon> >;
40 
41 private:
42  Downloader m_downloader;
43  const std::string m_addon_directory;
44  const std::string m_cache_directory;
45  const std::string m_screenshots_cache_directory;
46  std::string m_repository_url;
47  std::vector<Config::Addon>& m_addon_config;
48 
49  AddonMap m_installed_addons;
50  AddonMap m_repository_addons;
51 
52  bool m_initialized;
53  bool m_has_been_updated;
54 
55  TransferStatusListPtr m_transfer_statuses;
56 
57 public:
58  AddonManager(const std::string& addon_directory,
59  std::vector<Config::Addon>& addon_config);
60  ~AddonManager() override;
61 
62  void empty_cache_directory();
63 
64  bool has_online_support() const;
65  bool has_been_updated() const;
66  void check_online();
67  TransferStatusPtr request_check_online();
68 
69  std::vector<AddonId> get_repository_addons() const;
70  std::vector<AddonId> get_installed_addons() const;
71 
72  Addon& get_repository_addon(const AddonId& addon) const;
73  Addon& get_installed_addon(const AddonId& addon) const;
74 
75  TransferStatusListPtr request_install_addon(const AddonId& addon_id);
76  TransferStatusListPtr request_install_addon_dependencies(const AddonId& addon_id);
77  void install_addon(const AddonId& addon_id);
78  void uninstall_addon(const AddonId& addon_id);
79  void install_addon_from_local_file(const std::string& filename);
80 
81  TransferStatusListPtr request_download_addon_screenshots(const AddonId& addon_id);
82  std::vector<std::string> get_local_addon_screenshots(const AddonId& addon_id);
83 
84  void enable_addon(const AddonId& addon_id);
85  void disable_addon(const AddonId& addon_id);
86 
87  bool is_old_enabled_addon(const std::unique_ptr<Addon>& addon) const;
88  bool is_old_addon_enabled() const;
89  void disable_old_addons();
90  void mount_old_addons();
91  void unmount_old_addons();
92  bool is_from_old_addon(const std::string& filename) const;
93  bool is_addon_installed(const std::string& id) const;
94 
95  std::vector<AddonId> get_depending_addons(const std::string& id) const;
96 
97  void update();
98  void check_for_langpack_updates();
99 
100 #ifdef EMSCRIPTEN
101  void onDownloadProgress(int id, int loaded, int total);
102  void onDownloadFinished(int id);
103  void onDownloadError(int id);
104  void onDownloadAborted(int id);
105 #endif
106 
107 private:
108  TransferStatusListPtr request_install_addon_dependencies(const Addon& addon);
109 
110  std::vector<std::string> scan_for_archives() const;
111  void add_installed_addons();
112  AddonMap parse_addon_infos(const std::string& filename) const;
113 
116  void add_installed_archive(const std::string& archive, const std::string& md5, bool user_install = false);
117 
120  std::string scan_for_info(const std::string& archive) const;
121 
122 private:
123  AddonManager(const AddonManager&) = delete;
124  AddonManager& operator=(const AddonManager&) = delete;
125 };
126 
127 #endif
128 
129 /* EOF */
Definition: downloader.hpp:118
A &#39;Currenton&#39; allows access to the currently active instance of a class via the static current() func...
Definition: currenton.hpp:30
Checks for, installs and removes Add-ons.
Definition: addon_manager.hpp:36
Definition: addon.hpp:27