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 // MARKER(update_precomp.py): autogen include statement, do not remove 28*cdf0e10cSrcweir #include "precompiled_desktop.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <osl/file.hxx> 31*cdf0e10cSrcweir #include <rtl/bootstrap.hxx> 32*cdf0e10cSrcweir #include <rtl/ustring.hxx> 33*cdf0e10cSrcweir #include <tools/datetime.hxx> 34*cdf0e10cSrcweir #include <unotools/configmgr.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 37*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include "app.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using ::rtl::OUString; 44*cdf0e10cSrcweir using namespace ::desktop; 45*cdf0e10cSrcweir using namespace ::com::sun::star; 46*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir static const OUString sConfigSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ); 49*cdf0e10cSrcweir static const OUString sAccessSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) ); 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir /* Path of the license. */ 52*cdf0e10cSrcweir OUString Desktop::GetLicensePath() 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir // license file name 55*cdf0e10cSrcweir static const char *szLicensePath = "/share/readme"; 56*cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 57*cdf0e10cSrcweir static const char *szWNTLicenseName = "/license"; 58*cdf0e10cSrcweir static const char *szWNTLicenseExt = ".txt"; 59*cdf0e10cSrcweir #else 60*cdf0e10cSrcweir static const char *szUNXLicenseName = "/LICENSE"; 61*cdf0e10cSrcweir static const char *szUNXLicenseExt = ""; 62*cdf0e10cSrcweir #endif 63*cdf0e10cSrcweir static OUString aLicensePath; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir if (aLicensePath.getLength() > 0) 66*cdf0e10cSrcweir return aLicensePath; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir OUString aBaseInstallPath(RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR")); 69*cdf0e10cSrcweir rtl::Bootstrap::expandMacros(aBaseInstallPath); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // determine the filename of the license to show 72*cdf0e10cSrcweir OUString aLangString; 73*cdf0e10cSrcweir ::com::sun::star::lang::Locale aLocale; 74*cdf0e10cSrcweir OString aMgrName = OString("dkt"); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir AllSettings aSettings(Application::GetSettings()); 77*cdf0e10cSrcweir aLocale = aSettings.GetUILocale(); 78*cdf0e10cSrcweir ResMgr* pLocalResMgr = ResMgr::SearchCreateResMgr(aMgrName, aLocale); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir aLangString = aLocale.Language; 81*cdf0e10cSrcweir if ( aLocale.Country.getLength() != 0 ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir aLangString += OUString::createFromAscii("-"); 84*cdf0e10cSrcweir aLangString += aLocale.Country; 85*cdf0e10cSrcweir if ( aLocale.Variant.getLength() != 0 ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir aLangString += OUString::createFromAscii("-"); 88*cdf0e10cSrcweir aLangString += aLocale.Variant; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 92*cdf0e10cSrcweir aLicensePath = 93*cdf0e10cSrcweir aBaseInstallPath + OUString::createFromAscii(szLicensePath) 94*cdf0e10cSrcweir + OUString::createFromAscii(szWNTLicenseName) 95*cdf0e10cSrcweir + OUString::createFromAscii("_") 96*cdf0e10cSrcweir + aLangString 97*cdf0e10cSrcweir + OUString::createFromAscii(szWNTLicenseExt); 98*cdf0e10cSrcweir #else 99*cdf0e10cSrcweir aLicensePath = 100*cdf0e10cSrcweir aBaseInstallPath + OUString::createFromAscii(szLicensePath) 101*cdf0e10cSrcweir + OUString::createFromAscii(szUNXLicenseName) 102*cdf0e10cSrcweir + OUString::createFromAscii("_") 103*cdf0e10cSrcweir + aLangString 104*cdf0e10cSrcweir + OUString::createFromAscii(szUNXLicenseExt); 105*cdf0e10cSrcweir #endif 106*cdf0e10cSrcweir delete pLocalResMgr; 107*cdf0e10cSrcweir return aLicensePath; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir /* Check if we need to accept license. */ 111*cdf0e10cSrcweir sal_Bool Desktop::LicenseNeedsAcceptance() 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir // Don't show a license 114*cdf0e10cSrcweir return sal_False; 115*cdf0e10cSrcweir /* 116*cdf0e10cSrcweir sal_Bool bShowLicense = sal_True; 117*cdf0e10cSrcweir sal_Int32 nOpenSourceContext = 0; 118*cdf0e10cSrcweir try 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir ::utl::ConfigManager::GetDirectConfigProperty( 121*cdf0e10cSrcweir ::utl::ConfigManager::OPENSOURCECONTEXT ) >>= nOpenSourceContext; 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir catch( const ::com::sun::star::uno::Exception& ) {} 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir // open source needs no license 126*cdf0e10cSrcweir if ( nOpenSourceContext > 0 ) 127*cdf0e10cSrcweir bShowLicense = sal_False; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir return bShowLicense; 130*cdf0e10cSrcweir */ 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir /* Local function - get access to the configuration */ 134*cdf0e10cSrcweir static Reference< XPropertySet > impl_getConfigurationAccess( const OUString& rPath ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir Reference < XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // get configuration provider 139*cdf0e10cSrcweir Reference< XMultiServiceFactory > xConfigProvider = Reference< XMultiServiceFactory >( 140*cdf0e10cSrcweir xFactory->createInstance( sConfigSrvc ), UNO_QUERY_THROW ); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir Sequence< Any > aArgs( 1 ); 143*cdf0e10cSrcweir NamedValue aValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "NodePath" ) ), makeAny( rPath ) ); 144*cdf0e10cSrcweir aArgs[0] <<= aValue; 145*cdf0e10cSrcweir return Reference< XPropertySet >( 146*cdf0e10cSrcweir xConfigProvider->createInstanceWithArguments( sAccessSrvc, aArgs ), UNO_QUERY_THROW ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir /* Local function - was the wizard completed already? */ 150*cdf0e10cSrcweir static sal_Bool impl_isFirstStart() 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir try { 153*cdf0e10cSrcweir Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Setup/Office" ) ) ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir Any result = xPSet->getPropertyValue(OUString::createFromAscii("FirstStartWizardCompleted")); 156*cdf0e10cSrcweir sal_Bool bCompleted = sal_False; 157*cdf0e10cSrcweir if ((result >>= bCompleted) && bCompleted) 158*cdf0e10cSrcweir return sal_False; // wizard was already completed 159*cdf0e10cSrcweir else 160*cdf0e10cSrcweir return sal_True; 161*cdf0e10cSrcweir } catch (const Exception&) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir return sal_True; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir /* Local function - convert oslDateTime to tools DateTime */ 168*cdf0e10cSrcweir static DateTime impl_oslDateTimeToDateTime(const oslDateTime& aDateTime) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir return DateTime( 171*cdf0e10cSrcweir Date(aDateTime.Day, aDateTime.Month, aDateTime.Year), 172*cdf0e10cSrcweir Time(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds)); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir /* Local function - get DateTime from a string */ 176*cdf0e10cSrcweir static sal_Bool impl_parseDateTime(const OUString& aString, DateTime& aDateTime) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir // take apart a canonical literal xsd:dateTime string 179*cdf0e10cSrcweir //CCYY-MM-DDThh:mm:ss(Z) 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir OUString aDateTimeString = aString.trim(); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // check length 184*cdf0e10cSrcweir if (aDateTimeString.getLength() < 19 || aDateTimeString.getLength() > 20) 185*cdf0e10cSrcweir return sal_False; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir sal_Int32 nDateLength = 10; 188*cdf0e10cSrcweir sal_Int32 nTimeLength = 8; 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir OUString aDateTimeSep = OUString::createFromAscii("T"); 191*cdf0e10cSrcweir OUString aDateSep = OUString::createFromAscii("-"); 192*cdf0e10cSrcweir OUString aTimeSep = OUString::createFromAscii(":"); 193*cdf0e10cSrcweir OUString aUTCString = OUString::createFromAscii("Z"); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir OUString aDateString = aDateTimeString.copy(0, nDateLength); 196*cdf0e10cSrcweir OUString aTimeString = aDateTimeString.copy(nDateLength+1, nTimeLength); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir sal_Int32 nIndex = 0; 199*cdf0e10cSrcweir sal_Int32 nYear = aDateString.getToken(0, '-', nIndex).toInt32(); 200*cdf0e10cSrcweir sal_Int32 nMonth = aDateString.getToken(0, '-', nIndex).toInt32(); 201*cdf0e10cSrcweir sal_Int32 nDay = aDateString.getToken(0, '-', nIndex).toInt32(); 202*cdf0e10cSrcweir nIndex = 0; 203*cdf0e10cSrcweir sal_Int32 nHour = aTimeString.getToken(0, ':', nIndex).toInt32(); 204*cdf0e10cSrcweir sal_Int32 nMinute = aTimeString.getToken(0, ':', nIndex).toInt32(); 205*cdf0e10cSrcweir sal_Int32 nSecond = aTimeString.getToken(0, ':', nIndex).toInt32(); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir Date tmpDate((sal_uInt16)nDay, (sal_uInt16)nMonth, (sal_uInt16)nYear); 208*cdf0e10cSrcweir Time tmpTime(nHour, nMinute, nSecond); 209*cdf0e10cSrcweir DateTime tmpDateTime(tmpDate, tmpTime); 210*cdf0e10cSrcweir if (aString.indexOf(aUTCString) < 0) 211*cdf0e10cSrcweir tmpDateTime.ConvertToUTC(); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir aDateTime = tmpDateTime; 214*cdf0e10cSrcweir return sal_True; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir /* Local function - was the license accepted already? */ 218*cdf0e10cSrcweir static sal_Bool impl_isLicenseAccepted() 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir // If no license will be shown ... it must not be accepted. 221*cdf0e10cSrcweir // So it was accepted "hardly" by the outside installer. 222*cdf0e10cSrcweir // But if the configuration entry "HideEula" will be removed afterwards .. 223*cdf0e10cSrcweir // we have to show the licese page again and user has to accept it here .-) 224*cdf0e10cSrcweir if ( ! Desktop::LicenseNeedsAcceptance() ) 225*cdf0e10cSrcweir return sal_True; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir try 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Setup/Office" ) ) ); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir Any result = xPSet->getPropertyValue(OUString::createFromAscii("LicenseAcceptDate")); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir OUString aAcceptDate; 234*cdf0e10cSrcweir if (result >>= aAcceptDate) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir // compare to date of license file 237*cdf0e10cSrcweir OUString aLicenseURL = Desktop::GetLicensePath(); 238*cdf0e10cSrcweir osl::DirectoryItem aDirItem; 239*cdf0e10cSrcweir if (osl::DirectoryItem::get(aLicenseURL, aDirItem) != osl::FileBase::E_None) 240*cdf0e10cSrcweir return sal_False; 241*cdf0e10cSrcweir osl::FileStatus aStatus(FileStatusMask_All); 242*cdf0e10cSrcweir if (aDirItem.getFileStatus(aStatus) != osl::FileBase::E_None) 243*cdf0e10cSrcweir return sal_False; 244*cdf0e10cSrcweir TimeValue aTimeVal = aStatus.getModifyTime(); 245*cdf0e10cSrcweir oslDateTime aDateTimeVal; 246*cdf0e10cSrcweir if (!osl_getDateTimeFromTimeValue(&aTimeVal, &aDateTimeVal)) 247*cdf0e10cSrcweir return sal_False; 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir // compare dates 250*cdf0e10cSrcweir DateTime aLicenseDateTime = impl_oslDateTimeToDateTime(aDateTimeVal); 251*cdf0e10cSrcweir DateTime aAcceptDateTime; 252*cdf0e10cSrcweir if (!impl_parseDateTime(aAcceptDate, aAcceptDateTime)) 253*cdf0e10cSrcweir return sal_False; 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir if ( aAcceptDateTime > aLicenseDateTime ) 256*cdf0e10cSrcweir return sal_True; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir return sal_False; 259*cdf0e10cSrcweir } catch (const Exception&) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir return sal_False; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir /* Check if we need the first start wizard. */ 266*cdf0e10cSrcweir sal_Bool Desktop::IsFirstStartWizardNeeded() 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir return impl_isFirstStart() || !impl_isLicenseAccepted(); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir void Desktop::DoRestartActionsIfNecessary( sal_Bool bQuickStart ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir if ( bQuickStart ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir try 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Setup/Office" ) ) ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( "OfficeRestartInProgress" ) ); 280*cdf0e10cSrcweir Any aRestart = xPSet->getPropertyValue( sPropName ); 281*cdf0e10cSrcweir sal_Bool bRestart = sal_False; 282*cdf0e10cSrcweir if ( ( aRestart >>= bRestart ) && bRestart ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir xPSet->setPropertyValue( sPropName, makeAny( sal_False ) ); 285*cdf0e10cSrcweir Reference< util::XChangesBatch >( xPSet, UNO_QUERY_THROW )->commitChanges(); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir Sequence< Any > aSeq( 2 ); 288*cdf0e10cSrcweir aSeq[0] <<= sal_True; 289*cdf0e10cSrcweir aSeq[1] <<= sal_True; 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir Reference < XInitialization > xQuickstart( ::comphelper::getProcessServiceFactory()->createInstance( 292*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.office.Quickstart" ) ) ),UNO_QUERY_THROW ); 293*cdf0e10cSrcweir xQuickstart->initialize( aSeq ); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir catch( uno::Exception& ) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir // this is no critical operation so it should not prevent office from starting 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir void Desktop::SetRestartState() 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir try 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Setup/Office" ) ) ); 308*cdf0e10cSrcweir OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( "OfficeRestartInProgress" ) ); 309*cdf0e10cSrcweir xPSet->setPropertyValue( sPropName, makeAny( sal_True ) ); 310*cdf0e10cSrcweir Reference< util::XChangesBatch >( xPSet, UNO_QUERY_THROW )->commitChanges(); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir catch( uno::Exception& ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir // this is no critical operation, ignore the exception 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319