mirror of
https://github.com/godotengine/godot.git
synced 2025-10-20 16:33:30 +00:00
Make FileAccess and DirAccess classes reference counted.
This commit is contained in:
parent
ca9372622f
commit
9381acb6a4
193 changed files with 1122 additions and 1776 deletions
|
|
@ -64,8 +64,7 @@ void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
|
|||
}
|
||||
String resource_path = ProjectSettings::get_singleton()->get_resource_path();
|
||||
|
||||
FileAccess *src_f;
|
||||
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
||||
zlib_filefunc_def io = zipio_create_io();
|
||||
|
||||
// Name the downloaded ZIP file to contain the project name and download date for easier organization.
|
||||
// Replace characters not allowed (or risky) in Windows file names with safe characters.
|
||||
|
|
@ -82,22 +81,20 @@ void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
|
|||
const String base_path = resource_path.substr(0, resource_path.rfind("/")) + "/";
|
||||
_zip_recursive(resource_path, base_path, zip);
|
||||
zipClose(zip, nullptr);
|
||||
FileAccess *f = FileAccess::open(output_path, FileAccess::READ);
|
||||
ERR_FAIL_COND_MSG(!f, "Unable to create ZIP file.");
|
||||
Ref<FileAccess> f = FileAccess::open(output_path, FileAccess::READ);
|
||||
ERR_FAIL_COND_MSG(f.is_null(), "Unable to create ZIP file.");
|
||||
Vector<uint8_t> buf;
|
||||
buf.resize(f->get_length());
|
||||
f->get_buffer(buf.ptrw(), buf.size());
|
||||
godot_js_os_download_buffer(buf.ptr(), buf.size(), output_name.utf8().get_data(), "application/zip");
|
||||
|
||||
f->close();
|
||||
memdelete(f);
|
||||
// Remove the temporary file since it was sent to the user's native filesystem as a download.
|
||||
DirAccess::remove_file_or_error(output_path);
|
||||
}
|
||||
|
||||
void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, zipFile p_zip) {
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ);
|
||||
if (!f) {
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
|
||||
if (f.is_null()) {
|
||||
WARN_PRINT("Unable to open file for zipping: " + p_path);
|
||||
return;
|
||||
}
|
||||
|
|
@ -105,8 +102,6 @@ void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, z
|
|||
uint64_t len = f->get_length();
|
||||
data.resize(len);
|
||||
f->get_buffer(data.ptrw(), len);
|
||||
f->close();
|
||||
memdelete(f);
|
||||
|
||||
String path = p_path.replace_first(p_base_path, "");
|
||||
zipOpenNewFileInZip(p_zip,
|
||||
|
|
@ -124,7 +119,7 @@ void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, z
|
|||
}
|
||||
|
||||
void JavaScriptToolsEditorPlugin::_zip_recursive(String p_path, String p_base_path, zipFile p_zip) {
|
||||
DirAccessRef dir = DirAccess::open(p_path);
|
||||
Ref<DirAccess> dir = DirAccess::open(p_path);
|
||||
if (!dir) {
|
||||
WARN_PRINT("Unable to open directory for zipping: " + p_path);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue