1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #define _WIN32_WINDOWS 0x0410 29*cdf0e10cSrcweir #ifdef _MSC_VER 30*cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */ 31*cdf0e10cSrcweir #endif 32*cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN 33*cdf0e10cSrcweir #include <windows.h> 34*cdf0e10cSrcweir #include <msiquery.h> 35*cdf0e10cSrcweir #ifdef _MSC_VER 36*cdf0e10cSrcweir #pragma warning(pop) 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <malloc.h> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #ifdef UNICODE 42*cdf0e10cSrcweir #define _UNICODE 43*cdf0e10cSrcweir #define _tstring wstring 44*cdf0e10cSrcweir #else 45*cdf0e10cSrcweir #define _tstring string 46*cdf0e10cSrcweir #endif 47*cdf0e10cSrcweir #include <tchar.h> 48*cdf0e10cSrcweir #include <string> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace std; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir namespace 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir std::_tstring GetMsiProperty( MSIHANDLE handle, const std::_tstring& sProperty ) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir std::_tstring result; 57*cdf0e10cSrcweir TCHAR szDummy[1] = TEXT(""); 58*cdf0e10cSrcweir DWORD nChars = 0; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir if ( MsiGetProperty( handle, sProperty.c_str(), szDummy, &nChars ) == ERROR_MORE_DATA ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir DWORD nBytes = ++nChars * sizeof(TCHAR); 63*cdf0e10cSrcweir LPTSTR buffer = reinterpret_cast<LPTSTR>(_alloca(nBytes)); 64*cdf0e10cSrcweir ZeroMemory( buffer, nBytes ); 65*cdf0e10cSrcweir MsiGetProperty(handle, sProperty.c_str(), buffer, &nChars); 66*cdf0e10cSrcweir result = buffer; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir return result; 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir } // namespace 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir extern "C" UINT __stdcall CompleteInstallPath( MSIHANDLE handle ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir // This CustomAction is necessary for updates from OOo 3.0, OOo 3.1 and OOo 3.2 to versions 76*cdf0e10cSrcweir // OOo 3.3 or later. This is caused by a change of INSTALLLOCATION, that starting with OOo 3.3 77*cdf0e10cSrcweir // contains the name of the product again (instead of only "c:\program files"). Unfortunately 78*cdf0e10cSrcweir // this causes in an update installation, that INSTALLLOCATION is set to "c:\program files", 79*cdf0e10cSrcweir // so that in an OOo 3.3 or later, the directory "program" or "share" are directly created 80*cdf0e10cSrcweir // below "c:\program files". 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir TCHAR szValue[8192]; 83*cdf0e10cSrcweir DWORD nValueSize = sizeof(szValue); 84*cdf0e10cSrcweir HKEY hKey; 85*cdf0e10cSrcweir std::_tstring sInstDir; 86*cdf0e10cSrcweir std::_tstring mystr; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // Reading property OFFICEDIRHOSTNAME_, that contains the part of the path behind 89*cdf0e10cSrcweir // the program files folder. 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir std::_tstring sInstallLocation = GetMsiProperty( handle, TEXT("INSTALLLOCATION") ); 92*cdf0e10cSrcweir std::_tstring sOfficeDirHostname = GetMsiProperty( handle, TEXT("OFFICEDIRHOSTNAME_") ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir // If sInstallLocation ends with (contains) the string sOfficeDirHostname, 95*cdf0e10cSrcweir // INSTALLLOCATION is good and nothing has to be done here. 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir bool pathCompletionRequired = true; 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir if ( _tcsstr( sInstallLocation.c_str(), sOfficeDirHostname.c_str() ) ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir pathCompletionRequired = false; // nothing to do 102*cdf0e10cSrcweir // mystr = "Nothing to do, officedir is included into installlocation"; 103*cdf0e10cSrcweir // MessageBox( NULL, mystr.c_str(), "It is part of installlocation", MB_OK ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir // If the path INSTALLLOCATION does not end with this string, INSTALLLOCATION is maybe 107*cdf0e10cSrcweir // transfered from an OOo 3.0, OOo 3.1 and OOo 3.2 and need to be changed therefore. 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir if ( pathCompletionRequired ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir std::_tstring sManufacturer = GetMsiProperty( handle, TEXT("Manufacturer") ); 112*cdf0e10cSrcweir std::_tstring sDefinedName = GetMsiProperty( handle, TEXT("DEFINEDPRODUCT") ); 113*cdf0e10cSrcweir std::_tstring sUpgradeCode = GetMsiProperty( handle, TEXT("UpgradeCode") ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // sUpdateVersion can be "3.0", "3.1" or "3.2" 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir std::_tstring sProductKey30 = "Software\\" + sManufacturer + "\\" + sDefinedName + 118*cdf0e10cSrcweir "\\" + "3.0" + "\\" + sUpgradeCode; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir std::_tstring sProductKey31 = "Software\\" + sManufacturer + "\\" + sDefinedName + 121*cdf0e10cSrcweir "\\" + "3.1" + "\\" + sUpgradeCode; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir std::_tstring sProductKey32 = "Software\\" + sManufacturer + "\\" + sDefinedName + 124*cdf0e10cSrcweir "\\" + "3.2" + "\\" + sUpgradeCode; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir // mystr = "ProductKey: " + sProductKey; 127*cdf0e10cSrcweir // MessageBox( NULL, mystr.c_str(), "ProductKey", MB_OK ); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir // mystr = "Checking registry"; 130*cdf0e10cSrcweir // MessageBox( NULL, mystr.c_str(), "registry search", MB_OK ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir bool oldVersionExists = false; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey30.c_str(), &hKey ) ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir oldVersionExists = true; 137*cdf0e10cSrcweir RegCloseKey( hKey ); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir else if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey31.c_str(), &hKey ) ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir oldVersionExists = true; 142*cdf0e10cSrcweir RegCloseKey( hKey ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir else if ( ERROR_SUCCESS == RegOpenKey( HKEY_CURRENT_USER, sProductKey32.c_str(), &hKey ) ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir oldVersionExists = true; 147*cdf0e10cSrcweir RegCloseKey( hKey ); 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey30.c_str(), &hKey ) ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir oldVersionExists = true; 152*cdf0e10cSrcweir RegCloseKey( hKey ); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey31.c_str(), &hKey ) ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir oldVersionExists = true; 157*cdf0e10cSrcweir RegCloseKey( hKey ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir else if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, sProductKey32.c_str(), &hKey ) ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir oldVersionExists = true; 162*cdf0e10cSrcweir RegCloseKey( hKey ); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir if ( oldVersionExists ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir // Adding the new path content sOfficeDirHostname 168*cdf0e10cSrcweir sInstallLocation = sInstallLocation + sOfficeDirHostname; 169*cdf0e10cSrcweir // Setting the new property value 170*cdf0e10cSrcweir MsiSetProperty(handle, TEXT("INSTALLLOCATION"), sInstallLocation.c_str()); 171*cdf0e10cSrcweir // mystr = "Setting path to: " + sInstallLocation; 172*cdf0e10cSrcweir // MessageBox( NULL, mystr.c_str(), "sInstallLocation", MB_OK ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir // mystr = "Ending with INSTALLLOCATION: " + sInstallLocation; 177*cdf0e10cSrcweir // MessageBox( NULL, mystr.c_str(), "END", MB_OK ); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir return ERROR_SUCCESS; 180*cdf0e10cSrcweir } 181