setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx | 22 ++++++++-- 1 file changed, 18 insertions(+), 4 deletions(-)
New commits: commit 1dcdd2543d70348d93d7f8d8d2b95e3bd6515e2c Author: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> AuthorDate: Wed May 11 11:20:30 2022 +0200 Commit: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> CommitDate: Wed May 11 11:20:30 2022 +0200 Add error handling to RenamePrgFolder and RemovePrgFolder These routines can fail during MSI installation (seen leftover program_old folders, with program folder missing). We at least want to see the error in the MSI log file when this doesn't succeed. This outputs error messages like: MSI (s) (C4:5C) [10:47:54:280]: Invoking remote custom action. DLL: C:\Windows\Installer\MSI37B4.tmp, Entrypoint: RemovePrgFolder CustomAction RemovePrgFolder returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox) Action ended 10:47:54: RemovePrgFolder. Return value 3. Change-Id: I4ce4099eeb3e0ee79eb4a2e1d3887f9810fd9669 diff --git a/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx b/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx index ee4f7dc0df87..73f5f60ddda0 100644 --- a/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx +++ b/setup_native/source/win32/customactions/shellextensions/vistaspecial.cxx @@ -80,6 +80,12 @@ static BOOL RemoveCompleteDirectoryW(const std::wstring& rPath) return bDirectoryRemoved; } +/** Move program folder to program_old. Tries 10 times (program_old1, program_old2, ...). + * + * @return + * ERROR_INSTALL_FAILURE when the folder cannot be moved. + * ERROR_SUCCESS otherwise. + */ extern "C" __declspec(dllexport) UINT __stdcall RenamePrgFolder( MSIHANDLE handle ) { std::wstring sOfficeInstallPath = GetMsiPropertyW(handle, L"INSTALLLOCATION"); @@ -101,22 +107,30 @@ extern "C" __declspec(dllexport) UINT __stdcall RenamePrgFolder( MSIHANDLE handl } } - // ? This succeeds unconditionally, even if bSuccess is false! - return ERROR_SUCCESS; + return bSuccess ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; } + +/** Remove leftover program_old folder(s). + * + * @return + * ERROR_INSTALL_FAILURE when the folder cannot be removed. + * ERROR_SUCCESS otherwise. + */ extern "C" __declspec(dllexport) UINT __stdcall RemovePrgFolder( MSIHANDLE handle ) { std::wstring sOfficeInstallPath = GetMsiPropertyW(handle, L"INSTALLLOCATION"); std::wstring sRemoveDir = sOfficeInstallPath + L"program_old"; - RemoveCompleteDirectoryW( sRemoveDir ); + if (!RemoveCompleteDirectoryW(sRemoveDir)) + return ERROR_INSTALL_FAILURE; WCHAR sAppend[2] = L"0"; for ( int i = 0; i < 10; i++ ) { sRemoveDir = sOfficeInstallPath + L"program_old" + sAppend; - RemoveCompleteDirectoryW( sRemoveDir ); + if (!RemoveCompleteDirectoryW( sRemoveDir )) + return ERROR_INSTALL_FAILURE; sAppend[0] += 1; }