From 5d0dff54982b174d382aca8da00393273bc7b3e5 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 8 Sep 2020 13:21:50 +0300 Subject: DeleteDirectoryTreeW - new function that deletes a folder with all subfolders (recursively) --- src/mir_core/src/mir_core.def | 1 + src/mir_core/src/mir_core64.def | 1 + src/mir_core/src/path.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+) (limited to 'src/mir_core') diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 1636bc0239..d0e17162d9 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -2,6 +2,7 @@ LIBRARY mir_core.mir EXPORTS ?g_pCurrDb@@3PAVMDatabaseCommon@@A @1 NONAME +DeleteDirectoryTreeW @2 CallFunctionAsync @5 CallPluginEventHook @7 CallService @8 diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index bb77e99aac..797fb38dcd 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -2,6 +2,7 @@ LIBRARY mir_core.mir EXPORTS ?g_pCurrDb@@3PEAVMDatabaseCommon@@EA @1 NONAME +DeleteDirectoryTreeW @2 CallFunctionAsync @5 CallPluginEventHook @7 CallService @8 diff --git a/src/mir_core/src/path.cpp b/src/mir_core/src/path.cpp index 99d95d9757..596eea39c4 100644 --- a/src/mir_core/src/path.cpp +++ b/src/mir_core/src/path.cpp @@ -207,6 +207,30 @@ MIR_CORE_DLL(int) CreateDirectoryTreeW(const wchar_t *szDir) return (CreateDirectoryW(szTestDir, nullptr) == 0) ? GetLastError() : 0; } +MIR_CORE_DLL(int) DeleteDirectoryTreeW(const wchar_t *pwszDir, bool bAllowUndo) +{ + if (pwszDir == nullptr) + return ERROR_BAD_ARGUMENTS; + + CMStringW wszPath(pwszDir); + wszPath.AppendChar(0); + + SHFILEOPSTRUCTW file_op = { + nullptr, + FO_DELETE, + wszPath, + L"", + FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION, + false, + nullptr, + L"" }; + + if (bAllowUndo) + file_op.fFlags |= FOF_ALLOWUNDO; + + return SHFileOperationW(&file_op); +} + int InitPathUtils(void) { GetModuleFileNameA(nullptr, szMirandaPath, _countof(szMirandaPath)); -- cgit v1.2.3