Fix #120253: Batch export of STL files incorrectly handles .stl suffix

It was mostly correct, except for the case where a user sets an
empty string as the export filename. What was happening is:
- STL exporter invocation adds ".stl" extension, so the path becomes
  foo/.stl
- Code tries to replace extension with "ObjectName.stl", but
  BLI_path_extension_replace sees that the filename part starts with
  a dot and thinks the ".stl" part is the whole filename, not the
  extension
- Resulting path thus becomes "foo/.stlObjectName.stl"
This commit is contained in:
Aras Pranckevicius
2024-04-11 11:07:55 +03:00
parent 793b99ca7c
commit 1ea014112b

View File

@@ -77,10 +77,14 @@ void export_frame(Depsgraph *depsgraph,
std::replace(object_name.begin(), object_name.end(), ' ', '_');
/* Include object name in the exported file name. */
std::string suffix = object_name + ".stl";
char filepath[FILE_MAX];
STRNCPY(filepath, export_params.filepath);
BLI_path_extension_replace(filepath, FILE_MAX, suffix.c_str());
BLI_path_suffix(filepath, FILE_MAX, object_name.c_str(), "");
/* Make sure we have .stl extension (case insensitive). */
if (!BLI_path_extension_check(filepath, ".stl")) {
BLI_path_extension_ensure(filepath, FILE_MAX, ".stl");
}
try {
writer = std::make_unique<FileWriter>(filepath, export_params.ascii_format);
}