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
bc8b7dcd
Commit
bc8b7dcd
authored
Apr 19, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed handling of duplicate filenames for images export
parent
43d47e10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
+26
-12
src/gui/images_export_window.cpp
src/gui/images_export_window.cpp
+26
-12
No files found.
src/gui/images_export_window.cpp
View file @
bc8b7dcd
...
@@ -56,10 +56,8 @@ ImagesExportWindow::ImagesExportWindow(Window* parent, const SetP& set)
...
@@ -56,10 +56,8 @@ ImagesExportWindow::ImagesExportWindow(Window* parent, const SetP& set)
// ----------------------------------------------------------------------------- : Exporting the images
// ----------------------------------------------------------------------------- : Exporting the images
// filename.3.ext -> filename.4.ext
bool
is_filename_char
(
Char
c
)
{
void
inc_number_filename
(
String
&
filename
)
{
return
isAlnum
(
c
)
||
c
==
_
(
' '
)
||
c
==
_
(
'_'
)
||
c
==
_
(
'-'
)
||
c
==
_
(
'.'
);
// TODO
throw
"TODO"
;
}
}
void
ImagesExportWindow
::
onOk
(
wxCommandEvent
&
)
{
void
ImagesExportWindow
::
onOk
(
wxCommandEvent
&
)
{
...
@@ -75,7 +73,7 @@ void ImagesExportWindow::onOk(wxCommandEvent&) {
...
@@ -75,7 +73,7 @@ void ImagesExportWindow::onOk(wxCommandEvent&) {
ScriptP
filename_script
=
parse
(
gs
.
images_export_filename
,
true
);
ScriptP
filename_script
=
parse
(
gs
.
images_export_filename
,
true
);
// Select filename
// Select filename
String
name
=
wxFileSelector
(
_TITLE_
(
"export images"
),
_
(
""
),
_LABEL_
(
"filename is ignored"
),
_
(
""
),
String
name
=
wxFileSelector
(
_TITLE_
(
"export images"
),
_
(
""
),
_LABEL_
(
"filename is ignored"
),
_
(
""
),
_LABEL_
(
"
all files
"
)
+
_
(
"|*.*"
),
wxSAVE
,
this
);
_LABEL_
(
"
filename is ignored
"
)
+
_
(
"|*.*"
),
wxSAVE
,
this
);
if
(
name
.
empty
())
return
;
if
(
name
.
empty
())
return
;
wxFileName
fn
(
name
);
wxFileName
fn
(
name
);
// Export
// Export
...
@@ -86,25 +84,41 @@ void ImagesExportWindow::onOk(wxCommandEvent&) {
...
@@ -86,25 +84,41 @@ void ImagesExportWindow::onOk(wxCommandEvent&) {
Context
&
ctx
=
set
->
getContext
(
card
);
Context
&
ctx
=
set
->
getContext
(
card
);
String
filename
=
untag
(
ctx
.
eval
(
*
filename_script
)
->
toString
());
String
filename
=
untag
(
ctx
.
eval
(
*
filename_script
)
->
toString
());
if
(
!
filename
)
continue
;
// no filename -> no saving
if
(
!
filename
)
continue
;
// no filename -> no saving
fn
.
SetName
(
filename
);
// sanitize filename
filename
=
fn
.
GetFullPath
();
String
clean_filename
;
if
(
wxFileExists
(
filename
))
{
FOR_EACH
(
c
,
filename
)
{
if
(
is_filename_char
(
c
))
{
clean_filename
+=
c
;
}
}
if
(
clean_filename
.
empty
()
||
starts_with
(
clean_filename
,
_
(
"."
)))
{
clean_filename
=
_
(
"no-name"
)
+
clean_filename
;
}
fn
.
SetFullName
(
clean_filename
);
// does the file exist?
if
(
fn
.
FileExists
())
{
// file exists, what to do?
// file exists, what to do?
switch
(
gs
.
images_export_conflicts
)
{
switch
(
gs
.
images_export_conflicts
)
{
case
CONFLICT_KEEP_OLD
:
goto
next_card
;
case
CONFLICT_KEEP_OLD
:
goto
next_card
;
case
CONFLICT_OVERWRITE
:
break
;
case
CONFLICT_OVERWRITE
:
break
;
case
CONFLICT_NUMBER
:
{
case
CONFLICT_NUMBER
:
{
int
i
=
0
;
String
ext
=
fn
.
GetExt
();
do
{
do
{
inc_number_filename
(
filename
);
fn
.
SetExt
(
String
()
<<
++
i
<<
_
(
"."
)
<<
ext
);
}
while
(
wxFileExists
(
filename
));
}
while
(
fn
.
FileExists
(
));
}
}
case
CONFLICT_NUMBER_OVERWRITE
:
{
case
CONFLICT_NUMBER_OVERWRITE
:
{
while
(
used
.
find
(
filename
)
!=
used
.
end
())
{
int
i
=
0
;
inc_number_filename
(
filename
);
String
ext
=
fn
.
GetExt
();
while
(
used
.
find
(
fn
.
GetFullPath
())
!=
used
.
end
())
{
fn
.
SetExt
(
String
()
<<
++
i
<<
_
(
"."
)
<<
ext
);
}
}
}
}
}
}
}
}
// write image
filename
=
fn
.
GetFullPath
();
used
.
insert
(
filename
);
used
.
insert
(
filename
);
export_image
(
set
,
card
,
filename
);
export_image
(
set
,
card
,
filename
);
}
}
...
...
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