diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-05-02 16:18:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-02 16:18:17 +0200 |
commit | 647a2025138204e6d225a6f6db20caf46e5ee6f3 (patch) | |
tree | 3ef76154449599ee614d3de2993c19d4e2e9065b | |
parent | dd06cb90c541b39de764ac7bbafd61fb2b9abb48 (diff) | |
parent | 7b18c35ab29a2b91c888e384968ce2e666753a96 (diff) |
Merge pull request #60709 from bruvzg/fix_txt_res_dep_rename
-rw-r--r-- | core/io/resource_format_binary.cpp | 1 | ||||
-rw-r--r-- | scene/resources/resource_format_text.cpp | 32 |
2 files changed, 19 insertions, 14 deletions
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index b6988109c5..bc7e524892 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1287,6 +1287,7 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons fw->store_8(b); b = f->get_8(); } + f.unref(); bool all_ok = fw->get_error() == OK; diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index b18456d464..a239bf1ab9 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -890,7 +890,6 @@ Error ResourceLoaderText::rename_dependencies(Ref<FileAccess> p_f, const String fw->store_8(c); c = f->get_8(); } - f.unref(); bool all_ok = fw->get_error() == OK; @@ -898,12 +897,6 @@ Error ResourceLoaderText::rename_dependencies(Ref<FileAccess> p_f, const String return ERR_CANT_CREATE; } - fw.unref(); - - Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); - da->remove(p_path); - da->rename(p_path + ".depren", p_path); - return OK; } @@ -1439,15 +1432,26 @@ void ResourceFormatLoaderText::get_dependencies(const String &p_path, List<Strin } Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const Map<String, String> &p_map) { - Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); - if (f.is_null()) { - ERR_FAIL_V(ERR_CANT_OPEN); + Error err = OK; + { + Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ); + if (f.is_null()) { + ERR_FAIL_V(ERR_CANT_OPEN); + } + + ResourceLoaderText loader; + loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path); + loader.res_path = loader.local_path; + err = loader.rename_dependencies(f, p_path, p_map); } - ResourceLoaderText loader; - loader.local_path = ProjectSettings::get_singleton()->localize_path(p_path); - loader.res_path = loader.local_path; - return loader.rename_dependencies(f, p_path, p_map); + if (err == OK) { + Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + da->remove(p_path); + da->rename(p_path + ".depren", p_path); + } + + return err; } ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = nullptr; |