#99807: Add support for exporting to USDZ - ultimate fixes #105185

Merged
Bastien Montagne merged 12 commits from mont29/blender:usdz_export_fixes into main 2023-02-26 16:37:02 +01:00
3 changed files with 55 additions and 0 deletions
Showing only changes of commit 04359b840c - Show all commits

View File

@ -142,6 +142,12 @@ double BLI_dir_free_space(const char *dir) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(
*/
char *BLI_current_working_dir(char *dir, size_t maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
eFileAttributes BLI_file_attributes(const char *path);
/**
* Changes the current working directory to the provided path.
*
* \return true on success, false otherwise.
*/
bool BLI_change_working_dir(char *dir);
/** \} */

View File

@ -56,6 +56,22 @@
#include "BLI_string.h"
#include "BLI_utildefines.h"
bool BLI_change_working_dir(char *dir)
{
if (!BLI_is_dir(dir)) {
return false;
}
#if defined(WIN32)
wchar_t wdir[FILE_MAX];
if (conv_utf_8_to_16(dir, wdir, ARRAY_SIZE(wdir)) != 0) {
return false;
}
return _wchdir(wdir) == 0;
#else
return chdir(dir) == 0;
#endif
}
char *BLI_current_working_dir(char *dir, const size_t maxncpy)
{
#if defined(WIN32)

View File

@ -1,6 +1,8 @@
/* SPDX-License-Identifier: Apache-2.0 */
#include "BLI_fileops.hh"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "testing/testing.h"
@ -37,4 +39,35 @@ TEST(fileops, fstream_open_charptr_filename)
/* Reading the file not tested here. That's deferred to `std::fstream` anyway. */
}
TEST(fileops, change_working_directory)
{
char original_wd[FILE_MAX];
BLI_current_working_dir(original_wd, FILE_MAX);
char temp_wd[FILE_MAX];
BLI_path_join(temp_wd, FILE_MAX, original_wd, "test_temp");
if (BLI_exists(temp_wd)) {
BLI_delete(temp_wd, true, false);
}
bool result = BLI_change_working_dir(temp_wd);
ASSERT_FALSE(result);
BLI_dir_create_recursive(temp_wd);
result = BLI_change_working_dir(temp_wd);
ASSERT_TRUE(result);
char cwd[FILE_MAX];
BLI_current_working_dir(cwd, FILE_MAX);
ASSERT_TRUE(BLI_path_cmp(cwd, temp_wd) == 0);
result = BLI_change_working_dir(original_wd);
ASSERT_TRUE(result);
BLI_delete(temp_wd, true, false);
}
} // namespace blender::tests