Fix for coverity #29360
[supertux.git] / src / addon / addon.hpp
index 69b0bd9..37da298 100644 (file)
@@ -1,5 +1,6 @@
 //  SuperTux - Add-on
 //  Copyright (C) 2007 Christoph Sommer <christoph.sommer@2007.expires.deltadevelopment.de>
+//                2014 Ingo Ruhnke <grumbel@gmail.com>
 //
 //  This program is free software: you can redistribute it and/or modify
 //  it under the terms of the GNU General Public License as published by
 #ifndef HEADER_SUPERTUX_ADDON_ADDON_HPP
 #define HEADER_SUPERTUX_ADDON_ADDON_HPP
 
+#include <assert.h>
+#include <memory>
 #include <string>
 
 #include "util/reader_fwd.hpp"
-#include "util/writer_fwd.hpp"
 
-/**
- * Represents an (available or installed) Add-on, e.g. a level set
- */
 class Addon
 {
 public:
-  std::string kind;
-  std::string title;
-  std::string author;
-  std::string license;
-  std::string http_url;
-  /** filename suggested by addon author, e.g. "pak0.zip" */
-  std::string suggested_filename;
-  /** PhysFS filename on disk, e.g. "pak0.zip" */
-  std::string installed_physfs_filename;
-  /** complete path and filename on disk, e.g. "/home/sommer/.supertux2/pak0.zip" */
-  std::string installed_absolute_filename;
-  std::string stored_md5;
-  bool installed;
-  bool loaded;
-
-  /**
-   * Get MD5, based either on installed file's contents or stored value
-   */
-  std::string get_md5() const;
-
-  /**
-   * Read additional information from given contents of a (supertux-addoninfo ...) block
-   */
-  void parse(const Reader& lisp);
-
-  /**
-   * Read additional information from given file
-   */
-  void parse(std::string fname);
-
-  /**
-   * Writes out Add-on metainformation to a Lisp Writer
-   */
-  void write(Writer& writer) const;
-
-  /**
-   * Writes out Add-on metainformation to a file
-   */
-  void write(std::string fname) const;
-
-  /**
-   * Checks if Add-on is the same as given one.
-   * If available, checks MD5 sum, else relies on kind, author and title alone.
-   */
-  bool operator==(Addon addon2) const;
-
-protected:
-  friend class AddonManager;
-
-  mutable std::string calculated_md5;
-
-  Addon() :
-    kind(),
-    title(),
-    author(),
-    license(),
-    http_url(),
-    suggested_filename(),
-    installed_physfs_filename(),
-    installed_absolute_filename(),
-    stored_md5(),
-    installed(),
-    loaded(),
-    calculated_md5()
-  {};
+  static std::unique_ptr<Addon> parse(const Reader& lisp);
+  static std::unique_ptr<Addon> parse(const std::string& fname);
+
+  enum Type { WORLD, WORLDMAP, LEVELSET };
+
+private:
+  // fields provided by the addon.zip itself
+  std::string m_id;
+  int m_version;
+  Type m_type;
+  std::string m_title;
+  std::string m_author;
+  std::string m_license;
+
+  // additional fields provided for addons from an addon repository
+  std::string m_url;
+  std::string m_md5;
+
+  // fields filled by the AddonManager
+  std::string m_install_filename;
+  bool m_enabled;
+
+private:
+  Addon();
+
+public:
+  std::string get_id() const { return m_id; }
+  int get_version() const { return m_version; }
+
+  Type get_type() const { return m_type; }
+  std::string get_title() const { return m_title; }
+  std::string get_author() const { return m_author; }
+  std::string get_license() const { return m_license; }
+
+  std::string get_url() const { return m_url; }
+  std::string get_md5() const { return m_md5; }
+
+  std::string get_filename() const;
+  std::string get_install_filename() const;
+
+  bool is_installed() const;
+  bool is_enabled() const;
+
+  void set_install_filename(const std::string& absolute_filename, const std::string& md5);
+  void set_enabled(bool v);
+
+private:
+  Addon(const Addon&) = delete;
+  Addon& operator=(const Addon&) = delete;
 };
 
 #endif