Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
70ac30cc
Commit
70ac30cc
authored
Oct 07, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file/import/export formats
parent
85133302
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
0 deletions
+148
-0
src/data/format/formats.cpp
src/data/format/formats.cpp
+70
-0
src/data/format/formats.hpp
src/data/format/formats.hpp
+78
-0
No files found.
src/data/format/formats.cpp
0 → 100644
View file @
70ac30cc
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <data/format/formats.hpp>
#include <data/set.hpp>
DECLARE_POINTER_TYPE
(
FileFormat
);
DECLARE_TYPEOF_COLLECTION
(
FileFormatP
);
// ----------------------------------------------------------------------------- : Formats
// All supported file formats
vector
<
FileFormatP
>
fileFormats
;
void
initFileFormats
()
{
//fileFormats.push_back(new_shared<MSE2FileFilter>());
//fileFormats.push_back(new_shared<MSE1FileFilter>());
//fileFormats.push_back(new_shared<MtgEditorFileFilter>());
}
String
importFormats
()
{
String
allExtensions
;
// type1;type2
String
typeStrings
;
// |name1|type1|name2|type2
FOR_EACH
(
f
,
fileFormats
)
{
if
(
f
->
canImport
())
{
if
(
!
allExtensions
.
empty
())
allExtensions
+=
_
(
";"
);
allExtensions
+=
_
(
"*."
)
+
f
->
extension
();
typeStrings
+=
_
(
"|"
)
+
f
->
name
()
+
_
(
"|*."
)
+
f
->
extension
();
}
}
return
_
(
"Set files|"
)
+
allExtensions
+
typeStrings
+
_
(
"|All files (*.*)|*.*"
);
}
String
exportFormats
(
const
Game
&
game
)
{
String
typeStrings
;
// name1|type1|name2|type2
FOR_EACH
(
f
,
fileFormats
)
{
if
(
f
->
canExport
(
game
))
{
if
(
!
typeStrings
.
empty
())
typeStrings
+=
_
(
"|"
);
typeStrings
+=
f
->
name
()
+
_
(
"|*."
)
+
f
->
extension
();
}
}
return
typeStrings
;
}
void
exportSet
(
const
Set
&
set
,
const
String
&
filename
,
size_t
formatType
)
{
FileFormatP
format
=
fileFormats
.
at
(
formatType
);
if
(
!
format
->
canExport
(
*
set
.
game
))
{
throw
InternalError
(
_
(
"File format doesn't apply to set"
));
}
format
->
exportSet
(
set
,
filename
);
}
SetP
importSet
(
String
name
)
{
size_t
pos
=
name
.
find_last_of
(
_
(
'.'
));
String
extension
=
pos
==
String
::
npos
?
_
(
""
)
:
name
.
substr
(
pos
+
1
);
// determine format
FOR_EACH
(
f
,
fileFormats
)
{
if
(
f
->
extension
()
==
extension
)
{
return
f
->
importSet
(
name
);
}
}
// default : use first format = MSE2 format
assert
(
!
fileFormats
.
empty
()
&&
fileFormats
[
0
]
->
canImport
());
return
fileFormats
[
0
]
->
importSet
(
name
);
}
\ No newline at end of file
src/data/format/formats.hpp
0 → 100644
View file @
70ac30cc
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_FORMAT_FORMATS
#define HEADER_DATA_FORMAT_FORMATS
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/error.hpp>
class
Game
;
DECLARE_POINTER_TYPE
(
Set
);
// ----------------------------------------------------------------------------- : FileFormat
/// A filter for a specific file format
class
FileFormat
{
public:
/// File extension used by this file format
virtual
String
extension
()
=
0
;
/// Name of the filter
virtual
String
name
()
=
0
;
/// Can it be used for importing sets?
virtual
bool
canImport
()
=
0
;
/// Can it be used for exporting sets for a particular game?
virtual
bool
canExport
(
const
Game
&
)
=
0
;
/// Import using this filter
virtual
SetP
importSet
(
const
String
&
filename
)
{
throw
InternalError
(
_
(
"Import not supported by this file format"
));
}
/// Export using this filter
virtual
void
exportSet
(
const
Set
&
set
,
const
String
&
filename
)
{
throw
InternalError
(
_
(
"Export not supported by this file format"
));
}
};
// ----------------------------------------------------------------------------- : Formats
/// Initialize the list of file formats
/** Must be called before any other methods of this header */
void
initFileFormats
();
/// List of supported import formats
/** Formated as _("All supported (type1,...)|type1,...|name|type|...|All files(*.*)|*.*").
* For use in file selection dialogs.
*/
String
importFormats
();
// List of supported export formats that a set in a specific game can be exported.
/** Similair format as importFormats, except for _('all supported') and _('all files')
*/
String
exportFormats
(
const
Game
&
game
);
/// Opens a set with the specified filename.
/** File format is chosen based on the extension, default is fileFormats[0]
* (which is the MSE2 file filter)
* throws on error, always returns a valid set
*
* NOTE: String parameter must be passed by valueso we get a copy, otherwise
* changing the recent set list could change the filename while we are opening it
* (which would be bad)
*/
SetP
importSet
(
String
name
);
/// Save a set under the specified name.
/** filterType specifies what format to use for saving, used as index in the list of file formats
*/
void
exportSet
(
const
Set
&
set
,
const
String
&
filename
,
size_t
formatType
);
// ----------------------------------------------------------------------------- : Export
// ----------------------------------------------------------------------------- : EOF
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment