diff options
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/file_access_pack.cpp | 9 | ||||
-rw-r--r-- | core/io/file_access_pack.h | 34 |
2 files changed, 38 insertions, 5 deletions
diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index e2cb300ebc..6e03819aac 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -48,7 +48,10 @@ Error PackedData::add_pack(const String& p_path) { void PackedData::add_path(const String& pkg_path, const String& path, uint64_t ofs, uint64_t size,const uint8_t* p_md5, PackSource* p_src) { - bool exists = files.has(path); + PathMD5 pmd5(path.md5_buffer()); + //printf("adding path %ls, %lli, %lli\n", path.c_str(), pmd5.a, pmd5.b); + + bool exists = files.has(pmd5); PackedFile pf; pf.pack=pkg_path; @@ -58,7 +61,7 @@ void PackedData::add_path(const String& pkg_path, const String& path, uint64_t o pf.md5[i]=p_md5[i]; pf.src = p_src; - files[path]=pf; + files[pmd5]=pf; if (!exists) { //search for dir @@ -113,6 +116,8 @@ bool PackedSourcePCK::try_open_pack(const String& p_path) { if (!f) return false; + //printf("try open %ls!\n", p_path.c_str()); + uint32_t magic= f->get_32(); if (magic != 0x43504447) { diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index a4c750bf3c..5fcc79aaf4 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -60,8 +60,34 @@ private: Set<String> files; }; + struct PathMD5 { + uint64_t a; + uint64_t b; + bool operator < (const PathMD5& p_md5) const { + + if (p_md5.a == a) { + return b < p_md5.b; + } else { + return a < p_md5.a; + } + } + + bool operator == (const PathMD5& p_md5) const { + return a == p_md5.a && b == p_md5.b; + }; + + PathMD5() { + a = b = 0; + }; + + PathMD5(const Vector<uint8_t> p_buf) { + a = *((uint64_t*)&p_buf[0]); + b = *((uint64_t*)&p_buf[8]); + }; + }; + + Map<PathMD5,PackedFile> files; - Map<String,PackedFile> files; Vector<PackSource*> sources; PackedDir *root; @@ -151,7 +177,9 @@ public: FileAccess *PackedData::try_open_path(const String& p_path) { - Map<String,PackedFile>::Element *E=files.find(p_path); + //print_line("try open path " + p_path); + PathMD5 pmd5(p_path.md5_buffer()); + Map<PathMD5,PackedFile>::Element *E=files.find(pmd5); if (!E) return NULL; //not found if (E->get().offset==0) @@ -162,7 +190,7 @@ FileAccess *PackedData::try_open_path(const String& p_path) { bool PackedData::has_path(const String& p_path) { - return files.has(p_path); + return files.has(PathMD5(p_path.md5_buffer())); } |