| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // Copyright (c) 2008-2017 the Urho3D project.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #pragma once
- #include "../Core/Object.h"
- namespace Atomic
- {
- /// %File entry within the package file.
- struct PackageEntry
- {
- /// Offset from the beginning.
- unsigned offset_;
- /// File size.
- unsigned size_;
- /// File checksum.
- unsigned checksum_;
- };
- /// Stores files of a directory tree sequentially for convenient access.
- class ATOMIC_API PackageFile : public Object
- {
- ATOMIC_OBJECT(PackageFile, Object);
- public:
- /// Construct.
- PackageFile(Context* context);
- /// Construct and open.
- PackageFile(Context* context, const String& fileName, unsigned startOffset = 0);
- /// Destruct.
- virtual ~PackageFile();
- /// Open the package file. Return true if successful.
- bool Open(const String& fileName, unsigned startOffset = 0);
- /// Check if a file exists within the package file. This will be case-insensitive on Windows and case-sensitive on other platforms.
- bool Exists(const String& fileName) const;
- /// Return the file entry corresponding to the name, or null if not found. This will be case-insensitive on Windows and case-sensitive on other platforms.
- const PackageEntry* GetEntry(const String& fileName) const;
- /// Return all file entries.
- const HashMap<String, PackageEntry>& GetEntries() const { return entries_; }
- /// Return the package file name.
- const String& GetName() const { return fileName_; }
- /// Return hash of the package file name.
- StringHash GetNameHash() const { return nameHash_; }
- /// Return number of files.
- unsigned GetNumFiles() const { return entries_.Size(); }
- /// Return total size of the package file.
- unsigned GetTotalSize() const { return totalSize_; }
- /// Return total data size from all the file entries in the package file.
- unsigned GetTotalDataSize() const { return totalDataSize_; }
- /// Return checksum of the package file contents.
- unsigned GetChecksum() const { return checksum_; }
- /// Return whether the files are compressed.
- bool IsCompressed() const { return compressed_; }
- /// Return list of file names in the package.
- const Vector<String> GetEntryNames() const { return entries_.Keys(); }
- // ATOMIC BEGIN
- /// Return a file name in the package at the specified index
- const String& GetEntryName(unsigned index) const
- {
- unsigned nn = 0;
- for (HashMap<String, PackageEntry>::ConstIterator j = entries_.Begin(); j != entries_.End(); ++j)
- {
- if (nn == index) return j->first_;
- nn++;
- }
- return String::EMPTY;
- }
- /// Scan package for specified files.
- void Scan(Vector<String>& result, const String& pathName, const String& filter, bool recursive) const;
-
- // ATOMIC END
- private:
- /// File entries.
- HashMap<String, PackageEntry> entries_;
- /// File name.
- String fileName_;
- /// Package file name hash.
- StringHash nameHash_;
- /// Package file total size.
- unsigned totalSize_;
- /// Total data size in the package using each entry's actual size if it is a compressed package file.
- unsigned totalDataSize_;
- /// Package file checksum.
- unsigned checksum_;
- /// Compressed flag.
- bool compressed_;
- };
- }
|