1*03b7fc75SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*03b7fc75SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*03b7fc75SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*03b7fc75SAndrew Rist  * distributed with this work for additional information
6*03b7fc75SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*03b7fc75SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*03b7fc75SAndrew Rist  * "License"); you may not use this file except in compliance
9*03b7fc75SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*03b7fc75SAndrew Rist  *
11*03b7fc75SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*03b7fc75SAndrew Rist  *
13*03b7fc75SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*03b7fc75SAndrew Rist  * software distributed under the License is distributed on an
15*03b7fc75SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*03b7fc75SAndrew Rist  * KIND, either express or implied.  See the License for the
17*03b7fc75SAndrew Rist  * specific language governing permissions and limitations
18*03b7fc75SAndrew Rist  * under the License.
19*03b7fc75SAndrew Rist  *
20*03b7fc75SAndrew Rist  *************************************************************/
21*03b7fc75SAndrew Rist 
22*03b7fc75SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "dp_misc.h"
25cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
26cdf0e10cSrcweir #include "com/sun/star/lang/XComponent.hpp"
27cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
28cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp"
29cdf0e10cSrcweir #include "com/sun/star/deployment/XPackage.hpp"
30cdf0e10cSrcweir #include "tools/resmgr.hxx"
31cdf0e10cSrcweir #include "rtl/ustring.hxx"
32cdf0e10cSrcweir #include "unotools/configmgr.hxx"
33cdf0e10cSrcweir #include "ucbhelper/contentbroker.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #define APP_NAME "unopkg"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace css = ::com::sun::star;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace unopkg {
41cdf0e10cSrcweir 
toLocale(::rtl::OUString const & slang)42cdf0e10cSrcweir     inline ::com::sun::star::lang::Locale toLocale( ::rtl::OUString const & slang )
43cdf0e10cSrcweir     {
44cdf0e10cSrcweir         ::com::sun::star::lang::Locale locale;
45cdf0e10cSrcweir         sal_Int32 nIndex = 0;
46cdf0e10cSrcweir         locale.Language = slang.getToken( 0, '-', nIndex );
47cdf0e10cSrcweir         locale.Country = slang.getToken( 0, '-', nIndex );
48cdf0e10cSrcweir         locale.Variant = slang.getToken( 0, '-', nIndex );
49cdf0e10cSrcweir         return locale;
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	struct OfficeLocale :
54cdf0e10cSrcweir 		public rtl::StaticWithInit<const css::lang::Locale, OfficeLocale> {
operator ()unopkg::OfficeLocale55cdf0e10cSrcweir 			const css::lang::Locale operator () () {
56cdf0e10cSrcweir 				::rtl::OUString slang;
57cdf0e10cSrcweir         if (! (::utl::ConfigManager::GetDirectConfigProperty(
58cdf0e10cSrcweir                    ::utl::ConfigManager::LOCALE ) >>= slang))
59cdf0e10cSrcweir             throw css::uno::RuntimeException( OUSTR("Cannot determine language!"), 0 );
60cdf0e10cSrcweir         if (slang.getLength() == 0)
61cdf0e10cSrcweir             slang = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en-US"));
62cdf0e10cSrcweir 		return toLocale(slang);
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir };
65cdf0e10cSrcweir 
66cdf0e10cSrcweir struct DeploymentResMgr :  public rtl::StaticWithInit< ResMgr *, DeploymentResMgr >
67cdf0e10cSrcweir {
operator ()unopkg::DeploymentResMgr68cdf0e10cSrcweir 	ResMgr * operator () () {
69cdf0e10cSrcweir         return ResMgr::CreateResMgr( "deployment", OfficeLocale::get());
70cdf0e10cSrcweir 	}
71cdf0e10cSrcweir };
72cdf0e10cSrcweir 
73cdf0e10cSrcweir struct OptionInfo
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     char const * m_name;
76cdf0e10cSrcweir     sal_uInt32 m_name_length;
77cdf0e10cSrcweir     sal_Unicode m_short_option;
78cdf0e10cSrcweir     bool m_has_argument;
79cdf0e10cSrcweir };
80cdf0e10cSrcweir 
81cdf0e10cSrcweir struct LockFileException : public css::uno::Exception
82cdf0e10cSrcweir {
LockFileExceptionunopkg::LockFileException83cdf0e10cSrcweir     LockFileException(::rtl::OUString const & sMessage) :
84cdf0e10cSrcweir         css::uno::Exception(sMessage, css::uno::Reference< css::uno::XInterface > ()) {}
85cdf0e10cSrcweir };
86cdf0e10cSrcweir 
87cdf0e10cSrcweir //==============================================================================
88cdf0e10cSrcweir ::rtl::OUString toString( OptionInfo const * info );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir //==============================================================================
91cdf0e10cSrcweir OptionInfo const * getOptionInfo(
92cdf0e10cSrcweir     OptionInfo const * list,
93cdf0e10cSrcweir     ::rtl::OUString const & opt, sal_Unicode copt = '\0' );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //==============================================================================
96cdf0e10cSrcweir bool isOption( OptionInfo const * option_info, sal_uInt32 * pIndex );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir //==============================================================================
99cdf0e10cSrcweir bool readArgument(
100cdf0e10cSrcweir     ::rtl::OUString * pValue, OptionInfo const * option_info,
101cdf0e10cSrcweir     sal_uInt32 * pIndex );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //==============================================================================
readOption(bool * flag,OptionInfo const * option_info,sal_uInt32 * pIndex)104cdf0e10cSrcweir inline bool readOption(
105cdf0e10cSrcweir     bool * flag, OptionInfo const * option_info, sal_uInt32 * pIndex )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     if (isOption( option_info, pIndex )) {
108cdf0e10cSrcweir         OSL_ASSERT( flag != 0 );
109cdf0e10cSrcweir         *flag = true;
110cdf0e10cSrcweir         return true;
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir     return false;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir //==============================================================================
115cdf0e10cSrcweir 
116cdf0e10cSrcweir /** checks if an argument is a bootstrap variable. These start with -env:. For example
117cdf0e10cSrcweir     -env:UNO_JAVA_JFW_USER_DATA=file:///d:/user
118cdf0e10cSrcweir */
119cdf0e10cSrcweir bool isBootstrapVariable(sal_uInt32 * pIndex);
120cdf0e10cSrcweir //==============================================================================
121cdf0e10cSrcweir ::rtl::OUString const & getExecutableDir();
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //==============================================================================
124cdf0e10cSrcweir ::rtl::OUString const & getProcessWorkingDir();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir //==============================================================================
127cdf0e10cSrcweir ::rtl::OUString makeAbsoluteFileUrl(
128cdf0e10cSrcweir     ::rtl::OUString const & sys_path, ::rtl::OUString const & base_url,
129cdf0e10cSrcweir     bool throw_exc = true );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir //##############################################################################
132cdf0e10cSrcweir 
133cdf0e10cSrcweir //==============================================================================
134cdf0e10cSrcweir class DisposeGuard
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     css::uno::Reference<css::lang::XComponent> m_xComp;
137cdf0e10cSrcweir     bool m_bDeinitUCB;
138cdf0e10cSrcweir public:
DisposeGuard()139cdf0e10cSrcweir     DisposeGuard(): m_bDeinitUCB(false) {}
~DisposeGuard()140cdf0e10cSrcweir     inline ~DisposeGuard()
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir         if (m_bDeinitUCB)
143cdf0e10cSrcweir             ::ucbhelper::ContentBroker::deinitialize();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         if (m_xComp.is())
146cdf0e10cSrcweir             m_xComp->dispose();
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
reset(css::uno::Reference<css::lang::XComponent> const & xComp)149cdf0e10cSrcweir     inline void reset(
150cdf0e10cSrcweir         css::uno::Reference<css::lang::XComponent> const & xComp )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         m_xComp = xComp;
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir 
setDeinitUCB()155cdf0e10cSrcweir     inline void setDeinitUCB()
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         m_bDeinitUCB = true;
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir };
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //==============================================================================
163cdf0e10cSrcweir css::uno::Reference<css::ucb::XCommandEnvironment> createCmdEnv(
164cdf0e10cSrcweir     css::uno::Reference<css::uno::XComponentContext> const & xContext,
165cdf0e10cSrcweir     ::rtl::OUString const & logFile,
166cdf0e10cSrcweir     bool option_force_overwrite,
167cdf0e10cSrcweir     bool option_verbose);
168cdf0e10cSrcweir //==============================================================================
169cdf0e10cSrcweir void printf_packages(
170cdf0e10cSrcweir     ::std::vector<
171cdf0e10cSrcweir     css::uno::Reference<css::deployment::XPackage> > const & allExtensions,
172cdf0e10cSrcweir     ::std::vector<bool> const & vecUnaccepted,
173cdf0e10cSrcweir     css::uno::Reference<css::ucb::XCommandEnvironment> const & xCmdEnv,
174cdf0e10cSrcweir     sal_Int32 level = 0 );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir //##############################################################################
177cdf0e10cSrcweir 
178cdf0e10cSrcweir //==============================================================================
179cdf0e10cSrcweir css::uno::Reference<css::uno::XComponentContext> getUNO(
180cdf0e10cSrcweir     DisposeGuard & disposeGuard, bool verbose, bool shared, bool bGui,
181cdf0e10cSrcweir     css::uno::Reference<css::uno::XComponentContext> & out_LocalComponentContext);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir bool hasNoFolder(::rtl::OUString const & folderUrl);
184cdf0e10cSrcweir 
185cdf0e10cSrcweir void removeFolder(::rtl::OUString const & folderUrl);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191