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