1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "dp_misc.h" 29 #include "com/sun/star/uno/Exception.hpp" 30 #include "com/sun/star/lang/XComponent.hpp" 31 #include "com/sun/star/uno/XComponentContext.hpp" 32 #include "com/sun/star/ucb/XCommandEnvironment.hpp" 33 #include "com/sun/star/deployment/XPackage.hpp" 34 #include "tools/resmgr.hxx" 35 #include "rtl/ustring.hxx" 36 #include "unotools/configmgr.hxx" 37 #include "ucbhelper/contentbroker.hxx" 38 39 40 #define APP_NAME "unopkg" 41 42 namespace css = ::com::sun::star; 43 44 namespace unopkg { 45 46 inline ::com::sun::star::lang::Locale toLocale( ::rtl::OUString const & slang ) 47 { 48 ::com::sun::star::lang::Locale locale; 49 sal_Int32 nIndex = 0; 50 locale.Language = slang.getToken( 0, '-', nIndex ); 51 locale.Country = slang.getToken( 0, '-', nIndex ); 52 locale.Variant = slang.getToken( 0, '-', nIndex ); 53 return locale; 54 } 55 56 57 struct OfficeLocale : 58 public rtl::StaticWithInit<const css::lang::Locale, OfficeLocale> { 59 const css::lang::Locale operator () () { 60 ::rtl::OUString slang; 61 if (! (::utl::ConfigManager::GetDirectConfigProperty( 62 ::utl::ConfigManager::LOCALE ) >>= slang)) 63 throw css::uno::RuntimeException( OUSTR("Cannot determine language!"), 0 ); 64 if (slang.getLength() == 0) 65 slang = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en-US")); 66 return toLocale(slang); 67 } 68 }; 69 70 struct DeploymentResMgr : public rtl::StaticWithInit< ResMgr *, DeploymentResMgr > 71 { 72 ResMgr * operator () () { 73 return ResMgr::CreateResMgr( "deployment", OfficeLocale::get()); 74 } 75 }; 76 77 struct OptionInfo 78 { 79 char const * m_name; 80 sal_uInt32 m_name_length; 81 sal_Unicode m_short_option; 82 bool m_has_argument; 83 }; 84 85 struct LockFileException : public css::uno::Exception 86 { 87 LockFileException(::rtl::OUString const & sMessage) : 88 css::uno::Exception(sMessage, css::uno::Reference< css::uno::XInterface > ()) {} 89 }; 90 91 //============================================================================== 92 ::rtl::OUString toString( OptionInfo const * info ); 93 94 //============================================================================== 95 OptionInfo const * getOptionInfo( 96 OptionInfo const * list, 97 ::rtl::OUString const & opt, sal_Unicode copt = '\0' ); 98 99 //============================================================================== 100 bool isOption( OptionInfo const * option_info, sal_uInt32 * pIndex ); 101 102 //============================================================================== 103 bool readArgument( 104 ::rtl::OUString * pValue, OptionInfo const * option_info, 105 sal_uInt32 * pIndex ); 106 107 //============================================================================== 108 inline bool readOption( 109 bool * flag, OptionInfo const * option_info, sal_uInt32 * pIndex ) 110 { 111 if (isOption( option_info, pIndex )) { 112 OSL_ASSERT( flag != 0 ); 113 *flag = true; 114 return true; 115 } 116 return false; 117 } 118 //============================================================================== 119 120 /** checks if an argument is a bootstrap variable. These start with -env:. For example 121 -env:UNO_JAVA_JFW_USER_DATA=file:///d:/user 122 */ 123 bool isBootstrapVariable(sal_uInt32 * pIndex); 124 //============================================================================== 125 ::rtl::OUString const & getExecutableDir(); 126 127 //============================================================================== 128 ::rtl::OUString const & getProcessWorkingDir(); 129 130 //============================================================================== 131 ::rtl::OUString makeAbsoluteFileUrl( 132 ::rtl::OUString const & sys_path, ::rtl::OUString const & base_url, 133 bool throw_exc = true ); 134 135 //############################################################################## 136 137 //============================================================================== 138 class DisposeGuard 139 { 140 css::uno::Reference<css::lang::XComponent> m_xComp; 141 bool m_bDeinitUCB; 142 public: 143 DisposeGuard(): m_bDeinitUCB(false) {} 144 inline ~DisposeGuard() 145 { 146 if (m_bDeinitUCB) 147 ::ucbhelper::ContentBroker::deinitialize(); 148 149 if (m_xComp.is()) 150 m_xComp->dispose(); 151 } 152 153 inline void reset( 154 css::uno::Reference<css::lang::XComponent> const & xComp ) 155 { 156 m_xComp = xComp; 157 } 158 159 inline void setDeinitUCB() 160 { 161 m_bDeinitUCB = true; 162 } 163 164 }; 165 166 //============================================================================== 167 css::uno::Reference<css::ucb::XCommandEnvironment> createCmdEnv( 168 css::uno::Reference<css::uno::XComponentContext> const & xContext, 169 ::rtl::OUString const & logFile, 170 bool option_force_overwrite, 171 bool option_verbose); 172 //============================================================================== 173 void printf_packages( 174 ::std::vector< 175 css::uno::Reference<css::deployment::XPackage> > const & allExtensions, 176 ::std::vector<bool> const & vecUnaccepted, 177 css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv, 178 sal_Int32 level = 0 ); 179 180 //############################################################################## 181 182 //============================================================================== 183 css::uno::Reference<css::uno::XComponentContext> getUNO( 184 DisposeGuard & disposeGuard, bool verbose, bool shared, bool bGui, 185 css::uno::Reference<css::uno::XComponentContext> & out_LocalComponentContext); 186 187 bool hasNoFolder(::rtl::OUString const & folderUrl); 188 189 void removeFolder(::rtl::OUString const & folderUrl); 190 191 } 192 193 194 195