Repository navigation
Expand file tree
/
Copy pathsettings.cpp
More file actions
308 lines (275 loc) · 9.98 KB
/
Copy pathsettings.cpp
File metadata and controls
308 lines (275 loc) · 9.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2012 Twan van Laarhoven and Sean Hunt |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include "util/prec.hpp"
#include "data/settings.hpp"
#include "data/installer.hpp"
#include "data/game.hpp"
#include "data/stylesheet.hpp"
#include "data/field.hpp"
#include "data/export_template.hpp"
#include "data/word_list.hpp"
#include "util/reflect.hpp"
#include "util/platform.hpp"
#include "util/io/reader.hpp"
#include "util/io/writer.hpp"
#include "util/delayed_index_maps.hpp"
#include "util/paths.hpp"
#include <wx/filename.h>
#include <wx/wfstream.h>
// ----------------------------------------------------------------------------- : Extra types
IMPLEMENT_REFLECTION_ENUM(CheckUpdates) {
VALUE_N("if connected", CHECK_IF_CONNECTED); //default
VALUE_N("always", CHECK_ALWAYS);
VALUE_N("never", CHECK_NEVER);
}
IMPLEMENT_REFLECTION_ENUM(InstallType) {
VALUE_N("default", INSTALL_DEFAULT); //default
VALUE_N("local", INSTALL_LOCAL);
VALUE_N("global", INSTALL_GLOBAL);
}
bool is_install_local(InstallType type) {
#ifdef __WXMSW__
#define DEFAULT_INSTALL_LOCAL false
#else
#define DEFAULT_INSTALL_LOCAL true
#endif
return type == INSTALL_DEFAULT ? DEFAULT_INSTALL_LOCAL : type == INSTALL_LOCAL;
}
IMPLEMENT_REFLECTION_ENUM(FilenameConflicts) {
VALUE_N("keep old", CONFLICT_KEEP_OLD);
VALUE_N("overwrite", CONFLICT_OVERWRITE);
VALUE_N("number", CONFLICT_NUMBER);
VALUE_N("number overwrite", CONFLICT_NUMBER_OVERWRITE);
}
const int COLUMN_NOT_INITIALIZED = -100000;
ColumnSettings::ColumnSettings()
: width(100), position(COLUMN_NOT_INITIALIZED), visible(false)
{}
// dummy for ColumnSettings reflection
ScriptValueP to_script(const ColumnSettings&) { return script_nil; }
IMPLEMENT_REFLECTION_NO_SCRIPT(ColumnSettings) {
REFLECT(width);
REFLECT(position);
REFLECT(visible);
}
GameSettings::GameSettings()
: sort_cards_ascending(true)
, images_export_filename(_("{card.name}.jpg"))
, images_export_conflicts(CONFLICT_NUMBER_OVERWRITE)
, use_auto_replace(true)
, pack_seed_random(true)
, pack_seed(123456)
, initialized(false)
{}
void GameSettings::initDefaults(const Game& game) {
// Defer initialization until the game is fully loaded.
// This prevents data that needs to be initialized from
// being accessed from the new set window, but removes
// the need to load the entire file, which takes too long.
if (initialized || !game.isFullyLoaded()) return;
initialized = true;
// init auto_replaces, copy from game file
for(const auto& ar : game.auto_replaces) {
// do we have this one?
bool already_have = false;
for(auto& ar2 : auto_replaces) {
if (ar->match == ar2->match) {
ar2->custom = false;
already_have = true;
break;
}
}
if (!already_have) {
// TODO: when we start saving games, clone here
ar->custom = false;
auto_replaces.push_back(ar);
}
}
}
IMPLEMENT_REFLECTION_NO_SCRIPT(GameSettings) {
REFLECT(default_stylesheet);
REFLECT(default_export);
REFLECT(cardlist_columns);
REFLECT(sort_cards_by);
REFLECT(sort_cards_ascending);
REFLECT(images_export_filename);
REFLECT(images_export_conflicts);
REFLECT(use_auto_replace);
REFLECT(auto_replaces);
REFLECT(pack_amounts);
REFLECT(pack_seed_random);
REFLECT(pack_seed);
}
StyleSheetSettings::StyleSheetSettings()
: card_zoom (1.0, true)
, card_angle (0, true)
, card_anti_alias (true, true)
, card_borders (true, true)
, card_draw_editing (true, true)
, card_normal_export (true, true)
, card_spellcheck_enabled(true, true)
{}
void StyleSheetSettings::useDefault(const StyleSheetSettings& ss) {
if (card_zoom .isDefault()) card_zoom .assignDefault(ss.card_zoom);
if (card_angle .isDefault()) card_angle .assignDefault(ss.card_angle);
if (card_anti_alias .isDefault()) card_anti_alias .assignDefault(ss.card_anti_alias);
if (card_borders .isDefault()) card_borders .assignDefault(ss.card_borders);
if (card_draw_editing .isDefault()) card_draw_editing .assignDefault(ss.card_draw_editing);
if (card_normal_export .isDefault()) card_normal_export .assignDefault(ss.card_normal_export);
if (card_spellcheck_enabled.isDefault()) card_spellcheck_enabled.assignDefault(ss.card_spellcheck_enabled);
}
IMPLEMENT_REFLECTION_NO_SCRIPT(StyleSheetSettings) {
REFLECT(card_zoom);
REFLECT(card_angle);
REFLECT(card_anti_alias);
REFLECT(card_borders);
REFLECT(card_draw_editing);
REFLECT(card_normal_export);
REFLECT(card_spellcheck_enabled);
}
// ----------------------------------------------------------------------------- : Printing
IMPLEMENT_REFLECTION_ENUM(PageLayoutType) {
VALUE_N("no space", LAYOUT_NO_SPACE);
VALUE_N("equal space", LAYOUT_EQUAL_SPACE);
}
// ----------------------------------------------------------------------------- : Settings
Settings settings;
Settings::Settings()
: locale (_("en"))
, set_window_maximized (false)
, set_window_width (790)
, set_window_height (300)
, card_notes_height (40)
, open_sets_in_new_window(true)
, symbol_grid_size (30)
, symbol_grid (true)
, symbol_grid_snap (false)
, print_layout (LAYOUT_NO_SPACE)
#if USE_OLD_STYLE_UPDATE_CHECKER
, updates_url (_("http://magicseteditor.sourceforge.net/updates"))
#endif
, package_versions_url (_("http://magicseteditor.sourceforge.net/packages"))
, installer_list_url (_("http://magicseteditor.sourceforge.net/installers"))
, check_updates (CHECK_IF_CONNECTED)
, check_updates_all (true)
, website_url (_("http://magicseteditor.sourceforge.net/"))
, install_type (INSTALL_DEFAULT)
{}
void Settings::addRecentFile(const String& filename) {
// get absolute path
wxFileName fn(filename);
fn.Normalize();
String filenameAbs = fn.GetFullPath();
// remove duplicates
recent_sets.erase(
remove(recent_sets.begin(), recent_sets.end(), filenameAbs),
recent_sets.end()
);
// add to front of list
recent_sets.insert(recent_sets.begin(), filenameAbs);
// enforce size limit
if (recent_sets.size() > max_recent_sets) recent_sets.resize(max_recent_sets);
}
GameSettings& Settings::gameSettingsFor(const Game& game) {
GameSettingsP& gs = game_settings[game.name()];
if (!gs) gs = intrusive(new GameSettings);
gs->initDefaults(game);
return *gs;
}
ColumnSettings& Settings::columnSettingsFor(const Game& game, const Field& field) {
// Get game info
GameSettings& gs = gameSettingsFor(game);
// Get column info
ColumnSettings& cs = gs.cardlist_columns[field.name];
if (cs.position == COLUMN_NOT_INITIALIZED) {
// column info not set, initialize based on the game
cs.visible = field.card_list_visible;
cs.position = field.card_list_column;
cs.width = field.card_list_width;
}
return cs;
}
StyleSheetSettings& Settings::stylesheetSettingsFor(const StyleSheet& stylesheet) {
StyleSheetSettingsP& ss = stylesheet_settings[stylesheet.name()];
if (!ss) ss = intrusive(new StyleSheetSettings);
ss->useDefault(default_stylesheet_settings); // update default settings
return *ss;
}
IndexMap<FieldP,ValueP>& Settings::exportOptionsFor(const ExportTemplate& export_template) {
return export_options.get(export_template.name(), export_template.option_fields);
}
/// Retrieve the directory to use for settings and other data files
String user_settings_dir() {
String dir = getUserDataDir();
if (!wxDirExists(dir)) wxMkdir(dir);
return dir + _("/");
}
String Settings::settingsFile() {
// return user_settings_dir() + _("mse.config");
return user_settings_dir() + _("mse8.config"); // use different file during development of C++ port
}
IMPLEMENT_REFLECTION_NO_SCRIPT(Settings) {
REFLECT(locale);
REFLECT(recent_sets);
REFLECT(default_set_dir);
REFLECT(default_image_dir);
REFLECT(default_symbol_dir);
REFLECT(default_export_dir);
REFLECT(set_window_maximized);
REFLECT(set_window_width);
REFLECT(set_window_height);
REFLECT(card_notes_height);
REFLECT(open_sets_in_new_window);
REFLECT(symbol_grid_size);
REFLECT(symbol_grid);
REFLECT(symbol_grid_snap);
REFLECT(default_game);
REFLECT(print_layout);
REFLECT(apprentice_location);
#if USE_OLD_STYLE_UPDATE_CHECKER
REFLECT(updates_url);
#else
REFLECT_COMPAT_IGNORE(<306,"updates url",String);
#endif
REFLECT(package_versions_url);
REFLECT(installer_list_url);
REFLECT(check_updates);
REFLECT(check_updates_all);
REFLECT(install_type);
REFLECT(website_url);
REFLECT(game_settings);
REFLECT(stylesheet_settings);
REFLECT(default_stylesheet_settings);
REFLECT_COMPAT(<300, "style_settings", stylesheet_settings);
REFLECT_COMPAT(<300, "default_style_settings", default_stylesheet_settings);
REFLECT(export_options);
}
void Settings::clear() {
recent_sets.clear();
game_settings.clear();
stylesheet_settings.clear();
default_stylesheet_settings = StyleSheetSettings();
export_options.clear();
}
void Settings::read() {
// clear current settings, otherwise we duplicate vector elements
clear();
// (re)load settings
String filename = settingsFile();
if (wxFileExists(filename)) {
// settings file not existing is not an error
wxFileInputStream stream(filename);
if (!stream.Ok()) return; // failure is not an error
Reader reader(stream, nullptr, filename);
reader.handle_greedy(*this);
}
}
void Settings::write() {
wxFileOutputStream stream(settingsFile());
Writer writer(stream, app_version);
writer.handle(*this);
}