zipTempStream.h
Engine/source/core/util/zip/zipTempStream.h
Classes:
class
Namespaces:
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include "core/util/zip/zipArchive.h" 25#include "core/util/str.h" 26 27#ifndef _ZIPTEMPSTREAM_H_ 28#define _ZIPTEMPSTREAM_H_ 29 30namespace Zip 31{ 32 33/// @addtogroup zipint_group 34/// @ingroup zip_group 35// @{ 36 37class ZipTempStream : public FileStream 38{ 39 typedef FileStream Parent; 40 41protected: 42 CentralDir *mCD; 43 bool mDeleteOnClose; 44 String mFilename; 45 46public: 47 ZipTempStream() : mCD(NULL), mDeleteOnClose(false) {} 48 ZipTempStream(CentralDir *cd) : mCD(cd), mDeleteOnClose(false) {} 49 virtual ~ZipTempStream() { close(); } 50 51 void setCentralDir(CentralDir *cd) { mCD = cd; } 52 CentralDir *getCentralDir() { return mCD; } 53 54 void setDeleteOnClose(bool del) { mDeleteOnClose = del; } 55 56 virtual bool open(String filename, Torque::FS::File::AccessMode mode); 57 58 /// Open a temporary file in ReadWrite mode. The file will be deleted when the stream is closed. 59 virtual bool open() 60 { 61 return open(String(), Torque::FS::File::ReadWrite); 62 } 63 64 virtual void close() 65 { 66 Parent::close(); 67 68 if(mDeleteOnClose) 69 Torque::FS::Remove(mFilename); 70 71 } 72 73 /// Disallow setPosition() 74 virtual bool setPosition(const U32 i_newPosition) { return false; } 75 76 /// Seek back to the start of the file. 77 /// This is used internally by the zip code and should never be called whilst 78 /// filters are attached (e.g. when reading or writing in a zip file) 79 bool rewind() 80 { 81 mStreamCaps |= U32(StreamPosition); 82 bool ret = Parent::setPosition(0); 83 mStreamCaps &= ~<a href="/coding/file/types_8h/#types_8h_1ac3df7cf3c8cb172a588adec881447d68">U32</a>(StreamPosition); 84 85 return ret; 86 } 87}; 88 89// @} 90 91} // end namespace Zip 92 93#endif // _ZIPTEMPSTREAM_H_ 94