diff options
author | Juan Linietsky <reduzio@gmail.com> | 2022-12-05 19:01:59 +0100 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2023-01-09 18:52:00 +0100 |
commit | 07a964fce34bf72610db5d0a50c5c18adb974f97 (patch) | |
tree | f0d804da58e697b9a58ad47b624d0b2524064933 /core/io/resource_importer.cpp | |
parent | 964fc6e15d8631a06c2f442299759041328a8473 (diff) |
Ability to change a resource UID from API
* Works for text, binary and imported resources
* Allows better clean up of duplicate files.
TODO (future PRs):
* Use this API for assigning new UIDs to copied files.
* Use this API for UID conflict on FS scanning (if more than one file has the same UID, the newer one(s) should get assigned a different UID).
Diffstat (limited to 'core/io/resource_importer.cpp')
-rw-r--r-- | core/io/resource_importer.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/io/resource_importer.cpp b/core/io/resource_importer.cpp index a4f4d705ee..dc1de6b9ce 100644 --- a/core/io/resource_importer.cpp +++ b/core/io/resource_importer.cpp @@ -31,6 +31,7 @@ #include "resource_importer.h" #include "core/config/project_settings.h" +#include "core/io/config_file.h" #include "core/os/os.h" #include "core/variant/variant_parser.h" @@ -484,3 +485,18 @@ void ResourceFormatImporter::add_importer(const Ref<ResourceImporter> &p_importe importers.push_back(p_importer); } } + +///// + +Error ResourceFormatImporterSaver::set_uid(const String &p_path, ResourceUID::ID p_uid) { + Ref<ConfigFile> cf; + cf.instantiate(); + Error err = cf->load(p_path + ".import"); + if (err != OK) { + return err; + } + cf->set_value("remap", "uid", ResourceUID::get_singleton()->id_to_text(p_uid)); + cf->save(p_path + ".import"); + + return OK; +} |