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
40291a4d
Commit
40291a4d
authored
Aug 07, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved clean_filename to file_utils.cpp where it belongs;
Split up images exporting, and moved it to data/formats/image
parent
f5e9fc0d
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
101 additions
and
95 deletions
+101
-95
src/data/format/formats.hpp
src/data/format/formats.hpp
+5
-0
src/data/format/image.cpp
src/data/format/image.cpp
+32
-0
src/gui/images_export_window.cpp
src/gui/images_export_window.cpp
+6
-50
src/gui/images_export_window.hpp
src/gui/images_export_window.hpp
+1
-16
src/main.cpp
src/main.cpp
+1
-4
src/util/file_utils.cpp
src/util/file_utils.cpp
+45
-0
src/util/file_utils.hpp
src/util/file_utils.hpp
+11
-1
src/util/string.cpp
src/util/string.cpp
+0
-19
src/util/string.hpp
src/util/string.hpp
+0
-5
No files found.
src/data/format/formats.hpp
View file @
40291a4d
...
...
@@ -11,6 +11,7 @@
#include <util/prec.hpp>
#include <util/error.hpp>
#include <data/settings.hpp>
class
Game
;
DECLARE_POINTER_TYPE
(
Set
);
...
...
@@ -85,6 +86,10 @@ FileFormatP mtg_editor_file_format();
/// Export images for each card in a set to a list of files
void
export_images
(
Window
*
parent
,
const
SetP
&
set
);
/// Export the image for each card in a list of cards
void
export_images
(
const
SetP
&
set
,
vector
<
CardP
>&
cards
,
const
String
&
path
,
const
String
&
filename_template
,
FilenameConflicts
conflicts
);
/// Export the image of a single card
void
export_image
(
const
SetP
&
set
,
const
CardP
&
card
,
const
String
&
filename
);
...
...
src/data/format/image.cpp
View file @
40291a4d
...
...
@@ -7,11 +7,16 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/tagged_string.hpp>
#include <data/format/formats.hpp>
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/stylesheet.hpp>
#include <data/settings.hpp>
#include <render/card/viewer.hpp>
#include <wx/filename.h>
DECLARE_TYPEOF_COLLECTION
(
CardP
);
// ----------------------------------------------------------------------------- : Single card export
...
...
@@ -59,3 +64,30 @@ Bitmap export_bitmap(const SetP& set, const CardP& card) {
}
// ----------------------------------------------------------------------------- : Multiple card export
void
export_images
(
const
SetP
&
set
,
vector
<
CardP
>&
cards
,
const
String
&
path
,
const
String
&
filename_template
,
FilenameConflicts
conflicts
)
{
wxBusyCursor
busy
;
// Script
ScriptP
filename_script
=
parse
(
filename_template
,
nullptr
,
true
);
// Path
wxFileName
fn
(
path
);
// Export
std
::
set
<
String
>
used
;
// for CONFLICT_NUMBER_OVERWRITE
FOR_EACH_CONST
(
card
,
cards
)
{
// filename for this card
Context
&
ctx
=
set
->
getContext
(
card
);
String
filename
=
clean_filename
(
untag
(
ctx
.
eval
(
*
filename_script
)
->
toString
()));
if
(
!
filename
)
continue
;
// no filename -> no saving
// full path
fn
.
SetFullName
(
filename
);
// does the file exist?
if
(
!
resolve_filename_conflicts
(
fn
,
conflicts
,
used
))
continue
;
// write image
filename
=
fn
.
GetFullPath
();
used
.
insert
(
filename
);
export_image
(
set
,
card
,
filename
);
}
}
src/gui/images_export_window.cpp
View file @
40291a4d
...
...
@@ -57,50 +57,6 @@ ImagesExportWindow::ImagesExportWindow(Window* parent, const SetP& set)
// ----------------------------------------------------------------------------- : Exporting the images
void
ExportCardImages
::
exportImages
(
const
SetP
&
set
,
wxFileName
&
fn
,
const
String
&
filename_template
,
FilenameConflicts
conflicts
)
{
// Script
ScriptP
filename_script
=
parse
(
filename_template
,
nullptr
,
true
);
// Export
std
::
set
<
String
>
used
;
// for CONFLICT_NUMBER_OVERWRITE
FOR_EACH
(
card
,
set
->
cards
)
{
if
(
includeCard
(
card
))
{
// filename for this card
Context
&
ctx
=
set
->
getContext
(
card
);
String
filename
=
untag
(
ctx
.
eval
(
*
filename_script
)
->
toString
());
if
(
!
filename
)
continue
;
// no filename -> no saving
// sanitize filename
fn
.
SetFullName
(
clean_filename
(
filename
));
// does the file exist?
if
(
fn
.
FileExists
())
{
// file exists, what to do?
switch
(
conflicts
)
{
case
CONFLICT_KEEP_OLD
:
goto
next_card
;
case
CONFLICT_OVERWRITE
:
break
;
case
CONFLICT_NUMBER
:
{
int
i
=
0
;
String
ext
=
fn
.
GetExt
();
do
{
fn
.
SetExt
(
String
()
<<
++
i
<<
_
(
"."
)
<<
ext
);
}
while
(
fn
.
FileExists
());
}
case
CONFLICT_NUMBER_OVERWRITE
:
{
int
i
=
0
;
String
ext
=
fn
.
GetExt
();
while
(
used
.
find
(
fn
.
GetFullPath
())
!=
used
.
end
())
{
fn
.
SetExt
(
String
()
<<
++
i
<<
_
(
"."
)
<<
ext
);
}
}
}
}
// write image
filename
=
fn
.
GetFullPath
();
used
.
insert
(
filename
);
export_image
(
set
,
card
,
filename
);
}
next_card:
;
}
}
void
ImagesExportWindow
::
onOk
(
wxCommandEvent
&
)
{
// Update settings
GameSettings
&
gs
=
settings
.
gameSettingsFor
(
*
set
->
game
);
...
...
@@ -114,17 +70,17 @@ void ImagesExportWindow::onOk(wxCommandEvent&) {
String
name
=
wxFileSelector
(
_TITLE_
(
"export images"
),
_
(
""
),
_LABEL_
(
"filename is ignored"
),
_
(
""
),
_LABEL_
(
"filename is ignored"
)
+
_
(
"|*"
),
wxSAVE
,
this
);
if
(
name
.
empty
())
return
;
wxFileName
fn
(
name
);
// Cards to export
vector
<
CardP
>
cards
;
FOR_EACH
(
card
,
set
->
cards
)
{
if
(
isSelected
(
card
))
cards
.
push_back
(
card
);
}
// Export
export
Images
(
set
,
fn
,
gs
.
images_export_filename
,
gs
.
images_export_conflicts
);
export
_images
(
set
,
cards
,
name
,
gs
.
images_export_filename
,
gs
.
images_export_conflicts
);
// Done
EndModal
(
wxID_OK
);
}
bool
ImagesExportWindow
::
includeCard
(
const
CardP
&
card
)
const
{
return
isSelected
(
card
);
}
BEGIN_EVENT_TABLE
(
ImagesExportWindow
,
CardSelectWindow
)
EVT_BUTTON
(
wxID_OK
,
ImagesExportWindow
::
onOk
)
...
...
src/gui/images_export_window.hpp
View file @
40291a4d
...
...
@@ -12,24 +12,11 @@
#include <util/prec.hpp>
#include <gui/card_select_window.hpp>
#include <data/settings.hpp>
class
wxFileName
;
// ----------------------------------------------------------------------------- : ImagesExportWindow
/// Export the cards in a set
class
ExportCardImages
{
public:
void
exportImages
(
const
SetP
&
set
,
wxFileName
&
filename
,
const
String
&
filename_template
,
FilenameConflicts
conflicts
);
virtual
~
ExportCardImages
()
{}
protected:
/// Should the given card be exported?
virtual
bool
includeCard
(
const
CardP
&
card
)
const
{
return
true
;
}
};
// ----------------------------------------------------------------------------- : ImagesExportWindow
/// A window for selecting a subset of the cards from a set to export to images
class
ImagesExportWindow
:
public
CardSelectWindow
,
private
ExportCardImages
{
class
ImagesExportWindow
:
public
CardSelectWindow
{
public:
ImagesExportWindow
(
Window
*
parent
,
const
SetP
&
set
);
...
...
@@ -38,8 +25,6 @@ class ImagesExportWindow : public CardSelectWindow, private ExportCardImages {
void
onOk
(
wxCommandEvent
&
);
virtual
bool
includeCard
(
const
CardP
&
card
)
const
;
wxTextCtrl
*
format
;
wxChoice
*
conflicts
;
};
...
...
src/main.cpp
View file @
40291a4d
...
...
@@ -18,7 +18,6 @@
#include <cli/text_io_handler.hpp>
#include <gui/welcome_window.hpp>
#include <gui/update_checker.hpp>
#include <gui/images_export_window.hpp>
#include <gui/packages_window.hpp>
#include <gui/set/window.hpp>
#include <gui/symbol/window.hpp>
...
...
@@ -220,10 +219,8 @@ int MSE::OnRun() {
path
+=
_
(
"/x"
);
out
=
out
.
substr
(
pos
+
1
);
}
wxFileName
fn
(
path
);
// export
ExportCardImages
exporter
;
exporter
.
exportImages
(
set
,
fn
,
out
,
CONFLICT_NUMBER_OVERWRITE
);
export_images
(
set
,
set
->
cards
,
path
,
out
,
CONFLICT_NUMBER_OVERWRITE
);
return
EXIT_SUCCESS
;
}
else
{
handle_error
(
_
(
"Invalid command line argument:
\n
"
)
+
String
(
argv
[
1
]));
...
...
src/util/file_utils.cpp
View file @
40291a4d
...
...
@@ -36,6 +36,51 @@ bool ignore_file(const String& name) {
return
name
==
_
(
"Thumbs.db"
);
// winXP explorer thumbnails
}
bool
is_filename_char
(
Char
c
)
{
return
isAlnum
(
c
)
||
c
==
_
(
' '
)
||
c
==
_
(
'_'
)
||
c
==
_
(
'-'
)
||
c
==
_
(
'.'
);
}
String
clean_filename
(
const
String
&
name
)
{
String
clean
;
FOR_EACH_CONST
(
c
,
name
)
{
if
(
is_filename_char
(
c
))
{
clean
+=
c
;
}
}
if
(
clean
.
empty
()
||
starts_with
(
clean
,
_
(
"."
)))
{
clean
=
_
(
"no-name"
)
+
clean
;
}
return
clean
;
}
bool
resolve_filename_conflicts
(
wxFileName
&
fn
,
FilenameConflicts
conflicts
,
set
<
String
>&
used
)
{
switch
(
conflicts
)
{
case
CONFLICT_KEEP_OLD
:
return
!
fn
.
FileExists
();
case
CONFLICT_OVERWRITE
:
return
true
;
case
CONFLICT_NUMBER
:
{
int
i
=
0
;
String
ext
=
fn
.
GetExt
();
while
(
fn
.
FileExists
())
{
fn
.
SetExt
(
String
()
<<
++
i
<<
_
(
"."
)
<<
ext
);
}
return
true
;
}
case
CONFLICT_NUMBER_OVERWRITE
:
{
int
i
=
0
;
String
ext
=
fn
.
GetExt
();
while
(
used
.
find
(
fn
.
GetFullPath
())
!=
used
.
end
())
{
fn
.
SetExt
(
String
()
<<
++
i
<<
_
(
"."
)
<<
ext
);
}
return
true
;
}
default:
{
throw
InternalError
(
_
(
"resolve_filename_conflicts: default case"
));
}
}
}
// ----------------------------------------------------------------------------- : Directories
bool
create_parent_dirs
(
const
String
&
file
)
{
...
...
src/util/file_utils.hpp
View file @
40291a4d
...
...
@@ -10,6 +10,8 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/settings.hpp>
class
wxFileName
;
// ----------------------------------------------------------------------------- : File names
...
...
@@ -19,9 +21,17 @@ String normalize_filename(const String& filename);
/// Normalize a filename as much as possible, for files in packages
String
normalize_internal_filename
(
const
String
&
filename
);
/// Should a file with the given name be ignored?
/// Should a file with the given name be ignored in packages?
/** true for hidden OS and version control files */
bool
ignore_file
(
const
String
&
name
);
/// Make sure a string is safe to use as a filename
String
clean_filename
(
const
String
&
name
);
/// Change the filename fn if it already exists, in the way described by conflicts.
/** Returns true if the filename should be used, false if failed. */
bool
resolve_filename_conflicts
(
wxFileName
&
fn
,
FilenameConflicts
conflicts
,
set
<
String
>&
used
);
// ----------------------------------------------------------------------------- : Removing and renaming
/// Ensure that the parent directories of the given filename exist
...
...
src/util/string.cpp
View file @
40291a4d
...
...
@@ -397,25 +397,6 @@ bool cannocial_name_compare(const String& as, const Char* b) {
}
}
// ----------------------------------------------------------------------------- : Filenames
bool
is_filename_char
(
Char
c
)
{
return
isAlnum
(
c
)
||
c
==
_
(
' '
)
||
c
==
_
(
'_'
)
||
c
==
_
(
'-'
)
||
c
==
_
(
'.'
);
}
String
clean_filename
(
const
String
&
name
)
{
String
clean
;
FOR_EACH_CONST
(
c
,
name
)
{
if
(
is_filename_char
(
c
))
{
clean
+=
c
;
}
}
if
(
clean
.
empty
()
||
starts_with
(
clean
,
_
(
"."
)))
{
clean
=
_
(
"no-name"
)
+
clean
;
}
return
clean
;
}
// ----------------------------------------------------------------------------- : Regular expressions
/// Escape a single character for use in regular expressions
...
...
src/util/string.hpp
View file @
40291a4d
...
...
@@ -196,11 +196,6 @@ bool is_substr_i(const String& str, size_t pos, const String& cmp);
/// Compare two strings for equality, b may contain '_' where a contains ' '
bool
cannocial_name_compare
(
const
String
&
a
,
const
Char
*
b
);
// ----------------------------------------------------------------------------- : Filenames
/// Make sure a string is safe to use as a filename
String
clean_filename
(
const
String
&
name
);
// ----------------------------------------------------------------------------- : Regular expressions
/// Escape a single character for use in regular expressions
...
...
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