1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _TOOLS_TEMPFILE_HXX 24 #define _TOOLS_TEMPFILE_HXX 25 26 #include <tools/string.hxx> 27 #include "tools/toolsdllapi.h" 28 29 struct TempFile_Impl; 30 class TOOLS_DLLPUBLIC TempFile 31 { 32 TempFile_Impl* pImp; 33 sal_Bool bKillingFileEnabled; 34 35 public: 36 // Create a temporary file or directory in a given folder or the default tempfile folder 37 TempFile( const String* pParent=NULL, sal_Bool bDirectory=sal_False ); 38 39 // Create a temporary file or directory in a given folder or the default tempfile folder; its name starts 40 // with some given characters followed by a counter ( example: rLeadingChars="abc" means "abc0","abc1" 41 // and so on, depending on existing files in that folder ). 42 // The extension string may be f.e. ".txt" or "", if no extension string is given, ".tmp" is used 43 TempFile( const String& rLeadingChars, const String* pExtension=NULL, const String* pParent=NULL, sal_Bool bDirectory=sal_False ); 44 45 // TempFile will be removed from disk in dtor if EnableKillingTempFile was called before. 46 // TempDirs will be removed recursively in that case. 47 ~TempFile(); 48 49 sal_Bool IsValid() const; 50 51 // Returns the real name of the tempfile in file URL scheme. 52 String GetName() const; 53 54 // If enabled the file will be removed from disk when the dtor is called ( default is not enabled ) EnableKillingFile(sal_Bool bEnable=sal_True)55 void EnableKillingFile( sal_Bool bEnable=sal_True ) 56 { bKillingFileEnabled = bEnable; } 57 IsKillingFileEnabled() const58 sal_Bool IsKillingFileEnabled() const 59 { return bKillingFileEnabled; } 60 61 // Only create a name for a temporary file that would be valid at that moment. 62 static String CreateTempName( const String* pParent=NULL ); 63 64 // The TempNameBase is a folder in the default ( system ) tempfile folder. 65 // This subfolder will be used if a TempFile or TempName is created without a parent name. 66 // The caller of the SetTempNameBase is responsible for deleting this folder and all temporary files in it. 67 // The argument must be a simple name, not a complete URL. 68 // The return value of both methods is the complete URL of the tempname base folder. 69 static String SetTempNameBaseDirectory( const String &rBaseName ); 70 static String GetTempNameBaseDirectory(); 71 }; 72 73 #endif 74