Skip to content

Commit 19242b5

Browse files
authored
fix: issues/380(osgb导出gltf不支持文件名包含路径) (#381)
1 parent 97a8048 commit 19242b5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/fun_c.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#[no_mangle]
22
pub extern "C" fn write_file(file_name: *const libc::c_char, buf: *const u8, buf_len: u32) -> bool {
33
use std::ffi;
4+
use std::fs;
45
use std::fs::File;
56
use std::io::prelude::*;
67
use std::slice;
78

89
unsafe {
910
if let Ok(file_name) = ffi::CStr::from_ptr(file_name).to_str() {
11+
use std::path::Path;
12+
let path = Path::new(file_name);
13+
if let Some(parent) = path.parent() {
14+
if !parent.as_os_str().is_empty() {
15+
if let Err(e) = fs::create_dir_all(parent) {
16+
error!("create dir fail: {}", e);
17+
return false;
18+
}
19+
}
20+
}
1021
if let Ok(mut f) = File::create(file_name) {
1122
let arr = slice::from_raw_parts(buf, buf_len as usize);
1223
match f.write_all(arr) {

0 commit comments

Comments
 (0)