LibreOffice Module setup_native (master) 1
completeinstallpath.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "shlxtmsi.hxx"
21
22#include <malloc.h>
23
24extern "C" __declspec(dllexport) UINT __stdcall CompleteInstallPath( MSIHANDLE handle )
25{
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".
32
33 HKEY hKey;
34
35 // Reading property OFFICEDIRHOSTNAME_, that contains the part of the path behind
36 // the program files folder.
37
38 std::wstring sInstallLocation = GetMsiPropertyW( handle, L"INSTALLLOCATION" );
39 std::wstring sOfficeDirHostname = GetMsiPropertyW( handle, L"OFFICEDIRHOSTNAME_" );
40
41 // If sInstallLocation ends with (contains) the string sOfficeDirHostname,
42 // INSTALLLOCATION is good and nothing has to be done here.
43
44 bool pathCompletionRequired = true;
45
46 if ( wcsstr( sInstallLocation.c_str(), sOfficeDirHostname.c_str() ) )
47 {
48 pathCompletionRequired = false; // nothing to do
49 }
50
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.
53
54 if ( pathCompletionRequired )
55 {
56 std::wstring sManufacturer = GetMsiPropertyW( handle, L"Manufacturer" );
57 std::wstring sDefinedName = GetMsiPropertyW( handle, L"DEFINEDPRODUCT" );
58 std::wstring sUpgradeCode = GetMsiPropertyW( handle, L"UpgradeCode" );
59
60 // sUpdateVersion can be "3.0", "3.1" or "3.2"
61
62 std::wstring sProductKey30 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
63 L"\\" L"3.0" L"\\" + sUpgradeCode;
64
65 std::wstring sProductKey31 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
66 L"\\" L"3.1" L"\\" + sUpgradeCode;
67
68 std::wstring sProductKey32 = L"Software\\" + sManufacturer + L"\\" + sDefinedName +
69 L"\\" L"3.2" L"\\" + sUpgradeCode;
70
71 bool oldVersionExists = false;
72
73 if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey30.c_str(), &hKey ) )
74 {
75 oldVersionExists = true;
76 RegCloseKey( hKey );
77 }
78 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey31.c_str(), &hKey ) )
79 {
80 oldVersionExists = true;
81 RegCloseKey( hKey );
82 }
83 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_CURRENT_USER, sProductKey32.c_str(), &hKey ) )
84 {
85 oldVersionExists = true;
86 RegCloseKey( hKey );
87 }
88 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey30.c_str(), &hKey ) )
89 {
90 oldVersionExists = true;
91 RegCloseKey( hKey );
92 }
93 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey31.c_str(), &hKey ) )
94 {
95 oldVersionExists = true;
96 RegCloseKey( hKey );
97 }
98 else if ( ERROR_SUCCESS == RegOpenKeyW( HKEY_LOCAL_MACHINE, sProductKey32.c_str(), &hKey ) )
99 {
100 oldVersionExists = true;
101 RegCloseKey( hKey );
102 }
103
104 if ( oldVersionExists )
105 {
106 // Adding the new path content sOfficeDirHostname
107 sInstallLocation += sOfficeDirHostname;
108 // Setting the new property value
109 MsiSetPropertyW(handle, L"INSTALLLOCATION", sInstallLocation.c_str());
110 }
111 }
112
113 return ERROR_SUCCESS;
114}
115
116/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
__declspec(dllexport) UINT __stdcall CompleteInstallPath(MSIHANDLE handle)
static std::wstring GetMsiPropertyW(MSIHANDLE handle, const std::wstring &sProperty)
Definition: shlxtmsi.hxx:29