Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Do not generate *.uid files for JSON, certificates, and translations #99540

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class ResourceFormatLoaderCrypto : public ResourceFormatLoader {
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
virtual bool handles_type(const String &p_type) const override;
virtual String get_resource_type(const String &p_path) const override;

// Treat certificates as text files, do not generate a `*.{crt,key,pub}.uid` file.
virtual ResourceUID::ID get_resource_uid(const String &p_path) const override { return ResourceUID::INVALID_ID; }
virtual bool has_custom_uid_support() const override { return true; }
};

class ResourceFormatSaverCrypto : public ResourceFormatSaver {
Expand Down
4 changes: 4 additions & 0 deletions core/io/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class ResourceFormatLoaderJSON : public ResourceFormatLoader {
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
virtual bool handles_type(const String &p_type) const override;
virtual String get_resource_type(const String &p_path) const override;

// Treat JSON as a text file, do not generate a `*.json.uid` file.
virtual ResourceUID::ID get_resource_uid(const String &p_path) const override { return ResourceUID::INVALID_ID; }
virtual bool has_custom_uid_support() const override { return true; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that both overrides are required. This may seem odd, since in fact JSON does not have a UID. But we define "support" for custom UID... which is invalid. It might make sense to separate these three lines with a blank line for better readability.

ResourceUID::ID ResourceFormatLoader::get_resource_uid(const String &p_path) const {
int64_t uid = ResourceUID::INVALID_ID;
if (has_custom_uid_support()) {
GDVIRTUAL_CALL(_get_resource_uid, p_path, uid);
} else {
Ref<FileAccess> file = FileAccess::open(p_path + ".uid", FileAccess::READ);
if (file.is_valid()) {
uid = ResourceUID::get_singleton()->text_to_id(file->get_line());
}
}
return uid;
}

godot/editor/editor_node.cpp

Lines 1457 to 1465 in f952bfe

void EditorNode::ensure_uid_file(const String &p_new_resource_path) {
if (ResourceLoader::exists(p_new_resource_path) && !ResourceLoader::has_custom_uid_support(p_new_resource_path) && !FileAccess::exists(p_new_resource_path + ".uid")) {
Ref<FileAccess> f = FileAccess::open(p_new_resource_path + ".uid", FileAccess::WRITE);
if (f.is_valid()) {
const ResourceUID::ID id = ResourceUID::get_singleton()->create_id();
f->store_line(ResourceUID::get_singleton()->id_to_text(id));
}
}
}

if (fi->uid == ResourceUID::INVALID_ID && ResourceLoader::exists(path) && !ResourceLoader::has_custom_uid_support(path) && !FileAccess::exists(path + ".uid")) {
// Create a UID.
Ref<FileAccess> f = FileAccess::open(path + ".uid", FileAccess::WRITE);
if (f.is_valid()) {
fi->uid = ResourceUID::get_singleton()->create_id();
f->store_line(ResourceUID::get_singleton()->id_to_text(fi->uid));
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make it into a macro called DISABLE_UID or something. These 2 lines will be the same for every class.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is redundant for now. But we may reconsider this in the future if more exceptions are added.

};

class ResourceFormatSaverJSON : public ResourceFormatSaver {
Expand Down
4 changes: 4 additions & 0 deletions core/io/translation_loader_po.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class TranslationLoaderPO : public ResourceFormatLoader {
virtual bool handles_type(const String &p_type) const override;
virtual String get_resource_type(const String &p_path) const override;

// Treat translations as text/binary files, do not generate a `*.{po,mo}.uid` file.
virtual ResourceUID::ID get_resource_uid(const String &p_path) const override { return ResourceUID::INVALID_ID; }
virtual bool has_custom_uid_support() const override { return true; }

TranslationLoaderPO() {}
};

Expand Down
Loading