Kaydet (Commit) 9c0a3904 authored tarafından Palenik Mihály's avatar Palenik Mihály Kaydeden (comit) Andras Timar

fdo#63133: Write tools/tempfile.hxx out

I deleted TempFile class and changed it to utl::TempFile class
-which in unotools/tempfile.hxx- in the followings: Storage,
StgTmpStrm, SwXMailMerge classes; and RenderAsEMF function.
I modified header in precompiled_sw.hxx.

Change-Id: I3dae5333dc42538e1b905f6a6bbc85534c591dc1
Reviewed-on: https://gerrit.libreoffice.org/4938Reviewed-by: 's avatarAndras Timar <atimar@suse.com>
Tested-by: 's avatarAndras Timar <atimar@suse.com>
üst 22adf4e7
...@@ -27,6 +27,7 @@ $(eval $(call gb_Library_use_libraries,ips,\ ...@@ -27,6 +27,7 @@ $(eval $(call gb_Library_use_libraries,ips,\
vcl \ vcl \
tl \ tl \
sal \ sal \
utl \
$(gb_UWINAPI) \ $(gb_UWINAPI) \
)) ))
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <vcl/virdev.hxx> #include <vcl/virdev.hxx>
#include <vcl/cvtgrf.hxx> #include <vcl/cvtgrf.hxx>
#include <vcl/bmpacc.hxx> #include <vcl/bmpacc.hxx>
#include <tools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <osl/process.h> #include <osl/process.h>
#include <osl/file.hxx> #include <osl/file.hxx>
...@@ -189,14 +189,14 @@ static oslProcessError runProcessWithPathSearch(const OUString &rProgName, ...@@ -189,14 +189,14 @@ static oslProcessError runProcessWithPathSearch(const OUString &rProgName,
static bool RenderAsEMF(const sal_uInt8* pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic) static bool RenderAsEMF(const sal_uInt8* pBuf, sal_uInt32 nBytesRead, Graphic &rGraphic)
{ {
TempFile aTemp; utl::TempFile aTemp;
aTemp.EnableKillingFile(); aTemp.EnableKillingFile();
OUString fileName("pstoedit" EXESUFFIX); OUString fileName("pstoedit" EXESUFFIX);
OUString arg1("-f"); OUString arg1("-f");
OUString arg2("emf:-OO"); OUString arg2("emf:-OO");
OUString arg3("-"); OUString arg3("-");
OUString output; OUString output;
osl::FileBase::getSystemPathFromFileURL(aTemp.GetName(), output); osl::FileBase::getSystemPathFromFileURL(aTemp.GetURL(), output);
rtl_uString *args[] = rtl_uString *args[] =
{ {
arg1.pData, arg2.pData, arg3.pData, output.pData arg1.pData, arg2.pData, arg3.pData, output.pData
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef _TOOLS_TEMPFILE_HXX
#define _TOOLS_TEMPFILE_HXX
#include <rtl/ustring.hxx>
#include "tools/toolsdllapi.h"
struct TempFile_Impl;
class TOOLS_DLLPUBLIC TempFile
{
TempFile_Impl* pImp;
bool bKillingFileEnabled;
public:
/** Create a temporary file in the default tempfile folder. */
TempFile();
/** Create a temporary file in the default tempfile folder; its name starts
with some given characters followed by a counter ( example:
rLeadingChars="abc" means "abc0", "abc1" and so on, depending on
existing files in that folder ).
The extension string may be f.e. ".txt" or "", if no extension string is
given, ".tmp" is used.
*/
TempFile( const OUString& rLeadingChars, const OUString* pExtension=NULL );
/** TempFile will be removed from disk in dtor if EnableKillingTempFile was
called before. TempDirs will be removed recursively in that case. */
~TempFile();
bool IsValid() const;
/** Returns the real name of the tempfile in file URL scheme. */
OUString GetName() const;
/** If enabled the file will be removed from disk when the dtor is called
(default is not enabled) */
void EnableKillingFile( bool bEnable=true ) { bKillingFileEnabled = bEnable; }
bool IsKillingFileEnabled() const { return bKillingFileEnabled; }
/** Only create a name for a temporary file that would be valid at that moment. */
static OUString CreateTempName();
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <sot/storinfo.hxx> #include <sot/storinfo.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <tools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <tools/debug.hxx> #include <tools/debug.hxx>
...@@ -371,7 +371,7 @@ Storage::Storage( const OUString& rFile, StreamMode m, bool bDirect ) ...@@ -371,7 +371,7 @@ Storage::Storage( const OUString& rFile, StreamMode m, bool bDirect )
if( aName.isEmpty() ) if( aName.isEmpty() )
{ {
// no name = temporary name! // no name = temporary name!
aName = TempFile::CreateTempName(); aName = utl::TempFile::CreateTempName();
bTemp = true; bTemp = true;
} }
// the root storage creates the I/O system // the root storage creates the I/O system
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <string.h> // memcpy() #include <string.h> // memcpy()
#include <sal/log.hxx> #include <sal/log.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <tools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include "sot/stg.hxx" #include "sot/stg.hxx"
#include "stgelem.hxx" #include "stgelem.hxx"
...@@ -1186,7 +1186,7 @@ void StgTmpStrm::SetSize( sal_uLong n ) ...@@ -1186,7 +1186,7 @@ void StgTmpStrm::SetSize( sal_uLong n )
{ {
if( n > THRESHOLD ) if( n > THRESHOLD )
{ {
aName = TempFile::CreateTempName(); aName = utl::TempFile::CreateTempName();
SvFileStream* s = new SvFileStream( aName, STREAM_READWRITE ); SvFileStream* s = new SvFileStream( aName, STREAM_READWRITE );
sal_uLong nCur = Tell(); sal_uLong nCur = Tell();
sal_uLong i = nEndOfData; sal_uLong i = nEndOfData;
......
...@@ -977,7 +977,6 @@ ...@@ -977,7 +977,6 @@
#include <tools/solar.h> #include <tools/solar.h>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <tools/string.hxx> #include <tools/string.hxx>
#include <tools/tempfile.hxx>
#include <tools/time.hxx> #include <tools/time.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <ucbhelper/content.hxx> #include <ucbhelper/content.hxx>
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <svl/urihelper.hxx> #include <svl/urihelper.hxx>
#include <svx/dataaccessdescriptor.hxx> #include <svx/dataaccessdescriptor.hxx>
#include <tools/shl.hxx> // GetAppData #include <tools/shl.hxx> // GetAppData
#include <tools/tempfile.hxx> #include <unotools/tempfile.hxx>
#include <sfx2/app.hxx> #include <sfx2/app.hxx>
#include <sfx2/docfile.hxx> #include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx> #include <sfx2/docfilt.hxx>
...@@ -755,8 +755,8 @@ uno::Any SAL_CALL SwXMailMerge::execute( ...@@ -755,8 +755,8 @@ uno::Any SAL_CALL SwXMailMerge::execute(
OUString( FILTER_XML ), OUString( FILTER_XML ),
SwDocShell::Factory().GetFilterContainer() ); SwDocShell::Factory().GetFilterContainer() );
OUString aExtension(comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(), '*')); OUString aExtension(comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(), '*'));
TempFile aTempFile( OUString("SwMM"), &aExtension ); utl::TempFile aTempFile( OUString("SwMM"), &aExtension );
aTmpFileName = aTempFile.GetName(); aTmpFileName = aTempFile.GetURL();
Reference< XStorable > xStorable( xCurModel, UNO_QUERY ); Reference< XStorable > xStorable( xCurModel, UNO_QUERY );
bool bStoredAsTemporary = false; bool bStoredAsTemporary = false;
......
...@@ -47,7 +47,6 @@ $(eval $(call gb_Library_add_exception_objects,tl,\ ...@@ -47,7 +47,6 @@ $(eval $(call gb_Library_add_exception_objects,tl,\
tools/source/datetime/tdate \ tools/source/datetime/tdate \
tools/source/datetime/ttime \ tools/source/datetime/ttime \
tools/source/debug/debug \ tools/source/debug/debug \
tools/source/fsys/tempfile \
tools/source/fsys/urlobj \ tools/source/fsys/urlobj \
tools/source/fsys/wldcrd \ tools/source/fsys/wldcrd \
tools/source/generic/b3dtrans \ tools/source/generic/b3dtrans \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <tools/tempfile.hxx>
#include <rtl/ustrbuf.hxx>
#include <osl/file.hxx>
#include <rtl/instance.hxx>
#include <tools/time.hxx>
#include <tools/debug.hxx>
#include <stdio.h>
using namespace osl;
namespace { struct TempNameBase_Impl : public rtl::Static< OUString, TempNameBase_Impl > {}; }
struct TempFile_Impl
{
OUString aName;
};
OUString ConstructTempDir_Impl()
{
// use system directory
OUString& rTempNameBase_Impl = TempNameBase_Impl::get();
if ( rTempNameBase_Impl.isEmpty() )
osl::FileBase::getTempDirURL( rTempNameBase_Impl );
OUString aName = rTempNameBase_Impl;
// Make sure that directory ends with a separator
if( !aName.endsWith( "/" ) )
aName += "/";
return aName;
}
void CreateTempName_Impl( OUString& rName, bool bKeep, bool bDir = true )
{
// add a suitable tempname
// Prefix can have 5 chars, leaving 3 for numbers. 26 ** 3 == 17576
// ER 13.07.00 why not radix 36 [0-9A-Z] ?!?
const unsigned nRadix = 26;
OUString aName( rName );
aName += "sv";
rName = "";
static unsigned long u = Time::GetSystemTicks();
for ( unsigned long nOld = u; ++u != nOld; )
{
u %= (nRadix*nRadix*nRadix);
OUString aTmp = OUStringBuffer(aName).
append((sal_Int32)(unsigned)u, nRadix).
append(".tmp").
makeStringAndClear();
if ( bDir )
{
FileBase::RC err = Directory::create( aTmp );
if ( err == FileBase::E_None )
{
// !bKeep: only for creating a name, not a file or directory
if ( bKeep || Directory::remove( aTmp ) == FileBase::E_None )
rName = aTmp;
break;
}
else if ( err != FileBase::E_EXIST )
{
// if f.e. name contains invalid chars stop trying to create dirs
break;
}
}
else
{
DBG_ASSERT( bKeep, "Too expensive, use directory for creating name!" );
File aFile( aTmp );
FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
if ( err == FileBase::E_None )
{
rName = aTmp;
aFile.close();
break;
}
else if ( err != FileBase::E_EXIST )
{
// if f.e. name contains invalid chars stop trying to create files
break;
}
}
}
}
OUString TempFile::CreateTempName()
{
// get correct directory
OUString aName = ConstructTempDir_Impl();
// get TempFile name with default naming scheme
CreateTempName_Impl( aName, false );
return aName;
}
TempFile::TempFile()
: pImp( new TempFile_Impl )
, bKillingFileEnabled( false )
{
// get correct directory
pImp->aName = ConstructTempDir_Impl();
// get TempFile with default naming scheme
CreateTempName_Impl( pImp->aName, true, false );
}
TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension )
: pImp( new TempFile_Impl )
, bKillingFileEnabled( false )
{
// get correct directory
OUString aName = ConstructTempDir_Impl();
// now use special naming scheme ( name takes leading chars and an index counting up from zero
aName += rLeadingChars;
for ( sal_Int32 i=0; ; i++ )
{
OUStringBuffer aTmpBuffer(aName);
aTmpBuffer.append(i);
if ( pExtension )
aTmpBuffer.append(*pExtension);
else
aTmpBuffer.append(".tmp");
OUString aTmp = aTmpBuffer.makeStringAndClear();
File aFile( aTmp );
FileBase::RC err = aFile.open(osl_File_OpenFlag_Create);
if ( err == FileBase::E_None )
{
pImp->aName = aTmp;
aFile.close();
break;
}
else if ( err != FileBase::E_EXIST )
// if f.e. name contains invalid chars stop trying to create dirs
break;
}
}
TempFile::~TempFile()
{
if ( bKillingFileEnabled )
{
File::remove( pImp->aName );
}
delete pImp;
}
OUString TempFile::GetName() const
{
OUString aTmp;
aTmp = pImp->aName;
return aTmp;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment