Saving a non-sequence file type (aseprite/gif/webp/fli/etc.) must create all required directories too

This commit is contained in:
David Capello 2023-05-08 14:27:52 -03:00
parent d75424fe87
commit 948bf98b86
3 changed files with 18 additions and 15 deletions

View File

@ -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

View File

@ -325,6 +325,7 @@ namespace app {
void prepareForSequence();
void makeAbstractImage();
void makeDirectories();
};
// Available extensions for each load/save operation.

View File

@ -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 <<EOF