mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 21:47:00 -04:00
fixed handling of duplicate filenames for images export
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@268 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -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&) {
|
|||||||
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&) {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user