summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx91
1 files changed, 54 insertions, 37 deletions
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index c873f3a6fdad..12f2bc87b439 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -4,9 +4,9 @@
*
* $RCSfile: tempfile.cxx,v $
*
- * $Revision: 1.26 $
+ * $Revision: 1.27 $
*
- * last change: $Author: ihi $ $Date: 2007-06-05 18:32:32 $
+ * last change: $Author: ihi $ $Date: 2007-11-20 19:18:22 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -273,49 +273,22 @@ umask(old_mode);
}
}
-String TempFile::CreateTempName( const String* pParent )
+void lcl_createName(TempFile_Impl& _rImpl,const String& rLeadingChars,sal_Bool _bStartWithZero, const String* pExtension, const String* pParent, sal_Bool bDirectory)
{
- // get correct directory
- String aName = ConstructTempDir_Impl( pParent );
-
- // get TempFile name with default naming scheme
- CreateTempName_Impl( aName, sal_False );
-
- // convert to file URL
- rtl::OUString aTmp;
- if ( aName.Len() )
- FileBase::getSystemPathFromFileURL( aName, aTmp );
- return aTmp;
-}
-
-TempFile::TempFile( const String* pParent, sal_Bool bDirectory )
- : pImp( new TempFile_Impl )
- , bKillingFileEnabled( sal_False )
-{
- pImp->bIsDirectory = bDirectory;
-
- // get correct directory
- pImp->aName = ConstructTempDir_Impl( pParent );
-
- // get TempFile with default naming scheme
- CreateTempName_Impl( pImp->aName, sal_True, bDirectory );
-}
-
-TempFile::TempFile( const String& rLeadingChars, const String* pExtension, const String* pParent, sal_Bool bDirectory )
- : pImp( new TempFile_Impl )
- , bKillingFileEnabled( sal_False )
-{
- pImp->bIsDirectory = bDirectory;
+ _rImpl.bIsDirectory = bDirectory;
// get correct directory
String aName = ConstructTempDir_Impl( pParent );
+ sal_Bool bUseNumber = _bStartWithZero;
// now use special naming scheme ( name takes leading chars and an index counting up from zero
aName += rLeadingChars;
for ( sal_Int32 i=0;; i++ )
{
String aTmp( aName );
- aTmp += String::CreateFromInt32( i );
+ if ( bUseNumber )
+ aTmp += String::CreateFromInt32( i );
+ bUseNumber = sal_True;
if ( pExtension )
aTmp += *pExtension;
else
@@ -325,7 +298,7 @@ TempFile::TempFile( const String& rLeadingChars, const String* pExtension, const
FileBase::RC err = Directory::create( aTmp );
if ( err == FileBase::E_None )
{
- pImp->aName = aTmp;
+ _rImpl.aName = aTmp;
break;
}
else if ( err != FileBase::E_EXIST )
@@ -345,7 +318,7 @@ umask(old_mode);
#endif
if ( err == FileBase::E_None )
{
- pImp->aName = aTmp;
+ _rImpl.aName = aTmp;
aFile.close();
break;
}
@@ -362,9 +335,53 @@ umask(old_mode);
break;
}
}
+ if ( !_bStartWithZero )
+ aTmp += String::CreateFromInt32( i );
}
}
+
+String TempFile::CreateTempName( const String* pParent )
+{
+ // get correct directory
+ String aName = ConstructTempDir_Impl( pParent );
+
+ // get TempFile name with default naming scheme
+ CreateTempName_Impl( aName, sal_False );
+
+ // convert to file URL
+ rtl::OUString aTmp;
+ if ( aName.Len() )
+ FileBase::getSystemPathFromFileURL( aName, aTmp );
+ return aTmp;
+}
+
+TempFile::TempFile( const String* pParent, sal_Bool bDirectory )
+ : pImp( new TempFile_Impl )
+ , bKillingFileEnabled( sal_False )
+{
+ pImp->bIsDirectory = bDirectory;
+
+ // get correct directory
+ pImp->aName = ConstructTempDir_Impl( pParent );
+
+ // get TempFile with default naming scheme
+ CreateTempName_Impl( pImp->aName, sal_True, bDirectory );
+}
+
+TempFile::TempFile( const String& rLeadingChars, const String* pExtension, const String* pParent, sal_Bool bDirectory)
+ : pImp( new TempFile_Impl )
+ , bKillingFileEnabled( sal_False )
+{
+ lcl_createName(*pImp,rLeadingChars,sal_True, pExtension, pParent, bDirectory);
+}
+TempFile::TempFile( const String& rLeadingChars,sal_Bool _bStartWithZero, const String* pExtension, const String* pParent, sal_Bool bDirectory)
+ : pImp( new TempFile_Impl )
+ , bKillingFileEnabled( sal_False )
+{
+ lcl_createName(*pImp,rLeadingChars,_bStartWithZero, pExtension, pParent, bDirectory);
+}
+
TempFile::~TempFile()
{
delete pImp->pStream;