From 6058db4dbc4f0f7627bac09a49a775d1953c428c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 9 Jan 2022 18:36:39 +0300 Subject: more thorough fix for #2992 --- src/mir_app/src/db_ini.cpp | 10 ++-------- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/pu_utils.cpp | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mir_app/src/db_ini.cpp b/src/mir_app/src/db_ini.cpp index c920716303..a164e9eb83 100644 --- a/src/mir_app/src/db_ini.cpp +++ b/src/mir_app/src/db_ini.cpp @@ -36,14 +36,8 @@ static void MyDeleteFile(const wchar_t *pwszFileName) static void ToRecycleBin(const wchar_t *pwszFileName) { - CMStringW tmpPath(pwszFileName); - tmpPath.AppendChar(0); - - SHFILEOPSTRUCT shfo = {}; - shfo.wFunc = FO_DELETE; - shfo.pFrom = tmpPath; - shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&shfo); + if (PU::PrepareEscalation()) + PU::SafeRecycleBin(pwszFileName); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 484658e218..575fe053e1 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -789,3 +789,4 @@ _Netlib_SslShutdown@4 @876 NONAME _Netlib_SslWrite@12 @877 NONAME ?AllowTyping@CSrmmBaseDialog@@IBE_NXZ @878 NONAME ?setTyping@CSrmmBaseDialog@@QAEXHPBUUSERINFO@@@Z @879 NONAME +?SafeRecycleBin@PU@@YGHPB_W@Z @880 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index babafe60b3..f867e78aa7 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -789,3 +789,4 @@ Netlib_SslShutdown @876 NONAME Netlib_SslWrite @877 NONAME ?AllowTyping@CSrmmBaseDialog@@IEBA_NXZ @878 NONAME ?setTyping@CSrmmBaseDialog@@QEAAXHPEBUUSERINFO@@@Z @879 NONAME +?SafeRecycleBin@PU@@YAHPEB_W@Z @880 NONAME diff --git a/src/mir_app/src/pu_utils.cpp b/src/mir_app/src/pu_utils.cpp index 64666c2912..3851b4d949 100644 --- a/src/mir_app/src/pu_utils.cpp +++ b/src/mir_app/src/pu_utils.cpp @@ -269,6 +269,22 @@ MIR_APP_DLL(int) PU::SafeDeleteFile(const wchar_t *pwszFile) return TransactPipe(3, pwszFile, nullptr); } +MIR_APP_DLL(int) PU::SafeRecycleBin(const wchar_t *pwszFile) +{ + if (g_hPipe == nullptr) { + CMStringW tmpPath(pwszFile); + tmpPath.AppendChar(0); + + SHFILEOPSTRUCT shfo = {}; + shfo.wFunc = FO_DELETE; + shfo.pFrom = tmpPath; + shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; + return SHFileOperation(&shfo); + } + + return TransactPipe(7, pwszFile, nullptr); +} + MIR_APP_DLL(int) PU::SafeCreateDirectory(const wchar_t *pwszFolder) { if (g_hPipe == nullptr) -- cgit v1.2.3