22 #include <rtl/byteseq.hxx>
23 #include <rtl/strbuf.hxx>
26 using namespace ::
rtl;
43 , m_bToBeCreated( true )
50 : m_MapFile( OUString() )
52 , m_bToBeCreated( false )
69 const char*
pChar = rStr.getStr();
70 const sal_Int32 nLen = rStr.getLength();
75 const unsigned char c =
static_cast<unsigned char>(*(pChar++));
85 OStringBuffer aEncStr( nLen + 32);
86 aEncStr.append( pChar - (nLen-i), nLen - i);
89 unsigned char c =
static_cast<unsigned char>(*(pChar++));
93 c += (c <= 0x09) ?
'0' :
'A'-10;
96 aEncStr.append(
char(c) );
99 return aEncStr.makeStringAndClear();
106 const char*
pChar = pEncChars;
110 if( *(pChar++) ==
'%')
113 return OString( pEncChars, nLen);
116 OStringBuffer aDecStr( nLen);
118 for( i = nLen; --i >= 0;)
127 if( (
'0' <= c) && (c <=
'9'))
131 OSL_ASSERT( (
'A' <= c) && (c <=
'F'));
138 return aDecStr.makeStringAndClear();
144 sal_uInt32
const nOpenFlags = osl_File_OpenFlag_Read | osl_File_OpenFlag_Write;
146 const osl::File::RC rcOpen =
m_MapFile.open( nOpenFlags);
147 m_bIsOpen = (rcOpen == osl::File::E_None);
163 const osl::FileBase::RC nRes =
m_MapFile.setPos( osl_Pos_Absolut, 0);
164 if (nRes != osl::FileBase::E_None)
166 SAL_WARN(
"desktop.deployment",
"setPos failed with " << +nRes);
172 sal_uInt64 nBytesRead = 0;
173 m_MapFile.read( aHeaderBytes,
sizeof(aHeaderBytes), nBytesRead);
174 OSL_ASSERT( nBytesRead ==
sizeof(aHeaderBytes));
175 if( nBytesRead !=
sizeof(aHeaderBytes))
178 for(
int i = 0;
i <
int(
sizeof(PmapMagic)); ++
i)
179 if( aHeaderBytes[
i] != PmapMagic[
i])
183 ByteSequence aKeyLine;
184 ByteSequence aValLine;
189 if(
m_MapFile.readLine( aKeyLine) != osl::File::E_None)
191 if( !aKeyLine.getLength())
193 if(
m_MapFile.readLine( aValLine) != osl::File::E_None)
196 const OString aKeyName =
decodeString( reinterpret_cast<char const *>(aKeyLine.getConstArray()), aKeyLine.getLength());
197 const OString aValName =
decodeString( reinterpret_cast<char const *>(aValLine.getConstArray()), aValLine.getLength());
199 add( aKeyName, aValName );
202 if(
m_MapFile.isEndOfFile( &bIsEOF) != osl::File::E_None )
217 const sal_uInt32 nOpenFlags = osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create;
218 const osl::File::RC rcOpen =
m_MapFile.open( nOpenFlags);
219 m_bIsOpen = (rcOpen == osl::File::E_None);
226 const osl::FileBase::RC nRes =
m_MapFile.setPos( osl_Pos_Absolut, 0);
227 if (nRes != osl::FileBase::E_None)
229 SAL_WARN(
"desktop.deployment",
"setPos failed with " << +nRes);
232 sal_uInt64 nBytesWritten = 0;
233 m_MapFile.write( PmapMagic,
sizeof(PmapMagic), nBytesWritten);
240 const sal_Int32 nKeyLen = aKeyString.getLength();
241 m_MapFile.write( aKeyString.getStr(), nKeyLen, nBytesWritten);
242 OSL_ASSERT( nKeyLen == static_cast<sal_Int32>(nBytesWritten));
243 m_MapFile.write(
"\n", 1, nBytesWritten);
245 const OString& rValString =
encodeString( entry.second);
246 const sal_Int32 nValLen = rValString.getLength();
247 m_MapFile.write( rValString.getStr(), nValLen, nBytesWritten);
248 OSL_ASSERT( nValLen == static_cast<sal_Int32>(nBytesWritten));
249 m_MapFile.write(
"\n", 1, nBytesWritten);
253 m_MapFile.write(
"\n", 1, nBytesWritten);
255 sal_uInt64 nNewFileSize;
256 if(
m_MapFile.getPos( nNewFileSize) == osl::File::E_None)
266 return get(
nullptr, key );
271 t_string2string_map::const_iterator it =
m_entries.find( key);
bool get(OString *value, OString const &key) const
static OString encodeString(const OString &rStr)
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
void put(OString const &key, OString const &value)
bool has(OString const &key) const
t_string2string_map m_entries
void add(OString const &key, OString const &value)
OUString expandUnoRcUrl(OUString const &url)
static OString decodeString(const char *pEncChars, int nLen)
bool erase(OString const &key)
#define SAL_WARN(area, stream)