mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Merge pull request #53 from haganbmj/export_subdirectories
export scripts can write to subdirectories
This commit is contained in:
@@ -54,6 +54,13 @@ String get_export_full_path(String& rel_name) {
|
||||
return fn.GetFullPath();
|
||||
}
|
||||
|
||||
void ensure_dir_valid(String& path) {
|
||||
if (!wxDirExists(path)) {
|
||||
wxFileName filename = path;
|
||||
filename.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : HTML
|
||||
|
||||
// An HTML tag
|
||||
@@ -386,6 +393,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 +408,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 +441,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 +454,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user