| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "NCMsiHelper.h" |
| 7 |
#include "utility.h" |
| 8 |
#include "LogResult.h" |
| 9 |
|
| 10 |
using namespace NCTools; |
| 11 |
|
| 12 |
HRESULT NCMSIHELPER_API DoExecNsisUninstaller(int argc, LPWSTR *argv) |
| 13 |
{ |
| 14 |
if (argc != 2) { |
| 15 |
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); |
| 16 |
} |
| 17 |
|
| 18 |
const auto appShortName = std::wstring(argv[0]); |
| 19 |
const auto uninstallExePath = std::wstring(argv[1]); |
| 20 |
|
| 21 |
if (appShortName.empty() |
| 22 |
|| uninstallExePath.empty()) { |
| 23 |
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); |
| 24 |
} |
| 25 |
|
| 26 |
auto appInstallDir = uninstallExePath; |
| 27 |
const auto posLastSlash = appInstallDir.find_last_of(PathSeparator); |
| 28 |
if (posLastSlash != std::wstring::npos) { |
| 29 |
appInstallDir.erase(posLastSlash); |
| 30 |
} else { |
| 31 |
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); |
| 32 |
} |
| 33 |
|
| 34 |
// Run uninstaller |
| 35 |
const std::wstring cmd = L'\"' + uninstallExePath + L"\" /S _?=" + appInstallDir; |
| 36 |
LogResult(S_OK, "Running '%ls'.", cmd.data()); |
| 37 |
Utility::execCmd(cmd); |
| 38 |
|
| 39 |
LogResult(S_OK, "Waiting for NSIS uninstaller."); |
| 40 |
|
| 41 |
// Can't wait for the process because Uninstall.exe (opposed to Setup.exe) immediately returns, so we'll sleep a bit. |
| 42 |
Utility::waitForNsisUninstaller(appShortName); |
| 43 |
|
| 44 |
LogResult(S_OK, "Removing the NSIS uninstaller."); |
| 45 |
|
| 46 |
// Sleep a bit and clean up the NSIS mess |
| 47 |
Sleep(1500); |
| 48 |
DeleteFile(uninstallExePath.data()); |
| 49 |
RemoveDirectory(appInstallDir.data()); |
| 50 |
|
| 51 |
LogResult(S_OK, "Finished."); |
| 52 |
|
| 53 |
return S_OK; |
| 54 |
} |
| 55 |
|
| 56 |
HRESULT NCMSIHELPER_API DoRemoveNavigationPaneEntries(int argc, LPWSTR *argv) |
| 57 |
{ |
| 58 |
if (argc != 1) { |
| 59 |
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); |
| 60 |
} |
| 61 |
|
| 62 |
const auto appName = std::wstring(argv[0]); |
| 63 |
|
| 64 |
if (appName.empty()) { |
| 65 |
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); |
| 66 |
} |
| 67 |
|
| 68 |
LogResult(S_OK, "Removing '%ls' sync folders from Explorer's Navigation Pane for the current user.", appName.data()); |
| 69 |
|
| 70 |
Utility::removeNavigationPaneEntries(appName); |
| 71 |
|
| 72 |
LogResult(S_OK, "Finished."); |
| 73 |
|
| 74 |
return S_OK; |
| 75 |
} |