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
|
|
@ -1030,7 +1030,7 @@ Error GDScript::load_byte_code(const String &p_path) {
|
|||
Error GDScript::load_source_code(const String &p_path) {
|
||||
Vector<uint8_t> sourcef;
|
||||
Error err;
|
||||
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (err) {
|
||||
ERR_FAIL_COND_V(err, err);
|
||||
}
|
||||
|
|
@ -1039,8 +1039,6 @@ Error GDScript::load_source_code(const String &p_path) {
|
|||
sourcef.resize(len + 1);
|
||||
uint8_t *w = sourcef.ptrw();
|
||||
uint64_t r = f->get_buffer(w, len);
|
||||
f->close();
|
||||
memdelete(f);
|
||||
ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);
|
||||
w[len] = 0;
|
||||
|
||||
|
|
@ -2099,7 +2097,7 @@ bool GDScriptLanguage::handles_global_class_type(const String &p_type) const {
|
|||
String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const {
|
||||
Vector<uint8_t> sourcef;
|
||||
Error err;
|
||||
FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (err) {
|
||||
return String();
|
||||
}
|
||||
|
|
@ -2133,8 +2131,8 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b
|
|||
} else {
|
||||
Vector<StringName> extend_classes = subclass->extends;
|
||||
|
||||
FileAccessRef subfile = FileAccess::open(subclass->extends_path, FileAccess::READ);
|
||||
if (!subfile) {
|
||||
Ref<FileAccess> subfile = FileAccess::open(subclass->extends_path, FileAccess::READ);
|
||||
if (subfile.is_null()) {
|
||||
break;
|
||||
}
|
||||
String subsource = subfile->get_as_utf8_string();
|
||||
|
|
@ -2331,8 +2329,8 @@ String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) con
|
|||
}
|
||||
|
||||
void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
|
||||
FileAccessRef file = FileAccess::open(p_path, FileAccess::READ);
|
||||
ERR_FAIL_COND_MSG(!file, "Cannot open file '" + p_path + "'.");
|
||||
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::READ);
|
||||
ERR_FAIL_COND_MSG(file.is_null(), "Cannot open file '" + p_path + "'.");
|
||||
|
||||
String source = file->get_as_utf8_string();
|
||||
if (source.is_empty()) {
|
||||
|
|
@ -2356,17 +2354,14 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou
|
|||
String source = sqscr->get_source_code();
|
||||
|
||||
Error err;
|
||||
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
|
||||
|
||||
ERR_FAIL_COND_V_MSG(err, err, "Cannot save GDScript file '" + p_path + "'.");
|
||||
|
||||
file->store_string(source);
|
||||
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
|
||||
memdelete(file);
|
||||
return ERR_CANT_CREATE;
|
||||
}
|
||||
file->close();
|
||||
memdelete(file);
|
||||
|
||||
if (ScriptServer::is_reload_scripts_on_save_enabled()) {
|
||||
GDScriptLanguage::get_singleton()->reload_tool_script(p_resource, false);
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ Ref<GDScriptParserRef> GDScriptCache::get_parser(const String &p_path, GDScriptP
|
|||
String GDScriptCache::get_source_code(const String &p_path) {
|
||||
Vector<uint8_t> source_file;
|
||||
Error err;
|
||||
FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
|
||||
if (err) {
|
||||
ERR_FAIL_COND_V(err, "");
|
||||
}
|
||||
|
|
@ -153,7 +153,6 @@ String GDScriptCache::get_source_code(const String &p_path) {
|
|||
uint64_t len = f->get_length();
|
||||
source_file.resize(len + 1);
|
||||
uint64_t r = f->get_buffer(source_file.ptrw(), len);
|
||||
f->close();
|
||||
ERR_FAIL_COND_V(r != len, "");
|
||||
source_file.write[len] = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ void ExtendGDScriptParser::update_document_links(const String &p_code) {
|
|||
document_links.clear();
|
||||
|
||||
GDScriptTokenizer tokenizer;
|
||||
FileAccessRef fs = FileAccess::create(FileAccess::ACCESS_RESOURCES);
|
||||
Ref<FileAccess> fs = FileAccess::create(FileAccess::ACCESS_RESOURCES);
|
||||
tokenizer.set_source_code(p_code);
|
||||
while (true) {
|
||||
GDScriptTokenizer::Token token = tokenizer.scan();
|
||||
|
|
|
|||
|
|
@ -424,10 +424,6 @@ GDScriptTextDocument::GDScriptTextDocument() {
|
|||
file_checker = FileAccess::create(FileAccess::ACCESS_RESOURCES);
|
||||
}
|
||||
|
||||
GDScriptTextDocument::~GDScriptTextDocument() {
|
||||
memdelete(file_checker);
|
||||
}
|
||||
|
||||
void GDScriptTextDocument::sync_script_content(const String &p_path, const String &p_content) {
|
||||
String path = GDScriptLanguageProtocol::get_singleton()->get_workspace()->get_file_path(p_path);
|
||||
GDScriptLanguageProtocol::get_singleton()->get_workspace()->parse_script(path, p_content);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class GDScriptTextDocument : public RefCounted {
|
|||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
FileAccess *file_checker = nullptr;
|
||||
Ref<FileAccess> file_checker;
|
||||
|
||||
void didOpen(const Variant &p_param);
|
||||
void didClose(const Variant &p_param);
|
||||
|
|
@ -75,7 +75,6 @@ public:
|
|||
void initialize();
|
||||
|
||||
GDScriptTextDocument();
|
||||
virtual ~GDScriptTextDocument();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ void GDScriptWorkspace::reload_all_workspace_scripts() {
|
|||
|
||||
void GDScriptWorkspace::list_script_files(const String &p_root_dir, List<String> &r_files) {
|
||||
Error err;
|
||||
DirAccessRef dir = DirAccess::open(p_root_dir, &err);
|
||||
Ref<DirAccess> dir = DirAccess::open(p_root_dir, &err);
|
||||
if (OK == err) {
|
||||
dir->list_dir_begin();
|
||||
String file_name = dir->get_next();
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ bool GDScriptTestRunner::generate_outputs() {
|
|||
|
||||
bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {
|
||||
Error err = OK;
|
||||
DirAccessRef dir(DirAccess::open(p_dir, &err));
|
||||
Ref<DirAccess> dir(DirAccess::open(p_dir, &err));
|
||||
|
||||
if (err != OK) {
|
||||
return false;
|
||||
|
|
@ -254,7 +254,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {
|
|||
#ifndef DEBUG_ENABLED
|
||||
// On release builds, skip tests marked as debug only.
|
||||
Error open_err = OK;
|
||||
FileAccessRef script_file(FileAccess::open(current_dir.plus_file(next), FileAccess::READ, &open_err));
|
||||
Ref<FileAccess> script_file(FileAccess::open(current_dir.plus_file(next), FileAccess::READ, &open_err));
|
||||
if (open_err != OK) {
|
||||
ERR_PRINT(vformat(R"(Couldn't open test file "%s".)", next));
|
||||
next = dir->get_next();
|
||||
|
|
@ -286,7 +286,7 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {
|
|||
|
||||
bool GDScriptTestRunner::make_tests() {
|
||||
Error err = OK;
|
||||
DirAccessRef dir(DirAccess::open(source_dir, &err));
|
||||
Ref<DirAccess> dir(DirAccess::open(source_dir, &err));
|
||||
|
||||
ERR_FAIL_COND_V_MSG(err != OK, false, "Could not open specified test directory.");
|
||||
|
||||
|
|
@ -611,7 +611,7 @@ bool GDScriptTest::generate_output() {
|
|||
}
|
||||
|
||||
Error err = OK;
|
||||
FileAccessRef out_file = FileAccess::open(output_file, FileAccess::WRITE, &err);
|
||||
Ref<FileAccess> out_file = FileAccess::open(output_file, FileAccess::WRITE, &err);
|
||||
if (err != OK) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -620,7 +620,6 @@ bool GDScriptTest::generate_output() {
|
|||
output += "\n"; // Make sure to insert newline for CI static checks.
|
||||
|
||||
out_file->store_string(output);
|
||||
out_file->close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,8 +204,8 @@ void test(TestType p_type) {
|
|||
return;
|
||||
}
|
||||
|
||||
FileAccessRef fa = FileAccess::open(test, FileAccess::READ);
|
||||
ERR_FAIL_COND_MSG(!fa, "Could not open file: " + test);
|
||||
Ref<FileAccess> fa = FileAccess::open(test, FileAccess::READ);
|
||||
ERR_FAIL_COND_MSG(fa.is_null(), "Could not open file: " + test);
|
||||
|
||||
// Initialize the language for the test routine.
|
||||
init_language(fa->get_path_absolute().get_base_dir());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue