Browse Source

Added OS::move_path_to_trash function, implemented only on OS X for now.

Marcelo Fernandez 8 years ago
parent
commit
b0d5596738
3 changed files with 17 additions and 0 deletions
  1. 2 0
      core/os/os.h
  2. 2 0
      platform/osx/os_osx.h
  3. 13 0
      platform/osx/os_osx.mm

+ 2 - 0
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,

+ 2 - 0
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();
 };
 

+ 13 - 0
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() {