From d9f79ef99bb7c85b999d3bee0db4b42f034f15fc Mon Sep 17 00:00:00 2001 From: Djack Donovan Date: Tue, 11 Oct 2022 21:35:02 +0200 Subject: [PATCH 1/2] export scripts can write to subdirectories Allow export scripts to write files to new subdirectories --- src/script/functions/export.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/script/functions/export.cpp b/src/script/functions/export.cpp index 361112a8..cf868a7a 100644 --- a/src/script/functions/export.cpp +++ b/src/script/functions/export.cpp @@ -54,6 +54,12 @@ String get_export_full_path(String& rel_name) { return fn.GetFullPath(); } +void ensure_dir_valid(String& path) { + wxFileName filename = path; + if (!filename.DirExists()) + filename.Mkdir(); +} + // ----------------------------------------------------------------------------- : HTML // An HTML tag @@ -386,6 +392,7 @@ SCRIPT_FUNCTION(copy_file) { // copy ExportInfo& ei = *export_info(); auto in = ei.export_template->openIn(input); + ensure_dir_valid(out_path); wxFileOutputStream out(out_path); if (!out.Ok()) throw Error(_("Unable to open file '") + out_path + _("' for output")); out.Write(*in); @@ -400,6 +407,7 @@ SCRIPT_FUNCTION(write_text_file) { // output path String out_path = get_export_full_path(file); // write + ensure_dir_valid(out_path); wxFileOutputStream out(out_path); if (!out.Ok()) throw Error(_("Unable to open file '") + out_path + _("' for output")); wxTextOutputStream tout(out); @@ -432,6 +440,7 @@ SCRIPT_FUNCTION(write_image_file) { } if (!image.Ok()) throw Error(_("Unable to generate image for file ") + file); // write + ensure_dir_valid(out_path); image.SaveFile(out_path); ei.exported_images.insert(make_pair(file, wxSize(image.GetWidth(), image.GetHeight()))); SCRIPT_RETURN(file); @@ -444,6 +453,7 @@ SCRIPT_FUNCTION(write_set_file) { String out_path = get_export_full_path(file); // export SCRIPT_PARAM_C(Set*, set); + ensure_dir_valid(out_path); set->saveCopy(out_path); // TODO: use export_set instead? SCRIPT_RETURN(file); From 5ba9a33e18d0e2ecc6547ad39be8e5b1c78e929f Mon Sep 17 00:00:00 2001 From: Brendan Hagan Date: Fri, 18 Nov 2022 21:58:33 -0500 Subject: [PATCH 2/2] misc: make export directory creation recursive --- src/script/functions/export.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/script/functions/export.cpp b/src/script/functions/export.cpp index cf868a7a..4de7e5b2 100644 --- a/src/script/functions/export.cpp +++ b/src/script/functions/export.cpp @@ -54,10 +54,11 @@ String get_export_full_path(String& rel_name) { return fn.GetFullPath(); } -void ensure_dir_valid(String& path) { - wxFileName filename = path; - if (!filename.DirExists()) - filename.Mkdir(); +void ensure_dir_valid(String& path) { + if (!wxDirExists(path)) { + wxFileName filename = path; + filename.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL); + } } // ----------------------------------------------------------------------------- : HTML