Make FileAccess and DirAccess classes reference counted.
This commit is contained in:
@@ -256,8 +256,8 @@ Error GLTFDocument::_serialize_scenes(Ref<GLTFState> state) {
|
||||
|
||||
Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> state) {
|
||||
Error err;
|
||||
FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (!f) {
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (f.is_null()) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ Error GLTFDocument::_parse_json(const String &p_path, Ref<GLTFState> state) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error GLTFDocument::_parse_glb(FileAccess *f, Ref<GLTFState> state) {
|
||||
Error GLTFDocument::_parse_glb(Ref<FileAccess> f, Ref<GLTFState> state) {
|
||||
ERR_FAIL_NULL_V(f, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_NULL_V(state, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(f->get_position() != 0, ERR_FILE_CANT_READ);
|
||||
@@ -696,8 +696,8 @@ Error GLTFDocument::_encode_buffer_glb(Ref<GLTFState> state, const String &p_pat
|
||||
String filename = p_path.get_basename().get_file() + itos(i) + ".bin";
|
||||
String path = p_path.get_base_dir() + "/" + filename;
|
||||
Error err;
|
||||
FileAccessRef f = FileAccess::open(path, FileAccess::WRITE, &err);
|
||||
if (!f) {
|
||||
Ref<FileAccess> f = FileAccess::open(path, FileAccess::WRITE, &err);
|
||||
if (f.is_null()) {
|
||||
return err;
|
||||
}
|
||||
if (buffer_data.size() == 0) {
|
||||
@@ -705,7 +705,6 @@ Error GLTFDocument::_encode_buffer_glb(Ref<GLTFState> state, const String &p_pat
|
||||
}
|
||||
f->create(FileAccess::ACCESS_RESOURCES);
|
||||
f->store_buffer(buffer_data.ptr(), buffer_data.size());
|
||||
f->close();
|
||||
gltf_buffer["uri"] = filename;
|
||||
gltf_buffer["byteLength"] = buffer_data.size();
|
||||
buffers.push_back(gltf_buffer);
|
||||
@@ -729,8 +728,8 @@ Error GLTFDocument::_encode_buffer_bins(Ref<GLTFState> state, const String &p_pa
|
||||
String filename = p_path.get_basename().get_file() + itos(i) + ".bin";
|
||||
String path = p_path.get_base_dir() + "/" + filename;
|
||||
Error err;
|
||||
FileAccessRef f = FileAccess::open(path, FileAccess::WRITE, &err);
|
||||
if (!f) {
|
||||
Ref<FileAccess> f = FileAccess::open(path, FileAccess::WRITE, &err);
|
||||
if (f.is_null()) {
|
||||
return err;
|
||||
}
|
||||
if (buffer_data.size() == 0) {
|
||||
@@ -738,7 +737,6 @@ Error GLTFDocument::_encode_buffer_bins(Ref<GLTFState> state, const String &p_pa
|
||||
}
|
||||
f->create(FileAccess::ACCESS_RESOURCES);
|
||||
f->store_buffer(buffer_data.ptr(), buffer_data.size());
|
||||
f->close();
|
||||
gltf_buffer["uri"] = filename;
|
||||
gltf_buffer["byteLength"] = buffer_data.size();
|
||||
buffers.push_back(gltf_buffer);
|
||||
@@ -3021,7 +3019,7 @@ Error GLTFDocument::_serialize_images(Ref<GLTFState> state, const String &p_path
|
||||
String texture_dir = "textures";
|
||||
String path = p_path.get_base_dir();
|
||||
String new_texture_dir = path + "/" + texture_dir;
|
||||
DirAccessRef da = DirAccess::open(path);
|
||||
Ref<DirAccess> da = DirAccess::open(path);
|
||||
if (!da->dir_exists(new_texture_dir)) {
|
||||
da->make_dir(new_texture_dir);
|
||||
}
|
||||
@@ -6588,9 +6586,9 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> state, AnimationPlayer *ap,
|
||||
}
|
||||
}
|
||||
|
||||
Error GLTFDocument::_parse(Ref<GLTFState> state, String p_path, FileAccess *f, int p_bake_fps) {
|
||||
Error GLTFDocument::_parse(Ref<GLTFState> state, String p_path, Ref<FileAccess> f, int p_bake_fps) {
|
||||
Error err;
|
||||
if (!f) {
|
||||
if (f.is_null()) {
|
||||
return FAILED;
|
||||
}
|
||||
f->seek(0);
|
||||
@@ -6614,7 +6612,6 @@ Error GLTFDocument::_parse(Ref<GLTFState> state, String p_path, FileAccess *f, i
|
||||
ERR_FAIL_COND_V(err != OK, ERR_PARSE_ERROR);
|
||||
state->json = json.get_data();
|
||||
}
|
||||
f->close();
|
||||
|
||||
if (!state->json.has("asset")) {
|
||||
return ERR_PARSE_ERROR;
|
||||
@@ -6703,8 +6700,8 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) {
|
||||
if (p_path.to_lower().ends_with("glb")) {
|
||||
err = _encode_buffer_glb(state, p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V(!f, FAILED);
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V(f.is_null(), FAILED);
|
||||
|
||||
String json = Variant(state->json).to_json_string();
|
||||
|
||||
@@ -6741,18 +6738,15 @@ Error GLTFDocument::_serialize_file(Ref<GLTFState> state, const String p_path) {
|
||||
for (uint32_t pad_i = binary_data_length; pad_i < binary_chunk_length; pad_i++) {
|
||||
f->store_8(0);
|
||||
}
|
||||
|
||||
f->close();
|
||||
} else {
|
||||
err = _encode_buffer_bins(state, p_path);
|
||||
ERR_FAIL_COND_V(err != OK, err);
|
||||
FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V(!f, FAILED);
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V(f.is_null(), FAILED);
|
||||
|
||||
f->create(FileAccess::ACCESS_RESOURCES);
|
||||
String json = Variant(state->json).to_json_string();
|
||||
f->store_string(json);
|
||||
f->close();
|
||||
}
|
||||
return err;
|
||||
}
|
||||
@@ -6927,9 +6921,10 @@ Error GLTFDocument::append_from_buffer(PackedByteArray p_bytes, String p_base_pa
|
||||
ERR_FAIL_COND_V(state.is_null(), FAILED);
|
||||
// TODO Add missing texture and missing .bin file paths to r_missing_deps 2021-09-10 fire
|
||||
Error err = FAILED;
|
||||
state->use_named_skin_binds =
|
||||
p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS;
|
||||
FileAccessMemory *file_access = memnew(FileAccessMemory);
|
||||
state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS;
|
||||
|
||||
Ref<FileAccessMemory> file_access;
|
||||
file_access.instantiate();
|
||||
file_access->open_custom(p_bytes.ptr(), p_bytes.size());
|
||||
err = _parse(state, p_base_path.get_base_dir(), file_access, p_bake_fps);
|
||||
ERR_FAIL_COND_V(err != OK, FAILED);
|
||||
@@ -7032,7 +7027,7 @@ Error GLTFDocument::append_from_file(String p_path, Ref<GLTFState> r_state, uint
|
||||
r_state->filename = p_path.get_file().get_basename();
|
||||
r_state->use_named_skin_binds = p_flags & GLTF_IMPORT_USE_NAMED_SKIN_BINDS;
|
||||
Error err;
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN);
|
||||
ERR_FAIL_NULL_V(f, ERR_FILE_CANT_OPEN);
|
||||
String base_path = p_base_path;
|
||||
|
||||
Reference in New Issue
Block a user