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