23#include <systools/win32/uwinapi.h>
25extern "C" __declspec(dllexport) UINT __stdcall MigrateInstallPath(MSIHANDLE handle)
28 if (!sInstDir.empty())
31 auto RegValue = [](HKEY hRoot,
const WCHAR* sKey,
const WCHAR* sVal) {
34 DWORD bufsize =
sizeof(buf);
35 if (RegGetValueW(hRoot, sKey, sVal, RRF_RT_REG_SZ,
nullptr, buf, &bufsize) == ERROR_SUCCESS)
41 const std::wstring sManufacturer =
GetMsiPropertyW( handle, L
"Manufacturer" );
42 const std::wstring sDefinedName =
GetMsiPropertyW( handle, L
"DEFINEDPRODUCT" );
43 const std::wstring sUpdateVersion =
GetMsiPropertyW( handle, L
"DEFINEDVERSION" );
44 const std::wstring sUpgradeCode =
GetMsiPropertyW( handle, L
"UpgradeCode" );
45 const std::wstring sBrandPackageVersion =
GetMsiPropertyW(handle, L
"BRANDPACKAGEVERSION");
47 std::wstring sKey = L
"Software\\" + sManufacturer + L
"\\" + sDefinedName +
48 L
"\\" + sUpdateVersion + L
"\\" + sUpgradeCode;
50 sInstDir =
RegValue(HKEY_CURRENT_USER, sKey.c_str(), L
"INSTALLLOCATION");
52 sInstDir =
RegValue(HKEY_LOCAL_MACHINE, sKey.c_str(), L
"INSTALLLOCATION");
56 sKey = L
"Software\\LibreOffice\\Layers\\" + sDefinedName + L
"\\" + sBrandPackageVersion;
57 sInstDir =
RegValue(HKEY_CURRENT_USER, sKey.c_str(), L
"INSTALLLOCATION");
61 sKey = L
"Software\\LibreOffice\\Layers_\\" + sDefinedName + L
"\\" + sBrandPackageVersion;
62 sInstDir =
RegValue(HKEY_CURRENT_USER, sKey.c_str(), L
"INSTALLLOCATION");
66 sKey = L
"Software\\LibreOffice\\Layers\\" + sDefinedName + L
"\\" + sBrandPackageVersion;
67 sInstDir =
RegValue(HKEY_LOCAL_MACHINE, sKey.c_str(), L
"INSTALLLOCATION");
71 sKey = L
"Software\\LibreOffice\\Layers_\\" + sDefinedName + L
"\\" + sBrandPackageVersion;
72 sInstDir =
RegValue(HKEY_LOCAL_MACHINE, sKey.c_str(), L
"INSTALLLOCATION");
78 while (std::getline(sOlds, sOld, L
';'))
82 sKey = L
"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + sOld;
83 sInstDir =
RegValue(HKEY_LOCAL_MACHINE, sKey.c_str(), L
"InstallLocation");
84 if (!sInstDir.empty())
89 if (!sInstDir.empty())
90 MsiSetPropertyW(handle, L
"INSTALLLOCATION", sInstDir.c_str());
__declspec(dllexport) UINT __stdcall MigrateInstallPath(MSIHANDLE handle)
static std::wstring GetMsiPropertyW(MSIHANDLE handle, const std::wstring &sProperty)