The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
info.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2017 by Ignacio R. Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "version.hpp"
18 
19 #include "addon/validation.hpp"
20 
21 #include <ctime>
22 #include <set>
23 #include <map>
24 
25 struct addon_info;
26 class config;
27 typedef std::map<std::string, addon_info> addons_list;
28 
29 struct addon_info
30 {
34 
36 
38 
40 
41  int size;
42  int downloads;
43  int uploads;
44 
46 
47  std::vector<std::string> locales;
48 
50 
51  std::vector<std::string> depends;
52  // std::vector<addon_dependency> conflicts, recommends, replaces;
53 
55 
56  time_t updated;
57  time_t created;
58 
59  // Artificial upload order index used to preserve add-ons upload order
60  // until we have actual first-upload timestamps implemented. This index
61  // is not serialized anywhere.
62  unsigned order;
63 
64  // Flag to indicate whether this object was generaled from pbl info for an addon
65  // not previously published.
66  bool local_only;
67 
69  : id(), title(), description(), icon()
70  , version(), author(), size(), downloads()
71  , uploads(), type(), locales()
72  , core()
73  , depends()
74  , feedback_url()
75  , updated()
76  , created()
77  , order()
78  , local_only(false)
79  {}
80 
81  explicit addon_info(const config& cfg)
82  : id(), title(), description(), icon()
83  , version(), author(), size(), downloads()
84  , uploads(), type(), locales()
85  , core()
86  , depends()
87  , feedback_url()
88  , updated()
89  , created()
90  , order()
91  , local_only(false)
92  {
93  this->read(cfg);
94  }
95 
97  if(this != &o) {
98  this->id = o.id;
99  this->title = o.title;
100  this->description = o.description;
101  this->icon = o.icon;
102  this->version = o.version;
103  this->author = o.author;
104  this->size = o.size;
105  this->downloads = o.downloads;
106  this->uploads = o.uploads;
107  this->type = o.type;
108  this->locales = o.locales;
109  this->core = o.core;
110  this->depends = o.depends;
111  this->feedback_url = o.feedback_url;
112  this->updated = o.updated;
113  this->created = o.created;
114  this->order = o.order;
115  this->local_only = o.local_only;
116  }
117  return *this;
118  }
119 
120  void read(const config& cfg);
121 
122  void write(config& cfg) const;
123 
124  /**
125  * Write only minimal WML used for state tracking (_info.cfg) files.
126  *
127  * This currently only includes the add-on type, upload count,
128  * title, and version number.
129  *
130  * @param cfg Target WML config object.
131  */
132  void write_minimal(config& cfg) const;
133 
134  /**
135  * Get a title or automatic title for display.
136  *
137  * If the real @a title is empty, the returned value is the @a id with
138  * underscores replaced with blanks.
139  *
140  * @todo FIXME: Is it even possible for the add-ons server to provide untitled
141  * add-ons in its reply anymore? Titles seem to be required at upload time.
142  */
143  std::string display_title() const;
144 
145  /** Get an icon path fixed for display (e.g. when TC is missing, or the image doesn't exist). */
146  std::string display_icon() const;
147 
148  /** Get an add-on type identifier for display in the user's language. */
149  std::string display_type() const;
150 
151  /**
152  * Resolve an add-on's dependency tree in a recursive fashion.
153  *
154  * The returned vector contains the list of resolved dependencies for this
155  * and any other add-ons upon which it depends.
156  *
157  * @param addons The add-ons list.
158  *
159  * @todo Tag resolved dependencies with information about where they come from,
160  * and implement more dependency tiers.
161  */
162  std::set<std::string> resolve_dependencies(const addons_list& addons) const;
163 };
164 
165 /**
166  * Parse the specified add-ons list WML into an actual addons_list object.
167  *
168  * @param cfg Add-ons list WML, currently a [campaigns] node from a server response.
169  * @param dest Target addons_list object. It will be cleared first.
170  */
171 void read_addons_list(const config& cfg, addons_list& dest);
172 
173 /**
174  * Get a human-readable representation of the specified byte count.
175  *
176  * The result includes the size unit, which is the largest byte multiply
177  * that makes sense. (e.g. 1 MiB for 1048576 bytes.)
178  */
180 
181 /**
182  * Replaces underscores to dress up file or dirnames as add-on titles.
183  *
184  * @todo In the future we should store more local information about add-ons and use
185  * this only as a fallback; it could be desirable to fetch translated names as well
186  * somehow.
187  */
int size
Definition: info.hpp:41
std::vector< char_t > string
ADDON_TYPE
Values used for add-on classification; UI-only at the moment, in the future it could be used for dire...
Definition: validation.hpp:40
addon_info & operator=(const addon_info &o)
Definition: info.hpp:96
std::string size_display_string(double size)
Get a human-readable representation of the specified byte count.
Definition: info.cpp:214
std::string description
Definition: info.hpp:33
addon_info(const config &cfg)
Definition: info.hpp:81
std::string make_addon_title(const std::string &id)
Replaces underscores to dress up file or dirnames as add-on titles.
Definition: info.cpp:223
std::string feedback_url
Definition: info.hpp:54
time_t created
Definition: info.hpp:57
unsigned order
Definition: info.hpp:62
void write_minimal(config &cfg) const
Write only minimal WML used for state tracking (_info.cfg) files.
Definition: info.cpp:113
std::string display_title() const
Get a title or automatic title for display.
Definition: info.cpp:123
std::string id
Definition: info.hpp:31
addon_info()
Definition: info.hpp:68
ADDON_TYPE type
Definition: info.hpp:45
std::string display_icon() const
Get an icon path fixed for display (e.g.
Definition: info.cpp:132
void read(const config &cfg)
Definition: info.cpp:61
bool local_only
Definition: info.hpp:66
size_t size(const utf8::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
std::vector< std::string > locales
Definition: info.hpp:47
std::string icon
Definition: info.hpp:35
std::string display_type() const
Get an add-on type identifier for display in the user's language.
Definition: info.cpp:149
int uploads
Definition: info.hpp:43
Represents version numbers.
Definition: version.hpp:43
void write(config &cfg) const
Definition: info.cpp:88
std::vector< std::string > depends
Definition: info.hpp:51
std::string title
Definition: info.hpp:32
version_info version
Definition: info.hpp:37
int downloads
Definition: info.hpp:42
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
Interfaces for manipulating version numbers of engine, add-ons, etc.
std::map< std::string, addon_info > addons_list
Definition: info.hpp:26
void read_addons_list(const config &cfg, addons_list &dest)
Parse the specified add-ons list WML into an actual addons_list object.
std::set< std::string > resolve_dependencies(const addons_list &addons) const
Resolve an add-on's dependency tree in a recursive fashion.
Definition: info.cpp:181
std::string author
Definition: info.hpp:39
time_t updated
Definition: info.hpp:56
std::string core
Definition: info.hpp:49