add include for gcc3 in trunk, too
[supertux.git] / src / addon.cpp
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
22 #include <sstream>
23 #include <stdexcept>
24 #include "addon.hpp"
25 #include "addon_manager.hpp"
26
27 void
28 Addon::install()
29 {
30   AddonManager& adm = AddonManager::get_instance();
31   adm.install(*this);
32 }
33
34 void
35 Addon::remove()
36 {
37   AddonManager& adm = AddonManager::get_instance();
38   adm.remove(*this);
39 }
40   
41 void
42 Addon::parse(const lisp::Lisp& lisp)
43 {
44   try {
45     lisp.get("kind", kind);  
46     lisp.get("title", title);
47     lisp.get("author", author);
48     lisp.get("license", license);
49     lisp.get("http-url", http_url);
50     lisp.get("file", file);
51     lisp.get("md5", md5);
52   } catch(std::exception& e) {
53     std::stringstream msg;
54     msg << "Problem when parsing addoninfo: " << e.what();
55     throw std::runtime_error(msg.str());
56   }
57 }
58
59 void
60 Addon::parse(std::string fname)
61 {
62   try {
63     lisp::Parser parser;
64     const lisp::Lisp* root = parser.parse(fname);
65     const lisp::Lisp* addon = root->get_lisp("supertux-addoninfo");
66     if(!addon) throw std::runtime_error("file is not a supertux-addoninfo file.");
67     parse(*addon);
68   } catch(std::exception& e) {
69     std::stringstream msg;
70     msg << "Problem when reading addoninfo '" << fname << "': " << e.what();
71     throw std::runtime_error(msg.str());
72   }
73 }
74
75 void
76 Addon::write(lisp::Writer& writer) const
77 {
78   writer.start_list("supertux-addoninfo");
79   if (kind != "") writer.write_string("kind", kind);  
80   if (title != "") writer.write_string("title", title);
81   if (author != "") writer.write_string("author", author);
82   if (license != "") writer.write_string("license", license);
83   if (http_url != "") writer.write_string("http-url", http_url);
84   if (file != "") writer.write_string("file", file);
85   if (md5 != "") writer.write_string("md5", md5);
86   writer.end_list("supertux-addoninfo");
87 }
88
89 void 
90 Addon::write(std::string fname) const
91 {
92   lisp::Writer writer(fname);
93   write(writer);
94 }
95
96 bool 
97 Addon::equals(const Addon& addon2) const
98 {
99   if ((this->md5 == "") || (addon2.md5 == "")) return (this->title == addon2.title);
100   return (this->md5 == addon2.md5);
101 }
102