diff options
author | Marcelo Fernandez <marcelofg55@gmail.com> | 2018-03-09 11:45:21 -0300 |
---|---|---|
committer | Marcelo Fernandez <marcelofg55@gmail.com> | 2018-03-13 12:07:37 -0300 |
commit | a4e64c545406be00c00fe93818994977ae378fb9 (patch) | |
tree | 3c348b2d9184db62e2e4e89b5c9269568e8cf7a8 /core | |
parent | b84236944215445be191047ab628e570ffd69e99 (diff) |
Added File.get_path and File.get_path_absolute functions
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 13 | ||||
-rw-r--r-- | core/bind/core_bind.h | 3 | ||||
-rw-r--r-- | core/os/file_access.h | 3 |
3 files changed, 19 insertions, 0 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index a81301e8ea..20adf7ff02 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1535,6 +1535,17 @@ bool _File::is_open() const { return f != NULL; } +String _File::get_path() const { + + ERR_FAIL_COND_V(!f, ""); + return f->get_path(); +} + +String _File::get_path_absolute() const { + + ERR_FAIL_COND_V(!f, ""); + return f->get_path_absolute(); +} void _File::seek(int64_t p_position) { @@ -1824,6 +1835,8 @@ void _File::_bind_methods() { ClassDB::bind_method(D_METHOD("open", "path", "flags"), &_File::open); 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); ClassDB::bind_method(D_METHOD("is_open"), &_File::is_open); ClassDB::bind_method(D_METHOD("seek", "position"), &_File::seek); ClassDB::bind_method(D_METHOD("seek_end", "position"), &_File::seek_end, DEFVAL(0)); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 8ce7b4f7fe..c40abd51f6 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -415,6 +415,9 @@ public: void close(); ///< close a file bool is_open() const; ///< true when file is open + String get_path() const; /// returns the path for the current open file + String get_path_absolute() const; /// returns the absolute path for the current open file + void seek(int64_t p_position); ///< seek to a given position void seek_end(int64_t p_position = 0); ///< seek from the end of file int64_t get_position() const; ///< get position in the file diff --git a/core/os/file_access.h b/core/os/file_access.h index 5d10c1a9aa..c4635fdfbb 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -89,6 +89,9 @@ public: virtual void close() = 0; ///< close a file virtual bool is_open() const = 0; ///< true when file is open + virtual String get_path() const { return ""; } /// returns the path for the current open file + virtual String get_path_absolute() const { return ""; } /// returns the absolute path for the current open file + virtual void seek(size_t p_position) = 0; ///< seek to a given position virtual void seek_end(int64_t p_position = 0) = 0; ///< seek from the end of file virtual size_t get_position() const = 0; ///< get position in the file |