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