summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater/pu_stub/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-09-08 13:21:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-09-08 13:21:50 +0300
commit5d0dff54982b174d382aca8da00393273bc7b3e5 (patch)
treeb18df845cd408a8f4d32fe02e9e65109e01c58c0 /plugins/PluginUpdater/pu_stub/src
parent7997d0ec5810ad7699d0de6417510ab756be320d (diff)
DeleteDirectoryTreeW - new function that deletes a folder with all subfolders (recursively)
Diffstat (limited to 'plugins/PluginUpdater/pu_stub/src')
-rw-r--r--plugins/PluginUpdater/pu_stub/src/pu_stub.cpp32
-rw-r--r--plugins/PluginUpdater/pu_stub/src/stdafx.h1
2 files changed, 31 insertions, 2 deletions
diff --git a/plugins/PluginUpdater/pu_stub/src/pu_stub.cpp b/plugins/PluginUpdater/pu_stub/src/pu_stub.cpp
index 60c67f7c1a..c3cd302482 100644
--- a/plugins/PluginUpdater/pu_stub/src/pu_stub.cpp
+++ b/plugins/PluginUpdater/pu_stub/src/pu_stub.cpp
@@ -21,8 +21,9 @@ void log(const wchar_t *tszFormat, ...)
int CreateDirectoryTreeW(const wchar_t* szDir)
{
- wchar_t szTestDir[MAX_PATH];
- lstrcpynW(szTestDir, szDir, MAX_PATH);
+ wchar_t szTestDir[MAX_PATH+1];
+ if (lstrcpynW(szTestDir, szDir, MAX_PATH) == nullptr)
+ szTestDir[MAX_PATH] = 0;
DWORD dwAttributes = GetFileAttributesW(szTestDir);
if (dwAttributes != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
@@ -38,6 +39,28 @@ int CreateDirectoryTreeW(const wchar_t* szDir)
return (CreateDirectoryW(szTestDir, nullptr) == 0) ? GetLastError() : 0;
}
+int DeleteDirectoryTreeW(const wchar_t *pwszDirName)
+{
+ // file name shall be double sero ended
+ wchar_t wszPath[MAX_PATH + 2];
+ if (lstrcpynW(wszPath, pwszDirName, MAX_PATH) == nullptr)
+ wszPath[MAX_PATH] = 0;
+ wszPath[lstrlenW(wszPath) + 1] = 0;
+
+ SHFILEOPSTRUCTW file_op = {
+ NULL,
+ FO_DELETE,
+ wszPath,
+ L"",
+ FOF_NOCONFIRMATION |
+ FOF_NOERRORUI |
+ FOF_SILENT,
+ false,
+ 0,
+ L"" };
+ return SHFileOperationW(&file_op);
+}
+
void CreatePathToFileW(wchar_t *wszFilePath)
{
wchar_t* pszLastBackslash = wcsrchr(wszFilePath, '\\');
@@ -132,6 +155,11 @@ int APIENTRY wWinMain(HINSTANCE /*hInstance*/, HINSTANCE, LPTSTR lpCmdLine, int)
dwError = 0;
break;
+ case 6: // delete folder recursively
+ DeleteDirectoryTreeW(ptszFile1);
+ dwError = 0;
+ break;
+
default:
dwError = ERROR_UNKNOWN_FEATURE;
}
diff --git a/plugins/PluginUpdater/pu_stub/src/stdafx.h b/plugins/PluginUpdater/pu_stub/src/stdafx.h
index b6f494b071..7ad5b19462 100644
--- a/plugins/PluginUpdater/pu_stub/src/stdafx.h
+++ b/plugins/PluginUpdater/pu_stub/src/stdafx.h
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#include <shellapi.h>
// C RunTime Header Files
#include <stdlib.h>