Added "Nothing New" indicator after check for new packages with no new results
[supertux.git] / src / addon / 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 <vector>
24
25 #include "addon/downloader.hpp"
26 #include "util/currenton.hpp"
27 #include "util/reader_fwd.hpp"
28 #include "util/writer_fwd.hpp"
29
30 class Addon;
31 class AddonRepository;
32
33 typedef std::string AddonId;
34
35 /** Checks for, installs and removes Add-ons */
36 class AddonManager : public Currenton<AddonManager>
37 {
38 private:
39   typedef std::vector<std::unique_ptr<Addon> > AddonList;
40
41   Downloader m_downloader;
42   std::string m_addon_directory;
43   std::string m_repository_url;
44   std::vector<std::string>& m_ignored_addon_ids;
45
46   AddonList m_installed_addons;
47   AddonList m_repository_addons;
48
49   bool m_has_been_updated;
50
51 public:
52   AddonManager(const std::string& addon_directory,
53                std::vector<std::string>& enabled_addons_);
54   ~AddonManager();
55
56   bool has_online_support() const;
57   bool has_been_updated() const;
58   void check_online();
59
60   std::vector<AddonId> get_repository_addons() const;
61   std::vector<AddonId> get_installed_addons() const;
62
63   Addon& get_repository_addon(const AddonId& addon);
64   Addon& get_installed_addon(const AddonId& addon);
65
66   void install_addon(const AddonId& addon_id);
67   void uninstall_addon(const AddonId& addon_id);
68
69   void enable_addon(const AddonId& addon_id);
70   void disable_addon(const AddonId& addon_id);
71
72 private:
73   std::vector<std::string> scan_for_archives() const;
74   void add_installed_addons();
75   AddonList parse_addon_infos(const std::string& addoninfos) const;
76
77   /** add \a archive, given as physfs path, to the list of installed
78       archives */
79   void add_installed_archive(const std::string& archive, const std::string& md5);
80
81   /** search for an .nfo file in the top level directory that
82       originates from \a archive, \a archive is a OS path */
83   std::string scan_for_info(const std::string& archive) const;
84
85 private:
86   AddonManager(const AddonManager&) = delete;
87   AddonManager& operator=(const AddonManager&) = delete;
88 };
89
90 #endif
91
92 /* EOF */