File: NCMsiHelper.cpp

package info (click to toggle)
nextcloud-desktop 4.0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,740 kB
  • sloc: cpp: 119,301; objc: 752; python: 606; ansic: 389; sh: 377; makefile: 44; javascript: 32; xml: 6
file content (75 lines) | stat: -rw-r--r-- 2,131 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "NCMsiHelper.h"
#include "utility.h"
#include "LogResult.h"

using namespace NCTools;

HRESULT NCMSIHELPER_API DoExecNsisUninstaller(int argc, LPWSTR *argv)
{
    if (argc != 2) {
        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
    }

    const auto appShortName = std::wstring(argv[0]);
    const auto uninstallExePath = std::wstring(argv[1]);

    if (appShortName.empty()
         || uninstallExePath.empty()) {
        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
    }

    auto appInstallDir = uninstallExePath;
    const auto posLastSlash = appInstallDir.find_last_of(PathSeparator);
    if (posLastSlash != std::wstring::npos) {
        appInstallDir.erase(posLastSlash);
    } else {
        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
    }

    // Run uninstaller
    const std::wstring cmd = L'\"' + uninstallExePath + L"\" /S _?=" + appInstallDir;
    LogResult(S_OK, "Running '%ls'.", cmd.data());
    Utility::execCmd(cmd);

    LogResult(S_OK, "Waiting for NSIS uninstaller.");

    // Can't wait for the process because Uninstall.exe (opposed to Setup.exe) immediately returns, so we'll sleep a bit.
    Utility::waitForNsisUninstaller(appShortName);

    LogResult(S_OK, "Removing the NSIS uninstaller.");

    // Sleep a bit and clean up the NSIS mess
    Sleep(1500);
    DeleteFile(uninstallExePath.data());
    RemoveDirectory(appInstallDir.data());

    LogResult(S_OK, "Finished.");

    return S_OK;
}

HRESULT NCMSIHELPER_API DoRemoveNavigationPaneEntries(int argc, LPWSTR *argv)
{
    if (argc != 1) {
        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
    }

    const auto appName = std::wstring(argv[0]);

    if (appName.empty()) {
        return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
    }

    LogResult(S_OK, "Removing '%ls' sync folders from Explorer's Navigation Pane for the current user.", appName.data());

    Utility::removeNavigationPaneEntries(appName);

    LogResult(S_OK, "Finished.");

    return S_OK;
}