Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/script/functions/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -375,6 +381,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);
Expand All @@ -389,6 +396,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);
Expand Down Expand Up @@ -421,6 +429,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);
Expand All @@ -433,6 +442,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);

Expand Down