Fix T13879 new OBJ exporter not saving files with Unicode characters.

Need to use BLI_fopen instead of fopen.
This commit is contained in:
Aras Pranckevicius 2022-01-21 20:14:01 -05:00 committed by Howard Trickey
parent 1f026a3db9
commit 9350005d8b
Notes: blender-bot 2024-03-22 15:57:27 +01:00
Referenced by issue #95044, New object exporter not save as right name
2 changed files with 14 additions and 9 deletions

View File

@ -26,6 +26,7 @@
#include <type_traits>
#include "BLI_compiler_attrs.h"
#include "BLI_fileops.h"
#include "BLI_string_ref.hh"
#include "BLI_utility_mixins.hh"
@ -276,7 +277,7 @@ template<eFileType filetype> class FormattedFileHandler : NonCopyable, NonMovabl
FormattedFileHandler(std::string outfile_path) noexcept(false)
: outfile_path_(std::move(outfile_path))
{
outfile_ = std::fopen(outfile_path_.c_str(), "w");
outfile_ = BLI_fopen(outfile_path_.c_str(), "w");
if (!outfile_) {
throw std::system_error(errno, std::system_category(), "Cannot open file " + outfile_path_);
}

View File

@ -1,10 +1,8 @@
/* Apache License, Version 2.0 */
#include <fstream>
#include <gtest/gtest.h>
#include <ios>
#include <memory>
#include <sstream>
#include <string>
#include <system_error>
@ -185,15 +183,21 @@ static std::unique_ptr<OBJWriter> init_writer(const OBJExportParams &params,
}
}
/* The following is relative to BKE_tempdir_base. */
const char *const temp_file_path = "output.OBJ";
/* The following is relative to BKE_tempdir_base.
* Use Latin Capital Letter A with Ogonek, Cyrillic Capital Letter Zhe
* at the end, to test I/O on non-English file names. */
const char *const temp_file_path = "output\xc4\x84\xd0\x96.OBJ";
static std::string read_temp_file_in_string(const std::string &file_path)
{
std::ifstream temp_stream(file_path);
std::ostringstream input_ss;
input_ss << temp_stream.rdbuf();
return input_ss.str();
std::string res;
size_t buffer_len;
void *buffer = BLI_file_read_text_as_mem(file_path.c_str(), 0, &buffer_len);
if (buffer != NULL) {
res.assign((const char *)buffer, buffer_len);
MEM_freeN(buffer);
}
return res;
}
TEST(obj_exporter_writer, header)