From f53ed6c50378634eb8c3a8a4561fdf1e3e027309 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 4 Jul 2013 15:27:52 +0800 Subject: [PATCH] Implement MoveItemToTrash on Windows. --- common/platform_util_win.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/platform_util_win.cc b/common/platform_util_win.cc index ffdd340c..3735999a 100644 --- a/common/platform_util_win.cc +++ b/common/platform_util_win.cc @@ -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 -- 2.43.0