Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/io/file_access_pack.cpp
20929 views
1
/**************************************************************************/
2
/* file_access_pack.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "file_access_pack.h"
32
33
#include "core/io/file_access_encrypted.h"
34
#include "core/io/file_access_patched.h"
35
#include "core/object/script_language.h"
36
#include "core/os/os.h"
37
#include "core/version.h"
38
39
Error PackedData::add_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) {
40
for (int i = 0; i < sources.size(); i++) {
41
if (sources[i]->try_open_pack(p_path, p_replace_files, p_offset)) {
42
return OK;
43
}
44
}
45
46
return ERR_FILE_UNRECOGNIZED;
47
}
48
49
void PackedData::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, bool p_bundle, bool p_delta, const String &p_salt) {
50
String simplified_path = p_path.simplify_path().trim_prefix("res://");
51
PathMD5 pmd5(simplified_path.md5_buffer());
52
53
bool exists = files.has(pmd5);
54
55
PackedFile pf;
56
pf.encrypted = p_encrypted;
57
pf.bundle = p_bundle;
58
pf.delta = p_delta;
59
pf.pack = p_pkg_path;
60
pf.salt = p_salt;
61
pf.offset = p_ofs;
62
pf.size = p_size;
63
for (int i = 0; i < 16; i++) {
64
pf.md5[i] = p_md5[i];
65
}
66
pf.src = p_src;
67
68
if (p_delta) {
69
delta_patches[pmd5].push_back(pf);
70
} else if (!exists || p_replace_files) {
71
files[pmd5] = pf;
72
delta_patches[pmd5].clear();
73
}
74
75
if (!exists) {
76
// Search for directory.
77
PackedDir *cd = root;
78
79
if (simplified_path.contains_char('/')) { // In a subdirectory.
80
Vector<String> ds = simplified_path.get_base_dir().split("/");
81
82
for (int j = 0; j < ds.size(); j++) {
83
if (!cd->subdirs.has(ds[j])) {
84
PackedDir *pd = memnew(PackedDir);
85
pd->name = ds[j];
86
pd->parent = cd;
87
cd->subdirs[pd->name] = pd;
88
cd = pd;
89
} else {
90
cd = cd->subdirs[ds[j]];
91
}
92
}
93
}
94
String filename = simplified_path.get_file();
95
// Don't add as a file if the path points to a directory.
96
if (!filename.is_empty()) {
97
cd->files.insert(filename);
98
}
99
}
100
}
101
102
void PackedData::remove_path(const String &p_path) {
103
String simplified_path = p_path.simplify_path().trim_prefix("res://");
104
PathMD5 pmd5(simplified_path.md5_buffer());
105
if (!files.has(pmd5)) {
106
return;
107
}
108
109
// Search for directory.
110
PackedDir *cd = root;
111
112
if (simplified_path.contains_char('/')) { // In a subdirectory.
113
Vector<String> ds = simplified_path.get_base_dir().split("/");
114
115
for (int j = 0; j < ds.size(); j++) {
116
if (!cd->subdirs.has(ds[j])) {
117
return; // Subdirectory does not exist, do not bother creating.
118
} else {
119
cd = cd->subdirs[ds[j]];
120
}
121
}
122
}
123
124
cd->files.erase(simplified_path.get_file());
125
126
files.erase(pmd5);
127
}
128
129
void PackedData::add_pack_source(PackSource *p_source) {
130
if (p_source != nullptr) {
131
sources.push_back(p_source);
132
}
133
}
134
135
uint8_t *PackedData::get_file_hash(const String &p_path) {
136
String simplified_path = p_path.simplify_path().trim_prefix("res://");
137
PathMD5 pmd5(simplified_path.md5_buffer());
138
HashMap<PathMD5, PackedFile, PathMD5>::Iterator E = files.find(pmd5);
139
if (!E) {
140
return nullptr;
141
}
142
143
return E->value.md5;
144
}
145
146
Vector<PackedData::PackedFile> PackedData::get_delta_patches(const String &p_path) const {
147
String simplified_path = p_path.simplify_path().trim_prefix("res://");
148
PathMD5 pmd5(simplified_path.md5_buffer());
149
HashMap<PathMD5, Vector<PackedFile>, PathMD5>::ConstIterator E = delta_patches.find(pmd5);
150
if (!E) {
151
return Vector<PackedFile>();
152
}
153
154
return E->value;
155
}
156
157
bool PackedData::has_delta_patches(const String &p_path) const {
158
String simplified_path = p_path.simplify_path().trim_prefix("res://");
159
PathMD5 pmd5(simplified_path.md5_buffer());
160
HashMap<PathMD5, Vector<PackedFile>, PathMD5>::ConstIterator E = delta_patches.find(pmd5);
161
if (!E) {
162
return false;
163
}
164
165
return !E->value.is_empty();
166
}
167
168
HashSet<String> PackedData::get_file_paths() const {
169
HashSet<String> file_paths;
170
_get_file_paths(root, root->name, file_paths);
171
return file_paths;
172
}
173
174
void PackedData::_get_file_paths(PackedDir *p_dir, const String &p_parent_dir, HashSet<String> &r_paths) const {
175
for (const String &E : p_dir->files) {
176
r_paths.insert(p_parent_dir.path_join(E));
177
}
178
179
for (const KeyValue<String, PackedDir *> &E : p_dir->subdirs) {
180
_get_file_paths(E.value, p_parent_dir.path_join(E.key), r_paths);
181
}
182
}
183
184
void PackedData::clear() {
185
files.clear();
186
delta_patches.clear();
187
_free_packed_dirs(root);
188
root = memnew(PackedDir);
189
}
190
191
PackedData::PackedData() {
192
singleton = this;
193
root = memnew(PackedDir);
194
195
add_pack_source(memnew(PackedSourcePCK));
196
}
197
198
void PackedData::_free_packed_dirs(PackedDir *p_dir) {
199
for (const KeyValue<String, PackedDir *> &E : p_dir->subdirs) {
200
_free_packed_dirs(E.value);
201
}
202
memdelete(p_dir);
203
}
204
205
PackedData::~PackedData() {
206
if (singleton == this) {
207
singleton = nullptr;
208
}
209
210
for (int i = 0; i < sources.size(); i++) {
211
memdelete(sources[i]);
212
}
213
_free_packed_dirs(root);
214
}
215
216
//////////////////////////////////////////////////////////////////
217
218
bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) {
219
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
220
if (f.is_null()) {
221
return false;
222
}
223
224
bool pck_header_found = false;
225
226
// Search for the header at the start offset - standalone PCK file.
227
f->seek(p_offset);
228
uint32_t magic = f->get_32();
229
if (magic == PACK_HEADER_MAGIC) {
230
pck_header_found = true;
231
}
232
233
// Search for the header in the executable "pck" section - self contained executable.
234
if (!pck_header_found) {
235
// Loading with offset feature not supported for self contained exe files.
236
if (p_offset != 0) {
237
ERR_FAIL_V_MSG(false, "Loading self-contained executable with offset not supported.");
238
}
239
240
int64_t pck_off = OS::get_singleton()->get_embedded_pck_offset();
241
if (pck_off != 0) {
242
// Search for the header, in case PCK start and section have different alignment.
243
for (int i = 0; i < 8; i++) {
244
f->seek(pck_off);
245
magic = f->get_32();
246
if (magic == PACK_HEADER_MAGIC) {
247
#ifdef DEBUG_ENABLED
248
print_verbose("PCK header found in executable pck section, loading from offset 0x" + String::num_int64(pck_off - 4, 16));
249
#endif
250
pck_header_found = true;
251
break;
252
}
253
pck_off++;
254
}
255
}
256
}
257
258
// Search for the header at the end of file - self contained executable.
259
if (!pck_header_found) {
260
// Loading with offset feature not supported for self contained exe files.
261
if (p_offset != 0) {
262
ERR_FAIL_V_MSG(false, "Loading self-contained executable with offset not supported.");
263
}
264
265
f->seek_end();
266
f->seek(f->get_position() - 4);
267
magic = f->get_32();
268
269
if (magic == PACK_HEADER_MAGIC) {
270
f->seek(f->get_position() - 12);
271
uint64_t ds = f->get_64();
272
f->seek(f->get_position() - ds - 8);
273
magic = f->get_32();
274
if (magic == PACK_HEADER_MAGIC) {
275
#ifdef DEBUG_ENABLED
276
print_verbose("PCK header found at the end of executable, loading from offset 0x" + String::num_int64(f->get_position() - 4, 16));
277
#endif
278
pck_header_found = true;
279
}
280
}
281
}
282
283
if (!pck_header_found) {
284
return false;
285
}
286
287
int64_t pck_start_pos = f->get_position() - 4;
288
289
// Read header.
290
uint32_t version = f->get_32();
291
uint32_t ver_major = f->get_32();
292
uint32_t ver_minor = f->get_32();
293
uint32_t ver_patch = f->get_32(); // Not used for validation.
294
295
ERR_FAIL_COND_V_MSG(version != PACK_FORMAT_VERSION_V4 && version != PACK_FORMAT_VERSION_V3 && version != PACK_FORMAT_VERSION_V2, false, vformat("Pack version unsupported: %d.", version));
296
ERR_FAIL_COND_V_MSG(ver_major > GODOT_VERSION_MAJOR || (ver_major == GODOT_VERSION_MAJOR && ver_minor > GODOT_VERSION_MINOR), false, vformat("Pack created with a newer version of the engine: %d.%d.%d.", ver_major, ver_minor, ver_patch));
297
298
uint32_t pack_flags = f->get_32();
299
bool enc_directory = (pack_flags & PACK_DIR_ENCRYPTED);
300
bool rel_filebase = (pack_flags & PACK_REL_FILEBASE); // Note: Always enabled for V3.
301
bool sparse_bundle = (pack_flags & PACK_SPARSE_BUNDLE);
302
String salt;
303
304
uint64_t file_base = f->get_64();
305
if ((version == PACK_FORMAT_VERSION_V4) || (version == PACK_FORMAT_VERSION_V3) || (version == PACK_FORMAT_VERSION_V2 && rel_filebase)) {
306
file_base += pck_start_pos;
307
}
308
309
if (version == PACK_FORMAT_VERSION_V3 || version == PACK_FORMAT_VERSION_V4) {
310
// V3/V4: Read directory offset and skip reserved part of the header.
311
uint64_t dir_offset = f->get_64() + pck_start_pos;
312
if (sparse_bundle && enc_directory && version == PACK_FORMAT_VERSION_V4) {
313
// V4: Read encrypted directory salt.
314
Vector<uint8_t> salt_data = f->get_buffer(32);
315
salt.append_latin1(Span((const char *)salt_data.ptr(), salt_data.size()));
316
}
317
f->seek(dir_offset);
318
} else if (version == PACK_FORMAT_VERSION_V2) {
319
// V2: Directory directly after the header.
320
for (int i = 0; i < 16; i++) {
321
f->get_32(); // Reserved.
322
}
323
}
324
325
// Read directory.
326
int file_count = f->get_32();
327
if (enc_directory) {
328
Ref<FileAccessEncrypted> fae;
329
fae.instantiate();
330
ERR_FAIL_COND_V_MSG(fae.is_null(), false, "Can't open encrypted pack directory.");
331
332
Vector<uint8_t> key;
333
key.resize(32);
334
for (int i = 0; i < key.size(); i++) {
335
key.write[i] = script_encryption_key[i];
336
}
337
338
Error err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_READ, false);
339
ERR_FAIL_COND_V_MSG(err, false, "Can't open encrypted pack directory.");
340
f = fae;
341
}
342
343
for (int i = 0; i < file_count; i++) {
344
uint32_t sl = f->get_32();
345
CharString cs;
346
cs.resize_uninitialized(sl + 1);
347
f->get_buffer((uint8_t *)cs.ptr(), sl);
348
cs[sl] = 0;
349
350
String path = String::utf8(cs.ptr(), sl);
351
uint64_t ofs = f->get_64();
352
uint64_t size = f->get_64();
353
uint8_t md5[16];
354
f->get_buffer(md5, 16);
355
uint32_t flags = f->get_32();
356
357
if (flags & PACK_FILE_REMOVAL) { // The file was removed.
358
PackedData::get_singleton()->remove_path(path);
359
} else {
360
PackedData::get_singleton()->add_path(p_path, path, file_base + ofs, size, md5, this, p_replace_files, (flags & PACK_FILE_ENCRYPTED), sparse_bundle, (flags & PACK_FILE_DELTA), salt);
361
}
362
}
363
364
return true;
365
}
366
367
Ref<FileAccess> PackedSourcePCK::get_file(const String &p_path, PackedData::PackedFile *p_file) {
368
Ref<FileAccess> file(memnew(FileAccessPack(p_path, *p_file)));
369
370
if (PackedData::get_singleton()->has_delta_patches(p_path)) {
371
Ref<FileAccessPatched> file_patched;
372
file_patched.instantiate();
373
Error err = file_patched->open_custom(file);
374
ERR_FAIL_COND_V(err != OK, Ref<FileAccess>());
375
file = file_patched;
376
}
377
378
return file;
379
}
380
381
//////////////////////////////////////////////////////////////////
382
383
bool PackedSourceDirectory::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) {
384
// Load with offset feature only supported for PCK files.
385
ERR_FAIL_COND_V_MSG(p_offset != 0, false, "Invalid PCK data. Note that loading files with a non-zero offset isn't supported with directories.");
386
387
if (p_path != "res://") {
388
return false;
389
}
390
add_directory(p_path, p_replace_files);
391
return true;
392
}
393
394
Ref<FileAccess> PackedSourceDirectory::get_file(const String &p_path, PackedData::PackedFile *p_file) {
395
Ref<FileAccess> ret = FileAccess::create_for_path(p_path);
396
ret->reopen(p_path, FileAccess::READ);
397
return ret;
398
}
399
400
void PackedSourceDirectory::add_directory(const String &p_path, bool p_replace_files) {
401
Ref<DirAccess> da = DirAccess::open(p_path);
402
if (da.is_null()) {
403
return;
404
}
405
da->set_include_hidden(true);
406
407
for (const String &file_name : da->get_files()) {
408
String file_path = p_path.path_join(file_name);
409
uint8_t md5[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
410
PackedData::get_singleton()->add_path(p_path, file_path, 0, 0, md5, this, p_replace_files, false, false, false);
411
}
412
413
for (const String &sub_dir_name : da->get_directories()) {
414
String sub_dir_path = p_path.path_join(sub_dir_name);
415
add_directory(sub_dir_path, p_replace_files);
416
}
417
}
418
419
//////////////////////////////////////////////////////////////////
420
421
Error FileAccessPack::open_internal(const String &p_path, int p_mode_flags) {
422
ERR_PRINT("Can't open pack-referenced file.");
423
return ERR_UNAVAILABLE;
424
}
425
426
bool FileAccessPack::is_open() const {
427
if (f.is_valid()) {
428
return f->is_open();
429
} else {
430
return false;
431
}
432
}
433
434
void FileAccessPack::seek(uint64_t p_position) {
435
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
436
437
if (p_position > pf.size) {
438
eof = true;
439
} else {
440
eof = false;
441
}
442
443
f->seek(off + p_position);
444
pos = p_position;
445
}
446
447
void FileAccessPack::seek_end(int64_t p_position) {
448
seek(pf.size + p_position);
449
}
450
451
uint64_t FileAccessPack::get_position() const {
452
return pos;
453
}
454
455
uint64_t FileAccessPack::get_length() const {
456
return pf.size;
457
}
458
459
bool FileAccessPack::eof_reached() const {
460
return eof;
461
}
462
463
uint64_t FileAccessPack::get_buffer(uint8_t *p_dst, uint64_t p_length) const {
464
ERR_FAIL_COND_V_MSG(f.is_null(), -1, "File must be opened before use.");
465
ERR_FAIL_COND_V(!p_dst && p_length > 0, -1);
466
467
if (eof) {
468
return 0;
469
}
470
471
int64_t to_read = p_length;
472
if (to_read + pos > pf.size) {
473
eof = true;
474
to_read = (int64_t)pf.size - (int64_t)pos;
475
}
476
477
pos += to_read;
478
479
if (to_read <= 0) {
480
return 0;
481
}
482
f->get_buffer(p_dst, to_read);
483
484
return to_read;
485
}
486
487
void FileAccessPack::set_big_endian(bool p_big_endian) {
488
ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use.");
489
490
FileAccess::set_big_endian(p_big_endian);
491
f->set_big_endian(p_big_endian);
492
}
493
494
Error FileAccessPack::get_error() const {
495
if (eof) {
496
return ERR_FILE_EOF;
497
}
498
return OK;
499
}
500
501
void FileAccessPack::flush() {
502
ERR_FAIL();
503
}
504
505
bool FileAccessPack::store_buffer(const uint8_t *p_src, uint64_t p_length) {
506
ERR_FAIL_V(false);
507
}
508
509
bool FileAccessPack::file_exists(const String &p_name) {
510
return false;
511
}
512
513
void FileAccessPack::close() {
514
f = Ref<FileAccess>();
515
}
516
517
FileAccessPack::FileAccessPack(const String &p_path, const PackedData::PackedFile &p_file) {
518
path = p_path;
519
pf = p_file;
520
if (pf.bundle) {
521
String simplified_path = p_path.simplify_path();
522
if (pf.salt.is_empty()) {
523
f = FileAccess::open(simplified_path, FileAccess::READ | FileAccess::SKIP_PACK);
524
} else {
525
f = FileAccess::open("res://" + (simplified_path + pf.salt).sha256_text(), FileAccess::READ | FileAccess::SKIP_PACK);
526
}
527
ERR_FAIL_COND_MSG(f.is_null(), vformat(R"(Can't open pack-referenced file "%s" from sparse pack "%s".)", simplified_path, pf.pack));
528
off = 0; // For the sparse pack offset is always zero.
529
} else {
530
f = FileAccess::open(pf.pack, FileAccess::READ);
531
ERR_FAIL_COND_MSG(f.is_null(), vformat(R"(Can't open pack-referenced file "%s" from pack "%s".)", p_path, pf.pack));
532
f->seek(pf.offset);
533
off = pf.offset;
534
}
535
536
if (pf.encrypted) {
537
Ref<FileAccessEncrypted> fae;
538
fae.instantiate();
539
ERR_FAIL_COND_MSG(fae.is_null(), vformat(R"(Can't open encrypted pack-referenced file "%s" from pack "%s".)", p_path, pf.pack));
540
541
Vector<uint8_t> key;
542
key.resize(32);
543
for (int i = 0; i < key.size(); i++) {
544
key.write[i] = script_encryption_key[i];
545
}
546
547
Error err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_READ, false);
548
ERR_FAIL_COND_MSG(err, vformat(R"(Can't open encrypted pack-referenced file "%s" from pack "%s".)", p_path, pf.pack));
549
f = fae;
550
off = 0;
551
}
552
pos = 0;
553
eof = false;
554
}
555
556
//////////////////////////////////////////////////////////////////////////////////
557
// DIR ACCESS
558
//////////////////////////////////////////////////////////////////////////////////
559
560
Error DirAccessPack::list_dir_begin() {
561
list_dirs.clear();
562
list_files.clear();
563
564
for (const KeyValue<String, PackedData::PackedDir *> &E : current->subdirs) {
565
list_dirs.push_back(E.key);
566
}
567
568
for (const String &E : current->files) {
569
list_files.push_back(E);
570
}
571
572
return OK;
573
}
574
575
String DirAccessPack::get_next() {
576
if (list_dirs.size()) {
577
cdir = true;
578
String d = list_dirs.front()->get();
579
list_dirs.pop_front();
580
return d;
581
} else if (list_files.size()) {
582
cdir = false;
583
String f = list_files.front()->get();
584
list_files.pop_front();
585
return f;
586
} else {
587
return String();
588
}
589
}
590
591
bool DirAccessPack::current_is_dir() const {
592
return cdir;
593
}
594
595
bool DirAccessPack::current_is_hidden() const {
596
return false;
597
}
598
599
void DirAccessPack::list_dir_end() {
600
list_dirs.clear();
601
list_files.clear();
602
}
603
604
int DirAccessPack::get_drive_count() {
605
return 0;
606
}
607
608
String DirAccessPack::get_drive(int p_drive) {
609
return "";
610
}
611
612
PackedData::PackedDir *DirAccessPack::_find_dir(const String &p_dir) {
613
String nd = p_dir.replace_char('\\', '/');
614
615
// Special handling since simplify_path() will forbid it
616
if (p_dir == "..") {
617
return current->parent;
618
}
619
620
bool absolute = false;
621
if (nd.begins_with("res://")) {
622
nd = nd.replace_first("res://", "");
623
absolute = true;
624
}
625
626
nd = nd.simplify_path();
627
628
if (nd.is_empty()) {
629
nd = ".";
630
}
631
632
if (nd.begins_with("/")) {
633
nd = nd.replace_first("/", "");
634
absolute = true;
635
}
636
637
Vector<String> paths = nd.split("/");
638
639
PackedData::PackedDir *pd;
640
641
if (absolute) {
642
pd = PackedData::get_singleton()->root;
643
} else {
644
pd = current;
645
}
646
647
for (int i = 0; i < paths.size(); i++) {
648
const String &p = paths[i];
649
if (p == ".") {
650
continue;
651
} else if (p == "..") {
652
if (pd->parent) {
653
pd = pd->parent;
654
}
655
} else if (pd->subdirs.has(p)) {
656
pd = pd->subdirs[p];
657
658
} else {
659
return nullptr;
660
}
661
}
662
663
return pd;
664
}
665
666
Error DirAccessPack::change_dir(String p_dir) {
667
PackedData::PackedDir *pd = _find_dir(p_dir);
668
if (pd) {
669
current = pd;
670
return OK;
671
} else {
672
return ERR_INVALID_PARAMETER;
673
}
674
}
675
676
String DirAccessPack::get_current_dir(bool p_include_drive) const {
677
PackedData::PackedDir *pd = current;
678
String p = current->name;
679
680
while (pd->parent) {
681
pd = pd->parent;
682
p = pd->name.path_join(p);
683
}
684
685
return "res://" + p;
686
}
687
688
bool DirAccessPack::file_exists(String p_file) {
689
PackedData::PackedDir *pd = _find_dir(p_file.get_base_dir());
690
if (!pd) {
691
return false;
692
}
693
return pd->files.has(p_file.get_file());
694
}
695
696
bool DirAccessPack::dir_exists(String p_dir) {
697
return _find_dir(p_dir) != nullptr;
698
}
699
700
Error DirAccessPack::make_dir(String p_dir) {
701
return ERR_UNAVAILABLE;
702
}
703
704
Error DirAccessPack::rename(String p_from, String p_to) {
705
return ERR_UNAVAILABLE;
706
}
707
708
Error DirAccessPack::remove(String p_name) {
709
return ERR_UNAVAILABLE;
710
}
711
712
uint64_t DirAccessPack::get_space_left() {
713
return 0;
714
}
715
716
String DirAccessPack::get_filesystem_type() const {
717
return "PCK";
718
}
719
720
DirAccessPack::DirAccessPack() {
721
current = PackedData::get_singleton()->root;
722
}
723
724