20 #include <config_folders.h>
21 #include <config_features.h>
23 #include <rtl/bootstrap.hxx>
24 #include <rtl/ustring.hxx>
34 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
35 #include <com/sun/star/ucb/CommandAbortedException.hpp>
36 #include <com/sun/star/ucb/CommandFailedException.hpp>
37 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/beans/NamedValue.hpp>
40 #include <com/sun/star/configuration/theDefaultProvider.hpp>
41 #include <com/sun/star/deployment/DeploymentException.hpp>
42 #include <com/sun/star/deployment/XPackage.hpp>
43 #include <com/sun/star/deployment/ExtensionManager.hpp>
44 #include <com/sun/star/deployment/LicenseException.hpp>
45 #include <com/sun/star/deployment/ui/LicenseDialog.hpp>
46 #include <com/sun/star/task/OfficeRestartManager.hpp>
47 #include <com/sun/star/task/XInteractionApprove.hpp>
48 #include <com/sun/star/task/XInteractionAbort.hpp>
49 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
50 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
51 #include <com/sun/star/util/XChangesBatch.hpp>
66 class SilentCommandEnv
67 :
public ::cppu::WeakImplHelper< ucb::XCommandEnvironment,
68 task::XInteractionHandler,
69 ucb::XProgressHandler >
71 uno::Reference<uno::XComponentContext>
mxContext;
78 uno::Reference<uno::XComponentContext>
const &
xContext,
80 virtual ~SilentCommandEnv()
override;
83 virtual uno::Reference<task::XInteractionHandler > SAL_CALL
84 getInteractionHandler()
override;
85 virtual uno::Reference<ucb::XProgressHandler >
86 SAL_CALL getProgressHandler()
override;
89 virtual void SAL_CALL handle(
90 uno::Reference<task::XInteractionRequest >
const & xRequest )
override;
95 virtual void SAL_CALL pop()
override;
99 SilentCommandEnv::SilentCommandEnv(
100 uno::Reference<uno::XComponentContext>
const &
xContext,
103 mpDesktop( pDesktop ),
109 SilentCommandEnv::~SilentCommandEnv()
112 mpDesktop->SetSplashScreenText(OUString());
131 deployment::LicenseException licExc;
133 uno::Any request( xRequest->getRequest() );
134 bool bApprove =
true;
136 if ( request >>= licExc )
138 uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
141 licExc.ExtensionName, licExc.Text ) );
142 sal_Int16 res = xDialog->execute();
143 if ( res == ui::dialogs::ExecutableDialogResults::CANCEL )
145 else if ( res == ui::dialogs::ExecutableDialogResults::OK )
154 uno::Sequence< Reference< task::XInteractionContinuation > > conts( xRequest->getContinuations() );
156 sal_Int32 len = conts.getLength();
158 for ( sal_Int32 pos = 0;
pos < len; ++
pos )
162 uno::Reference< task::XInteractionApprove > xInteractionApprove( pConts[ pos ], uno::UNO_QUERY );
163 if ( xInteractionApprove.is() )
164 xInteractionApprove->select();
168 uno::Reference< task::XInteractionAbort > xInteractionAbort( pConts[ pos ], uno::UNO_QUERY );
169 if ( xInteractionAbort.is() )
170 xInteractionAbort->select();
177 void SilentCommandEnv::push(
uno::Any const & rStatus )
182 if (mpDesktop && rStatus.
hasValue() && (rStatus >>= sText))
185 mpDesktop->SetSplashScreenText( sText );
187 mpDesktop->SetSplashScreenProgress( ++mnProgress );
195 if (mpDesktop && rStatus.
hasValue() && (rStatus >>= sText))
197 mpDesktop->SetSplashScreenText( sText );
202 void SilentCommandEnv::pop()
210 constexpr OUStringLiteral
aAccessSrvc =
u"com.sun.star.configuration.ConfigurationUpdateAccess";
214 uno::Reference< uno::XInterface > xService;
217 uno::Reference< lang::XMultiComponentFactory > xServiceManager( xContext->getServiceManager() );
218 if( !xServiceManager.is() )
219 throw uno::RuntimeException(
220 "impl_showExtensionDialog(): unable to obtain service manager from component context", uno::Reference< uno::XInterface > () );
222 xService = xServiceManager->createInstanceWithContext(
"com.sun.star.deployment.ui.UpdateRequiredDialog", xContext );
223 uno::Reference< ui::dialogs::XExecutableDialog > xExecutable( xService, uno::UNO_QUERY );
224 if ( xExecutable.is() )
225 nRet = xExecutable->execute();
235 uno::Sequence< uno::Sequence< uno::Reference< deployment::XPackage > > > xAllPackages;
236 uno::Reference< deployment::XExtensionManager > xExtensionManager = deployment::ExtensionManager::get( xContext );
238 if ( !xExtensionManager.is() )
240 SAL_WARN(
"desktop.app",
"Could not get the Extension Manager!" );
245 xAllPackages = xExtensionManager->getAllExtensions( uno::Reference< task::XAbortChannel >(),
246 uno::Reference< ucb::XCommandEnvironment >() );
248 catch (
const deployment::DeploymentException & ) {
return true; }
249 catch (
const ucb::CommandFailedException & ) {
return true; }
250 catch (
const ucb::CommandAbortedException & ) {
return true; }
251 catch (
const lang::IllegalArgumentException & e ) {
253 throw css::lang::WrappedTargetRuntimeException( e.Message,
258 sal_Int32
const nMax = 3;
260 sal_Int32
const nMax = 2;
263 for ( uno::Sequence< uno::Reference< deployment::XPackage > >
const & xPackageList : std::as_const(xAllPackages) )
265 for ( sal_Int32 j = 0; (j<nMax) && (j < xPackageList.getLength()); ++j )
267 uno::Reference< deployment::XPackage > xPackage = xPackageList[j];
270 bool bRegistered =
false;
272 beans::Optional< beans::Ambiguous< sal_Bool > >
option( xPackage->isRegistered( uno::Reference< task::XAbortChannel >(),
273 uno::Reference< ucb::XCommandEnvironment >() ) );
276 ::beans::Ambiguous< sal_Bool >
const & reg =
option.Value;
277 if ( reg.IsAmbiguous )
280 bRegistered = reg.Value;
285 catch (
const uno::RuntimeException & ) {
throw; }
286 catch (
const uno::Exception & ) {
292 bool bDependenciesValid =
false;
294 bDependenciesValid = xPackage->checkDependencies( uno::Reference< ucb::XCommandEnvironment >() );
296 catch (
const deployment::DeploymentException & ) {}
297 if ( ! bDependenciesValid )
315 configuration::theDefaultProvider::get(
319 beans::NamedValue
v(
"nodepath",
320 makeAny( OUString(
"org.openoffice.Setup/Office") ) );
323 theConfigProvider->createInstanceWithArguments( aAccessSrvc, theArgs ), UNO_QUERY_THROW );
327 pset->setPropertyValue(
"LastCompatibilityCheckID", value );
339 bool bNeedsCheck =
false;
340 OUString aLastCheckBuildID;
341 OUString aCurrentBuildID(
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE(
"version")
":buildid}" );
342 rtl::Bootstrap::expandMacros( aCurrentBuildID );
346 configuration::theDefaultProvider::get(
350 beans::NamedValue
v(
"nodepath",
351 makeAny( OUString(
"org.openoffice.Setup/Office") ) );
354 theConfigProvider->createInstanceWithArguments( aAccessSrvc, theArgs ), UNO_QUERY_THROW );
356 Any result = pset->getPropertyValue(
"LastCompatibilityCheckID");
358 result >>= aLastCheckBuildID;
359 if ( aLastCheckBuildID != aCurrentBuildID )
362 result <<= aCurrentBuildID;
363 pset->setPropertyValue(
"LastCompatibilityCheckID", result );
370 catch (
const css::uno::Exception&) {}
378 bool Desktop::CheckExtensionDependencies()
385 uno::Reference< uno::XComponentContext >
xContext(
392 if ( !bDependenciesValid )
404 void Desktop::SynchronizeExtensionRepositories(
bool bCleanedExtensionCache,
Desktop* pDesktop)
406 uno::Reference< uno::XComponentContext > context(
408 uno::Reference< ucb::XCommandEnvironment > silent(
409 new SilentCommandEnv(context, pDesktop));
410 if (bCleanedExtensionCache) {
411 deployment::ExtensionManager::get(context)->reinstallDeployedExtensions(
413 #if !HAVE_FEATURE_MACOSX_SANDBOX
415 task::OfficeRestartManager::get(context)->requestRestart(
416 silent->getInteractionHandler());
static bool impl_checkDependencies(const uno::Reference< uno::XComponentContext > &xContext)
void syncRepositories(bool force, Reference< ucb::XCommandEnvironment > const &xCmdEnv)
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)
constexpr OUStringLiteral aAccessSrvc
Any SAL_CALL getCaughtException()
static bool impl_needsCompatCheck()
#define SAL_CONFIGFILE(name)
#define TOOLS_WARN_EXCEPTION(area, stream)
static sal_Int16 impl_showExtensionDialog(uno::Reference< uno::XComponentContext > const &xContext)
static void impl_setNeedsCompatCheck()
static uno::Reference< css::uno::XComponentContext > xContext
Reference< XComponentContext > getProcessComponentContext()
#define SAL_WARN(area, stream)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)