mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Expose a File.flush() method to scripting
This can be used to ensure a file has its contents saved
even if the project crashes or is killed by the user
(among other use cases).
See discussion in #29075.
(cherry picked from commit ab397460e9)
This commit is contained in:
committed by
Rémi Verschelde
parent
15d9f77f97
commit
6c6f4e9895
@@ -1992,6 +1992,11 @@ Error _File::open(const String &p_path, ModeFlags p_mode_flags) {
|
||||
return err;
|
||||
}
|
||||
|
||||
void _File::flush() {
|
||||
ERR_FAIL_COND_MSG(!f, "File must be opened before flushing.");
|
||||
f->flush();
|
||||
}
|
||||
|
||||
void _File::close() {
|
||||
|
||||
if (f)
|
||||
@@ -2308,6 +2313,7 @@ void _File::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("open", "path", "flags"), &_File::open);
|
||||
ClassDB::bind_method(D_METHOD("flush"), &_File::flush);
|
||||
ClassDB::bind_method(D_METHOD("close"), &_File::close);
|
||||
ClassDB::bind_method(D_METHOD("get_path"), &_File::get_path);
|
||||
ClassDB::bind_method(D_METHOD("get_path_absolute"), &_File::get_path_absolute);
|
||||
|
||||
Reference in New Issue
Block a user