diff --git a/core/os/os.h b/core/os/os.h index 41b1956dc5..12b0696644 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -334,6 +334,8 @@ public: virtual String get_data_dir() const; virtual String get_resource_dir() const; + virtual Error move_path_to_trash(String p_dir) { return FAILED; } + enum SystemDir { SYSTEM_DIR_DESKTOP, SYSTEM_DIR_DCIM, diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index de97b89ec0..dd9a9cef53 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -220,6 +220,8 @@ public: void disable_crash_handler(); bool is_disable_crash_handler() const; + virtual Error move_path_to_trash(String p_dir); + OS_OSX(); }; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index a55354a425..1a382a8ade 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1797,6 +1797,19 @@ String OS_OSX::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } +Error OS_OSX::move_path_to_trash(String p_dir) { + NSFileManager *fm = [NSFileManager defaultManager]; + NSURL *url = [NSURL fileURLWithPath:@(p_dir.utf8().get_data())]; + NSError *err; + + if (![fm trashItemAtURL:url resultingItemURL:nil error:&err]) { + ERR_PRINTS("trashItemAtURL error: " + String(err.localizedDescription.UTF8String)); + return FAILED; + } + + return OK; +} + OS_OSX *OS_OSX::singleton = NULL; OS_OSX::OS_OSX() {