Skip to content
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
9 changes: 9 additions & 0 deletions modules/zip/doc_classes/ZIPReader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
Closes the underlying resources used by this instance.
</description>
</method>
<method name="file_exists">
<return type="bool" />
<param index="0" name="path" type="String" />
<param index="1" name="case_sensitive" type="bool" default="true" />
<description>
Returns [code]true[/code] if the file exists in the loaded zip archive.
Must be called after [method open].
</description>
</method>
<method name="get_files">
<return type="PackedStringArray" />
<description>
Expand Down
16 changes: 16 additions & 0 deletions modules/zip/zip_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ PackedByteArray ZIPReader::read_file(String p_path, bool p_case_sensitive) {
return data;
}

bool ZIPReader::file_exists(String p_path, bool p_case_sensitive) {
ERR_FAIL_COND_V_MSG(fa.is_null(), false, "ZIPReader must be opened before use.");

int cs = p_case_sensitive ? 1 : 2;
if (unzLocateFile(uzf, p_path.utf8().get_data(), cs) != UNZ_OK) {
return false;
}
if (unzOpenCurrentFile(uzf) != UNZ_OK) {
return false;
}

unzCloseCurrentFile(uzf);
return true;
}

ZIPReader::ZIPReader() {}

ZIPReader::~ZIPReader() {
Expand All @@ -131,4 +146,5 @@ void ZIPReader::_bind_methods() {
ClassDB::bind_method(D_METHOD("close"), &ZIPReader::close);
ClassDB::bind_method(D_METHOD("get_files"), &ZIPReader::get_files);
ClassDB::bind_method(D_METHOD("read_file", "path", "case_sensitive"), &ZIPReader::read_file, DEFVAL(Variant(true)));
ClassDB::bind_method(D_METHOD("file_exists", "path", "case_sensitive"), &ZIPReader::file_exists, DEFVAL(Variant(true)));
}
1 change: 1 addition & 0 deletions modules/zip/zip_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ZIPReader : public RefCounted {

PackedStringArray get_files();
PackedByteArray read_file(String p_path, bool p_case_sensitive);
bool file_exists(String p_path, bool p_case_sensitive);

ZIPReader();
~ZIPReader();
Expand Down