diff options
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/dir_access.cpp | 2 | ||||
-rw-r--r-- | core/os/file_access.cpp | 55 | ||||
-rw-r--r-- | core/os/file_access.h | 10 | ||||
-rw-r--r-- | core/os/input.cpp | 1 | ||||
-rw-r--r-- | core/os/input.h | 4 | ||||
-rw-r--r-- | core/os/os.cpp | 10 | ||||
-rw-r--r-- | core/os/os.h | 9 |
7 files changed, 79 insertions, 12 deletions
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 2c1c655175..d81c30f33a 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -330,7 +330,7 @@ Error DirAccess::copy(String p_from, String p_to, int p_chmod_flags) { if (err == OK && p_chmod_flags != -1) { fdst->close(); - err = fdst->_chmod(p_to, p_chmod_flags); + err = FileAccess::set_unix_permissions(p_to, p_chmod_flags); // If running on a platform with no chmod support (i.e., Windows), don't fail if (err == ERR_UNAVAILABLE) err = OK; diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 39d9f45bd7..079f51bada 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -507,6 +507,29 @@ uint64_t FileAccess::get_modified_time(const String &p_file) { return mt; } +uint32_t FileAccess::get_unix_permissions(const String &p_file) { + + if (PackedData::get_singleton() && !PackedData::get_singleton()->is_disabled() && PackedData::get_singleton()->has_path(p_file)) + return 0; + + FileAccess *fa = create_for_path(p_file); + ERR_FAIL_COND_V(!fa, 0); + + uint32_t mt = fa->_get_unix_permissions(p_file); + memdelete(fa); + return mt; +} + +Error FileAccess::set_unix_permissions(const String &p_file, uint32_t p_permissions) { + + FileAccess *fa = create_for_path(p_file); + ERR_FAIL_COND_V(!fa, ERR_CANT_CREATE); + + Error err = fa->_set_unix_permissions(p_file, p_permissions); + memdelete(fa); + return err; +} + void FileAccess::store_string(const String &p_string) { if (p_string.length() == 0) @@ -571,10 +594,16 @@ void FileAccess::store_buffer(const uint8_t *p_src, int p_length) { store_8(p_src[i]); } -Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) { +Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path, Error *r_error) { - FileAccess *f = FileAccess::open(p_path, READ); - ERR_FAIL_COND_V(!f, Vector<uint8_t>()); + FileAccess *f = FileAccess::open(p_path, READ, r_error); + if (!f) { + if (r_error) { // if error requested, do not throw error + return Vector<uint8_t>(); + } else { + ERR_FAIL_COND_V(!f, Vector<uint8_t>()); + } + } Vector<uint8_t> data; data.resize(f->get_len()); f->get_buffer(data.ptrw(), data.size()); @@ -582,6 +611,26 @@ Vector<uint8_t> FileAccess::get_file_as_array(const String &p_path) { return data; } +String FileAccess::get_file_as_string(const String &p_path, Error *r_error) { + + Error err; + Vector<uint8_t> array = get_file_as_array(p_path, &err); + if (r_error) { + *r_error = err; + } + if (err != OK) { + if (r_error) { + return String(); + } else { + ERR_FAIL_COND_V(err != OK, String()); + } + } + + String ret; + ret.parse_utf8((const char *)array.ptr(), array.size()); + return ret; +} + String FileAccess::get_md5(const String &p_file) { FileAccess *f = FileAccess::open(p_file, READ); diff --git a/core/os/file_access.h b/core/os/file_access.h index c65b75369c..4930eae35a 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -56,6 +56,9 @@ public: bool endian_swap; bool real_is_double; + virtual uint32_t _get_unix_permissions(const String &p_file) = 0; + virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) = 0; + protected: String fix_path(const String &p_path) const; virtual Error _open(const String &p_path, int p_mode_flags) = 0; ///< open a file @@ -148,14 +151,14 @@ public: virtual Error reopen(const String &p_path, int p_mode_flags); ///< does not change the AccessType - virtual Error _chmod(const String &p_path, int p_mod) { return ERR_UNAVAILABLE; } - static FileAccess *create(AccessType p_access); /// Create a file access (for the current platform) this is the only portable way of accessing files. static FileAccess *create_for_path(const String &p_path); static FileAccess *open(const String &p_path, int p_mode_flags, Error *r_error = NULL); /// Create a file access (for the current platform) this is the only portable way of accessing files. static CreateFunc get_create_func(AccessType p_access); static bool exists(const String &p_name); ///< return true if a file exists static uint64_t get_modified_time(const String &p_file); + static uint32_t get_unix_permissions(const String &p_file); + static Error set_unix_permissions(const String &p_file, uint32_t p_permissions); static void set_backup_save(bool p_enable) { backup_save = p_enable; }; static bool is_backup_save_enabled() { return backup_save; }; @@ -164,7 +167,8 @@ public: static String get_sha256(const String &p_file); static String get_multiple_md5(const Vector<String> &p_file); - static Vector<uint8_t> get_file_as_array(const String &p_path); + static Vector<uint8_t> get_file_as_array(const String &p_path, Error *r_error = NULL); + static String get_file_as_string(const String &p_path, Error *r_error = NULL); template <class T> static void make_default(AccessType p_access) { diff --git a/core/os/input.cpp b/core/os/input.cpp index caa9fb1493..63bf1db499 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -89,6 +89,7 @@ void Input::_bind_methods() { ClassDB::bind_method(D_METHOD("action_press", "action", "strength"), &Input::action_press, DEFVAL(1.f)); ClassDB::bind_method(D_METHOD("action_release", "action"), &Input::action_release); ClassDB::bind_method(D_METHOD("set_default_cursor_shape", "shape"), &Input::set_default_cursor_shape, DEFVAL(CURSOR_ARROW)); + ClassDB::bind_method(D_METHOD("get_current_cursor_shape"), &Input::get_current_cursor_shape); ClassDB::bind_method(D_METHOD("set_custom_mouse_cursor", "image", "shape", "hotspot"), &Input::set_custom_mouse_cursor, DEFVAL(CURSOR_ARROW), DEFVAL(Vector2())); ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event); ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &Input::set_use_accumulated_input); diff --git a/core/os/input.h b/core/os/input.h index c8b80b28d0..de04f239e6 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -121,10 +121,10 @@ public: virtual bool is_emulating_touch_from_mouse() const = 0; virtual bool is_emulating_mouse_from_touch() const = 0; - virtual CursorShape get_default_cursor_shape() = 0; + virtual CursorShape get_default_cursor_shape() const = 0; virtual void set_default_cursor_shape(CursorShape p_shape) = 0; + virtual CursorShape get_current_cursor_shape() const = 0; virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = CURSOR_ARROW, const Vector2 &p_hotspot = Vector2()) = 0; - virtual void set_mouse_in_window(bool p_in_window) = 0; virtual String get_joy_button_string(int p_button) = 0; virtual String get_joy_axis_string(int p_axis) = 0; diff --git a/core/os/os.cpp b/core/os/os.cpp index 03e63f636e..ea378c9e83 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -220,6 +220,16 @@ int OS::get_virtual_keyboard_height() const { return 0; } +void OS::set_cursor_shape(CursorShape p_shape) { +} + +OS::CursorShape OS::get_cursor_shape() const { + return CURSOR_ARROW; +} + +void OS::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { +} + void OS::print_all_resources(String p_to_file) { ERR_FAIL_COND(p_to_file != "" && _OSPRF); diff --git a/core/os/os.h b/core/os/os.h index d02d5a2c84..4ae8a354e5 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -45,6 +45,8 @@ @author Juan Linietsky <reduzio@gmail.com> */ +class Mutex; + class OS { static OS *singleton; @@ -260,7 +262,7 @@ public: virtual int get_low_processor_usage_mode_sleep_usec() const; virtual String get_executable_path() const; - virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false) = 0; + virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false, Mutex *p_pipe_mutex = NULL) = 0; virtual Error kill(const ProcessID &p_pid) = 0; virtual int get_process_id() const; @@ -377,8 +379,9 @@ public: // returns height of the currently shown virtual keyboard (0 if keyboard is hidden) virtual int get_virtual_keyboard_height() const; - virtual void set_cursor_shape(CursorShape p_shape) = 0; - virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) = 0; + virtual void set_cursor_shape(CursorShape p_shape); + virtual CursorShape get_cursor_shape() const; + virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot); virtual bool get_swap_ok_cancel() { return false; } virtual void dump_memory_to_file(const char *p_file); |