28#include <com/sun/star/lang/IllegalArgumentException.hpp>
29#include <osl/file.hxx>
47 BackendImpl * getMyBackend()
const;
50 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
51 ::osl::ResettableMutexGuard & guard,
53 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
54 virtual void processPackage_(
55 ::osl::ResettableMutexGuard & guard,
59 Reference<XCommandEnvironment>
const & xCmdEnv )
override;
61 bool getFileAttributes(sal_uInt64& out_Attributes);
62 bool isUrlTargetInExtension()
const;
65 ExecutablePackageImpl(
67 OUString
const & url, OUString
const &
name,
68 Reference<deployment::XPackageTypeInfo>
const & xPackageType,
74 friend class ExecutablePackageImpl;
77 virtual Reference<deployment::XPackage> bindPackage_(
78 OUString
const & url, OUString
const & mediaType,
bool bRemoved,
79 OUString
const &
identifier, Reference<XCommandEnvironment>
const & xCmdEnv )
override;
81 void addDataToDb(OUString
const & url);
82 bool hasActiveEntry(std::u16string_view url);
83 void revokeEntryFromDb(std::u16string_view url);
88 BackendImpl( Sequence<Any>
const & args,
89 Reference<XComponentContext>
const & xComponentContext );
97 virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
98 getSupportedPackageTypes()
override;
99 virtual void SAL_CALL packageRemoved(OUString
const & url, OUString
const & mediaType)
override;
104BackendImpl::BackendImpl(
105 Sequence<Any>
const & args,
106 Reference<XComponentContext>
const & xComponentContext )
107 : PackageRegistryBackend(
args, xComponentContext ),
109 "application/vnd.sun.star.executable",
112 if (!transientMode())
114 OUString dbFile =
makeURL(getCachePath(),
"backenddb.xml");
121OUString BackendImpl::getImplementationName()
123 return "com.sun.star.comp.deployment.executable.PackageRegistryBackend";
126sal_Bool BackendImpl::supportsService(
const OUString& ServiceName )
131css::uno::Sequence< OUString > BackendImpl::getSupportedServiceNames()
136void BackendImpl::addDataToDb(OUString
const & url)
142void BackendImpl::revokeEntryFromDb(std::u16string_view url)
148bool BackendImpl::hasActiveEntry(std::u16string_view url)
157Sequence< Reference<deployment::XPackageTypeInfo> >
158BackendImpl::getSupportedPackageTypes()
160 return Sequence<Reference<deployment::XPackageTypeInfo> >(
164void BackendImpl::packageRemoved(OUString
const & url, OUString
const & )
171Reference<deployment::XPackage> BackendImpl::bindPackage_(
172 OUString
const & url, OUString
const & mediaType,
bool bRemoved,
173 OUString
const & identifier, Reference<XCommandEnvironment>
const & xCmdEnv )
175 if (mediaType.isEmpty())
177 throw lang::IllegalArgumentException(
178 StrCannotDetectMediaType() + url,
179 static_cast<OWeakObject *
>(
this),
static_cast<sal_Int16
>(-1) );
182 OUString
type, subType;
186 if (
type.equalsIgnoreAsciiCase(
"application"))
193 name = StrTitle::getTitle( ucbContent );
195 if (subType.equalsIgnoreAsciiCase(
"vnd.sun.star.executable"))
197 return new BackendImpl::ExecutablePackageImpl(
203 return Reference<deployment::XPackage>();
208BackendImpl * BackendImpl::ExecutablePackageImpl::getMyBackend()
const
210 BackendImpl * pBackend =
static_cast<BackendImpl *
>(m_myBackend.get());
211 if (
nullptr == pBackend)
217 static_cast<OWeakObject*
>(
const_cast<ExecutablePackageImpl *
>(
this)));
222beans::Optional< beans::Ambiguous<sal_Bool> >
223BackendImpl::ExecutablePackageImpl::isRegistered_(
224 ::osl::ResettableMutexGuard &,
226 Reference<XCommandEnvironment>
const & )
228 bool registered = getMyBackend()->hasActiveEntry(getURL());
229 return beans::Optional< beans::Ambiguous<sal_Bool> >(
231 beans::Ambiguous<sal_Bool>(
232 registered,
false ) );
235void BackendImpl::ExecutablePackageImpl::processPackage_(
236 ::osl::ResettableMutexGuard &,
237 bool doRegisterPackage,
240 Reference<XCommandEnvironment>
const & )
242 checkAborted(abortChannel);
243 if (doRegisterPackage)
245 if (!isUrlTargetInExtension())
250 sal_uInt64 attributes = 0;
252 if (getFileAttributes(attributes))
254 if(getMyBackend()->m_context ==
"user")
255 attributes |= osl_File_Attribute_OwnExe;
256 else if (getMyBackend()->m_context ==
"shared")
257 attributes |= (osl_File_Attribute_OwnExe | osl_File_Attribute_GrpExe
258 | osl_File_Attribute_OthExe);
259 else if (getMyBackend()->m_context !=
"bundled")
265 osl::File::setAttributes(
268 getMyBackend()->addDataToDb(getURL());
272 getMyBackend()->revokeEntryFromDb(getURL());
280bool BackendImpl::ExecutablePackageImpl::isUrlTargetInExtension()
const
282 bool bSuccess =
false;
283 OUString sExtensionDir;
284 if(getMyBackend()->m_context ==
"user")
286 else if (getMyBackend()->m_context ==
"shared")
288 else if (getMyBackend()->m_context ==
"bundled")
293 if (osl::File::E_None == osl::File::getAbsoluteFileURL(OUString(), sExtensionDir, sExtensionDir))
296 if (osl::File::E_None == osl::File::getAbsoluteFileURL(
299 if (sFile.match(sExtensionDir))
306bool BackendImpl::ExecutablePackageImpl::getFileAttributes(sal_uInt64& out_Attributes)
308 bool bSuccess =
false;
310 osl::DirectoryItem item;
311 if (osl::FileBase::E_None == osl::DirectoryItem::get(url, item))
313 osl::FileStatus aStatus(osl_FileStatus_Mask_Attributes);
314 if( osl::FileBase::E_None == item.getFileStatus(aStatus))
316 out_Attributes = aStatus.getAttributes();
329extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
331 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& args)
333 return cppu::acquire(
new dp_registry::backend::executable::BackendImpl(
args, context));
static bool parse(OUString const &rMediaType, OUString &rType, OUString &rSubType, INetContentTypeParameterList *pParameters=nullptr)
std::unique_ptr< ExecutableBackendDb > m_backendDb
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_deployment_executable_PackageRegistryBackend_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
Reference< deployment::XPackageTypeInfo > m_xExecutableTypeInfo
std::unordered_map< OString, INetContentTypeParameter > INetContentTypeParameterList
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString makeURL(std::u16string_view baseURL, OUString const &relPath_)
appends a relative path to a url.
OUString expandUnoRcUrl(OUString const &url)
OUString expandUnoRcTerm(OUString const &term_)
constexpr OUStringLiteral BACKEND_SERVICE_NAME
::boost::spirit::classic::rule< ScannerT > identifier