Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / setup_native / source / win32 / customactions / shellextensions / migrateinstallpath.cxx
blob66bb99ae18e8d32516218c5e7e316ac5fe8d1c82
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "shlxtmsi.hxx"
21 #include <algorithm>
22 #include <systools/win32/uwinapi.h>
24 extern "C" __declspec(dllexport) UINT __stdcall MigrateInstallPath( MSIHANDLE handle )
26 WCHAR szValue[8192];
27 DWORD nValueSize = sizeof(szValue); // yes, it is the number of bytes
28 HKEY hKey;
29 std::wstring sInstDir;
31 std::wstring sManufacturer = GetMsiPropertyW( handle, L"Manufacturer" );
32 std::wstring sDefinedName = GetMsiPropertyW( handle, L"DEFINEDPRODUCT" );
33 std::wstring sUpdateVersion = GetMsiPropertyW( handle, L"DEFINEDVERSION" );
34 std::wstring sUpgradeCode = GetMsiPropertyW( handle, L"UpgradeCode" );
36 std::wstring sProductKey = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
37 L"\\" + sUpdateVersion + L"\\" + sUpgradeCode;
39 if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey.c_str(), &hKey ) )
41 if ( ERROR_SUCCESS == RegQueryValueExW( hKey, L"INSTALLLOCATION", nullptr, nullptr, reinterpret_cast<LPBYTE>(szValue), &nValueSize ) )
43 szValue[std::min(static_cast<unsigned int>(SAL_N_ELEMENTS(szValue) - 1), static_cast<unsigned int>(nValueSize / sizeof(*szValue)))] = 0;
44 sInstDir = szValue;
45 MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstDir.c_str());
46 // MessageBoxW( NULL, sInstDir.c_str(), L"Found in HKEY_CURRENT_USER", MB_OK );
49 RegCloseKey( hKey );
51 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey.c_str(), &hKey ) )
53 if ( ERROR_SUCCESS == RegQueryValueExW( hKey, L"INSTALLLOCATION", nullptr, nullptr, reinterpret_cast<LPBYTE>(szValue), &nValueSize ) )
55 szValue[std::min(static_cast<unsigned int>(SAL_N_ELEMENTS(szValue) - 1), static_cast<unsigned int>(nValueSize / sizeof(*szValue)))] = 0;
56 sInstDir = szValue;
57 MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstDir.c_str());
58 // MessageBoxW( NULL, sInstDir.c_str(), L"Found in HKEY_LOCAL_MACHINE", MB_OK );
61 RegCloseKey( hKey );
64 return ERROR_SUCCESS;
68 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */