diff options
author | Joachim Lingner <jl@openoffice.org> | 2010-04-19 11:33:33 +0200 |
---|---|---|
committer | Joachim Lingner <jl@openoffice.org> | 2010-04-19 11:33:33 +0200 |
commit | 3c289e248a4f7c6940bb7429ee70d17a6196016c (patch) | |
tree | a5e449c5cc48918708f7bc98dc921a49db95ca70 /desktop/source/deployment/misc | |
parent | fb70a4cd3b77e0ea6bb5820b47bfd7ea39fa3228 (diff) |
jl152 import 263446 from native0jl:#i77196# supporting licenses, suppress license switch, subsequent accepting of licenses for bundled/shared extensions
Diffstat (limited to 'desktop/source/deployment/misc')
-rw-r--r-- | desktop/source/deployment/misc/dp_misc.cxx | 142 | ||||
-rw-r--r-- | desktop/source/deployment/misc/dp_ucb.cxx | 46 |
2 files changed, 177 insertions, 11 deletions
diff --git a/desktop/source/deployment/misc/dp_misc.cxx b/desktop/source/deployment/misc/dp_misc.cxx index 1f1fde7ca7bf..919f134b3fb9 100644 --- a/desktop/source/deployment/misc/dp_misc.cxx +++ b/desktop/source/deployment/misc/dp_misc.cxx @@ -44,8 +44,10 @@ #include "com/sun/star/ucb/CommandAbortedException.hpp" #include "com/sun/star/bridge/UnoUrlResolver.hpp" #include "com/sun/star/bridge/XUnoUrlResolver.hpp" +#include "com/sun/star/deployment/ExtensionManager.hpp" #include "boost/scoped_array.hpp" #include "boost/shared_ptr.hpp" +#include <comphelper/processfactory.hxx> #ifdef WNT //#include "tools/prewin.h" @@ -138,6 +140,103 @@ bool existsOfficePipe() return pipe.is(); } + +//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) + { + OSL_ENSURE(0, "Cannot access extension folder"); + 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) + { + OSL_ENSURE(0, "Cannot access file lastsynchronized"); + return true; //sync just in case + } + + //compare the modification time of the extension folder and the last + //modified file + ::osl::FileStatus statFolder(FileStatusMask_ModifyTime); + ::osl::FileStatus statFile(FileStatusMask_ModifyTime); + if (itemExtFolder.getFileStatus(statFolder) == ::osl::File::E_None) + { + if (itemFile.getFileStatus(statFile) == ::osl::File::E_None) + { + TimeValue timeFolder = statFolder.getModifyTime(); + TimeValue timeFile = statFile.getModifyTime(); + + if (timeFile.Seconds < timeFolder.Seconds) + bNeedsSync = true; + } + else + { + OSL_ASSERT(0); + bNeedsSync = true; + } + } + else + { + OSL_ASSERT(0); + bNeedsSync = true; + } + return bNeedsSync; +} + +bool needToSyncRepostitory(OUString const & name) +{ + OUString folder; + OUString file; + if (name.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("bundled")))) + { + folder = OUString( + RTL_CONSTASCII_USTRINGPARAM("$BUNDLED_EXTENSIONS")); + file = OUString ( + RTL_CONSTASCII_USTRINGPARAM( + "$BUNDLED_EXTENSIONS_USER/lastsynchronized")); + } + else if (name.equals(OUString(RTL_CONSTASCII_USTRINGPARAM("shared")))) + { + 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); +} + + } // anon namespace //============================================================================== @@ -480,22 +579,43 @@ void TRACE(::rtl::OString const & sText) #endif } -bool hasExtensionRepositoryChanged(::rtl::OUString const & repository) +void syncRepositories(Reference<ucb::XCommandEnvironment> const & xCmdEnv) { - if (repository.equals(OUSTR("shared"))) + Reference<deployment::XExtensionManager> xExtensionManager; + //synchronize shared before bundled otherewise there are + //more revoke and registration calls. + OUString sShared(RTL_CONSTASCII_USTRINGPARAM("shared")); + if (needToSyncRepostitory(sShared)) { - //get the extensions folder - OUString folder(RTL_CONSTASCII_USTRINGPARAM("BUNDLED_EXTENSIONS")); - ::rtl::Bootstrap::expandMacros(folder); + xExtensionManager = + deployment::ExtensionManager::get( + comphelper_getProcessComponentContext()); + + if (xExtensionManager.is()) + { + xExtensionManager->synchronize( + sShared, Reference<task::XAbortChannel>(), xCmdEnv); + } } - else if (repository.equals(OUSTR("bundled"))) + + OUString sBundled(RTL_CONSTASCII_USTRINGPARAM("bundled")); + if (needToSyncRepostitory( sBundled)) { - } - else - throw lang::IllegalArgumentException( - OUSTR("Invalid repository name."), 0, 0); + if (!xExtensionManager.is()) + { + xExtensionManager = + deployment::ExtensionManager::get( + comphelper_getProcessComponentContext()); + } + if (xExtensionManager.is()) + { + xExtensionManager->synchronize( + sBundled, Reference<task::XAbortChannel>(), xCmdEnv); - return false; + } + } } + + } diff --git a/desktop/source/deployment/misc/dp_ucb.cxx b/desktop/source/deployment/misc/dp_ucb.cxx index 571aef9c1b95..795a492aa0d5 100644 --- a/desktop/source/deployment/misc/dp_ucb.cxx +++ b/desktop/source/deployment/misc/dp_ucb.cxx @@ -271,4 +271,50 @@ bool readLine( OUString * res, OUString const & startingWith, return false; } +bool readProperties( ::std::list< ::std::pair< ::rtl::OUString, ::rtl::OUString> > & out_result, + ::ucbhelper::Content & ucb_content ) +{ + // read whole file: + ::rtl::ByteSequence bytes( readFile( ucb_content ) ); + OUString file( reinterpret_cast<sal_Char const *>(bytes.getConstArray()), + bytes.getLength(), RTL_TEXTENCODING_UTF8); + sal_Int32 pos = 0; + + for (;;) + { + + ::rtl::OUStringBuffer buf; + sal_Int32 start = pos; + + bool bEOF = false; + pos = file.indexOf( LF, pos ); + if (pos < 0) { // EOF + buf.append( file.copy( start ) ); + bEOF = true; + } + else + { + if (pos > 0 && file[ pos - 1 ] == CR) + // consume extra CR + buf.append( file.copy( start, pos - start - 1 ) ); + else + buf.append( file.copy( start, pos - start ) ); + pos++; + } + OUString aLine = buf.makeStringAndClear(); + + sal_Int32 posEqual = aLine.indexOf('='); + if (posEqual > 0 && (posEqual + 1) < aLine.getLength()) + { + OUString name = aLine.copy(0, posEqual); + OUString value = aLine.copy(posEqual + 1); + out_result.push_back(::std::make_pair(name, value)); + } + + if (bEOF) + break; + } + return false; +} + } |