diff options
author | Palenik Mihály <palenik.mihaly@gmail.com> | 2013-07-16 16:37:36 +0200 |
---|---|---|
committer | Andras Timar <atimar@suse.com> | 2013-07-16 18:40:45 +0000 |
commit | 9c0a390489dd99aee4beaf73845740776b8083aa (patch) | |
tree | 6c833c56639e77c7fe6e7fcd6c7be9a39d96c200 /tools/source | |
parent | Teach configure about distro-packaged external firebird. (diff) | |
download | core-9c0a390489dd99aee4beaf73845740776b8083aa.tar.gz core-9c0a390489dd99aee4beaf73845740776b8083aa.zip |
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/4938
Reviewed-by: Andras Timar <atimar@suse.com>
Tested-by: Andras Timar <atimar@suse.com>
Diffstat (limited to 'tools/source')
-rw-r--r-- | tools/source/fsys/tempfile.cxx | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/tools/source/fsys/tempfile.cxx b/tools/source/fsys/tempfile.cxx deleted file mode 100644 index bfc1a0df5e43..000000000000 --- a/tools/source/fsys/tempfile.cxx +++ /dev/null @@ -1,181 +0,0 @@ -/* -*- 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: */ |