xoreos  0.0.5
zipfile.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/zipfile.h"
26 #include "src/common/filepath.h"
27 
28 #include "src/aurora/zipfile.h"
29 #include "src/aurora/util.h"
30 
31 namespace Aurora {
32 
34  assert(zip);
35 
36  _zipFile.reset(new Common::ZipFile(zip));
37 
38  load();
39 }
40 
42 }
43 
45  return _resources;
46 }
47 
49  return _zipFile->getFileSize(index);
50 }
51 
53  return _zipFile->getFile(index, tryNoCopy);
54 }
55 
56 void ZIPFile::load() {
57  const Common::ZipFile::FileList &files = _zipFile->getFiles();
58  for (Common::ZipFile::FileList::const_iterator file = files.begin(); file != files.end(); ++file) {
59  Resource res;
60 
61  res.name = Common::FilePath::getStem(file->name);
62  res.type = TypeMan.getFileType(file->name);
63  res.index = file->index;
64 
65  _resources.push_back(res);
66  }
67 }
68 
69 } // End of namespace Aurora
const ResourceList & getResources() const
Return the list of resources.
Definition: zipfile.cpp:44
#define TypeMan
Shortcut for accessing the file type manager.
Definition: util.h:85
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
Common::SeekableReadStream * getResource(uint32 index, bool tryNoCopy=false) const
Return a stream of the resource&#39;s contents.
Definition: zipfile.cpp:52
uint32 getResourceSize(uint32 index) const
Return the size of a resource.
Definition: zipfile.cpp:48
Utility functions to handle files used in BioWare&#39;s Aurora engine.
Common::UString name
The resource&#39;s name.
Definition: archive.h:49
ZIP file decompression.
A ZIP archive.
std::list< File > FileList
Definition: zipfile.h:50
std::list< Resource > ResourceList
Definition: archive.h:57
A class encapsulating ZIP file access.
Definition: zipfile.h:42
A resource within the archive.
Definition: archive.h:48
static UString getStem(const UString &p)
Return a file name&#39;s stem.
Definition: filepath.cpp:87
ResourceList _resources
External list of resource names and types.
Definition: zipfile.h:62
FileType type
The resource&#39;s type.
Definition: archive.h:51
uint32_t uint32
Definition: types.h:204
Interface for a seekable & readable data stream.
Definition: readstream.h:265
Utility class for manipulating file paths.
uint32 index
The resource&#39;s local index within the archive.
Definition: archive.h:52
ZIPFile(Common::SeekableReadStream *zip)
Take over this stream and read a ZIP file out of it.
Definition: zipfile.cpp:33
Common::ScopedPtr< Common::ZipFile > _zipFile
The actual zip file.
Definition: zipfile.h:59