diff options
author | Joachim Lingner <jl@openoffice.org> | 2011-02-25 15:46:46 +0100 |
---|---|---|
committer | Joachim Lingner <jl@openoffice.org> | 2011-02-25 15:46:46 +0100 |
commit | 301719567fe1c26c923e47c4ed60ce04e3a54b78 (patch) | |
tree | 20101a05f78edccf0dbc9894d83c334959451b45 /xmlhelp | |
parent | 58d8e8412ea0a4c8108662deb2fc219b62da8df6 (diff) |
jl164 #i109096# Displaying help content fails for extensions when user installation has a long path on windows
Diffstat (limited to 'xmlhelp')
-rwxr-xr-x[-rw-r--r--] | xmlhelp/source/cxxhelp/provider/databases.cxx | 52 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/provider/databases.hxx | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | xmlhelp/source/cxxhelp/provider/db.cxx | 45 | ||||
-rwxr-xr-x[-rw-r--r--] | xmlhelp/source/cxxhelp/provider/db.hxx | 21 |
4 files changed, 69 insertions, 51 deletions
diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx index 8eeafa64c9..a82b33bf5a 100644..100755 --- a/xmlhelp/source/cxxhelp/provider/databases.cxx +++ b/xmlhelp/source/cxxhelp/provider/databases.cxx @@ -416,9 +416,6 @@ rtl::OUString Databases::getInstallPathAsSystemPath() return m_aInstallDirectoryAsSystemPath; } - - - rtl::OUString Databases::getInstallPathAsURL() { osl::MutexGuard aGuard( m_aMutex ); @@ -642,22 +639,18 @@ Db* Databases::getBerkeley( const rtl::OUString& Database, { Db* table = new Db(); - rtl::OUString fileNameOU; + rtl::OUString fileURL; if( pExtensionPath ) - { - rtl::OUString aExpandedURL = expandURL( *pExtensionPath ); - aExpandedURL += Language + dbFileName; - osl::FileBase::getSystemPathFromFileURL( aExpandedURL, fileNameOU ); - } + fileURL = expandURL(*pExtensionPath) + Language + dbFileName; else - fileNameOU = getInstallPathAsSystemPath() + key; - + fileURL = getInstallPathAsURL() + key; - rtl::OString fileName( fileNameOU.getStr(),fileNameOU.getLength(),osl_getThreadTextEncoding() ); - - rtl::OUString fileNameDBHelp( fileNameOU ); + rtl::OUString fileNameDBHelp( fileURL ); + //Extensions always use the new format if( pExtensionPath != NULL ) fileNameDBHelp += rtl::OUString::createFromAscii( "_" ); + //SimpleFileAccess takes file URLs as arguments!!! Using filenames works accidentally but + //fails for example when using long path names on Windows (starting with \\?\) if( m_xSFA->exists( fileNameDBHelp ) ) { DBHelp* pDBHelp = new DBHelp( fileNameDBHelp, m_xSFA ); @@ -666,13 +659,13 @@ Db* Databases::getBerkeley( const rtl::OUString& Database, #ifdef TEST_DBHELP bool bSuccess; bool bOldDbAccess = false; - bSuccess = pDBHelp->testAgainstDb( fileName, bOldDbAccess ); + bSuccess = pDBHelp->testAgainstDb( fileURL, bOldDbAccess ); bOldDbAccess = true; - bSuccess = pDBHelp->testAgainstDb( fileName, bOldDbAccess ); + bSuccess = pDBHelp->testAgainstDb( fileURL, bOldDbAccess ); #endif } - else if( table->open( 0,fileName.getStr(),0,DB_BTREE,DB_RDONLY,0644 ) ) + else if( table->open( 0,fileURL, DB_BTREE,DB_RDONLY,0644 ) ) { table->close( 0 ); delete table; @@ -950,17 +943,13 @@ KeywordInfo* Databases::getKeyword( const rtl::OUString& Database, std::vector<KeywordInfo::KeywordElement> aVector; KeyDataBaseFileIterator aDbFileIt( m_xContext, *this, Database, Language ); - rtl::OUString fileNameOU; + rtl::OUString fileURL; bool bExtension = false; - while( (fileNameOU = aDbFileIt.nextDbFile( bExtension )).getLength() > 0 ) + while( (fileURL = aDbFileIt.nextDbFile( bExtension )).getLength() > 0 ) { - rtl::OString fileName( fileNameOU.getStr(), - fileNameOU.getLength(), - osl_getThreadTextEncoding() ); - Db table; - rtl::OUString fileNameDBHelp( fileNameOU ); + rtl::OUString fileNameDBHelp( fileURL ); if( bExtension ) fileNameDBHelp += rtl::OUString::createFromAscii( "_" ); if( m_xSFA->exists( fileNameDBHelp ) ) @@ -1009,16 +998,16 @@ KeywordInfo* Databases::getKeyword( const rtl::OUString& Database, #ifdef TEST_DBHELP bool bSuccess; bool bOldDbAccess = false; - bSuccess = aDBHelp.testAgainstDb( fileName, bOldDbAccess ); + bSuccess = aDBHelp.testAgainstDb( fileURL, bOldDbAccess ); bOldDbAccess = true; - bSuccess = aDBHelp.testAgainstDb( fileName, bOldDbAccess ); + bSuccess = aDBHelp.testAgainstDb( fileURL, bOldDbAccess ); int nDummy = 0; #endif } - else if( 0 == table.open( 0,fileName.getStr(),0,DB_BTREE,DB_RDONLY,0644 ) ) + else if( 0 == table.open( 0,fileURL,DB_BTREE,DB_RDONLY,0644 ) ) { Db* idmap = getBerkeley( Database,Language ); @@ -1867,6 +1856,7 @@ Db* DataBaseIterator::implGetDbFromPackage( Reference< deployment::XPackage > xP //=================================================================== // class KeyDataBaseFileIterator +//returns a file URL rtl::OUString KeyDataBaseFileIterator::nextDbFile( bool& o_rbExtension ) { rtl::OUString aRetFile; @@ -1877,7 +1867,7 @@ rtl::OUString KeyDataBaseFileIterator::nextDbFile( bool& o_rbExtension ) { case INITIAL_MODULE: aRetFile = - m_rDatabases.getInstallPathAsSystemPath() + + m_rDatabases.getInstallPathAsURL() + m_rDatabases.processLang( m_aLanguage ) + aSlash + m_aInitialModule + rtl::OUString::createFromAscii( ".key" ); @@ -1935,16 +1925,14 @@ rtl::OUString KeyDataBaseFileIterator::nextDbFile( bool& o_rbExtension ) return aRetFile; } +//Returns a file URL, that does not contain macros rtl::OUString KeyDataBaseFileIterator::implGetDbFileFromPackage ( Reference< deployment::XPackage > xPackage ) { rtl::OUString aExpandedURL = implGetFileFromPackage( rtl::OUString::createFromAscii( ".key" ), xPackage ); - rtl::OUString aRetFile; - osl::FileBase::getSystemPathFromFileURL( aExpandedURL, aRetFile ); - - return aRetFile; + return aExpandedURL; } diff --git a/xmlhelp/source/cxxhelp/provider/databases.hxx b/xmlhelp/source/cxxhelp/provider/databases.hxx index 0b26e2501b..8876da2e18 100644 --- a/xmlhelp/source/cxxhelp/provider/databases.hxx +++ b/xmlhelp/source/cxxhelp/provider/databases.hxx @@ -506,7 +506,7 @@ namespace chelp { Databases& rDatabases, const rtl::OUString& aInitialModule, const rtl::OUString& aLanguage ) : ExtensionIteratorBase( xContext, rDatabases, aInitialModule, aLanguage ) {} - + //Returns a file URL rtl::OUString nextDbFile( bool& o_rbExtension ); private: diff --git a/xmlhelp/source/cxxhelp/provider/db.cxx b/xmlhelp/source/cxxhelp/provider/db.cxx index aafa1bf4dc..8b16197911 100644..100755 --- a/xmlhelp/source/cxxhelp/provider/db.cxx +++ b/xmlhelp/source/cxxhelp/provider/db.cxx @@ -35,6 +35,8 @@ #include "com/sun/star/io/XSeekable.hpp" +#include "osl/file.hxx" +#include "osl/thread.hxx" #ifdef TEST_DBHELP #include <osl/time.h> #endif @@ -115,21 +117,25 @@ void testWriteKeyValue( FILE* pFile, const KeyValPair& rKeyValPair ) fprintf( pFile, "%c", cLF ); } -bool DBHelp::testAgainstDb( const rtl::OString& fileName, bool bOldDbAccess ) +bool DBHelp::testAgainstDb( const rtl::OUString& fileURL, bool bOldDbAccess ) { bool bSuccess = true; KeyValPairVector avKeyValPair; - rtl::OString aOutFileName = fileName; - aOutFileName += "_TestOut"; + rtl::OUString aOutFileName = fileURL; + aOutFileName += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_TestOut")); if( bOldDbAccess ) - aOutFileName += "_Old"; - FILE* pFile = fopen( aOutFileName.getStr(), "wb" ); - + aOutFileName += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_Old")); +#ifdef WNT + FILE* pFile = _wfopen( aOutFileName.getStr(), L"wb" ); +#else + rtl::OString sFile = rtl::OUStringToOString(aOutFileName, osl_getThreadTextEncoding()); + FILE* pFile = fopen( sFile.getStr(), "wb" ); +#endif // Get all values Db table; - if( 0 == table.open( 0,fileName.getStr(),0,DB_BTREE,DB_RDONLY,0644 ) ) + if( 0 == table.open( 0,fileURL,DB_BTREE,DB_RDONLY,0644 ) ) { bool first = true; @@ -206,7 +212,7 @@ bool DBHelp::testAgainstDb( const rtl::OString& fileName, bool bOldDbAccess ) { if( bFirst ) { - if( tableTest.open( 0,fileName.getStr(),0,DB_BTREE,DB_RDONLY,0644 ) ) + if( tableTest.open( 0,fileURL, DB_BTREE,DB_RDONLY,0644 ) ) { if( pFile != NULL ) fprintf( pFile, "Cannot open database\n" ); @@ -305,11 +311,11 @@ void DBHelp::createHashMap( bool bOptimizeForPerformance ) m_pStringToValPosMap = new StringToValPosMap(); } - Reference< XInputStream > xIn = m_xSFA->openFileRead( m_aFileName ); + Reference< XInputStream > xIn = m_xSFA->openFileRead( m_aFileURL ); if( xIn.is() ) { Sequence< sal_Int8 > aData; - sal_Int32 nSize = m_xSFA->getSize( m_aFileName ); + sal_Int32 nSize = m_xSFA->getSize( m_aFileURL ); sal_Int32 nRead = xIn->readBytes( aData, nSize ); const char* pData = (const char*)aData.getConstArray(); @@ -388,7 +394,7 @@ bool DBHelp::getValueForKey( const rtl::OString& rKey, DBData& rValue ) int iValuePos = rValPair.first; int nValueLen = rValPair.second; - Reference< XInputStream > xIn = m_xSFA->openFileRead( m_aFileName ); + Reference< XInputStream > xIn = m_xSFA->openFileRead( m_aFileURL ); if( xIn.is() ) { Reference< XSeekable > xXSeekable( xIn, UNO_QUERY ); @@ -436,9 +442,9 @@ bool DBHelp::startIteration( void ) { bool bSuccess = false; - sal_Int32 nSize = m_xSFA->getSize( m_aFileName ); + sal_Int32 nSize = m_xSFA->getSize( m_aFileURL ); - Reference< XInputStream > xIn = m_xSFA->openFileRead( m_aFileName ); + Reference< XInputStream > xIn = m_xSFA->openFileRead( m_aFileURL ); if( xIn.is() ) { m_nItRead = xIn->readBytes( m_aItData, nSize ); @@ -519,6 +525,19 @@ int Db::open(DB_TXN *txnid, return db_internal::check_error( err,"Db::open" ); } +int Db::open(DB_TXN *txnid, + ::rtl::OUString const & fileURL, + DBTYPE type, + u_int32_t flags, + int mode) +{ + ::rtl::OUString ouPath; + ::osl::FileBase::getSystemPathFromFileURL(fileURL, ouPath); + const ::rtl::OString sPath = ::rtl::OUStringToOString(ouPath, osl_getThreadTextEncoding()); + return open(txnid, sPath.getStr(), 0, type, flags, mode); +} + + int Db::get(DB_TXN *txnid, Dbt *key, Dbt *data, u_int32_t flags) { diff --git a/xmlhelp/source/cxxhelp/provider/db.hxx b/xmlhelp/source/cxxhelp/provider/db.hxx index 58bb06bde4..62f97c0488 100644..100755 --- a/xmlhelp/source/cxxhelp/provider/db.hxx +++ b/xmlhelp/source/cxxhelp/provider/db.hxx @@ -118,7 +118,7 @@ namespace berkeleydbproxy { class DBHelp { - rtl::OUString m_aFileName; + rtl::OUString m_aFileURL; StringToDataMap* m_pStringToDataMap; StringToValPosMap* m_pStringToValPosMap; com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess > @@ -133,16 +133,21 @@ namespace berkeleydbproxy { bool implReadLenAndData( const char* pData, int& riPos, DBData& rValue ); public: - DBHelp( const rtl::OUString& rFileName, + //DBHelp must get a fileURL which can then directly be used by simple file access. + //SimpleFileAccess requires file URLs as arguments. Passing file path may work but fails + //for example when using long file paths on Windows, which start with "\\?\" + DBHelp( const rtl::OUString& rFileURL, com::sun::star::uno::Reference< com::sun::star::ucb::XSimpleFileAccess > xSFA ) - : m_aFileName( rFileName ) + : m_aFileURL( rFileURL ) , m_pStringToDataMap( NULL ) , m_pStringToValPosMap( NULL ) , m_xSFA( xSFA ) , m_pItData( NULL ) , m_nItRead( -1 ) , m_iItPos( -1 ) - {} + { + OSL_ASSERT(!rFileURL.compareTo(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("file:")), 5)); + } ~DBHelp() { releaseHashMap(); } @@ -150,7 +155,7 @@ namespace berkeleydbproxy { void releaseHashMap( void ); #ifdef TEST_DBHELP - bool testAgainstDb( const rtl::OString& fileName, bool bOldDbAccess ); + bool testAgainstDb( const rtl::OUString& fileURL, bool bOldDbAccess ); #endif bool getValueForKey( const rtl::OString& rKey, DBData& rValue ); @@ -184,6 +189,12 @@ namespace berkeleydbproxy { u_int32_t flags, int mode); + int open(DB_TXN *txnid, + ::rtl::OUString const & fileURL, + DBTYPE type, + u_int32_t flags, + int mode); + int get(DB_TXN* txnid, Dbt *key, Dbt *data, u_int32_t flags); |