The Battle for Wesnoth  1.15.0-dev
info.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2018 by Iris Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project https://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 "game_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 {
31  std::string id;
32  std::string title;
33  std::string description;
34 
35  std::string icon;
36 
38 
39  std::string author;
40 
41  int size;
42  int downloads;
43  int uploads;
44 
46 
47  std::vector<std::string> tags;
48  std::vector<std::string> locales;
49 
50  std::string core;
51 
52  std::vector<std::string> depends;
53  // std::vector<addon_dependency> conflicts, recommends, replaces;
54 
55  std::string feedback_url;
56 
57  std::time_t updated;
58  std::time_t created;
59 
60  // Artificial upload order index used to preserve add-ons upload order
61  // until we have actual first-upload timestamps implemented. This index
62  // is not serialized anywhere.
63  unsigned order;
64 
65  // Flag to indicate whether this object was generaled from pbl info for an addon
66  // not previously published.
67  bool local_only;
68 
70  : id(), title(), description(), icon()
71  , version(), author(), size(), downloads()
72  , uploads(), type(), tags(), locales()
73  , core()
74  , depends()
75  , feedback_url()
76  , updated()
77  , created()
78  , order()
79  , local_only(false)
80  {}
81 
82  explicit addon_info(const config& cfg)
83  : id(), title(), description(), icon()
84  , version(), author(), size(), downloads()
85  , uploads(), type(), tags(), locales()
86  , core()
87  , depends()
88  , feedback_url()
89  , updated()
90  , created()
91  , order()
92  , local_only(false)
93  {
94  this->read(cfg);
95  }
96 
98  if(this != &o) {
99  this->id = o.id;
100  this->title = o.title;
101  this->description = o.description;
102  this->icon = o.icon;
103  this->version = o.version;
104  this->author = o.author;
105  this->size = o.size;
106  this->downloads = o.downloads;
107  this->uploads = o.uploads;
108  this->type = o.type;
109  this->tags = o.tags;
110  this->locales = o.locales;
111  this->core = o.core;
112  this->depends = o.depends;
113  this->feedback_url = o.feedback_url;
114  this->updated = o.updated;
115  this->created = o.created;
116  this->order = o.order;
117  this->local_only = o.local_only;
118  }
119  return *this;
120  }
121 
122  void read(const config& cfg);
123 
124  void write(config& cfg) const;
125 
126  /**
127  * Write only minimal WML used for state tracking (_info.cfg) files.
128  *
129  * This currently only includes the add-on type, upload count,
130  * title, and version number.
131  *
132  * @param cfg Target WML config object.
133  */
134  void write_minimal(config& cfg) const;
135 
136  /**
137  * Get a title or automatic title for display.
138  *
139  * If the real @a title is empty, the returned value is the @a id with
140  * underscores replaced with blanks.
141  *
142  * @todo FIXME: Is it even possible for the add-ons server to provide untitled
143  * add-ons in its reply anymore? Titles seem to be required at upload time.
144  */
145  std::string display_title() const;
146 
147  /** Get an icon path fixed for display (e.g. when TC is missing, or the image doesn't exist). */
148  std::string display_icon() const;
149 
150  /** Get an add-on type identifier for display in the user's language. */
151  std::string display_type() const;
152 
153  /**
154  * Resolve an add-on's dependency tree in a recursive fashion.
155  *
156  * The returned vector contains the list of resolved dependencies for this
157  * and any other add-ons upon which it depends.
158  *
159  * @param addons The add-ons list.
160  *
161  * @todo Tag resolved dependencies with information about where they come from,
162  * and implement more dependency tiers.
163  */
164  std::set<std::string> resolve_dependencies(const addons_list& addons) const;
165 };
166 
167 /**
168  * Parse the specified add-ons list WML into an actual addons_list object.
169  *
170  * @param cfg Add-ons list WML, currently a [campaigns] node from a server response.
171  * @param dest Target addons_list object. It will be cleared first.
172  */
173 void read_addons_list(const config& cfg, addons_list& dest);
174 
175 /**
176  * Get a human-readable representation of the specified byte count.
177  *
178  * The result includes the size unit, which is the largest byte multiply
179  * that makes sense. (e.g. 1 MiB for 1048576 bytes.)
180  */
181 std::string size_display_string(double size);
182 
183 /**
184  * Replaces underscores to dress up file or dirnames as add-on titles.
185  *
186  * @todo In the future we should store more local information about add-ons and use
187  * this only as a fallback; it could be desirable to fetch translated names as well
188  * somehow.
189  */
190 std::string make_addon_title(const std::string& id);
int size
Definition: info.hpp:41
void write(config &cfg) const
Definition: info.cpp:90
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
Interfaces for manipulating version numbers of engine, add-ons, etc.
std::string display_title() const
Get a title or automatic title for display.
Definition: info.cpp:126
addon_info & operator=(const addon_info &o)
Definition: info.hpp:97
std::string size_display_string(double size)
Get a human-readable representation of the specified byte count.
Definition: info.cpp:217
std::string description
Definition: info.hpp:33
addon_info(const config &cfg)
Definition: info.hpp:82
std::vector< std::string > tags
Definition: info.hpp:47
std::string make_addon_title(const std::string &id)
Replaces underscores to dress up file or dirnames as add-on titles.
Definition: info.cpp:226
std::string feedback_url
Definition: info.hpp:55
void write_minimal(config &cfg) const
Write only minimal WML used for state tracking (_info.cfg) files.
Definition: info.cpp:116
unsigned order
Definition: info.hpp:63
std::string display_icon() const
Get an icon path fixed for display (e.g.
Definition: info.cpp:135
std::string id
Definition: info.hpp:31
std::string display_type() const
Get an add-on type identifier for display in the user&#39;s language.
Definition: info.cpp:152
addon_info()
Definition: info.hpp:69
ADDON_TYPE type
Definition: info.hpp:45
void read(const config &cfg)
Definition: info.cpp:60
bool local_only
Definition: info.hpp:67
std::time_t created
Definition: info.hpp:58
std::vector< std::string > locales
Definition: info.hpp:48
std::string icon
Definition: info.hpp:35
int uploads
Definition: info.hpp:43
std::time_t updated
Definition: info.hpp:57
Represents version numbers.
std::vector< std::string > depends
Definition: info.hpp:52
std::string title
Definition: info.hpp:32
std::set< std::string > resolve_dependencies(const addons_list &addons) const
Resolve an add-on&#39;s dependency tree in a recursive fashion.
Definition: info.cpp:184
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:68
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::string author
Definition: info.hpp:39
std::string core
Definition: info.hpp:50