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 #ifdef _MSC_VER 29*cdf0e10cSrcweir #pragma warning(push, 1) /* disable warnings within system headers */ 30*cdf0e10cSrcweir #endif 31*cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN 32*cdf0e10cSrcweir #include <windows.h> 33*cdf0e10cSrcweir #include <msiquery.h> 34*cdf0e10cSrcweir #ifdef _MSC_VER 35*cdf0e10cSrcweir #pragma warning(pop) 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <malloc.h> 39*cdf0e10cSrcweir #include <string> 40*cdf0e10cSrcweir #include <strsafe.h> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //---------------------------------------------------------- 43*cdf0e10cSrcweir static const CHAR* g_Extensions[] = 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir ".doc", // Microsoft Word Text [0] 46*cdf0e10cSrcweir ".dot", // Microsoft Word Template 47*cdf0e10cSrcweir ".rtf", // rtf text 48*cdf0e10cSrcweir ".docx", // Office Word 2007 XML document 49*cdf0e10cSrcweir ".docm", // Office Word 2007 XML macro-enabled document 50*cdf0e10cSrcweir ".dotx", // Office Word 2007 XML template 51*cdf0e10cSrcweir ".dotm", // Office Word 2007 XML macro-enabled template 52*cdf0e10cSrcweir ".xlw", // Microsoft Excel 53*cdf0e10cSrcweir ".xls", // Microsoft Excel 54*cdf0e10cSrcweir ".xlt", // Microsoft Excel Template 55*cdf0e10cSrcweir ".xlsx", // Office Excel 2007 XML workbook 56*cdf0e10cSrcweir ".xlsm", // Office Excel 2007 XML macro-enabled workbook 57*cdf0e10cSrcweir ".xltx", // Office Excel 2007 XML template 58*cdf0e10cSrcweir ".xltm", // Office Excel 2007 XML macro-enabled template 59*cdf0e10cSrcweir ".xlsb", // Office Excel 2007 binary workbook (BIFF12) 60*cdf0e10cSrcweir ".ppt", // Microsoft Powerpoint 61*cdf0e10cSrcweir ".pps", // Microsoft Powerpoint 62*cdf0e10cSrcweir ".pot", // Microsoft Powerpoint Template 63*cdf0e10cSrcweir ".pptx", // Office PowerPoint 2007 XML presentation 64*cdf0e10cSrcweir ".pptm", // Office PowerPoint 2007 macro-enabled XML presentation 65*cdf0e10cSrcweir ".potx", // Office PowerPoint 2007 XML template 66*cdf0e10cSrcweir ".potm", // Office PowerPoint 2007 macro-enabled XML template 67*cdf0e10cSrcweir ".ppsx", // Office PowerPoint 2007 XML show 68*cdf0e10cSrcweir 0 69*cdf0e10cSrcweir }; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir static const int WORD_START = 0; 72*cdf0e10cSrcweir static const int EXCEL_START = 7; 73*cdf0e10cSrcweir static const int POWERPOINT_START = 15; 74*cdf0e10cSrcweir static const int POWERPOINT_END = 23; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // ".xlam", // Office Excel 2007 XML macro-enabled add-in 77*cdf0e10cSrcweir // ".ppam", // Office PowerPoint 2007 macro-enabled XML add-in 78*cdf0e10cSrcweir // ".ppsm", // Office PowerPoint 2007 macro-enabled XML show 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir //---------------------------------------------------------- 81*cdf0e10cSrcweir #ifdef DEBUG 82*cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCSTR pFormat, ... ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir CHAR buffer[1024]; 85*cdf0e10cSrcweir va_list args; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir va_start( args, pFormat ); 88*cdf0e10cSrcweir StringCchVPrintfA( buffer, sizeof(buffer), pFormat, args ); 89*cdf0e10cSrcweir OutputDebugStringA( buffer ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir #else 92*cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCSTR, ... ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir #endif 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir //---------------------------------------------------------- 98*cdf0e10cSrcweir static BOOL CheckExtensionInRegistry( LPCSTR lpSubKey ) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir BOOL bRet = false; 101*cdf0e10cSrcweir HKEY hKey = NULL; 102*cdf0e10cSrcweir LONG lResult = RegOpenKeyExA( HKEY_CLASSES_ROOT, lpSubKey, 0, KEY_QUERY_VALUE, &hKey ); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir CHAR szBuffer[1024]; 107*cdf0e10cSrcweir DWORD nSize = sizeof( szBuffer ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir lResult = RegQueryValueExA( hKey, "", NULL, NULL, (LPBYTE)szBuffer, &nSize ); 110*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir szBuffer[nSize] = '\0'; 113*cdf0e10cSrcweir OutputDebugStringFormat( "Found value [%s] for key [%s].\n", szBuffer, lpSubKey ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir if ( strncmp( szBuffer, "WordPad.Document.1", 18 ) == 0 ) 116*cdf0e10cSrcweir { // We will replace registration for word pad 117*cdf0e10cSrcweir bRet = true; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir else if ( strncmp( szBuffer, "OpenOffice.org.", 15 ) == 0 ) 120*cdf0e10cSrcweir { // We will replace registration for our own types, too 121*cdf0e10cSrcweir bRet = true; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir else if ( strncmp( szBuffer, "ooostub.", 8 ) == 0 ) 124*cdf0e10cSrcweir { // We will replace registration for ooostub, too 125*cdf0e10cSrcweir bRet = true; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir else 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir OutputDebugStringFormat( " Checking OpenWithList of [%s].\n", lpSubKey ); 130*cdf0e10cSrcweir HKEY hSubKey; 131*cdf0e10cSrcweir lResult = RegOpenKeyExA( hKey, "OpenWithList", 0, KEY_ENUMERATE_SUB_KEYS, &hSubKey ); 132*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir DWORD nIndex = 0; 135*cdf0e10cSrcweir while ( ERROR_SUCCESS == lResult ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir nSize = sizeof( szBuffer ); 138*cdf0e10cSrcweir lResult = RegEnumKeyExA( hSubKey, nIndex++, szBuffer, &nSize, NULL, NULL, NULL, NULL ); 139*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir OutputDebugStringFormat( " Found value [%s] in OpenWithList of [%s].\n", szBuffer, lpSubKey ); 142*cdf0e10cSrcweir if ( strncmp( szBuffer, "WordPad.exe", 11 ) == 0 ) 143*cdf0e10cSrcweir { // We will replace registration for word pad 144*cdf0e10cSrcweir bRet = true; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir else if ( nSize > 0 ) 147*cdf0e10cSrcweir bRet = false; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir else 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir OutputDebugStringFormat( " No OpenWithList found!\n" ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir else // no default value found -> return TRUE to register for that key 158*cdf0e10cSrcweir bRet = true; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir RegCloseKey( hKey ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir else // no key found -> return TRUE to register for that key 163*cdf0e10cSrcweir bRet = true; 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir return bRet; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir //---------------------------------------------------------- 169*cdf0e10cSrcweir static LONG DeleteSubKeyTree( HKEY RootKey, LPCSTR lpKey ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir HKEY hKey; 172*cdf0e10cSrcweir LONG rc = RegOpenKeyExA( RootKey, lpKey, 0, KEY_READ | DELETE, &hKey ); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir if (ERROR_SUCCESS == rc) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir LPCSTR lpSubKey; 177*cdf0e10cSrcweir DWORD nMaxSubKeyLen; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir rc = RegQueryInfoKeyA( hKey, 0, 0, 0, 0, &nMaxSubKeyLen, 0, 0, 0, 0, 0, 0 ); 180*cdf0e10cSrcweir nMaxSubKeyLen++; // space for trailing '\0' 181*cdf0e10cSrcweir lpSubKey = reinterpret_cast<CHAR*>( _alloca( nMaxSubKeyLen*sizeof(CHAR) ) ); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir while (ERROR_SUCCESS == rc) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir DWORD nLen = nMaxSubKeyLen; 186*cdf0e10cSrcweir rc = RegEnumKeyExA( hKey, 0, (LPSTR)lpSubKey, &nLen, 0, 0, 0, 0); // always index zero 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir if ( ERROR_NO_MORE_ITEMS == rc ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir rc = RegDeleteKeyA( RootKey, lpKey ); 191*cdf0e10cSrcweir if ( rc == ERROR_SUCCESS ) 192*cdf0e10cSrcweir OutputDebugStringFormat( "deleted key [%s] from registry.\n", lpKey ); 193*cdf0e10cSrcweir else 194*cdf0e10cSrcweir OutputDebugStringFormat( "RegDeleteKeyA %s returned %ld.\n", lpKey, rc ); 195*cdf0e10cSrcweir break; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir else if ( rc == ERROR_SUCCESS ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir rc = DeleteSubKeyTree( hKey, lpSubKey ); 200*cdf0e10cSrcweir if ( ERROR_SUCCESS != rc ) 201*cdf0e10cSrcweir OutputDebugStringFormat( "RegDeleteKeyA %s returned %ld.\n", lpSubKey, rc ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir RegCloseKey(hKey); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir else 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir OutputDebugStringFormat( "RegOpenKeyExA %s returned %ld.\n", lpKey, rc ); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir return rc; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir //---------------------------------------------------------- 216*cdf0e10cSrcweir static BOOL RemoveExtensionInRegistry( LPCSTR lpSubKey ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir CHAR szBuffer[4096]; 219*cdf0e10cSrcweir DWORD nSize = sizeof( szBuffer ); 220*cdf0e10cSrcweir HKEY hKey = NULL; 221*cdf0e10cSrcweir HKEY hSubKey = NULL; 222*cdf0e10cSrcweir LONG lResult = RegOpenKeyExA( HKEY_LOCAL_MACHINE, "SOFTWARE\\Classes", 0, KEY_QUERY_VALUE, &hKey ); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir lResult = RegOpenKeyExA( hKey, lpSubKey, 0, KEY_QUERY_VALUE, &hSubKey ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir DWORD nSubKeys = 1; 231*cdf0e10cSrcweir szBuffer[0] = '\0'; 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir // we get the value of the default key fist and while we are on querying, 234*cdf0e10cSrcweir // we ask for the subkey count, too 235*cdf0e10cSrcweir lResult = RegQueryValueExA( hSubKey, "", NULL, NULL, (LPBYTE)szBuffer, &nSize ); 236*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 237*cdf0e10cSrcweir RegQueryInfoKeyA( hSubKey, 0, 0, 0, &nSubKeys, 0, 0, 0, 0, 0, 0, 0 ); 238*cdf0e10cSrcweir RegCloseKey( hSubKey ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir // we will remove all key with an default value starting with ooostub but 241*cdf0e10cSrcweir // we have to be careful about MSO keys 242*cdf0e10cSrcweir if ( strncmp( szBuffer, "opendocument.", 13 ) == 0 ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir if ( nSubKeys == 0 ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir DeleteSubKeyTree( hKey, lpSubKey ); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir else 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir lResult = RegOpenKeyExA( hKey, lpSubKey, 0, KEY_SET_VALUE, &hSubKey ); 251*cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 252*cdf0e10cSrcweir RegDeleteValueA( hSubKey, "" ); 253*cdf0e10cSrcweir else 254*cdf0e10cSrcweir OutputDebugStringFormat( "Could not open key %s for deleting: RegOpenKeyEx returned %ld.\n", lpSubKey, lResult ); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir RegCloseKey( hKey ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir return ( ERROR_SUCCESS == lResult ); 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //---------------------------------------------------------- 266*cdf0e10cSrcweir bool GetMsiProp( MSIHANDLE handle, LPCSTR name, /*out*/std::string& value ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir DWORD sz = 0; 269*cdf0e10cSrcweir LPSTR dummy = ""; 270*cdf0e10cSrcweir if (MsiGetPropertyA(handle, name, dummy, &sz) == ERROR_MORE_DATA) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir sz++; 273*cdf0e10cSrcweir DWORD nbytes = sz * sizeof(TCHAR); 274*cdf0e10cSrcweir LPSTR buff = reinterpret_cast<LPSTR>(_alloca(nbytes)); 275*cdf0e10cSrcweir ZeroMemory(buff, nbytes); 276*cdf0e10cSrcweir MsiGetPropertyA(handle, name, buff, &sz); 277*cdf0e10cSrcweir value = buff; 278*cdf0e10cSrcweir return true; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir return false; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir //---------------------------------------------------------- 284*cdf0e10cSrcweir bool IsSetMsiProp( MSIHANDLE handle, LPCSTR name ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir std::string val; 287*cdf0e10cSrcweir GetMsiProp( handle, name, val ); 288*cdf0e10cSrcweir return (val == "1"); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir //---------------------------------------------------------- 292*cdf0e10cSrcweir static void registerForExtension( MSIHANDLE handle, const int nIndex, bool bRegister ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir CHAR sPropName[256]; 295*cdf0e10cSrcweir StringCchCopyA( sPropName, 256, "REGISTER_" ); 296*cdf0e10cSrcweir StringCchCatA( sPropName, 256, (g_Extensions[nIndex])+1 ); 297*cdf0e10cSrcweir CharUpperBuffA( sPropName+9, 4 ); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir if ( bRegister ) { 300*cdf0e10cSrcweir MsiSetPropertyA( handle, sPropName, "1" ); 301*cdf0e10cSrcweir OutputDebugStringFormat( "Set MSI property %s.\n", sPropName ); 302*cdf0e10cSrcweir } else { 303*cdf0e10cSrcweir MsiSetPropertyA( handle, sPropName, "0" ); 304*cdf0e10cSrcweir OutputDebugStringFormat( "Unset MSI property %s.\n", sPropName ); 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir //---------------------------------------------------------- 309*cdf0e10cSrcweir static void registerForExtensions( MSIHANDLE handle, BOOL bRegisterAll ) 310*cdf0e10cSrcweir { // Check all file extensions 311*cdf0e10cSrcweir int nIndex = 0; 312*cdf0e10cSrcweir while ( g_Extensions[nIndex] != 0 ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir BOOL bRegister = bRegisterAll || CheckExtensionInRegistry( g_Extensions[nIndex] ); 315*cdf0e10cSrcweir if ( bRegister ) 316*cdf0e10cSrcweir registerForExtension( handle, nIndex, true ); 317*cdf0e10cSrcweir ++nIndex; 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir //---------------------------------------------------------- 322*cdf0e10cSrcweir static bool checkSomeExtensionInRegistry( const int nStart, const int nEnd ) 323*cdf0e10cSrcweir { // Check all file extensions 324*cdf0e10cSrcweir int nIndex = nStart; 325*cdf0e10cSrcweir bool bFound = false; 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir while ( !bFound && ( g_Extensions[nIndex] != 0 ) && ( nIndex < nEnd ) ) 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir bFound = ! CheckExtensionInRegistry( g_Extensions[nIndex] ); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir if ( bFound ) 332*cdf0e10cSrcweir OutputDebugStringFormat( "Found registration for [%s].\n", g_Extensions[nIndex] ); 333*cdf0e10cSrcweir 334*cdf0e10cSrcweir ++nIndex; 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir return bFound; 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir //---------------------------------------------------------- 340*cdf0e10cSrcweir static void registerSomeExtensions( MSIHANDLE handle, const int nStart, const int nEnd, bool bRegister ) 341*cdf0e10cSrcweir { // Check all file extensions 342*cdf0e10cSrcweir int nIndex = nStart; 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir while ( ( g_Extensions[nIndex] != 0 ) && ( nIndex < nEnd ) ) 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir registerForExtension( handle, nIndex++, bRegister ); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir //---------------------------------------------------------- 351*cdf0e10cSrcweir //---------------------------------------------------------- 352*cdf0e10cSrcweir //---------------------------------------------------------- 353*cdf0e10cSrcweir extern "C" UINT __stdcall LookForRegisteredExtensions( MSIHANDLE handle ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: " ); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir INSTALLSTATE current_state; 358*cdf0e10cSrcweir INSTALLSTATE future_state; 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir bool bWriterEnabled = false; 361*cdf0e10cSrcweir bool bCalcEnabled = false; 362*cdf0e10cSrcweir bool bImpressEnabled = false; 363*cdf0e10cSrcweir bool bRegisterNone = IsSetMsiProp( handle, "REGISTER_NO_MSO_TYPES" ); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir if ( ( ERROR_SUCCESS == MsiGetFeatureState( handle, L"gm_p_Wrt", ¤t_state, &future_state ) ) && 366*cdf0e10cSrcweir ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) ) 367*cdf0e10cSrcweir bWriterEnabled = true; 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Install state Writer is [%d], will be [%d]", current_state, future_state ); 370*cdf0e10cSrcweir if ( bWriterEnabled ) 371*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Writer is enabled" ); 372*cdf0e10cSrcweir else 373*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Writer is NOT enabled" ); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir if ( ( ERROR_SUCCESS == MsiGetFeatureState( handle, L"gm_p_Calc", ¤t_state, &future_state ) ) && 376*cdf0e10cSrcweir ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) ) 377*cdf0e10cSrcweir bCalcEnabled = true; 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Install state Calc is [%d], will be [%d]", current_state, future_state ); 380*cdf0e10cSrcweir if ( bCalcEnabled ) 381*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Calc is enabled" ); 382*cdf0e10cSrcweir else 383*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Calc is NOT enabled" ); 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir if ( ( ERROR_SUCCESS == MsiGetFeatureState( handle, L"gm_p_Impress", ¤t_state, &future_state ) ) && 386*cdf0e10cSrcweir ( (future_state == INSTALLSTATE_LOCAL) || ((current_state == INSTALLSTATE_LOCAL) && (future_state == INSTALLSTATE_UNKNOWN) ) ) ) 387*cdf0e10cSrcweir bImpressEnabled = true; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Install state Impress is [%d], will be [%d]", current_state, future_state ); 390*cdf0e10cSrcweir if ( bImpressEnabled ) 391*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Impress is enabled" ); 392*cdf0e10cSrcweir else 393*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Impress is NOT enabled" ); 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_WORD", "" ); 396*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_EXCEL", "" ); 397*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_POWERPOINT", "" ); 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir if ( ! bRegisterNone ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "REGISTER_ALL_MSO_TYPES" ) ) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir if ( bWriterEnabled ) 404*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_WORD", "1" ); 405*cdf0e10cSrcweir if ( bCalcEnabled ) 406*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_EXCEL", "1" ); 407*cdf0e10cSrcweir if ( bImpressEnabled ) 408*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_POWERPOINT", "1" ); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir else 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir if ( bWriterEnabled && ! checkSomeExtensionInRegistry( WORD_START, EXCEL_START ) ) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_WORD", "1" ); 415*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Register for MicroSoft Word" ); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir if ( bCalcEnabled && ! checkSomeExtensionInRegistry( EXCEL_START, POWERPOINT_START ) ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_EXCEL", "1" ); 420*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Register for MicroSoft Excel" ); 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir if ( bImpressEnabled && ! checkSomeExtensionInRegistry( POWERPOINT_START, POWERPOINT_END ) ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir MsiSetPropertyA( handle, "SELECT_POWERPOINT", "1" ); 425*cdf0e10cSrcweir OutputDebugStringFormat( "LookForRegisteredExtensions: Register for MicroSoft PowerPoint" ); 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir MsiSetPropertyA( handle, "FILETYPEDIALOGUSED", "1" ); 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir return ERROR_SUCCESS; 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //---------------------------------------------------------- 436*cdf0e10cSrcweir extern "C" UINT __stdcall RegisterSomeExtensions( MSIHANDLE handle ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir OutputDebugStringFormat( "RegisterSomeExtensions: " ); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "SELECT_WORD" ) ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir registerSomeExtensions( handle, WORD_START, EXCEL_START, true ); 443*cdf0e10cSrcweir MsiSetFeatureState( handle, L"gm_p_Wrt_MSO_Reg", INSTALLSTATE_LOCAL ); 444*cdf0e10cSrcweir OutputDebugStringFormat( "RegisterSomeExtensions: Register for MicroSoft Word" ); 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir else 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir registerSomeExtensions( handle, WORD_START, EXCEL_START, false ); 449*cdf0e10cSrcweir MsiSetFeatureState( handle, L"gm_p_Wrt_MSO_Reg", INSTALLSTATE_ABSENT ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "SELECT_EXCEL" ) ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir registerSomeExtensions( handle, EXCEL_START, POWERPOINT_START, true ); 455*cdf0e10cSrcweir MsiSetFeatureState( handle, L"gm_p_Calc_MSO_Reg", INSTALLSTATE_LOCAL ); 456*cdf0e10cSrcweir OutputDebugStringFormat( "RegisterSomeExtensions: Register for MicroSoft Excel" ); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir else 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir registerSomeExtensions( handle, EXCEL_START, POWERPOINT_START, false ); 461*cdf0e10cSrcweir MsiSetFeatureState( handle, L"gm_p_Calc_MSO_Reg", INSTALLSTATE_ABSENT ); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "SELECT_POWERPOINT" ) ) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir registerSomeExtensions( handle, POWERPOINT_START, POWERPOINT_END, true ); 467*cdf0e10cSrcweir MsiSetFeatureState( handle, L"gm_p_Impress_MSO_Reg", INSTALLSTATE_LOCAL ); 468*cdf0e10cSrcweir OutputDebugStringFormat( "RegisterSomeExtensions: Register for MicroSoft PowerPoint" ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir else 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir registerSomeExtensions( handle, POWERPOINT_START, POWERPOINT_END, false ); 473*cdf0e10cSrcweir MsiSetFeatureState( handle, L"gm_p_Impress_MSO_Reg", INSTALLSTATE_ABSENT ); 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir return ERROR_SUCCESS; 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir //---------------------------------------------------------- 480*cdf0e10cSrcweir extern "C" UINT __stdcall FindRegisteredExtensions( MSIHANDLE handle ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "FILETYPEDIALOGUSED" ) ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir OutputDebugStringFormat( "FindRegisteredExtensions: FILETYPEDIALOGUSED!" ); 485*cdf0e10cSrcweir return ERROR_SUCCESS; 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir OutputDebugStringFormat( "FindRegisteredExtensions:" ); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir bool bRegisterAll = IsSetMsiProp( handle, "REGISTER_ALL_MSO_TYPES" ); 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "REGISTER_NO_MSO_TYPES" ) ) 493*cdf0e10cSrcweir { 494*cdf0e10cSrcweir OutputDebugStringFormat( "FindRegisteredExtensions: Register none!" ); 495*cdf0e10cSrcweir return ERROR_SUCCESS; 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir else if ( bRegisterAll ) 498*cdf0e10cSrcweir OutputDebugStringFormat( "FindRegisteredExtensions: Force all on" ); 499*cdf0e10cSrcweir else 500*cdf0e10cSrcweir OutputDebugStringFormat( "FindRegisteredExtensions: " ); 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir // setting the msi properties SELECT_* will force registering for all corresponding 503*cdf0e10cSrcweir // file types 504*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "SELECT_WORD" ) ) 505*cdf0e10cSrcweir registerSomeExtensions( handle, WORD_START, EXCEL_START, true ); 506*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "SELECT_EXCEL" ) ) 507*cdf0e10cSrcweir registerSomeExtensions( handle, EXCEL_START, POWERPOINT_START, true ); 508*cdf0e10cSrcweir if ( IsSetMsiProp( handle, "SELECT_POWERPOINT" ) ) 509*cdf0e10cSrcweir registerSomeExtensions( handle, POWERPOINT_START, POWERPOINT_END, true ); 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir registerForExtensions( handle, bRegisterAll ); 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir return ERROR_SUCCESS; 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir //---------------------------------------------------------- 517*cdf0e10cSrcweir extern "C" UINT __stdcall DeleteRegisteredExtensions( MSIHANDLE /*handle*/ ) 518*cdf0e10cSrcweir { 519*cdf0e10cSrcweir OutputDebugStringFormat( "DeleteRegisteredExtensions\n" ); 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir // remove all file extensions 522*cdf0e10cSrcweir int nIndex = 0; 523*cdf0e10cSrcweir while ( g_Extensions[nIndex] != 0 ) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir RemoveExtensionInRegistry( g_Extensions[nIndex] ); 526*cdf0e10cSrcweir ++nIndex; 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir return ERROR_SUCCESS; 530*cdf0e10cSrcweir } 531