tdf#130857 qt weld: Introduce QtInstanceScrolledWindow
[LibreOffice.git] / setup_native / source / win32 / customactions / shellextensions / completeinstallpath.cxx
blob787041ed8f7ef1a90649616ffa67cce5870a8305
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"
22 #include <malloc.h>
24 extern "C" __declspec(dllexport) UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
26 // This CustomAction is necessary for updates from OOo 3.0, OOo 3.1 and OOo 3.2 to versions
27 // OOo 3.3 or later. This is caused by a change of INSTALLLOCATION, that starting with OOo 3.3
28 // contains the name of the product again (instead of only "c:\program files"). Unfortunately
29 // this causes in an update installation, that INSTALLLOCATION is set to "c:\program files",
30 // so that in an OOo 3.3 or later, the directory "program" or "share" are directly created
31 // below "c:\program files".
33 HKEY hKey;
35 // Reading property OFFICEDIRHOSTNAME_, that contains the part of the path behind
36 // the program files folder.
38 std::wstring sInstallLocation = GetMsiPropertyW( handle, L"INSTALLLOCATION" );
39 std::wstring sOfficeDirHostname = GetMsiPropertyW( handle, L"OFFICEDIRHOSTNAME_" );
41 // If sInstallLocation ends with (contains) the string sOfficeDirHostname,
42 // INSTALLLOCATION is good and nothing has to be done here.
44 bool pathCompletionRequired = true;
46 if ( wcsstr( sInstallLocation.c_str(), sOfficeDirHostname.c_str() ) )
48 pathCompletionRequired = false; // nothing to do
51 // If the path INSTALLLOCATION does not end with this string, INSTALLLOCATION is maybe
52 // transferred from an OOo 3.0, OOo 3.1 and OOo 3.2 and need to be changed therefore.
54 if ( pathCompletionRequired )
56 std::wstring sManufacturer = GetMsiPropertyW( handle, L"Manufacturer" );
57 std::wstring sDefinedName = GetMsiPropertyW( handle, L"DEFINEDPRODUCT" );
58 std::wstring sUpgradeCode = GetMsiPropertyW( handle, L"UpgradeCode" );
60 // sUpdateVersion can be "3.0", "3.1" or "3.2"
62 std::wstring sProductKey30 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
63 L"\\" L"3.0" L"\\" + sUpgradeCode;
65 std::wstring sProductKey31 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
66 L"\\" L"3.1" L"\\" + sUpgradeCode;
68 std::wstring sProductKey32 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
69 L"\\" L"3.2" L"\\" + sUpgradeCode;
71 bool oldVersionExists = false;
73 if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey30.c_str(), &hKey ) )
75 oldVersionExists = true;
76 RegCloseKey( hKey );
78 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey31.c_str(), &hKey ) )
80 oldVersionExists = true;
81 RegCloseKey( hKey );
83 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey32.c_str(), &hKey ) )
85 oldVersionExists = true;
86 RegCloseKey( hKey );
88 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey30.c_str(), &hKey ) )
90 oldVersionExists = true;
91 RegCloseKey( hKey );
93 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey31.c_str(), &hKey ) )
95 oldVersionExists = true;
96 RegCloseKey( hKey );
98 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey32.c_str(), &hKey ) )
100 oldVersionExists = true;
101 RegCloseKey( hKey );
104 if ( oldVersionExists )
106 // Adding the new path content sOfficeDirHostname
107 sInstallLocation += sOfficeDirHostname;
108 // Setting the new property value
109 MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstallLocation.c_str());
113 return ERROR_SUCCESS;
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */