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 #include "dp_misc.h" 29*cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp" 30*cdf0e10cSrcweir #include "com/sun/star/lang/XComponent.hpp" 31*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 32*cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp" 33*cdf0e10cSrcweir #include "com/sun/star/deployment/XPackage.hpp" 34*cdf0e10cSrcweir #include "tools/resmgr.hxx" 35*cdf0e10cSrcweir #include "rtl/ustring.hxx" 36*cdf0e10cSrcweir #include "unotools/configmgr.hxx" 37*cdf0e10cSrcweir #include "ucbhelper/contentbroker.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #define APP_NAME "unopkg" 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir namespace css = ::com::sun::star; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace unopkg { 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir inline ::com::sun::star::lang::Locale toLocale( ::rtl::OUString const & slang ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir ::com::sun::star::lang::Locale locale; 49*cdf0e10cSrcweir sal_Int32 nIndex = 0; 50*cdf0e10cSrcweir locale.Language = slang.getToken( 0, '-', nIndex ); 51*cdf0e10cSrcweir locale.Country = slang.getToken( 0, '-', nIndex ); 52*cdf0e10cSrcweir locale.Variant = slang.getToken( 0, '-', nIndex ); 53*cdf0e10cSrcweir return locale; 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir struct OfficeLocale : 58*cdf0e10cSrcweir public rtl::StaticWithInit<const css::lang::Locale, OfficeLocale> { 59*cdf0e10cSrcweir const css::lang::Locale operator () () { 60*cdf0e10cSrcweir ::rtl::OUString slang; 61*cdf0e10cSrcweir if (! (::utl::ConfigManager::GetDirectConfigProperty( 62*cdf0e10cSrcweir ::utl::ConfigManager::LOCALE ) >>= slang)) 63*cdf0e10cSrcweir throw css::uno::RuntimeException( OUSTR("Cannot determine language!"), 0 ); 64*cdf0e10cSrcweir if (slang.getLength() == 0) 65*cdf0e10cSrcweir slang = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en-US")); 66*cdf0e10cSrcweir return toLocale(slang); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir }; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir struct DeploymentResMgr : public rtl::StaticWithInit< ResMgr *, DeploymentResMgr > 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir ResMgr * operator () () { 73*cdf0e10cSrcweir return ResMgr::CreateResMgr( "deployment", OfficeLocale::get()); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir }; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir struct OptionInfo 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir char const * m_name; 80*cdf0e10cSrcweir sal_uInt32 m_name_length; 81*cdf0e10cSrcweir sal_Unicode m_short_option; 82*cdf0e10cSrcweir bool m_has_argument; 83*cdf0e10cSrcweir }; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir struct LockFileException : public css::uno::Exception 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir LockFileException(::rtl::OUString const & sMessage) : 88*cdf0e10cSrcweir css::uno::Exception(sMessage, css::uno::Reference< css::uno::XInterface > ()) {} 89*cdf0e10cSrcweir }; 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //============================================================================== 92*cdf0e10cSrcweir ::rtl::OUString toString( OptionInfo const * info ); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir //============================================================================== 95*cdf0e10cSrcweir OptionInfo const * getOptionInfo( 96*cdf0e10cSrcweir OptionInfo const * list, 97*cdf0e10cSrcweir ::rtl::OUString const & opt, sal_Unicode copt = '\0' ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir //============================================================================== 100*cdf0e10cSrcweir bool isOption( OptionInfo const * option_info, sal_uInt32 * pIndex ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir //============================================================================== 103*cdf0e10cSrcweir bool readArgument( 104*cdf0e10cSrcweir ::rtl::OUString * pValue, OptionInfo const * option_info, 105*cdf0e10cSrcweir sal_uInt32 * pIndex ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir //============================================================================== 108*cdf0e10cSrcweir inline bool readOption( 109*cdf0e10cSrcweir bool * flag, OptionInfo const * option_info, sal_uInt32 * pIndex ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir if (isOption( option_info, pIndex )) { 112*cdf0e10cSrcweir OSL_ASSERT( flag != 0 ); 113*cdf0e10cSrcweir *flag = true; 114*cdf0e10cSrcweir return true; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir return false; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir //============================================================================== 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir /** checks if an argument is a bootstrap variable. These start with -env:. For example 121*cdf0e10cSrcweir -env:UNO_JAVA_JFW_USER_DATA=file:///d:/user 122*cdf0e10cSrcweir */ 123*cdf0e10cSrcweir bool isBootstrapVariable(sal_uInt32 * pIndex); 124*cdf0e10cSrcweir //============================================================================== 125*cdf0e10cSrcweir ::rtl::OUString const & getExecutableDir(); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir //============================================================================== 128*cdf0e10cSrcweir ::rtl::OUString const & getProcessWorkingDir(); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir //============================================================================== 131*cdf0e10cSrcweir ::rtl::OUString makeAbsoluteFileUrl( 132*cdf0e10cSrcweir ::rtl::OUString const & sys_path, ::rtl::OUString const & base_url, 133*cdf0e10cSrcweir bool throw_exc = true ); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir //############################################################################## 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir //============================================================================== 138*cdf0e10cSrcweir class DisposeGuard 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir css::uno::Reference<css::lang::XComponent> m_xComp; 141*cdf0e10cSrcweir bool m_bDeinitUCB; 142*cdf0e10cSrcweir public: 143*cdf0e10cSrcweir DisposeGuard(): m_bDeinitUCB(false) {} 144*cdf0e10cSrcweir inline ~DisposeGuard() 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir if (m_bDeinitUCB) 147*cdf0e10cSrcweir ::ucbhelper::ContentBroker::deinitialize(); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir if (m_xComp.is()) 150*cdf0e10cSrcweir m_xComp->dispose(); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir inline void reset( 154*cdf0e10cSrcweir css::uno::Reference<css::lang::XComponent> const & xComp ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir m_xComp = xComp; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir inline void setDeinitUCB() 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir m_bDeinitUCB = true; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir }; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir //============================================================================== 167*cdf0e10cSrcweir css::uno::Reference<css::ucb::XCommandEnvironment> createCmdEnv( 168*cdf0e10cSrcweir css::uno::Reference<css::uno::XComponentContext> const & xContext, 169*cdf0e10cSrcweir ::rtl::OUString const & logFile, 170*cdf0e10cSrcweir bool option_force_overwrite, 171*cdf0e10cSrcweir bool option_verbose); 172*cdf0e10cSrcweir //============================================================================== 173*cdf0e10cSrcweir void printf_packages( 174*cdf0e10cSrcweir ::std::vector< 175*cdf0e10cSrcweir css::uno::Reference<css::deployment::XPackage> > const & allExtensions, 176*cdf0e10cSrcweir ::std::vector<bool> const & vecUnaccepted, 177*cdf0e10cSrcweir css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv, 178*cdf0e10cSrcweir sal_Int32 level = 0 ); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir //############################################################################## 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //============================================================================== 183*cdf0e10cSrcweir css::uno::Reference<css::uno::XComponentContext> getUNO( 184*cdf0e10cSrcweir DisposeGuard & disposeGuard, bool verbose, bool shared, bool bGui, 185*cdf0e10cSrcweir css::uno::Reference<css::uno::XComponentContext> & out_LocalComponentContext); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir bool hasNoFolder(::rtl::OUString const & folderUrl); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir void removeFolder(::rtl::OUString const & folderUrl); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195