First round of cleanup up the AddonManager a bit
[supertux.git] / src / addon / addon.hpp
1 //  SuperTux - Add-on
2 //  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_ADDON_ADDON_HPP
18 #define HEADER_SUPERTUX_ADDON_ADDON_HPP
19
20 #include <string>
21
22 #include "util/reader_fwd.hpp"
23
24 /** Represents an (available or installed) Add-on, e.g. a level set */
25 class Addon
26 {
27 public:
28   int id;
29   std::string kind;
30   std::string title;
31   std::string author;
32   std::string license;
33   std::string http_url;
34
35   /** filename suggested by addon author, e.g. "pak0.zip" */
36   std::string suggested_filename;
37
38   /** PhysFS filename on disk, e.g. "pak0.zip" */
39   std::string installed_physfs_filename;
40
41   /** complete path and filename on disk, e.g. "/home/sommer/.supertux2/pak0.zip" */
42   std::string installed_absolute_filename;
43
44   std::string stored_md5;
45   bool installed;
46   bool loaded;
47
48   /** Get MD5, based either on installed file's contents or stored value */
49   std::string get_md5() const;
50
51   /** Read additional information from given contents of a (supertux-addoninfo ...) block */
52   void parse(const Reader& lisp);
53
54   /** Read additional information from given file */
55   void parse(const std::string& fname);
56
57   /** Checks if Add-on is the same as given one. If available, checks
58       MD5 sum, else relies on kind, author and title alone. */
59   bool operator==(const Addon& addon2) const;
60
61 protected:
62   friend class AddonManager;
63
64   mutable std::string calculated_md5;
65
66   Addon(int id_) :
67     id(id_),
68     kind(),
69     title(),
70     author(),
71     license(),
72     http_url(),
73     suggested_filename(),
74     installed_physfs_filename(),
75     installed_absolute_filename(),
76     stored_md5(),
77     installed(),
78     loaded(),
79     calculated_md5()
80   {};
81
82 private:
83   Addon(const Addon&) = delete;
84   Addon& operator=(const Addon&) = delete;
85 };
86
87 #endif
88
89 /* EOF */