summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater
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
parent7997d0ec5810ad7699d0de6417510ab756be320d (diff)
DeleteDirectoryTreeW - new function that deletes a folder with all subfolders (recursively)
Diffstat (limited to 'plugins/PluginUpdater')
-rw-r--r--plugins/PluginUpdater/pu_stub/src/pu_stub.cpp32
-rw-r--r--plugins/PluginUpdater/pu_stub/src/stdafx.h1
-rw-r--r--plugins/PluginUpdater/src/Events.cpp16
3 files changed, 32 insertions, 17 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>
diff --git a/plugins/PluginUpdater/src/Events.cpp b/plugins/PluginUpdater/src/Events.cpp
index 4c808600dc..55a28341bd 100644
--- a/plugins/PluginUpdater/src/Events.cpp
+++ b/plugins/PluginUpdater/src/Events.cpp
@@ -30,20 +30,6 @@ int OnFoldersChanged(WPARAM, LPARAM)
return 0;
}
-void EmptyFolder()
-{
- SHFILEOPSTRUCT file_op = {
- nullptr,
- FO_DELETE,
- g_wszRoot,
- L"",
- FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION,
- false,
- nullptr,
- L"" };
- SHFileOperation(&file_op);
-}
-
int ModulesLoaded(WPARAM, LPARAM)
{
if (hPluginUpdaterFolder = FoldersRegisterCustomPathW(MODULEA, LPGEN("Plugin Updater"), MIRANDA_PATHW L"\\" DEFAULT_UPDATES_FOLDER)) {
@@ -59,7 +45,7 @@ int ModulesLoaded(WPARAM, LPARAM)
if (iRestartCount > 0)
g_plugin.setByte(DB_SETTING_RESTART_COUNT, iRestartCount - 1);
else
- EmptyFolder(); // silently
+ DeleteDirectoryTreeW(g_wszRoot);
CheckUpdateOnStartup();