Repository navigation
Expand file tree
/
Copy pathformats.cpp
More file actions
70 lines (60 loc) · 2.38 KB
/
Copy pathformats.cpp
File metadata and controls
70 lines (60 loc) · 2.38 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
//+----------------------------------------------------------------------------+
//| 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/format/formats.hpp>
#include <data/set.hpp>
DECLARE_POINTER_TYPE(FileFormat);
// ----------------------------------------------------------------------------- : Formats
// All supported file formats
vector<FileFormatP> file_formats;
void init_file_formats() {
file_formats.push_back(mse2_file_format());
file_formats.push_back(mse1_file_format());
file_formats.push_back(mtg_editor_file_format());
}
String import_formats() {
String all_extensions; // type1;type2
String type_strings; // |name1|type1|name2|type2
for(auto& f : file_formats) {
if (f->canImport()) {
if (!all_extensions.empty()) all_extensions += _(";");
all_extensions += f->matches();
type_strings += _("|") + f->name() + _("|") + f->matches();
}
}
return _("Set files|") + all_extensions + type_strings + _("|All files (*.*)|*");
}
String export_formats(const Game& game) {
String type_strings; // name1|type1|name2|type2
for(auto& f : file_formats) {
if (f->canExport(game)) {
if (!type_strings.empty()) type_strings += _("|");
type_strings += f->name() + _("|") + f->matches();
}
}
return type_strings;
}
void export_set(Set& set, const String& filename, size_t format_index, bool is_copy) {
FileFormatP format = file_formats.at(format_index);
if (!format->canExport(*set.game)) {
throw InternalError(_("File format doesn't apply to set"));
}
format->exportSet(set, filename, is_copy);
}
SetP import_set(String name) {
size_t pos = name.find_last_of(_('.'));
String extension = pos==String::npos ? _("") : name.substr(pos + 1);
// determine format
for(auto& f : file_formats) {
if (f->extension() == extension) {
return f->importSet(name);
}
}
// default: use first format = MSE2 format
assert(!file_formats.empty() && file_formats[0]->canImport());
return file_formats[0]->importSet(name);
}