Skip to content
Merged
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
20 changes: 13 additions & 7 deletions core/io/file_access_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "core/io/dir_access.h"
#include "core/io/file_access.h"
#include "core/io/resource_uid.h"
#include "core/string/print_string.h"
#include "core/templates/hash_set.h"
#include "core/templates/list.h"
Expand Down Expand Up @@ -119,6 +120,15 @@ class PackedData {
void _free_packed_dirs(PackedDir *p_dir);
void _get_file_paths(PackedDir *p_dir, const String &p_parent_dir, HashSet<String> &r_paths) const;

_FORCE_INLINE_ PathMD5 _get_simplified_path(const String &p_path) {
String simplified_path = p_path;
if (simplified_path.begins_with("uid://")) {
simplified_path = ResourceUID::uid_to_path(simplified_path);
}
simplified_path = simplified_path.simplify_path().trim_prefix("res://");
return PathMD5(simplified_path.md5_buffer());
}

public:
void add_pack_source(PackSource *p_source);
void add_path(const String &p_pkg_path, const String &p_path, uint64_t p_ofs, uint64_t p_size, const uint8_t *p_md5, PackSource *p_src, bool p_replace_files, bool p_encrypted = false, bool p_bundle = false, bool p_delta = false, const String &p_salt = String()); // for PackSource
Expand Down Expand Up @@ -222,9 +232,7 @@ class FileAccessPack : public FileAccess {
};

int64_t PackedData::get_size(const String &p_path) {
String simplified_path = p_path.simplify_path();
PathMD5 pmd5(simplified_path.md5_buffer());
HashMap<PathMD5, PackedFile, PathMD5>::Iterator E = files.find(pmd5);
HashMap<PathMD5, PackedFile, PathMD5>::Iterator E = files.find(_get_simplified_path(p_path));
if (!E) {
return -1; // File not found.
}
Expand All @@ -235,9 +243,7 @@ int64_t PackedData::get_size(const String &p_path) {
}

Ref<FileAccess> PackedData::try_open_path(const String &p_path, const Vector<uint8_t> &p_decryption_key) {
String simplified_path = p_path.simplify_path().trim_prefix("res://");
PathMD5 pmd5(simplified_path.md5_buffer());
HashMap<PathMD5, PackedFile, PathMD5>::Iterator E = files.find(pmd5);
HashMap<PathMD5, PackedFile, PathMD5>::Iterator E = files.find(_get_simplified_path(p_path));
if (!E) {
return nullptr; // Not found.
}
Expand All @@ -246,7 +252,7 @@ Ref<FileAccess> PackedData::try_open_path(const String &p_path, const Vector<uin
}

bool PackedData::has_path(const String &p_path) {
return files.has(PathMD5(p_path.simplify_path().trim_prefix("res://").md5_buffer()));
return files.has(_get_simplified_path(p_path));
}

bool PackedData::has_directory(const String &p_path) {
Expand Down
Loading