diff options
author | Juergen Schmidt <jsc@openoffice.org> | 2001-08-17 12:09:50 +0000 |
---|---|---|
committer | Juergen Schmidt <jsc@openoffice.org> | 2001-08-17 12:09:50 +0000 |
commit | a87e0923371a1821bc3bdb37515e15d831a4b113 (patch) | |
tree | 66af42686e353cb2d05ef73a3d3a320f1c949835 /rdbmaker/source/codemaker | |
parent | 4aee767252a8e145a5ac78654ecc01cc9bb2986d (diff) |
#91088# convert registry path to URL
Diffstat (limited to 'rdbmaker/source/codemaker')
-rw-r--r-- | rdbmaker/source/codemaker/global.cxx | 139 | ||||
-rw-r--r-- | rdbmaker/source/codemaker/typemanager.cxx | 10 |
2 files changed, 106 insertions, 43 deletions
diff --git a/rdbmaker/source/codemaker/global.cxx b/rdbmaker/source/codemaker/global.cxx index bec489b3102e..e539f6405c7e 100644 --- a/rdbmaker/source/codemaker/global.cxx +++ b/rdbmaker/source/codemaker/global.cxx @@ -2,9 +2,9 @@ * * $RCSfile: global.cxx,v $ * - * $Revision: 1.5 $ + * $Revision: 1.6 $ * - * last change: $Author: hjs $ $Date: 2001-07-18 18:02:39 $ + * last change: $Author: jsc $ $Date: 2001-08-17 13:09:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,6 +68,13 @@ #include <rtl/ustring.hxx> #endif +#ifndef _OSL_THREAD_H_ +#include <osl/thread.h> +#endif +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif + #include <stdlib.h> #include <stdio.h> #if defined(SAL_W32) || defined(SAL_OS2) @@ -86,7 +93,14 @@ #include <codemaker/global.hxx> #endif -using namespace rtl; +#ifdef SAL_UNX +#define SEPARATOR '/' +#else +#define SEPARATOR '\\' +#endif + +using namespace ::rtl; +using namespace ::osl; OString makeTempName(sal_Char* prefix) { @@ -224,11 +238,7 @@ OString createFileNameFromType( const OString& destination, if (mkdir((char*)nameBuffer.getStr()) == -1) #endif { -// #if __SUNPRO_CC >= 0x500 -// if( * ::___errno() == ENOENT ) -// #else if ( errno == ENOENT ) -// #endif return OString(); } @@ -311,6 +321,34 @@ const OString inGlobalSet(const OUString & rValue) return *(aGlobalMap.insert( sValue ).first); } +static sal_Bool isFileUrl(const OString& fileName) +{ + if (fileName.indexOf("file://") == 0 ) + return sal_True; + return sal_False; +} + +OUString convertToFileUrl(const OString& fileName) +{ + if ( isFileUrl(fileName) ) + { + return OStringToOUString(fileName, osl_getThreadTextEncoding()); + } + + OUString uUrlFileName; + OUString uFileName(fileName.getStr(), fileName.getLength(), osl_getThreadTextEncoding()); + if ( fileName.indexOf('.') == 0 || fileName.indexOf(SEPARATOR) < 0 ) + { + OUString uWorkingDir; + OSL_VERIFY( osl_getProcessWorkingDir(&uWorkingDir.pData) == osl_Process_E_None ); + OSL_VERIFY( FileBase::getAbsoluteFileURL(uWorkingDir, uFileName, uUrlFileName) == FileBase::E_None ); + } else + { + OSL_VERIFY( FileBase::getFileURLFromSystemPath(uFileName, uUrlFileName) == FileBase::E_None ); + } + + return uUrlFileName; +} //************************************************************************* // FileStream @@ -319,60 +357,85 @@ FileStream::FileStream() { } -FileStream::FileStream(const OString& name, sal_Int32 nMode) - : ofstream(name, nMode) - , m_name(name) +FileStream::FileStream(const OString& name, FileAccessMode mode) + : m_pFile(NULL) { + if ( name.getLength() > 0 ) + { + m_name = name; + m_pFile = fopen(m_name, checkAccessMode(mode)); + } } FileStream::~FileStream() { - flush(); - close(); + if ( isValid() ) + { + fflush(m_pFile); + fclose(m_pFile); + } } sal_Bool FileStream::isValid() { -#ifndef __STL_NO_NEW_IOSTREAMS -#if STLPORT_VERSION < 400 - if(rdbuf()->fd() < 0) -#else - if( !is_open() ) -#endif -#else - if(fd() < 0) -#endif - { - return sal_False; - } + if ( m_pFile ) + return sal_True; - return sal_True; + return sal_False; } -void FileStream::openFile(const OString& name, sal_Int32 nMode) +void FileStream::open(const OString& name, FileAccessMode mode) { if ( name.getLength() > 0 ) + { m_name = name; - - if ( m_name.getLength() > 0 ) - open(m_name, nMode); + m_pFile = fopen(m_name, checkAccessMode(mode)); + } } -void FileStream::closeFile() +void FileStream::close() { - flush(); - close(); + if ( isValid() ) + { + fflush(m_pFile); + fclose(m_pFile); + m_pFile = NULL; + m_name = OString(); + } } sal_Int32 FileStream::getSize() { - flush(); - - FILE* f = fopen(m_name, "r"); + sal_Int32 pos = 0; sal_Int32 size = 0; - if (!fseek(f, 0, SEEK_END)) - size = ftell(f); - fclose(f); + if ( isValid() ) + { + fflush(m_pFile); + pos = ftell(m_pFile); + if (!fseek(m_pFile, 0, SEEK_END)) + size = ftell(m_pFile); + fseek(m_pFile, pos, SEEK_SET); + } return size; } +const sal_Char* FileStream::checkAccessMode(FileAccessMode mode) +{ + switch( mode ) + { + case FAM_READ: + return "r"; + case FAM_WRITE: + return "w"; + case FAM_APPEND: + return "a"; + case FAM_READWRITE_EXIST: + return "r+"; + case FAM_READWRITE: + return "w+"; + case FAM_READAPPEND: + return "a+"; + } + return "w+"; +} + diff --git a/rdbmaker/source/codemaker/typemanager.cxx b/rdbmaker/source/codemaker/typemanager.cxx index 88031401083f..ce524f7973a8 100644 --- a/rdbmaker/source/codemaker/typemanager.cxx +++ b/rdbmaker/source/codemaker/typemanager.cxx @@ -2,9 +2,9 @@ * * $RCSfile: typemanager.cxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 15:29:08 $ + * last change: $Author: jsc $ $Date: 2001-08-17 13:09:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -153,7 +153,7 @@ sal_Bool RegistryTypeManager::init(sal_Bool bMerged, const StringVector& regFile Registry tmpReg(loader); while (iter != regFiles.end()) { - if (!tmpReg.open( OStringToOUString(*iter, RTL_TEXTENCODING_UTF8), REG_READONLY)) + if (!tmpReg.open( convertToFileUrl(*iter), REG_READONLY)) m_pImpl->m_registries.push_back(new Registry(tmpReg)); else { @@ -168,7 +168,7 @@ sal_Bool RegistryTypeManager::init(sal_Bool bMerged, const StringVector& regFile Registry *pTmpReg = new Registry(loader); OString tmpName(makeTempName(NULL)); - if (!pTmpReg->create( OStringToOUString(tmpName, RTL_TEXTENCODING_UTF8) ) ) + if (!pTmpReg->create( convertToFileUrl(tmpName) ) ) { RegistryKey rootKey; RegError ret = REG_NO_ERROR; @@ -178,7 +178,7 @@ sal_Bool RegistryTypeManager::init(sal_Bool bMerged, const StringVector& regFile while (iter != regFiles.end()) { - if ( ret = pTmpReg->mergeKey(rootKey, aRoot, OUString::createFromAscii( *iter )) ) + if ( ret = pTmpReg->mergeKey(rootKey, aRoot, convertToFileUrl( *iter )) ) { if (ret != REG_MERGE_CONFLICT) { |