2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-15 17:28:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-04-13 11:07:02 +00:00
|
|
|
|
|
|
|
#include "dp_misc.h"
|
2010-05-28 17:50:38 +02:00
|
|
|
#include "dp_version.hxx"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "dp_interact.h"
|
2004-04-13 11:07:02 +00:00
|
|
|
#include "rtl/uri.hxx"
|
|
|
|
#include "rtl/digest.h"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "rtl/random.h"
|
|
|
|
#include "rtl/bootstrap.hxx"
|
2006-09-13 10:51:22 +00:00
|
|
|
#include "unotools/bootstrap.hxx"
|
2004-04-13 11:07:02 +00:00
|
|
|
#include "osl/file.hxx"
|
|
|
|
#include "osl/pipe.hxx"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "osl/security.hxx"
|
|
|
|
#include "osl/thread.hxx"
|
|
|
|
#include "osl/mutex.hxx"
|
|
|
|
#include "com/sun/star/ucb/CommandAbortedException.hpp"
|
2010-05-12 16:11:41 +02:00
|
|
|
#include "com/sun/star/task/XInteractionHandler.hpp"
|
2012-10-30 17:11:59 +01:00
|
|
|
#include "com/sun/star/bridge/BridgeFactory.hpp"
|
2004-07-23 13:32:58 +00:00
|
|
|
#include "com/sun/star/bridge/UnoUrlResolver.hpp"
|
2004-06-11 11:09:03 +00:00
|
|
|
#include "com/sun/star/bridge/XUnoUrlResolver.hpp"
|
2010-04-19 11:33:33 +02:00
|
|
|
#include "com/sun/star/deployment/ExtensionManager.hpp"
|
2012-11-30 01:22:55 +01:00
|
|
|
#include "com/sun/star/task/OfficeRestartManager.hpp"
|
2004-11-09 13:09:07 +00:00
|
|
|
#include "boost/scoped_array.hpp"
|
|
|
|
#include "boost/shared_ptr.hpp"
|
2010-04-19 11:33:33 +02:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2011-05-25 08:53:52 +01:00
|
|
|
#include <salhelper/linkhelper.hxx>
|
2004-04-13 11:07:02 +00:00
|
|
|
|
2009-01-22 17:12:19 +00:00
|
|
|
#ifdef WNT
|
|
|
|
#define UNICODE
|
|
|
|
#define _UNICODE
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2011-07-21 23:33:35 +03:00
|
|
|
#include <windows.h>
|
2009-01-22 17:12:19 +00:00
|
|
|
#endif
|
2004-04-13 11:07:02 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
2004-11-09 13:09:07 +00:00
|
|
|
using ::rtl::OUString;
|
2009-01-22 17:12:19 +00:00
|
|
|
using ::rtl::OString;
|
2004-04-13 11:07:02 +00:00
|
|
|
|
2007-11-01 13:27:39 +00:00
|
|
|
|
|
|
|
#define SOFFICE1 "soffice.exe"
|
|
|
|
#define SOFFICE2 "soffice.bin"
|
|
|
|
#define SBASE "sbase.exe"
|
|
|
|
#define SCALC "scalc.exe"
|
|
|
|
#define SDRAW "sdraw.exe"
|
|
|
|
#define SIMPRESS "simpress.exe"
|
|
|
|
#define SWRITER "swriter.exe"
|
|
|
|
|
2004-08-12 11:08:13 +00:00
|
|
|
namespace dp_misc {
|
2004-11-09 13:09:07 +00:00
|
|
|
namespace {
|
2004-04-13 11:07:02 +00:00
|
|
|
|
2004-12-07 09:52:56 +00:00
|
|
|
struct UnoRc : public rtl::StaticWithInit<
|
2011-06-01 12:16:28 +01:00
|
|
|
boost::shared_ptr<rtl::Bootstrap>, UnoRc> {
|
2004-12-07 09:52:56 +00:00
|
|
|
const boost::shared_ptr<rtl::Bootstrap> operator () () {
|
2004-11-09 13:09:07 +00:00
|
|
|
OUString unorc( RTL_CONSTASCII_USTRINGPARAM(
|
2011-10-20 11:12:01 +02:00
|
|
|
"$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("uno")) );
|
2004-11-09 13:09:07 +00:00
|
|
|
::rtl::Bootstrap::expandMacros( unorc );
|
|
|
|
::boost::shared_ptr< ::rtl::Bootstrap > ret(
|
|
|
|
new ::rtl::Bootstrap( unorc ) );
|
|
|
|
OSL_ASSERT( ret->getHandle() != 0 );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-06-01 12:16:28 +01:00
|
|
|
struct OfficePipeId : public rtl::StaticWithInit<OUString, OfficePipeId> {
|
2004-12-07 09:52:56 +00:00
|
|
|
const OUString operator () ();
|
2004-11-09 13:09:07 +00:00
|
|
|
};
|
|
|
|
|
2004-12-07 09:52:56 +00:00
|
|
|
const OUString OfficePipeId::operator () ()
|
2004-11-09 13:09:07 +00:00
|
|
|
{
|
2006-09-13 10:51:22 +00:00
|
|
|
OUString userPath;
|
|
|
|
::utl::Bootstrap::PathStatus aLocateResult =
|
|
|
|
::utl::Bootstrap::locateUserInstallation( userPath );
|
|
|
|
if (!(aLocateResult == ::utl::Bootstrap::PATH_EXISTS ||
|
|
|
|
aLocateResult == ::utl::Bootstrap::PATH_VALID))
|
2004-11-09 13:09:07 +00:00
|
|
|
{
|
2006-09-13 10:51:22 +00:00
|
|
|
throw Exception(OUSTR("Extension Manager: Could not obtain path for UserInstallation."), 0);
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 );
|
2012-01-15 18:04:13 +01:00
|
|
|
if (!digest) {
|
2004-11-09 13:09:07 +00:00
|
|
|
throw RuntimeException(
|
|
|
|
OUSTR("cannot get digest rtl_Digest_AlgorithmMD5!"), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_uInt8 const * data =
|
|
|
|
reinterpret_cast<sal_uInt8 const *>(userPath.getStr());
|
|
|
|
sal_Size size = (userPath.getLength() * sizeof (sal_Unicode));
|
|
|
|
sal_uInt32 md5_key_len = rtl_digest_queryLength( digest );
|
|
|
|
::boost::scoped_array<sal_uInt8> md5_buf( new sal_uInt8 [ md5_key_len ] );
|
|
|
|
|
|
|
|
rtl_digest_init( digest, data, static_cast<sal_uInt32>(size) );
|
|
|
|
rtl_digest_update( digest, data, static_cast<sal_uInt32>(size) );
|
|
|
|
rtl_digest_get( digest, md5_buf.get(), md5_key_len );
|
|
|
|
rtl_digest_destroy( digest );
|
|
|
|
|
|
|
|
// create hex-value string from the MD5 value to keep
|
|
|
|
// the string size minimal
|
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SingleOfficeIPC_") );
|
|
|
|
for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) {
|
|
|
|
buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 );
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
2004-11-09 13:09:07 +00:00
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2007-11-01 13:27:39 +00:00
|
|
|
bool existsOfficePipe()
|
|
|
|
{
|
|
|
|
OUString const & pipeId = OfficePipeId::get();
|
2011-12-20 19:01:12 -02:00
|
|
|
if (pipeId.isEmpty())
|
2007-11-01 13:27:39 +00:00
|
|
|
return false;
|
|
|
|
::osl::Security sec;
|
|
|
|
::osl::Pipe pipe( pipeId, osl_Pipe_OPEN, sec );
|
|
|
|
return pipe.is();
|
|
|
|
}
|
|
|
|
|
2011-04-12 21:29:27 +01:00
|
|
|
//get modification time
|
|
|
|
static bool getModifyTimeTargetFile(const OUString &rFileURL, TimeValue &rTime)
|
|
|
|
{
|
2011-05-25 08:53:52 +01:00
|
|
|
salhelper::LinkResolver aResolver(osl_FileStatus_Mask_ModifyTime);
|
2011-04-12 21:29:27 +01:00
|
|
|
|
2011-05-25 08:53:52 +01:00
|
|
|
if (aResolver.fetchFileStatus(rFileURL) != osl::FileBase::E_None)
|
2011-04-12 21:29:27 +01:00
|
|
|
return false;
|
|
|
|
|
2011-05-25 08:53:52 +01:00
|
|
|
rTime = aResolver.m_aStatus.getModifyTime();
|
2011-04-12 21:29:27 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-04-19 11:33:33 +02:00
|
|
|
|
|
|
|
//Returns true if the Folder was more recently modified then
|
|
|
|
//the lastsynchronized file. That is the repository needs to
|
|
|
|
//be synchronized.
|
|
|
|
bool compareExtensionFolderWithLastSynchronizedFile(
|
|
|
|
OUString const & folderURL, OUString const & fileURL)
|
|
|
|
{
|
|
|
|
bool bNeedsSync = false;
|
|
|
|
::osl::DirectoryItem itemExtFolder;
|
|
|
|
::osl::File::RC err1 =
|
|
|
|
::osl::DirectoryItem::get(folderURL, itemExtFolder);
|
|
|
|
//If it does not exist, then there is nothing to be done
|
|
|
|
if (err1 == ::osl::File::E_NOENT)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (err1 != ::osl::File::E_None)
|
|
|
|
{
|
2011-03-12 12:08:22 +01:00
|
|
|
OSL_FAIL("Cannot access extension folder");
|
2010-04-19 11:33:33 +02:00
|
|
|
return true; //sync just in case
|
|
|
|
}
|
|
|
|
|
|
|
|
//If last synchronized does not exist, then OOo is started for the first time
|
|
|
|
::osl::DirectoryItem itemFile;
|
|
|
|
::osl::File::RC err2 = ::osl::DirectoryItem::get(fileURL, itemFile);
|
|
|
|
if (err2 == ::osl::File::E_NOENT)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (err2 != ::osl::File::E_None)
|
|
|
|
{
|
2011-03-12 12:08:22 +01:00
|
|
|
OSL_FAIL("Cannot access file lastsynchronized");
|
2010-04-19 11:33:33 +02:00
|
|
|
return true; //sync just in case
|
|
|
|
}
|
|
|
|
|
|
|
|
//compare the modification time of the extension folder and the last
|
|
|
|
//modified file
|
2011-04-12 21:29:27 +01:00
|
|
|
TimeValue timeFolder;
|
|
|
|
if (getModifyTimeTargetFile(folderURL, timeFolder))
|
2010-04-19 11:33:33 +02:00
|
|
|
{
|
2011-04-12 21:29:27 +01:00
|
|
|
TimeValue timeFile;
|
|
|
|
if (getModifyTimeTargetFile(fileURL, timeFile))
|
2010-04-19 11:33:33 +02:00
|
|
|
{
|
|
|
|
if (timeFile.Seconds < timeFolder.Seconds)
|
|
|
|
bNeedsSync = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ASSERT(0);
|
|
|
|
bNeedsSync = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ASSERT(0);
|
|
|
|
bNeedsSync = true;
|
|
|
|
}
|
2011-04-12 21:29:27 +01:00
|
|
|
|
2010-04-19 11:33:33 +02:00
|
|
|
return bNeedsSync;
|
|
|
|
}
|
|
|
|
|
2012-08-24 19:06:33 +02:00
|
|
|
bool needToSyncRepository(OUString const & name)
|
2010-04-19 11:33:33 +02:00
|
|
|
{
|
|
|
|
OUString folder;
|
|
|
|
OUString file;
|
2012-04-06 14:09:04 +02:00
|
|
|
if ( name == "bundled" )
|
2010-04-19 11:33:33 +02:00
|
|
|
{
|
|
|
|
folder = OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM("$BUNDLED_EXTENSIONS"));
|
|
|
|
file = OUString (
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"$BUNDLED_EXTENSIONS_USER/lastsynchronized"));
|
|
|
|
}
|
2012-04-06 14:09:04 +02:00
|
|
|
else if ( name == "shared" )
|
2010-04-19 11:33:33 +02:00
|
|
|
{
|
|
|
|
folder = OUString(
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"$UNO_SHARED_PACKAGES_CACHE/uno_packages"));
|
|
|
|
file = OUString (
|
|
|
|
RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"$SHARED_EXTENSIONS_USER/lastsynchronized"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSL_ASSERT(0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
::rtl::Bootstrap::expandMacros(folder);
|
|
|
|
::rtl::Bootstrap::expandMacros(file);
|
|
|
|
return compareExtensionFolderWithLastSynchronizedFile(
|
|
|
|
folder, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
//==============================================================================
|
2004-06-11 11:09:03 +00:00
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
namespace {
|
|
|
|
inline OUString encodeForRcFile( OUString const & str )
|
2004-06-11 11:09:03 +00:00
|
|
|
{
|
2004-11-09 13:09:07 +00:00
|
|
|
// escape $\{} (=> rtl bootstrap files)
|
2004-06-11 11:09:03 +00:00
|
|
|
::rtl::OUStringBuffer buf;
|
2004-11-09 13:09:07 +00:00
|
|
|
sal_Int32 pos = 0;
|
|
|
|
const sal_Int32 len = str.getLength();
|
|
|
|
for ( ; pos < len; ++pos ) {
|
|
|
|
sal_Unicode c = str[ pos ];
|
|
|
|
switch (c) {
|
|
|
|
case '$':
|
|
|
|
case '\\':
|
|
|
|
case '{':
|
|
|
|
case '}':
|
|
|
|
buf.append( static_cast<sal_Unicode>('\\') );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf.append( c );
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
|
|
|
|
//==============================================================================
|
2004-11-09 13:09:07 +00:00
|
|
|
OUString makeURL( OUString const & baseURL, OUString const & relPath_ )
|
2004-04-13 11:07:02 +00:00
|
|
|
{
|
2004-11-09 13:09:07 +00:00
|
|
|
::rtl::OUStringBuffer buf;
|
|
|
|
if (baseURL.getLength() > 1 && baseURL[ baseURL.getLength() - 1 ] == '/')
|
|
|
|
buf.append( baseURL.copy( 0, baseURL.getLength() - 1 ) );
|
|
|
|
else
|
|
|
|
buf.append( baseURL );
|
|
|
|
OUString relPath(relPath_);
|
2011-12-20 19:01:12 -02:00
|
|
|
if (!relPath.isEmpty() && relPath[ 0 ] == '/')
|
2004-11-09 13:09:07 +00:00
|
|
|
relPath = relPath.copy( 1 );
|
2011-12-20 19:01:12 -02:00
|
|
|
if (!relPath.isEmpty())
|
2004-11-09 13:09:07 +00:00
|
|
|
{
|
|
|
|
buf.append( static_cast<sal_Unicode>('/') );
|
|
|
|
if (baseURL.matchAsciiL(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) {
|
|
|
|
// encode for macro expansion: relPath is supposed to have no
|
|
|
|
// macros, so encode $, {} \ (bootstrap mimic)
|
|
|
|
relPath = encodeForRcFile(relPath);
|
|
|
|
|
|
|
|
// encode once more for vnd.sun.star.expand schema:
|
|
|
|
// vnd.sun.star.expand:$UNO_...
|
|
|
|
// will expand to file-url
|
|
|
|
relPath = ::rtl::Uri::encode( relPath, rtl_UriCharClassUric,
|
|
|
|
rtl_UriEncodeIgnoreEscapes,
|
|
|
|
RTL_TEXTENCODING_UTF8 );
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
2004-11-09 13:09:07 +00:00
|
|
|
buf.append( relPath );
|
|
|
|
}
|
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
2010-05-04 12:37:01 +02:00
|
|
|
OUString makeURLAppendSysPathSegment( OUString const & baseURL, OUString const & relPath_ )
|
|
|
|
{
|
|
|
|
OUString segment = relPath_;
|
|
|
|
OSL_ASSERT(segment.indexOf(static_cast<sal_Unicode>('/')) == -1);
|
|
|
|
|
|
|
|
::rtl::Uri::encode(
|
|
|
|
segment, rtl_UriCharClassPchar, rtl_UriEncodeIgnoreEscapes,
|
|
|
|
RTL_TEXTENCODING_UTF8);
|
|
|
|
return makeURL(baseURL, segment);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
//==============================================================================
|
|
|
|
OUString expandUnoRcTerm( OUString const & term_ )
|
|
|
|
{
|
|
|
|
OUString term(term_);
|
|
|
|
UnoRc::get()->expandMacrosFrom( term );
|
|
|
|
return term;
|
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
|
2010-05-07 17:02:22 +02:00
|
|
|
OUString makeRcTerm( OUString const & url )
|
|
|
|
{
|
|
|
|
OSL_ASSERT( url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM(
|
|
|
|
"vnd.sun.star.expand:") ) );
|
|
|
|
if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) {
|
|
|
|
// cut protocol:
|
|
|
|
OUString rcterm( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) );
|
|
|
|
// decode uric class chars:
|
|
|
|
rcterm = ::rtl::Uri::decode(
|
|
|
|
rcterm, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
|
|
|
|
return rcterm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
//==============================================================================
|
|
|
|
OUString expandUnoRcUrl( OUString const & url )
|
|
|
|
{
|
|
|
|
if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) {
|
2004-04-13 11:07:02 +00:00
|
|
|
// cut protocol:
|
2004-11-09 13:09:07 +00:00
|
|
|
OUString rcurl( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) );
|
2004-04-13 11:07:02 +00:00
|
|
|
// decode uric class chars:
|
2004-11-09 13:09:07 +00:00
|
|
|
rcurl = ::rtl::Uri::decode(
|
|
|
|
rcurl, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
|
2004-04-13 11:07:02 +00:00
|
|
|
// expand macro string:
|
2004-11-09 13:09:07 +00:00
|
|
|
UnoRc::get()->expandMacrosFrom( rcurl );
|
|
|
|
return rcurl;
|
|
|
|
}
|
|
|
|
else {
|
2004-04-13 11:07:02 +00:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
2004-06-11 11:09:03 +00:00
|
|
|
bool office_is_running()
|
2004-04-13 11:07:02 +00:00
|
|
|
{
|
2007-11-01 13:27:39 +00:00
|
|
|
//We need to check if we run within the office process. Then we must not use the pipe, because
|
|
|
|
//this could cause a deadlock. This is actually a workaround for i82778
|
|
|
|
OUString sFile;
|
|
|
|
oslProcessError err = osl_getExecutableFile(& sFile.pData);
|
|
|
|
bool ret = false;
|
|
|
|
if (osl_Process_E_None == err)
|
|
|
|
{
|
|
|
|
sFile = sFile.copy(sFile.lastIndexOf('/') + 1);
|
|
|
|
if (
|
|
|
|
#if defined UNIX
|
2012-04-06 14:09:04 +02:00
|
|
|
sFile == SOFFICE2
|
2011-05-21 16:26:08 +03:00
|
|
|
#elif defined WNT
|
2007-11-01 13:27:39 +00:00
|
|
|
//osl_getExecutableFile should deliver "soffice.bin" on windows
|
|
|
|
//even if swriter.exe, scalc.exe etc. was started. This is a bug
|
|
|
|
//in osl_getExecutableFile
|
2012-04-06 14:09:04 +02:00
|
|
|
sFile == SOFFICE1 || sFile == SOFFICE2 || sFile == SBASE || sFile == SCALC
|
|
|
|
|| sFile == SDRAW || sFile == SIMPRESS || sFile == SWRITER
|
2007-11-01 13:27:39 +00:00
|
|
|
#else
|
|
|
|
#error "Unsupported platform"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
)
|
|
|
|
ret = true;
|
|
|
|
else
|
|
|
|
ret = existsOfficePipe();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-12 12:08:22 +01:00
|
|
|
OSL_FAIL("NOT osl_Process_E_None ");
|
2007-11-01 13:27:39 +00:00
|
|
|
//if osl_getExecutable file than we take the risk of creating a pipe
|
|
|
|
ret = existsOfficePipe();
|
|
|
|
}
|
|
|
|
return ret;
|
2004-06-11 11:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
oslProcess raiseProcess(
|
|
|
|
OUString const & appURL, Sequence<OUString> const & args )
|
|
|
|
{
|
|
|
|
::osl::Security sec;
|
|
|
|
oslProcess hProcess = 0;
|
|
|
|
oslProcessError rc = osl_executeProcess(
|
2004-11-09 13:09:07 +00:00
|
|
|
appURL.pData,
|
|
|
|
reinterpret_cast<rtl_uString **>(
|
|
|
|
const_cast<OUString *>(args.getConstArray()) ),
|
|
|
|
args.getLength(),
|
2004-06-11 11:09:03 +00:00
|
|
|
osl_Process_DETACHED,
|
|
|
|
sec.getHandle(),
|
|
|
|
0, // => current working dir
|
|
|
|
0, 0, // => no env vars
|
|
|
|
&hProcess );
|
2004-04-13 11:07:02 +00:00
|
|
|
|
2004-08-12 11:08:13 +00:00
|
|
|
switch (rc) {
|
2004-06-11 11:09:03 +00:00
|
|
|
case osl_Process_E_None:
|
|
|
|
break;
|
|
|
|
case osl_Process_E_NotFound:
|
|
|
|
throw RuntimeException( OUSTR("image not found!"), 0 );
|
|
|
|
case osl_Process_E_TimedOut:
|
2010-12-04 13:16:21 +09:00
|
|
|
throw RuntimeException( OUSTR("timout occurred!"), 0 );
|
2004-06-11 11:09:03 +00:00
|
|
|
case osl_Process_E_NoPermission:
|
|
|
|
throw RuntimeException( OUSTR("permission denied!"), 0 );
|
|
|
|
case osl_Process_E_Unknown:
|
|
|
|
throw RuntimeException( OUSTR("unknown error!"), 0 );
|
|
|
|
case osl_Process_E_InvalidError:
|
|
|
|
default:
|
|
|
|
throw RuntimeException( OUSTR("unmapped error!"), 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return hProcess;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
OUString generateRandomPipeId()
|
|
|
|
{
|
|
|
|
// compute some good pipe id:
|
|
|
|
static rtlRandomPool s_hPool = rtl_random_createPool();
|
|
|
|
if (s_hPool == 0)
|
|
|
|
throw RuntimeException( OUSTR("cannot create random pool!?"), 0 );
|
|
|
|
sal_uInt8 bytes[ 32 ];
|
|
|
|
if (rtl_random_getBytes(
|
2004-11-09 13:09:07 +00:00
|
|
|
s_hPool, bytes, ARLEN(bytes) ) != rtl_Random_E_None) {
|
2004-06-11 11:09:03 +00:00
|
|
|
throw RuntimeException( OUSTR("random pool error!?"), 0 );
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
::rtl::OUStringBuffer buf;
|
2004-11-09 13:09:07 +00:00
|
|
|
for ( sal_uInt32 i = 0; i < ARLEN(bytes); ++i ) {
|
2004-06-11 11:09:03 +00:00
|
|
|
buf.append( static_cast<sal_Int32>(bytes[ i ]), 0x10 );
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-06-11 11:09:03 +00:00
|
|
|
return buf.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
Reference<XInterface> resolveUnoURL(
|
|
|
|
OUString const & connectString,
|
|
|
|
Reference<XComponentContext> const & xLocalContext,
|
|
|
|
AbortChannel * abortChannel )
|
|
|
|
{
|
|
|
|
Reference<bridge::XUnoUrlResolver> xUnoUrlResolver(
|
2004-07-23 13:32:58 +00:00
|
|
|
bridge::UnoUrlResolver::create( xLocalContext ) );
|
2004-06-11 11:09:03 +00:00
|
|
|
|
2004-11-09 13:09:07 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (abortChannel != 0 && abortChannel->isAborted()) {
|
2004-06-11 11:09:03 +00:00
|
|
|
throw ucb::CommandAbortedException(
|
|
|
|
OUSTR("abort!"), Reference<XInterface>() );
|
2004-11-09 13:09:07 +00:00
|
|
|
}
|
2004-08-12 11:08:13 +00:00
|
|
|
try {
|
2004-06-11 11:09:03 +00:00
|
|
|
return xUnoUrlResolver->resolve( connectString );
|
|
|
|
}
|
2011-12-06 00:19:44 +09:00
|
|
|
catch (const connection::NoConnectException &) {
|
2004-06-11 11:09:03 +00:00
|
|
|
TimeValue tv = { 0 /* secs */, 500000000 /* nanosecs */ };
|
|
|
|
::osl::Thread::wait( tv );
|
|
|
|
}
|
2004-04-13 11:07:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-22 17:12:19 +00:00
|
|
|
#ifdef WNT
|
|
|
|
void writeConsoleWithStream(::rtl::OUString const & sText, HANDLE stream)
|
|
|
|
{
|
|
|
|
DWORD nWrittenChars = 0;
|
|
|
|
WriteFile(stream, sText.getStr(),
|
|
|
|
sText.getLength() * 2, &nWrittenChars, NULL);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void writeConsoleWithStream(::rtl::OUString const & sText, FILE * stream)
|
|
|
|
{
|
|
|
|
OString s = OUStringToOString(sText, osl_getThreadTextEncoding());
|
|
|
|
fprintf(stream, "%s", s.getStr());
|
|
|
|
fflush(stream);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void writeConsole(::rtl::OUString const & sText)
|
|
|
|
{
|
|
|
|
#ifdef WNT
|
|
|
|
writeConsoleWithStream(sText, GetStdHandle(STD_OUTPUT_HANDLE));
|
|
|
|
#else
|
|
|
|
writeConsoleWithStream(sText, stdout);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeConsoleError(::rtl::OUString const & sText)
|
|
|
|
{
|
|
|
|
#ifdef WNT
|
|
|
|
writeConsoleWithStream(sText, GetStdHandle(STD_ERROR_HANDLE));
|
|
|
|
#else
|
|
|
|
writeConsoleWithStream(sText, stderr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString readConsole()
|
|
|
|
{
|
|
|
|
#ifdef WNT
|
|
|
|
sal_Unicode aBuffer[1024];
|
|
|
|
DWORD dwRead = 0;
|
|
|
|
//unopkg.com feeds unopkg.exe with wchar_t|s
|
|
|
|
if (ReadFile( GetStdHandle(STD_INPUT_HANDLE), &aBuffer, sizeof(aBuffer), &dwRead, NULL ) )
|
|
|
|
{
|
|
|
|
OSL_ASSERT((dwRead % 2) == 0);
|
|
|
|
OUString value( aBuffer, dwRead / 2);
|
2010-01-11 11:19:45 +01:00
|
|
|
return value.trim();
|
2009-01-22 17:12:19 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
char buf[1024];
|
2012-09-29 14:47:11 +02:00
|
|
|
memset(buf, 0, 1024);
|
2009-01-22 17:12:19 +00:00
|
|
|
// read one char less so that the last char in buf is always zero
|
2010-01-11 11:19:45 +01:00
|
|
|
if (fgets(buf, 1024, stdin) != NULL)
|
|
|
|
{
|
|
|
|
OUString value = ::rtl::OStringToOUString(::rtl::OString(buf), osl_getThreadTextEncoding());
|
|
|
|
return value.trim();
|
|
|
|
}
|
2009-01-22 17:12:19 +00:00
|
|
|
#endif
|
2010-01-11 11:19:45 +01:00
|
|
|
return OUString();
|
2009-01-22 17:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TRACE(::rtl::OUString const & sText)
|
|
|
|
{
|
|
|
|
(void) sText;
|
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
|
|
|
writeConsole(sText);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-04-24 19:16:06 +02:00
|
|
|
void syncRepositories(
|
2012-08-24 16:45:20 +02:00
|
|
|
bool force, Reference<ucb::XCommandEnvironment> const & xCmdEnv)
|
2010-05-04 12:37:01 +02:00
|
|
|
{
|
2010-07-02 14:21:42 +02:00
|
|
|
OUString sDisable;
|
|
|
|
::rtl::Bootstrap::get( OUSTR( "DISABLE_EXTENSION_SYNCHRONIZATION" ), sDisable, OUString() );
|
2011-12-20 19:01:12 -02:00
|
|
|
if (!sDisable.isEmpty())
|
2010-07-02 14:21:42 +02:00
|
|
|
return;
|
|
|
|
|
2010-04-19 11:33:33 +02:00
|
|
|
Reference<deployment::XExtensionManager> xExtensionManager;
|
|
|
|
//synchronize shared before bundled otherewise there are
|
|
|
|
//more revoke and registration calls.
|
2010-05-17 16:42:05 +02:00
|
|
|
sal_Bool bModified = false;
|
2012-08-24 16:45:20 +02:00
|
|
|
if (force
|
2012-08-24 19:06:33 +02:00
|
|
|
|| needToSyncRepository(OUString(RTL_CONSTASCII_USTRINGPARAM("shared")))
|
|
|
|
|| needToSyncRepository(OUString(RTL_CONSTASCII_USTRINGPARAM("bundled"))))
|
2010-05-04 12:37:01 +02:00
|
|
|
{
|
2010-04-19 11:33:33 +02:00
|
|
|
xExtensionManager =
|
|
|
|
deployment::ExtensionManager::get(
|
|
|
|
comphelper_getProcessComponentContext());
|
|
|
|
|
|
|
|
if (xExtensionManager.is())
|
|
|
|
{
|
2010-05-17 10:40:52 +02:00
|
|
|
bModified = xExtensionManager->synchronize(
|
2012-08-09 13:29:22 +02:00
|
|
|
Reference<task::XAbortChannel>(), xCmdEnv);
|
2010-04-19 11:33:33 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-12 16:11:41 +02:00
|
|
|
|
2010-05-17 10:40:52 +02:00
|
|
|
if (bModified)
|
2010-05-12 16:11:41 +02:00
|
|
|
{
|
2012-11-30 01:22:55 +01:00
|
|
|
Reference<task::XRestartManager> restarter(task::OfficeRestartManager::get(comphelper::getProcessComponentContext()));
|
2010-05-12 16:11:41 +02:00
|
|
|
if (restarter.is())
|
|
|
|
{
|
2010-10-29 18:05:32 +01:00
|
|
|
OSL_TRACE( "Request restart for modified extensions manager" );
|
2010-05-12 16:11:41 +02:00
|
|
|
restarter->requestRestart(xCmdEnv.is() == sal_True ? xCmdEnv->getInteractionHandler() :
|
|
|
|
Reference<task::XInteractionHandler>());
|
2010-05-17 10:40:52 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-04 12:37:01 +02:00
|
|
|
}
|
|
|
|
|
2012-10-30 17:11:59 +01:00
|
|
|
void disposeBridges(Reference<css::uno::XComponentContext> const & ctx)
|
|
|
|
{
|
|
|
|
if (!ctx.is())
|
|
|
|
return;
|
2010-04-19 11:33:33 +02:00
|
|
|
|
2012-10-30 17:11:59 +01:00
|
|
|
Reference<css::bridge::XBridgeFactory2> bridgeFac( css::bridge::BridgeFactory::create(ctx) );
|
|
|
|
|
|
|
|
const Sequence< Reference<css::bridge::XBridge> >seqBridges = bridgeFac->getExistingBridges();
|
|
|
|
for (sal_Int32 i = 0; i < seqBridges.getLength(); i++)
|
|
|
|
{
|
|
|
|
Reference<css::lang::XComponent> comp(seqBridges[i], UNO_QUERY);
|
|
|
|
if (comp.is())
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
comp->dispose();
|
|
|
|
}
|
|
|
|
catch ( const css::lang::DisposedException& )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-19 11:33:33 +02:00
|
|
|
|
2004-04-13 11:07:02 +00:00
|
|
|
}
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|