zipObject.h

Engine/source/core/util/zip/zipObject.h

More...

Classes:

class

Script wrapper for Zip::ZipArchive.

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 "console/simBase.h"
25#include "core/util/zip/zipArchive.h"
26#include "core/util/tVector.h"
27#include "core/stream/streamObject.h"
28#include "core/util/str.h"
29
30#ifndef _ZIPOBJECT_H_
31#define _ZIPOBJECT_H_
32
33/// @addtogroup zip_group
34// @{
35
36//-----------------------------------------------------------------------------
37/// @brief Script wrapper for Zip::ZipArchive.
38//-----------------------------------------------------------------------------
39class ZipObject : public SimObject
40{
41   typedef SimObject Parent;
42
43protected:
44   Zip::ZipArchive *mZipArchive;
45
46   // StreamObjects are pooled and reused to avoid creating tons of SimObjects
47   Vector<StreamObject*> mStreamPool;
48
49   StreamObject *createStreamObject(Stream *stream);
50
51public:
52   ZipObject();
53   virtual ~ZipObject();
54   DECLARE_CONOBJECT(ZipObject);
55
56   // Methods for accessing the archive
57   /// @see Zip::ZipArchive::openArchive()
58   bool openArchive(const char *filename, Zip::ZipArchive::AccessMode mode = Zip::ZipArchive::Read);
59   /// @see Zip::ZipArchive::closeArchive()
60   void closeArchive();
61
62   // Stream based file system style interface
63   /// @see Zip::ZipArchive::openFile()
64   StreamObject *openFileForRead(const char *filename);
65   /// @see Zip::ZipArchive::openFile()
66   StreamObject *openFileForWrite(const char *filename);
67   /// @see Zip::ZipArchive::closeFile()
68   void closeFile(StreamObject *stream);
69
70   // Alternative archiver style interface
71   /// @see Zip::ZipArchive::addFile()
72   bool addFile(const char *filename, const char *pathInZip, bool replace = true);
73   /// @see Zip::ZipArchive::extractFile()
74   bool extractFile(const char *pathInZip, const char *filename);
75   /// @see Zip::ZipArchive::deleteFile()
76   bool deleteFile(const char *filename);
77
78
79   // Methods for access the list of files
80   S32 getFileEntryCount();
81   String getFileEntry(S32 idx);
82};
83
84// @}
85
86#endif // _ZIPOBJECT_H_
87