29#include <rtl/ustrbuf.hxx>
34#include <com/sun/star/lang/WrappedTargetException.hpp>
35#include <com/sun/star/task/XInteractionAbort.hpp>
36#include <com/sun/star/task/XInteractionApprove.hpp>
37#include <com/sun/star/deployment/DeploymentException.hpp>
38#include <com/sun/star/deployment/InstallException.hpp>
39#include <com/sun/star/deployment/LicenseException.hpp>
40#include <com/sun/star/deployment/VersionException.hpp>
41#include <com/sun/star/deployment/PlatformException.hpp>
42#include <com/sun/star/i18n/Collator.hpp>
43#include <com/sun/star/i18n/CollatorOptions.hpp>
56class CommandEnvironmentImpl
57 :
public ::cppu::WeakImplHelper< XCommandEnvironment,
58 task::XInteractionHandler,
62 bool m_option_force_overwrite;
63 bool m_option_verbose;
64 bool m_option_suppress_license;
66 Reference< XProgressHandler > m_xLogFile;
69 void update_( Any
const &
Status );
70 void printLicense(std::u16string_view sName,std::u16string_view sLicense,
71 bool & accept,
bool & decline);
74 virtual ~CommandEnvironmentImpl()
override;
75 CommandEnvironmentImpl(
76 Reference<XComponentContext>
const & xComponentContext,
77 bool option_force_overwrite,
79 bool option_suppress_license);
83 getInteractionHandler()
override;
84 virtual Reference< XProgressHandler > SAL_CALL getProgressHandler()
override;
87 virtual void SAL_CALL handle(
88 Reference< task::XInteractionRequest >
const & xRequest )
override;
91 virtual void SAL_CALL push( Any
const &
Status )
override;
92 virtual void SAL_CALL
update( Any
const &
Status )
override;
93 virtual void SAL_CALL pop()
override;
97CommandEnvironmentImpl::CommandEnvironmentImpl(
98 Reference<XComponentContext>
const & xComponentContext,
99 bool option_force_overwrite,
101 bool option_suppressLicense)
103 m_option_force_overwrite( option_force_overwrite ),
104 m_option_verbose( option_verbose ),
105 m_option_suppress_license( option_suppressLicense ),
109 xComponentContext->getServiceManager()
110 ->createInstanceWithArgumentsAndContext(
111 "com.sun.star.comp.deployment.ProgressLog",
112 Sequence<Any>(), xComponentContext ),
117CommandEnvironmentImpl::~CommandEnvironmentImpl()
130void CommandEnvironmentImpl::printLicense(
131 std::u16string_view sName, std::u16string_view sLicense,
bool & accept,
bool &decline)
133 OUString s1tmp(
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_1));
134 OUString s1(s1tmp.replaceAll(
"$NAME", sName));
135 OUString s2 =
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_2);
136 OUString s3 =
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_3);
137 OUString s4 =
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_4);
138 OUString sYES =
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_YES);
139 OUString sY =
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_Y);
140 OUString sNO =
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_NO);
141 OUString sN =
DpResId(RID_STR_UNOPKG_ACCEPT_LIC_N);
143 OUString sNewLine(
"\n");
151 Reference< css::i18n::XCollator > xCollator =
153 xCollator->loadDefaultCollator(
155 css::i18n::CollatorOptions::CollatorOptions_IGNORE_CASE);
160 if (xCollator->compareString(sAnswer, sYES) == 0
161 || xCollator->compareString(sAnswer, sY) == 0)
166 else if(xCollator->compareString(sAnswer, sNO) == 0
167 || xCollator->compareString(sAnswer, sN) == 0)
183CommandEnvironmentImpl::getInteractionHandler()
189Reference< XProgressHandler > CommandEnvironmentImpl::getProgressHandler()
196void CommandEnvironmentImpl::handle(
197 Reference<task::XInteractionRequest>
const & xRequest )
199 Any request( xRequest->getRequest() );
200 OSL_ASSERT( request.getValueTypeClass() == TypeClass_EXCEPTION );
202 + ::comphelper::anyToString(request) +
"\n\n");
205 bool approve =
false;
208 lang::WrappedTargetException wtExc;
209 deployment::LicenseException licExc;
210 deployment::InstallException instExc;
211 deployment::PlatformException platExc;
213 if (request >>= wtExc) {
216 const Reference<deployment::XPackage> xPackage(
217 wtExc.Context, UNO_QUERY );
218 OSL_ASSERT( xPackage.is() );
220 const Reference<deployment::XPackageTypeInfo> xPackageType(
221 xPackage->getPackageType() );
222 OSL_ASSERT( xPackageType.is() );
223 if (xPackageType.is()) {
224 approve = (xPackage->isBundle() &&
225 xPackageType->getMediaType().match(
226 "application/vnd.sun.star.legacy-package-bundle") );
232 request = wtExc.TargetException;
237 update_( wtExc.TargetException );
240 else if (request >>= licExc)
242 if ( !m_option_suppress_license )
243 printLicense(licExc.ExtensionName, licExc.Text, approve, abort);
250 else if (request >>= instExc)
256 else if (request >>= platExc)
258 OUString sMsg(
DpResId(RID_STR_UNSUPPORTED_PLATFORM));
259 sMsg = sMsg.replaceAll(
"%Name", platExc.package->getDisplayName());
264 deployment::VersionException nc_exc;
265 if (request >>= nc_exc) {
266 approve = m_option_force_overwrite ||
275 if (abort && m_option_verbose)
277 OUString msg = ::comphelper::anyToString(request);
282 const css::uno::Sequence<css::uno::Reference<css::task::XInteractionContinuation>> xIC = xRequest->getContinuations();
283 for (
auto const& rCont : xIC )
286 Reference<task::XInteractionApprove> xInteractionApprove(
288 if (xInteractionApprove.is()) {
289 xInteractionApprove->select();
294 Reference<task::XInteractionAbort> xInteractionAbort(
296 if (xInteractionAbort.is()) {
297 xInteractionAbort->select();
306void CommandEnvironmentImpl::push( Any
const &
Status )
309 OSL_ASSERT( m_logLevel >= 0 );
312 m_xLogFile->push(
Status );
316void CommandEnvironmentImpl::update_( Any
const &
Status )
320 bool bUseErr =
false;
323 if (! m_option_verbose)
327 OUStringBuffer buf(
"WARNING: " );
328 deployment::DeploymentException dp_exc;
330 buf.append( dp_exc.Message +
", Cause: " + ::comphelper::anyToString(dp_exc.Cause) );
333 buf.append( ::comphelper::anyToString(
Status) );
335 msg = buf.makeStringAndClear();
338 OSL_ASSERT( m_logLevel >= 0 );
339 for ( sal_Int32 n = 0;
n < m_logLevel; ++
n )
358 m_xLogFile->update(
Status );
362void CommandEnvironmentImpl::pop()
364 OSL_ASSERT( m_logLevel > 0 );
377 Reference< XComponentContext >
const &
xContext,
378 bool option_force_overwrite,
380 bool option_suppress_license)
382 return new CommandEnvironmentImpl(
383 xContext, option_force_overwrite, option_verbose, option_suppress_license);
static OUString getUILocale()
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XComponentContext > const m_xComponentContext
OUString DpResId(TranslateId aId)
static uno::Reference< css::uno::XComponentContext > xContext
const LanguageTag & getLocale()
OUString readConsole()
reads from the console.
void writeConsoleError(std::u16string_view sText)
writes the argument to the console using the error stream.
void TRACE(OUString const &sText)
print the text to the console in a debug build.
void writeConsole(std::u16string_view sText)
writes the argument string to the console.
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC Order compareVersions(std::u16string_view version1, std::u16string_view version2)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
Reference< XCommandEnvironment > createCmdEnv(Reference< XComponentContext > const &xContext, bool option_force_overwrite, bool option_verbose, bool option_suppress_license)