diff options
author | George Hazan <ghazan@miranda.im> | 2020-09-08 13:21:50 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-09-08 13:21:50 +0300 |
commit | 5d0dff54982b174d382aca8da00393273bc7b3e5 (patch) | |
tree | b18df845cd408a8f4d32fe02e9e65109e01c58c0 /plugins/BasicHistory | |
parent | 7997d0ec5810ad7699d0de6417510ab756be320d (diff) |
DeleteDirectoryTreeW - new function that deletes a folder with all subfolders (recursively)
Diffstat (limited to 'plugins/BasicHistory')
-rw-r--r-- | plugins/BasicHistory/src/EventList.cpp | 3 | ||||
-rw-r--r-- | plugins/BasicHistory/src/RichHtmlExport.cpp | 29 | ||||
-rw-r--r-- | plugins/BasicHistory/src/Scheduler.cpp | 15 |
3 files changed, 9 insertions, 38 deletions
diff --git a/plugins/BasicHistory/src/EventList.cpp b/plugins/BasicHistory/src/EventList.cpp index f6d03409dd..b686dbc998 100644 --- a/plugins/BasicHistory/src/EventList.cpp +++ b/plugins/BasicHistory/src/EventList.cpp @@ -26,7 +26,6 @@ extern int iconsNum; static mir_cs csEventList;
-bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true);
std::wstring GetName(const std::wstring &path);
HistoryEventList::HistoryEventList() :
@@ -608,7 +607,7 @@ void HistoryEventList::Init() GetTempPath(MAX_PATH, temp);
m_contactFileDir = temp;
m_contactFileDir += L"BasicHistoryImportDir\\";
- DeleteDirectory(m_contactFileDir.c_str());
+ DeleteDirectoryTreeW(m_contactFileDir.c_str());
CreateDirectory(m_contactFileDir.c_str(), nullptr);
}
diff --git a/plugins/BasicHistory/src/RichHtmlExport.cpp b/plugins/BasicHistory/src/RichHtmlExport.cpp index bc316393d8..dc712cc1f2 100644 --- a/plugins/BasicHistory/src/RichHtmlExport.cpp +++ b/plugins/BasicHistory/src/RichHtmlExport.cpp @@ -253,39 +253,12 @@ void IcoSave(const std::wstring &fileName, HICON hicon) if (ii.hbmMask) DeleteObject(ii.hbmMask);
}
-bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true)
-{
- size_t len = mir_wstrlen(lpszDir);
- wchar_t *pszFrom = new wchar_t[len + 2];
- wcscpy_s(pszFrom, len + 2, lpszDir);
- pszFrom[len] = 0;
- pszFrom[len + 1] = 0;
-
- SHFILEOPSTRUCT fileop;
- fileop.hwnd = nullptr; // no status display
- fileop.wFunc = FO_DELETE; // delete operation
- fileop.pFrom = pszFrom; // source file name as double null terminated string
- fileop.pTo = nullptr; // no destination needed
- fileop.fFlags = FOF_NOCONFIRMATION | FOF_SILENT; // do not prompt the user
-
- if (!noRecycleBin)
- fileop.fFlags |= FOF_ALLOWUNDO;
-
- fileop.fAnyOperationsAborted = FALSE;
- fileop.lpszProgressTitle = nullptr;
- fileop.hNameMappings = nullptr;
-
- int ret = SHFileOperation(&fileop);
- delete[] pszFrom;
- return (ret == 0);
-}
-
void RichHtmlExport::WriteHeader(const std::wstring &fileName, const std::wstring &filterName, const std::wstring &myName, const std::wstring &myId, const std::wstring &name1, const std::wstring &proto1, const std::wstring &id1, const std::string& baseProto1, const std::wstring& encoding)
{
baseProto = baseProto1;
folder = RemoveExt(fileName) + L"_files";
folderName = GetName(folder);
- DeleteDirectory(folder.c_str());
+ DeleteDirectoryTreeW(folder.c_str());
CreateDirectory(folder.c_str(), nullptr);
std::wstring css = folder + L"\\history.css";
BOOL cssCopied = FALSE;
diff --git a/plugins/BasicHistory/src/Scheduler.cpp b/plugins/BasicHistory/src/Scheduler.cpp index a080d18e0e..51cce458ec 100644 --- a/plugins/BasicHistory/src/Scheduler.cpp +++ b/plugins/BasicHistory/src/Scheduler.cpp @@ -26,7 +26,6 @@ bool IsValidTask(TaskOptions& to, std::list<TaskOptions>* top = nullptr, std::ws std::wstring GetFileName(const std::wstring &baseName, std::wstring contactName, std::map<std::wstring, bool>& existingContacts, bool replaceContact);
std::wstring GetDirectoryName(const std::wstring &path);
std::wstring GetName(const std::wstring &path);
-bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true);
void ListDirectory(const std::wstring &basePath, const std::wstring &path, std::list<std::wstring>& files);
std::wstring ReplaceStr(const std::wstring& str, wchar_t oldCh, wchar_t newCh);
time_t GetNextExportTime(TaskOptions& to);
@@ -286,7 +285,7 @@ bool DoTask(TaskOptions& to) if (pos < dir.length())
dir = dir.substr(0, pos);
- DeleteDirectory(dir.c_str());
+ DeleteDirectoryTreeW(dir.c_str());
CreateDirectory(dir.c_str(), nullptr);
}
@@ -416,7 +415,7 @@ bool DoTask(TaskOptions& to) }
if (to.useFtp || to.compress)
- DeleteDirectory(dir.c_str());
+ DeleteDirectoryTreeW(dir.c_str());
}
else {
std::map<std::wstring, bool> existingContacts;
@@ -440,7 +439,7 @@ bool DoTask(TaskOptions& to) if (pos < dir.length())
dir = dir.substr(0, pos);
- DeleteDirectory(dir.c_str());
+ DeleteDirectoryTreeW(dir.c_str());
CreateDirectory(dir.c_str(), nullptr);
filePath = dir + L"\\" + filePath;
}
@@ -490,7 +489,7 @@ bool DoTask(TaskOptions& to) if (error) {
if (to.compress && !to.useFtp)
- DeleteDirectory(dir.c_str());
+ DeleteDirectoryTreeW(dir.c_str());
}
else if (to.compress) {
std::wstring zipFilePath = to.filePath;
@@ -508,7 +507,7 @@ bool DoTask(TaskOptions& to) zipDir = temp;
zipDir += L"zip<date>";
zipDir = GetFileName(zipDir, L"", existingContacts, true);
- DeleteDirectory(zipDir.c_str());
+ DeleteDirectoryTreeW(zipDir.c_str());
CreateDirectory(zipDir.c_str(), nullptr);
zipFilePath = zipDir + L"\\" + zipFilePath;
}
@@ -533,7 +532,7 @@ bool DoTask(TaskOptions& to) }
}
- DeleteDirectory(dir.c_str());
+ DeleteDirectoryTreeW(dir.c_str());
}
}
@@ -966,7 +965,7 @@ bool ZipFiles(const std::wstring &dir, std::wstring zipFilePath, const std::stri else error = true;
}
- DeleteDirectory(dir.c_str());
+ DeleteDirectoryTreeW(dir.c_str());
return error;
}
|