From 948bf98b86d62a53d8f32db8e0caf757d816e34d Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 8 May 2023 14:27:52 -0300 Subject: [PATCH] Saving a non-sequence file type (aseprite/gif/webp/fli/etc.) must create all required directories too --- src/app/file/file.cpp | 29 +++++++++++++++++------------ src/app/file/file.h | 1 + tests/cli/save-as.sh | 3 --- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index 8f9da324c..046c56ab8 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -1007,18 +1007,7 @@ void FileOp::operate(IFileOpProgress* progress) m_filename = m_seq.filename_list[outputFrame]; // Make directories - { - std::string dir = base::get_file_path(m_filename); - try { - if (!base::is_directory(dir)) - base::make_all_directories(dir); - } - catch (const std::exception& ex) { - // Ignore errors and make the delegate fail - setError("Error creating directory \"%s\"\n%s", - dir.c_str(), ex.what()); - } - } + makeDirectories(); // Call the "save" procedure... did it fail? if (!m_format->save(this)) { @@ -1039,6 +1028,8 @@ void FileOp::operate(IFileOpProgress* progress) } // Direct save to a file. else { + makeDirectories(); + // Call the "save" procedure. if (!m_format->save(this)) { setError("Error saving the sprite in the file \"%s\"\n", @@ -1472,4 +1463,18 @@ void FileOp::prepareForSequence() m_formatOptions.reset(); } +void FileOp::makeDirectories() +{ + std::string dir = base::get_file_path(m_filename); + try { + if (!base::is_directory(dir)) + base::make_all_directories(dir); + } + catch (const std::exception& ex) { + // Ignore errors and make the delegate fail + setError("Error creating directory \"%s\"\n%s", + dir.c_str(), ex.what()); + } +} + } // namespace app diff --git a/src/app/file/file.h b/src/app/file/file.h index 378330600..f6696c66d 100644 --- a/src/app/file/file.h +++ b/src/app/file/file.h @@ -325,6 +325,7 @@ namespace app { void prepareForSequence(); void makeAbstractImage(); + void makeDirectories(); }; // Available extensions for each load/save operation. diff --git a/tests/cli/save-as.sh b/tests/cli/save-as.sh index 80dced488..8edc709c2 100644 --- a/tests/cli/save-as.sh +++ b/tests/cli/save-as.sh @@ -36,7 +36,6 @@ layer (fg) 2.png" "list_files $d" # --save-as {layer} d=$t/save-as-layer -mkdir $d # TODO why do we need this? $ASEPRITE -b sprites/1empty3.aseprite --save-as $d/layer-{layer}.gif || exit 1 expect "layer-bg.gif layer-fg.gif" "list_files $d" @@ -182,7 +181,6 @@ if [[ "$(uname)" =~ "MINGW" ]] || [[ "$(uname)" =~ "MSYS" ]] ; then echo Do nothing else d=$t/save-as-groups-and-hidden -mkdir $d $ASEPRITE -b sprites/groups2.aseprite -layer \* -save-as "$d/g2-all.png" || exit 1 $ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer items -save-as "$d/g2-all-without-items.png" || exit 1 $ASEPRITE -b sprites/groups2.aseprite -layer \* -ignore-layer gun -save-as "$d/g2-all-without-gun1.png" || exit 1 @@ -327,7 +325,6 @@ square.png" "list_files $d" # Test that -save-as -tag will save the right tag frames in webp file format d=$t/save-as-tag-webp -mkdir $d # TODO why do we need this? $ASEPRITE -b -frame-tag "a" sprites/1empty3.aseprite -save-as $d/save-as-tag.webp || exit 1 expect "save-as-tag.webp" "list_files $d" cat >$d/compare.lua <