supertux/main, control/haptic_manager: Add SDL 1.2 compatibility code.
[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 #include "util/writer_fwd.hpp"
24
25 /**
26  * Represents an (available or installed) Add-on, e.g. a level set
27  */
28 class Addon
29 {
30 public:
31   std::string kind;
32   std::string title;
33   std::string author;
34   std::string license;
35   std::string http_url;
36   /** filename suggested by addon author, e.g. "pak0.zip" */
37   std::string suggested_filename;
38   /** PhysFS filename on disk, e.g. "pak0.zip" */
39   std::string installed_physfs_filename;
40   /** complete path and filename on disk, e.g. "/home/sommer/.supertux2/pak0.zip" */
41   std::string installed_absolute_filename;
42   std::string stored_md5;
43   bool installed;
44   bool loaded;
45
46   /**
47    * Get MD5, based either on installed file's contents or stored value
48    */
49   std::string get_md5() const;
50
51   /**
52    * Read additional information from given contents of a (supertux-addoninfo ...) block
53    */
54   void parse(const Reader& lisp);
55
56   /**
57    * Read additional information from given file
58    */
59   void parse(std::string fname);
60
61   /**
62    * Writes out Add-on metainformation to a Lisp Writer
63    */
64   void write(Writer& writer) const;
65
66   /**
67    * Writes out Add-on metainformation to a file
68    */
69   void write(std::string fname) const;
70
71   /**
72    * Checks if Add-on is the same as given one. 
73    * If available, checks MD5 sum, else relies on kind, author and title alone.
74    */
75   bool operator==(Addon addon2) const;
76
77 protected:
78   friend class AddonManager;
79
80   mutable std::string calculated_md5;
81
82   Addon() :
83     kind(),
84     title(),
85     author(),
86     license(),
87     http_url(),
88     suggested_filename(), 
89     installed_physfs_filename(), 
90     installed_absolute_filename(),
91     stored_md5(),
92     installed(),
93     loaded(),
94     calculated_md5()
95   {};
96 };
97
98 #endif
99
100 /* EOF */