PackageFile.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  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 deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // 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 FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #ifndef COMMON_PACKAGEFILE_H
  24. #define COMMON_PACKAGEFILE_H
  25. #include "File.h"
  26. #include <map>
  27. //! File entry within the package file
  28. struct PackageEntry
  29. {
  30. unsigned mOffset;
  31. unsigned mSize;
  32. unsigned mChecksum;
  33. };
  34. //! Stores files of a directory tree sequentially for convenient access
  35. class PackageFile : public RefCounted
  36. {
  37. public:
  38. //! Construct and read the package file directory
  39. PackageFile(const std::string& fileName);
  40. //! Destruct. Close the package file
  41. virtual ~PackageFile();
  42. //! Check if a file exists within the package file
  43. bool exists(const std::string& fileName) const;
  44. //! Return the file entry corresponding to the name. Throw an exception if not found
  45. const PackageEntry& getEntry(const std::string& fileName) const;
  46. //! Return all file entries
  47. const std::map<std::string, PackageEntry>& getEntries() const { return mEntries; }
  48. //! Return the package file name
  49. const std::string& getName() const { return mFileName; }
  50. //! Return hash of the package file name
  51. StringHash getNameHash() const { return mNameHash; }
  52. //! Return number of files
  53. unsigned getNumFiles() const { return mEntries.size(); }
  54. //! Return total size of the package file
  55. unsigned getTotalSize() const { return mTotalSize; }
  56. //! Return checksum of the package file contents
  57. unsigned getChecksum() const { return mChecksum; }
  58. private:
  59. //! File entries
  60. std::map<std::string, PackageEntry> mEntries;
  61. //! File name
  62. std::string mFileName;
  63. //! Package file name hash
  64. StringHash mNameHash;
  65. //! Package file total size
  66. unsigned mTotalSize;
  67. //! Package file checksum
  68. unsigned mChecksum;
  69. };
  70. #endif // COMMON_PACKAGEFILE_H