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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "../../deployment/gui/dp_gui.hrc"
32*cdf0e10cSrcweir #include "../../deployment/gui/dp_gui_shared.hxx"
33*cdf0e10cSrcweir #include "unopkg_shared.h"
34*cdf0e10cSrcweir #include "osl/thread.h"
35*cdf0e10cSrcweir #include "rtl/memory.h"
36*cdf0e10cSrcweir #include "tools/string.hxx"
37*cdf0e10cSrcweir #include "tools/resmgr.hxx"
38*cdf0e10cSrcweir #include "cppuhelper/implbase3.hxx"
39*cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
40*cdf0e10cSrcweir #include "comphelper/anytostring.hxx"
41*cdf0e10cSrcweir #include "unotools/configmgr.hxx"
42*cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetException.hpp"
43*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp"
44*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionApprove.hpp"
45*cdf0e10cSrcweir #include "com/sun/star/deployment/InstallException.hpp"
46*cdf0e10cSrcweir #include "com/sun/star/container/ElementExistException.hpp"
47*cdf0e10cSrcweir #include "com/sun/star/deployment/LicenseException.hpp"
48*cdf0e10cSrcweir #include "com/sun/star/deployment/VersionException.hpp"
49*cdf0e10cSrcweir #include "com/sun/star/deployment/PlatformException.hpp"
50*cdf0e10cSrcweir #include "com/sun/star/i18n/XCollator.hpp"
51*cdf0e10cSrcweir #include "com/sun/star/i18n/CollatorOptions.hpp"
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #include <stdio.h>
54*cdf0e10cSrcweir #include "deployment.hrc"
55*cdf0e10cSrcweir #include "dp_version.hxx"
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir namespace css = ::com::sun::star;
58*cdf0e10cSrcweir using namespace ::com::sun::star;
59*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
60*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
61*cdf0e10cSrcweir using namespace ::unopkg;
62*cdf0e10cSrcweir using ::rtl::OUString;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir namespace {
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir //==============================================================================
68*cdf0e10cSrcweir struct OfficeLocale :
69*cdf0e10cSrcweir         public rtl::StaticWithInit<const lang::Locale, OfficeLocale> {
70*cdf0e10cSrcweir     const lang::Locale operator () () {
71*cdf0e10cSrcweir         OUString slang;
72*cdf0e10cSrcweir         if (! (::utl::ConfigManager::GetDirectConfigProperty(
73*cdf0e10cSrcweir                    ::utl::ConfigManager::LOCALE ) >>= slang))
74*cdf0e10cSrcweir             throw RuntimeException( OUSTR("Cannot determine language!"), 0 );
75*cdf0e10cSrcweir         return toLocale(slang);
76*cdf0e10cSrcweir     }
77*cdf0e10cSrcweir };
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir //==============================================================================
80*cdf0e10cSrcweir class CommandEnvironmentImpl
81*cdf0e10cSrcweir     : public ::cppu::WeakImplHelper3< XCommandEnvironment,
82*cdf0e10cSrcweir                                       task::XInteractionHandler,
83*cdf0e10cSrcweir                                       XProgressHandler >
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     sal_Int32 m_logLevel;
86*cdf0e10cSrcweir     bool m_option_force_overwrite;
87*cdf0e10cSrcweir     bool m_option_verbose;
88*cdf0e10cSrcweir 	Reference< XComponentContext > m_xComponentContext;
89*cdf0e10cSrcweir     Reference< XProgressHandler > m_xLogFile;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     void update_( Any const & Status ) throw (RuntimeException);
92*cdf0e10cSrcweir 	void printLicense(const OUString & sName,const OUString& sLicense,
93*cdf0e10cSrcweir                       bool & accept, bool & decline);
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir public:
96*cdf0e10cSrcweir     virtual ~CommandEnvironmentImpl();
97*cdf0e10cSrcweir     CommandEnvironmentImpl(
98*cdf0e10cSrcweir         Reference<XComponentContext> const & xComponentContext,
99*cdf0e10cSrcweir         OUString const & log_file,
100*cdf0e10cSrcweir         bool option_force_overwrite,
101*cdf0e10cSrcweir         bool option_verbose);
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     // XCommandEnvironment
104*cdf0e10cSrcweir     virtual Reference< task::XInteractionHandler > SAL_CALL
105*cdf0e10cSrcweir     getInteractionHandler() throw (RuntimeException);
106*cdf0e10cSrcweir     virtual Reference< XProgressHandler > SAL_CALL getProgressHandler()
107*cdf0e10cSrcweir         throw (RuntimeException);
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     // XInteractionHandler
110*cdf0e10cSrcweir     virtual void SAL_CALL handle(
111*cdf0e10cSrcweir         Reference< task::XInteractionRequest > const & xRequest )
112*cdf0e10cSrcweir         throw (RuntimeException);
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     // XProgressHandler
115*cdf0e10cSrcweir     virtual void SAL_CALL push( Any const & Status ) throw (RuntimeException);
116*cdf0e10cSrcweir     virtual void SAL_CALL update( Any const & Status ) throw (RuntimeException);
117*cdf0e10cSrcweir     virtual void SAL_CALL pop() throw (RuntimeException);
118*cdf0e10cSrcweir };
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir //______________________________________________________________________________
122*cdf0e10cSrcweir CommandEnvironmentImpl::CommandEnvironmentImpl(
123*cdf0e10cSrcweir     Reference<XComponentContext> const & xComponentContext,
124*cdf0e10cSrcweir     OUString const & log_file,
125*cdf0e10cSrcweir     bool option_force_overwrite,
126*cdf0e10cSrcweir     bool option_verbose)
127*cdf0e10cSrcweir     : m_logLevel(0),
128*cdf0e10cSrcweir       m_option_force_overwrite( option_force_overwrite ),
129*cdf0e10cSrcweir       m_option_verbose( option_verbose ),
130*cdf0e10cSrcweir 	  m_xComponentContext(xComponentContext)
131*cdf0e10cSrcweir {
132*cdf0e10cSrcweir     if (log_file.getLength() > 0) {
133*cdf0e10cSrcweir         const Any logfile(log_file);
134*cdf0e10cSrcweir         m_xLogFile.set(
135*cdf0e10cSrcweir             xComponentContext->getServiceManager()
136*cdf0e10cSrcweir             ->createInstanceWithArgumentsAndContext(
137*cdf0e10cSrcweir                 OUSTR("com.sun.star.comp.deployment.ProgressLog"),
138*cdf0e10cSrcweir                 Sequence<Any>( &logfile, 1 ), xComponentContext ),
139*cdf0e10cSrcweir             UNO_QUERY_THROW );
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir //______________________________________________________________________________
144*cdf0e10cSrcweir CommandEnvironmentImpl::~CommandEnvironmentImpl()
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     try {
147*cdf0e10cSrcweir         Reference< lang::XComponent > xComp( m_xLogFile, UNO_QUERY );
148*cdf0e10cSrcweir         if (xComp.is())
149*cdf0e10cSrcweir             xComp->dispose();
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir     catch (RuntimeException & exc) {
152*cdf0e10cSrcweir         (void) exc;
153*cdf0e10cSrcweir         OSL_ENSURE( 0, ::rtl::OUStringToOString(
154*cdf0e10cSrcweir                         exc.Message, osl_getThreadTextEncoding() ).getStr() );
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir //May throw exceptions
159*cdf0e10cSrcweir void CommandEnvironmentImpl::printLicense(
160*cdf0e10cSrcweir     const OUString & sName, const OUString& sLicense, bool & accept, bool &decline)
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir     ResMgr * pResMgr = DeploymentResMgr::get();
163*cdf0e10cSrcweir     String s1tmp(ResId(RID_STR_UNOPKG_ACCEPT_LIC_1, *pResMgr));
164*cdf0e10cSrcweir     s1tmp.SearchAndReplaceAllAscii( "$NAME", sName );
165*cdf0e10cSrcweir 	OUString s1(s1tmp);
166*cdf0e10cSrcweir 	OUString s2 = String(ResId(RID_STR_UNOPKG_ACCEPT_LIC_2, *pResMgr));
167*cdf0e10cSrcweir 	OUString s3 = String(ResId(RID_STR_UNOPKG_ACCEPT_LIC_3, *pResMgr));
168*cdf0e10cSrcweir 	OUString s4 = String(ResId(RID_STR_UNOPKG_ACCEPT_LIC_4, *pResMgr));
169*cdf0e10cSrcweir 	OUString sYES = String(ResId(RID_STR_UNOPKG_ACCEPT_LIC_YES, *pResMgr));
170*cdf0e10cSrcweir 	OUString sY = String(ResId(RID_STR_UNOPKG_ACCEPT_LIC_Y, *pResMgr));
171*cdf0e10cSrcweir 	OUString sNO = String(ResId(RID_STR_UNOPKG_ACCEPT_LIC_NO, *pResMgr));
172*cdf0e10cSrcweir 	OUString sN = String(ResId(RID_STR_UNOPKG_ACCEPT_LIC_N, *pResMgr));
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir     OUString sNewLine(RTL_CONSTASCII_USTRINGPARAM("\n"));
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     dp_misc::writeConsole(sNewLine + sNewLine + s1 + sNewLine + sNewLine);
177*cdf0e10cSrcweir     dp_misc::writeConsole(sLicense + sNewLine + sNewLine);
178*cdf0e10cSrcweir     dp_misc::writeConsole(s2 + sNewLine);
179*cdf0e10cSrcweir     dp_misc::writeConsole(s3);
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	//the user may enter "yes" or "no", we compare in a case insensitive way
182*cdf0e10cSrcweir 	Reference< css::i18n::XCollator > xCollator(
183*cdf0e10cSrcweir 		m_xComponentContext->getServiceManager()
184*cdf0e10cSrcweir 			->createInstanceWithContext(
185*cdf0e10cSrcweir 				OUSTR("com.sun.star.i18n.Collator"),m_xComponentContext),
186*cdf0e10cSrcweir 			UNO_QUERY_THROW	);
187*cdf0e10cSrcweir 	xCollator->loadDefaultCollator(OfficeLocale::get(),
188*cdf0e10cSrcweir 		css::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE);
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 	do
191*cdf0e10cSrcweir 	{
192*cdf0e10cSrcweir         OUString sAnswer = dp_misc::readConsole();
193*cdf0e10cSrcweir 		if (xCollator->compareString(sAnswer, sYES) == 0
194*cdf0e10cSrcweir 			|| xCollator->compareString(sAnswer, sY) == 0)
195*cdf0e10cSrcweir 		{
196*cdf0e10cSrcweir 			accept = true;
197*cdf0e10cSrcweir 			break;
198*cdf0e10cSrcweir 		}
199*cdf0e10cSrcweir 		else if(xCollator->compareString(sAnswer, sNO) == 0
200*cdf0e10cSrcweir 			|| xCollator->compareString(sAnswer, sN) == 0)
201*cdf0e10cSrcweir 		{
202*cdf0e10cSrcweir 			decline = true;
203*cdf0e10cSrcweir 			break;
204*cdf0e10cSrcweir 		}
205*cdf0e10cSrcweir 		else
206*cdf0e10cSrcweir 		{
207*cdf0e10cSrcweir             dp_misc::writeConsole(sNewLine + sNewLine + s4 + sNewLine);
208*cdf0e10cSrcweir 		}
209*cdf0e10cSrcweir 	}
210*cdf0e10cSrcweir 	while(true);
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir // XCommandEnvironment
214*cdf0e10cSrcweir //______________________________________________________________________________
215*cdf0e10cSrcweir Reference< task::XInteractionHandler >
216*cdf0e10cSrcweir CommandEnvironmentImpl::getInteractionHandler() throw (RuntimeException)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     return this;
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir //______________________________________________________________________________
222*cdf0e10cSrcweir Reference< XProgressHandler > CommandEnvironmentImpl::getProgressHandler()
223*cdf0e10cSrcweir     throw (RuntimeException)
224*cdf0e10cSrcweir {
225*cdf0e10cSrcweir     return this;
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir // XInteractionHandler
229*cdf0e10cSrcweir //______________________________________________________________________________
230*cdf0e10cSrcweir void CommandEnvironmentImpl::handle(
231*cdf0e10cSrcweir     Reference<task::XInteractionRequest> const & xRequest )
232*cdf0e10cSrcweir     throw (RuntimeException)
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     Any request( xRequest->getRequest() );
235*cdf0e10cSrcweir     OSL_ASSERT( request.getValueTypeClass() == TypeClass_EXCEPTION );
236*cdf0e10cSrcweir     dp_misc::TRACE(OUSTR("[unopkg_cmdenv.cxx] incoming request:\n")
237*cdf0e10cSrcweir         + ::comphelper::anyToString(request) + OUSTR("\n\n"));
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir     // selections:
240*cdf0e10cSrcweir     bool approve = false;
241*cdf0e10cSrcweir     bool abort = false;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     lang::WrappedTargetException wtExc;
244*cdf0e10cSrcweir 	deployment::LicenseException licExc;
245*cdf0e10cSrcweir     deployment::InstallException instExc;
246*cdf0e10cSrcweir     deployment::PlatformException platExc;
247*cdf0e10cSrcweir     deployment::VersionException verExc;
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     bool bLicenseException = false;
251*cdf0e10cSrcweir     if (request >>= wtExc) {
252*cdf0e10cSrcweir         // ignore intermediate errors of legacy packages, i.e.
253*cdf0e10cSrcweir         // former pkgchk behaviour:
254*cdf0e10cSrcweir         const Reference<deployment::XPackage> xPackage(
255*cdf0e10cSrcweir             wtExc.Context, UNO_QUERY );
256*cdf0e10cSrcweir         OSL_ASSERT( xPackage.is() );
257*cdf0e10cSrcweir         if (xPackage.is()) {
258*cdf0e10cSrcweir             const Reference<deployment::XPackageTypeInfo> xPackageType(
259*cdf0e10cSrcweir                 xPackage->getPackageType() );
260*cdf0e10cSrcweir             OSL_ASSERT( xPackageType.is() );
261*cdf0e10cSrcweir             if (xPackageType.is()) {
262*cdf0e10cSrcweir                 approve = (xPackage->isBundle() &&
263*cdf0e10cSrcweir                            xPackageType->getMediaType().matchAsciiL(
264*cdf0e10cSrcweir                                RTL_CONSTASCII_STRINGPARAM(
265*cdf0e10cSrcweir                                    "application/"
266*cdf0e10cSrcweir                                    "vnd.sun.star.legacy-package-bundle") ));
267*cdf0e10cSrcweir             }
268*cdf0e10cSrcweir         }
269*cdf0e10cSrcweir         abort = !approve;
270*cdf0e10cSrcweir         if (abort) {
271*cdf0e10cSrcweir             // notify cause as error:
272*cdf0e10cSrcweir             request = wtExc.TargetException;
273*cdf0e10cSrcweir         }
274*cdf0e10cSrcweir         else {
275*cdf0e10cSrcweir             // handable deployment error signalled, e.g.
276*cdf0e10cSrcweir             // bundle item registration failed, notify as warning:
277*cdf0e10cSrcweir             update_( wtExc.TargetException );
278*cdf0e10cSrcweir         }
279*cdf0e10cSrcweir     }
280*cdf0e10cSrcweir 	else if (request >>= licExc)
281*cdf0e10cSrcweir 	{
282*cdf0e10cSrcweir         printLicense(licExc.ExtensionName, licExc.Text, approve, abort);
283*cdf0e10cSrcweir 	}
284*cdf0e10cSrcweir    	else if (request >>= instExc)
285*cdf0e10cSrcweir 	{
286*cdf0e10cSrcweir 		//Only if the unopgk was started with gui + extension then we user is asked.
287*cdf0e10cSrcweir         //In console mode there is no asking.
288*cdf0e10cSrcweir 		approve = true;
289*cdf0e10cSrcweir 	}
290*cdf0e10cSrcweir     else if (request >>= platExc)
291*cdf0e10cSrcweir     {
292*cdf0e10cSrcweir         String sMsg(ResId(RID_STR_UNSUPPORTED_PLATFORM, *dp_gui::DeploymentGuiResMgr::get()));
293*cdf0e10cSrcweir         sMsg.SearchAndReplaceAllAscii("%Name", platExc.package->getDisplayName());
294*cdf0e10cSrcweir         dp_misc::writeConsole(OUSTR("\n") + sMsg + OUSTR("\n\n"));
295*cdf0e10cSrcweir         approve = true;
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir     else {
298*cdf0e10cSrcweir         deployment::VersionException nc_exc;
299*cdf0e10cSrcweir         if (request >>= nc_exc) {
300*cdf0e10cSrcweir             approve = m_option_force_overwrite ||
301*cdf0e10cSrcweir                 (::dp_misc::compareVersions(nc_exc.NewVersion, nc_exc.Deployed->getVersion())
302*cdf0e10cSrcweir                  == ::dp_misc::GREATER);
303*cdf0e10cSrcweir             abort = !approve;
304*cdf0e10cSrcweir         }
305*cdf0e10cSrcweir         else
306*cdf0e10cSrcweir             return; // unknown request => no selection at all
307*cdf0e10cSrcweir     }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     //In case of a user declining a license abort is true but this is intended,
310*cdf0e10cSrcweir     //therefore no logging
311*cdf0e10cSrcweir     if (abort && m_option_verbose && !bLicenseException)
312*cdf0e10cSrcweir     {
313*cdf0e10cSrcweir         OUString msg = ::comphelper::anyToString(request);
314*cdf0e10cSrcweir         dp_misc::writeConsoleError(
315*cdf0e10cSrcweir             OUSTR("\nERROR: ") + msg + OUSTR("\n"));
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     // select:
319*cdf0e10cSrcweir     Sequence< Reference<task::XInteractionContinuation> > conts(
320*cdf0e10cSrcweir         xRequest->getContinuations() );
321*cdf0e10cSrcweir     Reference<task::XInteractionContinuation> const * pConts =
322*cdf0e10cSrcweir         conts.getConstArray();
323*cdf0e10cSrcweir     sal_Int32 len = conts.getLength();
324*cdf0e10cSrcweir     for ( sal_Int32 pos = 0; pos < len; ++pos )
325*cdf0e10cSrcweir     {
326*cdf0e10cSrcweir         if (approve) {
327*cdf0e10cSrcweir             Reference<task::XInteractionApprove> xInteractionApprove(
328*cdf0e10cSrcweir                 pConts[ pos ], UNO_QUERY );
329*cdf0e10cSrcweir             if (xInteractionApprove.is()) {
330*cdf0e10cSrcweir                 xInteractionApprove->select();
331*cdf0e10cSrcweir                 break;
332*cdf0e10cSrcweir             }
333*cdf0e10cSrcweir         }
334*cdf0e10cSrcweir         else if (abort) {
335*cdf0e10cSrcweir             Reference<task::XInteractionAbort> xInteractionAbort(
336*cdf0e10cSrcweir                 pConts[ pos ], UNO_QUERY );
337*cdf0e10cSrcweir             if (xInteractionAbort.is()) {
338*cdf0e10cSrcweir                 xInteractionAbort->select();
339*cdf0e10cSrcweir                 break;
340*cdf0e10cSrcweir             }
341*cdf0e10cSrcweir         }
342*cdf0e10cSrcweir     }
343*cdf0e10cSrcweir }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir // XProgressHandler
346*cdf0e10cSrcweir //______________________________________________________________________________
347*cdf0e10cSrcweir void CommandEnvironmentImpl::push( Any const & Status )
348*cdf0e10cSrcweir     throw (RuntimeException)
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir     update_( Status );
351*cdf0e10cSrcweir     OSL_ASSERT( m_logLevel >= 0 );
352*cdf0e10cSrcweir     ++m_logLevel;
353*cdf0e10cSrcweir     if (m_xLogFile.is())
354*cdf0e10cSrcweir         m_xLogFile->push( Status );
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir //______________________________________________________________________________
358*cdf0e10cSrcweir void CommandEnvironmentImpl::update_( Any const & Status )
359*cdf0e10cSrcweir     throw (RuntimeException)
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     if (! Status.hasValue())
362*cdf0e10cSrcweir         return;
363*cdf0e10cSrcweir     bool bUseErr = false;
364*cdf0e10cSrcweir     OUString msg;
365*cdf0e10cSrcweir     if (Status >>= msg) {
366*cdf0e10cSrcweir         if (! m_option_verbose)
367*cdf0e10cSrcweir             return;
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir     else {
370*cdf0e10cSrcweir         ::rtl::OUStringBuffer buf;
371*cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("WARNING: ") );
372*cdf0e10cSrcweir         deployment::DeploymentException dp_exc;
373*cdf0e10cSrcweir         if (Status >>= dp_exc) {
374*cdf0e10cSrcweir             buf.append( dp_exc.Message );
375*cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", Cause: ") );
376*cdf0e10cSrcweir             buf.append( ::comphelper::anyToString(dp_exc.Cause) );
377*cdf0e10cSrcweir         }
378*cdf0e10cSrcweir         else {
379*cdf0e10cSrcweir             buf.append( ::comphelper::anyToString(Status) );
380*cdf0e10cSrcweir         }
381*cdf0e10cSrcweir         msg = buf.makeStringAndClear();
382*cdf0e10cSrcweir         bUseErr = true;
383*cdf0e10cSrcweir     }
384*cdf0e10cSrcweir     OSL_ASSERT( m_logLevel >= 0 );
385*cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < m_logLevel; ++n )
386*cdf0e10cSrcweir     {
387*cdf0e10cSrcweir         if (bUseErr)
388*cdf0e10cSrcweir             dp_misc::writeConsoleError(" ");
389*cdf0e10cSrcweir         else
390*cdf0e10cSrcweir             dp_misc::writeConsole(" ");
391*cdf0e10cSrcweir     }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir     if (bUseErr)
394*cdf0e10cSrcweir         dp_misc::writeConsoleError(msg + OUSTR("\n"));
395*cdf0e10cSrcweir     else
396*cdf0e10cSrcweir         dp_misc::writeConsole(msg + OUSTR("\n"));
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir //______________________________________________________________________________
400*cdf0e10cSrcweir void CommandEnvironmentImpl::update( Any const & Status )
401*cdf0e10cSrcweir     throw (RuntimeException)
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     update_( Status );
404*cdf0e10cSrcweir     if (m_xLogFile.is())
405*cdf0e10cSrcweir         m_xLogFile->update( Status );
406*cdf0e10cSrcweir }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir //______________________________________________________________________________
409*cdf0e10cSrcweir void CommandEnvironmentImpl::pop() throw (RuntimeException)
410*cdf0e10cSrcweir {
411*cdf0e10cSrcweir     OSL_ASSERT( m_logLevel > 0 );
412*cdf0e10cSrcweir     --m_logLevel;
413*cdf0e10cSrcweir     if (m_xLogFile.is())
414*cdf0e10cSrcweir         m_xLogFile->pop();
415*cdf0e10cSrcweir }
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir } // anon namespace
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir namespace unopkg {
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir //==============================================================================
423*cdf0e10cSrcweir Reference< XCommandEnvironment > createCmdEnv(
424*cdf0e10cSrcweir     Reference< XComponentContext > const & xContext,
425*cdf0e10cSrcweir     OUString const & logFile,
426*cdf0e10cSrcweir     bool option_force_overwrite,
427*cdf0e10cSrcweir     bool option_verbose)
428*cdf0e10cSrcweir {
429*cdf0e10cSrcweir     return new CommandEnvironmentImpl(
430*cdf0e10cSrcweir         xContext, logFile, option_force_overwrite, option_verbose);
431*cdf0e10cSrcweir }
432*cdf0e10cSrcweir } // unopkg
433*cdf0e10cSrcweir 
434