]> khamidou — GitHub mirrors - electron.git/commitdiff
Implement MoveItemToTrash on Windows.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 4 Jul 2013 07:27:52 +0000 (15:27 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 4 Jul 2013 08:30:48 +0000 (16:30 +0800)
common/platform_util_win.cc

index ffdd340c3c963f227cb193c57d7ecf2b76009fc9..3735999a0265e9b04d65d018a33d9d6e19197f5b 100644 (file)
@@ -164,4 +164,22 @@ void OpenExternal(const GURL& url) {
   }
 }
 
+void MoveItemToTrash(const base::FilePath& path) {
+  // SHFILEOPSTRUCT wants the path to be terminated with two NULLs,
+  // so we have to use wcscpy because wcscpy_s writes non-NULLs
+  // into the rest of the buffer.
+  wchar_t double_terminated_path[MAX_PATH + 1] = {0};
+#pragma warning(suppress:4996)  // don't complain about wcscpy deprecation
+  wcscpy(double_terminated_path, path.value().c_str());
+
+  SHFILEOPSTRUCT file_operation = {0};
+  file_operation.wFunc = FO_DELETE;
+  file_operation.pFrom = double_terminated_path;
+  file_operation.fFlags = FOF_ALLOWUNDO;
+  SHFileOperation(&file_operation);
+}
+
+void Beep() {
+}
+
 }  // namespace platform_util