1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_desktop.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "dp_misc.h" 33*cdf0e10cSrcweir #include "dp_version.hxx" 34*cdf0e10cSrcweir #include "dp_interact.h" 35*cdf0e10cSrcweir #include "rtl/uri.hxx" 36*cdf0e10cSrcweir #include "rtl/digest.h" 37*cdf0e10cSrcweir #include "rtl/random.h" 38*cdf0e10cSrcweir #include "rtl/bootstrap.hxx" 39*cdf0e10cSrcweir #include "unotools/bootstrap.hxx" 40*cdf0e10cSrcweir #include "osl/file.hxx" 41*cdf0e10cSrcweir #include "osl/pipe.hxx" 42*cdf0e10cSrcweir #include "osl/security.hxx" 43*cdf0e10cSrcweir #include "osl/thread.hxx" 44*cdf0e10cSrcweir #include "osl/mutex.hxx" 45*cdf0e10cSrcweir #include "com/sun/star/ucb/CommandAbortedException.hpp" 46*cdf0e10cSrcweir #include "com/sun/star/task/XInteractionHandler.hpp" 47*cdf0e10cSrcweir #include "com/sun/star/bridge/UnoUrlResolver.hpp" 48*cdf0e10cSrcweir #include "com/sun/star/bridge/XUnoUrlResolver.hpp" 49*cdf0e10cSrcweir #include "com/sun/star/deployment/ExtensionManager.hpp" 50*cdf0e10cSrcweir #include "com/sun/star/task/XRestartManager.hpp" 51*cdf0e10cSrcweir #include "boost/scoped_array.hpp" 52*cdf0e10cSrcweir #include "boost/shared_ptr.hpp" 53*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir #ifdef WNT 56*cdf0e10cSrcweir //#include "tools/prewin.h" 57*cdf0e10cSrcweir #define UNICODE 58*cdf0e10cSrcweir #define _UNICODE 59*cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN 60*cdf0e10cSrcweir #include <Windows.h> 61*cdf0e10cSrcweir //#include "tools/postwin.h" 62*cdf0e10cSrcweir #endif 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir using namespace ::com::sun::star; 65*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 66*cdf0e10cSrcweir using ::rtl::OUString; 67*cdf0e10cSrcweir using ::rtl::OString; 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir #define SOFFICE1 "soffice.exe" 71*cdf0e10cSrcweir #define SOFFICE2 "soffice.bin" 72*cdf0e10cSrcweir #define SBASE "sbase.exe" 73*cdf0e10cSrcweir #define SCALC "scalc.exe" 74*cdf0e10cSrcweir #define SDRAW "sdraw.exe" 75*cdf0e10cSrcweir #define SIMPRESS "simpress.exe" 76*cdf0e10cSrcweir #define SWRITER "swriter.exe" 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir namespace dp_misc { 79*cdf0e10cSrcweir namespace { 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir struct UnoRc : public rtl::StaticWithInit< 82*cdf0e10cSrcweir const boost::shared_ptr<rtl::Bootstrap>, UnoRc> { 83*cdf0e10cSrcweir const boost::shared_ptr<rtl::Bootstrap> operator () () { 84*cdf0e10cSrcweir OUString unorc( RTL_CONSTASCII_USTRINGPARAM( 85*cdf0e10cSrcweir "$OOO_BASE_DIR/program/" SAL_CONFIGFILE("uno")) ); 86*cdf0e10cSrcweir ::rtl::Bootstrap::expandMacros( unorc ); 87*cdf0e10cSrcweir ::boost::shared_ptr< ::rtl::Bootstrap > ret( 88*cdf0e10cSrcweir new ::rtl::Bootstrap( unorc ) ); 89*cdf0e10cSrcweir OSL_ASSERT( ret->getHandle() != 0 ); 90*cdf0e10cSrcweir return ret; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir }; 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir struct OfficePipeId : public rtl::StaticWithInit<const OUString, OfficePipeId> { 95*cdf0e10cSrcweir const OUString operator () (); 96*cdf0e10cSrcweir }; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir const OUString OfficePipeId::operator () () 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir OUString userPath; 101*cdf0e10cSrcweir ::utl::Bootstrap::PathStatus aLocateResult = 102*cdf0e10cSrcweir ::utl::Bootstrap::locateUserInstallation( userPath ); 103*cdf0e10cSrcweir if (!(aLocateResult == ::utl::Bootstrap::PATH_EXISTS || 104*cdf0e10cSrcweir aLocateResult == ::utl::Bootstrap::PATH_VALID)) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir throw Exception(OUSTR("Extension Manager: Could not obtain path for UserInstallation."), 0); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir rtlDigest digest = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); 110*cdf0e10cSrcweir if (digest <= 0) { 111*cdf0e10cSrcweir throw RuntimeException( 112*cdf0e10cSrcweir OUSTR("cannot get digest rtl_Digest_AlgorithmMD5!"), 0 ); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir sal_uInt8 const * data = 116*cdf0e10cSrcweir reinterpret_cast<sal_uInt8 const *>(userPath.getStr()); 117*cdf0e10cSrcweir sal_Size size = (userPath.getLength() * sizeof (sal_Unicode)); 118*cdf0e10cSrcweir sal_uInt32 md5_key_len = rtl_digest_queryLength( digest ); 119*cdf0e10cSrcweir ::boost::scoped_array<sal_uInt8> md5_buf( new sal_uInt8 [ md5_key_len ] ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir rtl_digest_init( digest, data, static_cast<sal_uInt32>(size) ); 122*cdf0e10cSrcweir rtl_digest_update( digest, data, static_cast<sal_uInt32>(size) ); 123*cdf0e10cSrcweir rtl_digest_get( digest, md5_buf.get(), md5_key_len ); 124*cdf0e10cSrcweir rtl_digest_destroy( digest ); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir // create hex-value string from the MD5 value to keep 127*cdf0e10cSrcweir // the string size minimal 128*cdf0e10cSrcweir ::rtl::OUStringBuffer buf; 129*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("SingleOfficeIPC_") ); 130*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < md5_key_len; ++i ) { 131*cdf0e10cSrcweir buf.append( static_cast<sal_Int32>(md5_buf[ i ]), 0x10 ); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir return buf.makeStringAndClear(); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir bool existsOfficePipe() 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir OUString const & pipeId = OfficePipeId::get(); 139*cdf0e10cSrcweir if (pipeId.getLength() == 0) 140*cdf0e10cSrcweir return false; 141*cdf0e10cSrcweir ::osl::Security sec; 142*cdf0e10cSrcweir ::osl::Pipe pipe( pipeId, osl_Pipe_OPEN, sec ); 143*cdf0e10cSrcweir return pipe.is(); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir //Returns true if the Folder was more recently modified then 148*cdf0e10cSrcweir //the lastsynchronized file. That is the repository needs to 149*cdf0e10cSrcweir //be synchronized. 150*cdf0e10cSrcweir bool compareExtensionFolderWithLastSynchronizedFile( 151*cdf0e10cSrcweir OUString const & folderURL, OUString const & fileURL) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir bool bNeedsSync = false; 154*cdf0e10cSrcweir ::osl::DirectoryItem itemExtFolder; 155*cdf0e10cSrcweir ::osl::File::RC err1 = 156*cdf0e10cSrcweir ::osl::DirectoryItem::get(folderURL, itemExtFolder); 157*cdf0e10cSrcweir //If it does not exist, then there is nothing to be done 158*cdf0e10cSrcweir if (err1 == ::osl::File::E_NOENT) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir return false; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir else if (err1 != ::osl::File::E_None) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir OSL_ENSURE(0, "Cannot access extension folder"); 165*cdf0e10cSrcweir return true; //sync just in case 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir //If last synchronized does not exist, then OOo is started for the first time 169*cdf0e10cSrcweir ::osl::DirectoryItem itemFile; 170*cdf0e10cSrcweir ::osl::File::RC err2 = ::osl::DirectoryItem::get(fileURL, itemFile); 171*cdf0e10cSrcweir if (err2 == ::osl::File::E_NOENT) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir return true; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir else if (err2 != ::osl::File::E_None) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir OSL_ENSURE(0, "Cannot access file lastsynchronized"); 179*cdf0e10cSrcweir return true; //sync just in case 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //compare the modification time of the extension folder and the last 183*cdf0e10cSrcweir //modified file 184*cdf0e10cSrcweir ::osl::FileStatus statFolder(FileStatusMask_ModifyTime); 185*cdf0e10cSrcweir ::osl::FileStatus statFile(FileStatusMask_ModifyTime); 186*cdf0e10cSrcweir if (itemExtFolder.getFileStatus(statFolder) == ::osl::File::E_None) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir if (itemFile.getFileStatus(statFile) == ::osl::File::E_None) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir TimeValue timeFolder = statFolder.getModifyTime(); 191*cdf0e10cSrcweir TimeValue timeFile = statFile.getModifyTime(); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir if (timeFile.Seconds < timeFolder.Seconds) 194*cdf0e10cSrcweir bNeedsSync = true; 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir else 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir OSL_ASSERT(0); 199*cdf0e10cSrcweir bNeedsSync = true; 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir else 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir OSL_ASSERT(0); 205*cdf0e10cSrcweir bNeedsSync = true; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir return bNeedsSync; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir bool needToSyncRepostitory(OUString const & name) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir OUString folder; 213*cdf0e10cSrcweir OUString file; 214*cdf0e10cSrcweir if (name.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("bundled")))) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir folder = OUString( 217*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("$BUNDLED_EXTENSIONS")); 218*cdf0e10cSrcweir file = OUString ( 219*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 220*cdf0e10cSrcweir "$BUNDLED_EXTENSIONS_USER/lastsynchronized")); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir else if (name.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("shared")))) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir folder = OUString( 225*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 226*cdf0e10cSrcweir "$UNO_SHARED_PACKAGES_CACHE/uno_packages")); 227*cdf0e10cSrcweir file = OUString ( 228*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 229*cdf0e10cSrcweir "$SHARED_EXTENSIONS_USER/lastsynchronized")); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir else 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir OSL_ASSERT(0); 234*cdf0e10cSrcweir return true; 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir ::rtl::Bootstrap::expandMacros(folder); 237*cdf0e10cSrcweir ::rtl::Bootstrap::expandMacros(file); 238*cdf0e10cSrcweir return compareExtensionFolderWithLastSynchronizedFile( 239*cdf0e10cSrcweir folder, file); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir } // anon namespace 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir //============================================================================== 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir namespace { 248*cdf0e10cSrcweir inline OUString encodeForRcFile( OUString const & str ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir // escape $\{} (=> rtl bootstrap files) 251*cdf0e10cSrcweir ::rtl::OUStringBuffer buf; 252*cdf0e10cSrcweir sal_Int32 pos = 0; 253*cdf0e10cSrcweir const sal_Int32 len = str.getLength(); 254*cdf0e10cSrcweir for ( ; pos < len; ++pos ) { 255*cdf0e10cSrcweir sal_Unicode c = str[ pos ]; 256*cdf0e10cSrcweir switch (c) { 257*cdf0e10cSrcweir case '$': 258*cdf0e10cSrcweir case '\\': 259*cdf0e10cSrcweir case '{': 260*cdf0e10cSrcweir case '}': 261*cdf0e10cSrcweir buf.append( static_cast<sal_Unicode>('\\') ); 262*cdf0e10cSrcweir break; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir buf.append( c ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir return buf.makeStringAndClear(); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir //============================================================================== 271*cdf0e10cSrcweir OUString makeURL( OUString const & baseURL, OUString const & relPath_ ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir ::rtl::OUStringBuffer buf; 274*cdf0e10cSrcweir if (baseURL.getLength() > 1 && baseURL[ baseURL.getLength() - 1 ] == '/') 275*cdf0e10cSrcweir buf.append( baseURL.copy( 0, baseURL.getLength() - 1 ) ); 276*cdf0e10cSrcweir else 277*cdf0e10cSrcweir buf.append( baseURL ); 278*cdf0e10cSrcweir OUString relPath(relPath_); 279*cdf0e10cSrcweir if (relPath.getLength() > 0 && relPath[ 0 ] == '/') 280*cdf0e10cSrcweir relPath = relPath.copy( 1 ); 281*cdf0e10cSrcweir if (relPath.getLength() > 0) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir buf.append( static_cast<sal_Unicode>('/') ); 284*cdf0e10cSrcweir if (baseURL.matchAsciiL( 285*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) { 286*cdf0e10cSrcweir // encode for macro expansion: relPath is supposed to have no 287*cdf0e10cSrcweir // macros, so encode $, {} \ (bootstrap mimic) 288*cdf0e10cSrcweir relPath = encodeForRcFile(relPath); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir // encode once more for vnd.sun.star.expand schema: 291*cdf0e10cSrcweir // vnd.sun.star.expand:$UNO_... 292*cdf0e10cSrcweir // will expand to file-url 293*cdf0e10cSrcweir relPath = ::rtl::Uri::encode( relPath, rtl_UriCharClassUric, 294*cdf0e10cSrcweir rtl_UriEncodeIgnoreEscapes, 295*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8 ); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir buf.append( relPath ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir return buf.makeStringAndClear(); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir OUString makeURLAppendSysPathSegment( OUString const & baseURL, OUString const & relPath_ ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir OUString segment = relPath_; 305*cdf0e10cSrcweir OSL_ASSERT(segment.indexOf(static_cast<sal_Unicode>('/')) == -1); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir ::rtl::Uri::encode( 308*cdf0e10cSrcweir segment, rtl_UriCharClassPchar, rtl_UriEncodeIgnoreEscapes, 309*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8); 310*cdf0e10cSrcweir return makeURL(baseURL, segment); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir //============================================================================== 316*cdf0e10cSrcweir OUString expandUnoRcTerm( OUString const & term_ ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir OUString term(term_); 319*cdf0e10cSrcweir UnoRc::get()->expandMacrosFrom( term ); 320*cdf0e10cSrcweir return term; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir OUString makeRcTerm( OUString const & url ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir OSL_ASSERT( url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( 326*cdf0e10cSrcweir "vnd.sun.star.expand:") ) ); 327*cdf0e10cSrcweir if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) { 328*cdf0e10cSrcweir // cut protocol: 329*cdf0e10cSrcweir OUString rcterm( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) ); 330*cdf0e10cSrcweir // decode uric class chars: 331*cdf0e10cSrcweir rcterm = ::rtl::Uri::decode( 332*cdf0e10cSrcweir rcterm, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); 333*cdf0e10cSrcweir return rcterm; 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir else 336*cdf0e10cSrcweir return url; 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir //============================================================================== 340*cdf0e10cSrcweir OUString expandUnoRcUrl( OUString const & url ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) { 343*cdf0e10cSrcweir // cut protocol: 344*cdf0e10cSrcweir OUString rcurl( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) ); 345*cdf0e10cSrcweir // decode uric class chars: 346*cdf0e10cSrcweir rcurl = ::rtl::Uri::decode( 347*cdf0e10cSrcweir rcurl, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); 348*cdf0e10cSrcweir // expand macro string: 349*cdf0e10cSrcweir UnoRc::get()->expandMacrosFrom( rcurl ); 350*cdf0e10cSrcweir return rcurl; 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir else { 353*cdf0e10cSrcweir return url; 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //============================================================================== 358*cdf0e10cSrcweir bool office_is_running() 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir //We need to check if we run within the office process. Then we must not use the pipe, because 361*cdf0e10cSrcweir //this could cause a deadlock. This is actually a workaround for i82778 362*cdf0e10cSrcweir OUString sFile; 363*cdf0e10cSrcweir oslProcessError err = osl_getExecutableFile(& sFile.pData); 364*cdf0e10cSrcweir bool ret = false; 365*cdf0e10cSrcweir if (osl_Process_E_None == err) 366*cdf0e10cSrcweir { 367*cdf0e10cSrcweir sFile = sFile.copy(sFile.lastIndexOf('/') + 1); 368*cdf0e10cSrcweir if ( 369*cdf0e10cSrcweir #if defined UNIX 370*cdf0e10cSrcweir sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SOFFICE2))) 371*cdf0e10cSrcweir #elif defined WNT || defined OS2 372*cdf0e10cSrcweir //osl_getExecutableFile should deliver "soffice.bin" on windows 373*cdf0e10cSrcweir //even if swriter.exe, scalc.exe etc. was started. This is a bug 374*cdf0e10cSrcweir //in osl_getExecutableFile 375*cdf0e10cSrcweir sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SOFFICE1))) 376*cdf0e10cSrcweir || sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SOFFICE2))) 377*cdf0e10cSrcweir || sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SBASE))) 378*cdf0e10cSrcweir || sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SCALC))) 379*cdf0e10cSrcweir || sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SDRAW))) 380*cdf0e10cSrcweir || sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SIMPRESS))) 381*cdf0e10cSrcweir || sFile.equals(OUString(RTL_CONSTASCII_USTRINGPARAM(SWRITER))) 382*cdf0e10cSrcweir #else 383*cdf0e10cSrcweir #error "Unsupported platform" 384*cdf0e10cSrcweir #endif 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir ) 387*cdf0e10cSrcweir ret = true; 388*cdf0e10cSrcweir else 389*cdf0e10cSrcweir ret = existsOfficePipe(); 390*cdf0e10cSrcweir } 391*cdf0e10cSrcweir else 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir OSL_ENSURE(0, "NOT osl_Process_E_None "); 394*cdf0e10cSrcweir //if osl_getExecutable file than we take the risk of creating a pipe 395*cdf0e10cSrcweir ret = existsOfficePipe(); 396*cdf0e10cSrcweir } 397*cdf0e10cSrcweir return ret; 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir //============================================================================== 401*cdf0e10cSrcweir oslProcess raiseProcess( 402*cdf0e10cSrcweir OUString const & appURL, Sequence<OUString> const & args ) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir ::osl::Security sec; 405*cdf0e10cSrcweir oslProcess hProcess = 0; 406*cdf0e10cSrcweir oslProcessError rc = osl_executeProcess( 407*cdf0e10cSrcweir appURL.pData, 408*cdf0e10cSrcweir reinterpret_cast<rtl_uString **>( 409*cdf0e10cSrcweir const_cast<OUString *>(args.getConstArray()) ), 410*cdf0e10cSrcweir args.getLength(), 411*cdf0e10cSrcweir osl_Process_DETACHED, 412*cdf0e10cSrcweir sec.getHandle(), 413*cdf0e10cSrcweir 0, // => current working dir 414*cdf0e10cSrcweir 0, 0, // => no env vars 415*cdf0e10cSrcweir &hProcess ); 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir switch (rc) { 418*cdf0e10cSrcweir case osl_Process_E_None: 419*cdf0e10cSrcweir break; 420*cdf0e10cSrcweir case osl_Process_E_NotFound: 421*cdf0e10cSrcweir throw RuntimeException( OUSTR("image not found!"), 0 ); 422*cdf0e10cSrcweir case osl_Process_E_TimedOut: 423*cdf0e10cSrcweir throw RuntimeException( OUSTR("timout occured!"), 0 ); 424*cdf0e10cSrcweir case osl_Process_E_NoPermission: 425*cdf0e10cSrcweir throw RuntimeException( OUSTR("permission denied!"), 0 ); 426*cdf0e10cSrcweir case osl_Process_E_Unknown: 427*cdf0e10cSrcweir throw RuntimeException( OUSTR("unknown error!"), 0 ); 428*cdf0e10cSrcweir case osl_Process_E_InvalidError: 429*cdf0e10cSrcweir default: 430*cdf0e10cSrcweir throw RuntimeException( OUSTR("unmapped error!"), 0 ); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir return hProcess; 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir //============================================================================== 437*cdf0e10cSrcweir OUString generateRandomPipeId() 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir // compute some good pipe id: 440*cdf0e10cSrcweir static rtlRandomPool s_hPool = rtl_random_createPool(); 441*cdf0e10cSrcweir if (s_hPool == 0) 442*cdf0e10cSrcweir throw RuntimeException( OUSTR("cannot create random pool!?"), 0 ); 443*cdf0e10cSrcweir sal_uInt8 bytes[ 32 ]; 444*cdf0e10cSrcweir if (rtl_random_getBytes( 445*cdf0e10cSrcweir s_hPool, bytes, ARLEN(bytes) ) != rtl_Random_E_None) { 446*cdf0e10cSrcweir throw RuntimeException( OUSTR("random pool error!?"), 0 ); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir ::rtl::OUStringBuffer buf; 449*cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < ARLEN(bytes); ++i ) { 450*cdf0e10cSrcweir buf.append( static_cast<sal_Int32>(bytes[ i ]), 0x10 ); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir return buf.makeStringAndClear(); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir //============================================================================== 456*cdf0e10cSrcweir Reference<XInterface> resolveUnoURL( 457*cdf0e10cSrcweir OUString const & connectString, 458*cdf0e10cSrcweir Reference<XComponentContext> const & xLocalContext, 459*cdf0e10cSrcweir AbortChannel * abortChannel ) 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir Reference<bridge::XUnoUrlResolver> xUnoUrlResolver( 462*cdf0e10cSrcweir bridge::UnoUrlResolver::create( xLocalContext ) ); 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir for (;;) 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir if (abortChannel != 0 && abortChannel->isAborted()) { 467*cdf0e10cSrcweir throw ucb::CommandAbortedException( 468*cdf0e10cSrcweir OUSTR("abort!"), Reference<XInterface>() ); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir try { 471*cdf0e10cSrcweir return xUnoUrlResolver->resolve( connectString ); 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir catch (connection::NoConnectException &) { 474*cdf0e10cSrcweir TimeValue tv = { 0 /* secs */, 500000000 /* nanosecs */ }; 475*cdf0e10cSrcweir ::osl::Thread::wait( tv ); 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir #ifdef WNT 481*cdf0e10cSrcweir void writeConsoleWithStream(::rtl::OUString const & sText, HANDLE stream) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir DWORD nWrittenChars = 0; 484*cdf0e10cSrcweir WriteFile(stream, sText.getStr(), 485*cdf0e10cSrcweir sText.getLength() * 2, &nWrittenChars, NULL); 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir #else 488*cdf0e10cSrcweir void writeConsoleWithStream(::rtl::OUString const & sText, FILE * stream) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir OString s = OUStringToOString(sText, osl_getThreadTextEncoding()); 491*cdf0e10cSrcweir fprintf(stream, "%s", s.getStr()); 492*cdf0e10cSrcweir fflush(stream); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir #endif 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir #ifdef WNT 497*cdf0e10cSrcweir void writeConsoleWithStream(::rtl::OString const & sText, HANDLE stream) 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir writeConsoleWithStream(OStringToOUString( 500*cdf0e10cSrcweir sText, RTL_TEXTENCODING_UTF8), stream); 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir #else 503*cdf0e10cSrcweir void writeConsoleWithStream(::rtl::OString const & sText, FILE * stream) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir fprintf(stream, "%s", sText.getStr()); 506*cdf0e10cSrcweir fflush(stream); 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir #endif 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir void writeConsole(::rtl::OUString const & sText) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir #ifdef WNT 513*cdf0e10cSrcweir writeConsoleWithStream(sText, GetStdHandle(STD_OUTPUT_HANDLE)); 514*cdf0e10cSrcweir #else 515*cdf0e10cSrcweir writeConsoleWithStream(sText, stdout); 516*cdf0e10cSrcweir #endif 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir void writeConsole(::rtl::OString const & sText) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir #ifdef WNT 522*cdf0e10cSrcweir writeConsoleWithStream(sText, GetStdHandle(STD_OUTPUT_HANDLE)); 523*cdf0e10cSrcweir #else 524*cdf0e10cSrcweir writeConsoleWithStream(sText, stdout); 525*cdf0e10cSrcweir #endif 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir void writeConsoleError(::rtl::OUString const & sText) 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir #ifdef WNT 531*cdf0e10cSrcweir writeConsoleWithStream(sText, GetStdHandle(STD_ERROR_HANDLE)); 532*cdf0e10cSrcweir #else 533*cdf0e10cSrcweir writeConsoleWithStream(sText, stderr); 534*cdf0e10cSrcweir #endif 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir void writeConsoleError(::rtl::OString const & sText) 539*cdf0e10cSrcweir { 540*cdf0e10cSrcweir #ifdef WNT 541*cdf0e10cSrcweir writeConsoleWithStream(sText, GetStdHandle(STD_ERROR_HANDLE)); 542*cdf0e10cSrcweir #else 543*cdf0e10cSrcweir writeConsoleWithStream(sText, stderr); 544*cdf0e10cSrcweir #endif 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir OUString readConsole() 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir #ifdef WNT 552*cdf0e10cSrcweir sal_Unicode aBuffer[1024]; 553*cdf0e10cSrcweir DWORD dwRead = 0; 554*cdf0e10cSrcweir //unopkg.com feeds unopkg.exe with wchar_t|s 555*cdf0e10cSrcweir if (ReadFile( GetStdHandle(STD_INPUT_HANDLE), &aBuffer, sizeof(aBuffer), &dwRead, NULL ) ) 556*cdf0e10cSrcweir { 557*cdf0e10cSrcweir OSL_ASSERT((dwRead % 2) == 0); 558*cdf0e10cSrcweir OUString value( aBuffer, dwRead / 2); 559*cdf0e10cSrcweir return value.trim(); 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir #else 562*cdf0e10cSrcweir char buf[1024]; 563*cdf0e10cSrcweir rtl_zeroMemory(buf, 1024); 564*cdf0e10cSrcweir // read one char less so that the last char in buf is always zero 565*cdf0e10cSrcweir if (fgets(buf, 1024, stdin) != NULL) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir OUString value = ::rtl::OStringToOUString(::rtl::OString(buf), osl_getThreadTextEncoding()); 568*cdf0e10cSrcweir return value.trim(); 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir #endif 571*cdf0e10cSrcweir return OUString(); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir void TRACE(::rtl::OUString const & sText) 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir (void) sText; 577*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 578*cdf0e10cSrcweir writeConsole(sText); 579*cdf0e10cSrcweir #endif 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir void TRACE(::rtl::OString const & sText) 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir (void) sText; 585*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 586*cdf0e10cSrcweir writeConsole(sText); 587*cdf0e10cSrcweir #endif 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir void syncRepositories(Reference<ucb::XCommandEnvironment> const & xCmdEnv) 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir OUString sDisable; 593*cdf0e10cSrcweir ::rtl::Bootstrap::get( OUSTR( "DISABLE_EXTENSION_SYNCHRONIZATION" ), sDisable, OUString() ); 594*cdf0e10cSrcweir if (sDisable.getLength() > 0) 595*cdf0e10cSrcweir return; 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir Reference<deployment::XExtensionManager> xExtensionManager; 598*cdf0e10cSrcweir //synchronize shared before bundled otherewise there are 599*cdf0e10cSrcweir //more revoke and registration calls. 600*cdf0e10cSrcweir sal_Bool bModified = false; 601*cdf0e10cSrcweir if (needToSyncRepostitory(OUString(RTL_CONSTASCII_USTRINGPARAM("shared"))) 602*cdf0e10cSrcweir || needToSyncRepostitory(OUString(RTL_CONSTASCII_USTRINGPARAM("bundled")))) 603*cdf0e10cSrcweir { 604*cdf0e10cSrcweir xExtensionManager = 605*cdf0e10cSrcweir deployment::ExtensionManager::get( 606*cdf0e10cSrcweir comphelper_getProcessComponentContext()); 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir if (xExtensionManager.is()) 609*cdf0e10cSrcweir { 610*cdf0e10cSrcweir bModified = xExtensionManager->synchronize( 611*cdf0e10cSrcweir Reference<task::XAbortChannel>(), xCmdEnv); 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir } 614*cdf0e10cSrcweir 615*cdf0e10cSrcweir if (bModified) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir Reference<task::XRestartManager> restarter( 618*cdf0e10cSrcweir comphelper_getProcessComponentContext()->getValueByName( 619*cdf0e10cSrcweir OUSTR( "/singletons/com.sun.star.task.OfficeRestartManager") ), UNO_QUERY ); 620*cdf0e10cSrcweir if (restarter.is()) 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir restarter->requestRestart(xCmdEnv.is() == sal_True ? xCmdEnv->getInteractionHandler() : 623*cdf0e10cSrcweir Reference<task::XInteractionHandler>()); 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir } 626*cdf0e10cSrcweir } 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir } 631