Path: blob/master/Utilities/Release/WiX/CustomAction/detect_nsis_overwrite.cpp
3165 views
#include <string>1#include <vector>23#include <windows.h>45#include <msi.h>6#include <msiquery.h>78std::wstring get_property(MSIHANDLE msi_handle, std::wstring const& name)9{10DWORD size = 0;1112WCHAR value_buffer[] = L"";13UINT status = MsiGetPropertyW(msi_handle, name.c_str(), value_buffer, &size);1415if (status == ERROR_MORE_DATA) {16std::vector<wchar_t> buffer(size + 1);17MsiGetPropertyW(msi_handle, name.c_str(), &buffer[0], &size);18return std::wstring(&buffer[0]);19} else {20return std::wstring();21}22}2324void set_property(MSIHANDLE msi_handle, std::wstring const& name,25std::wstring const& value)26{27MsiSetPropertyW(msi_handle, name.c_str(), value.c_str());28}2930extern "C" UINT __stdcall DetectNsisOverwrite(MSIHANDLE msi_handle)31{32std::wstring install_root = get_property(msi_handle, L"INSTALL_ROOT");3334std::wstring uninstall_exe = install_root + L"\\uninstall.exe";3536bool uninstall_exe_exists =37GetFileAttributesW(uninstall_exe.c_str()) != INVALID_FILE_ATTRIBUTES;3839set_property(msi_handle, L"CMAKE_NSIS_OVERWRITE_DETECTED",40uninstall_exe_exists ? L"1" : L"0");4142return ERROR_SUCCESS;43}444546