Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/base/StarPackedAssetSource.hpp
blob: dbec948917d29725cc2641ab421985ca2251ca61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include "StarOrderedMap.hpp"
#include "StarFile.hpp"
#include "StarDirectoryAssetSource.hpp"

namespace Star {

STAR_CLASS(PackedAssetSource);

class PackedAssetSource : public AssetSource {
public:
  typedef function<void(size_t, size_t, String, String)> BuildProgressCallback;

  // Build a packed asset file from the given DirectoryAssetSource.
  //
  // 'extensionSorting' sorts the packed file with file extensions that case
  // insensitive match the given extensions in the order they are given.  If a
  // file has an extension that doesn't match any in this list, it goes after
  // all other files.  All files are sorted secondarily by case insensitive
  // alphabetical order.
  //
  // If given, 'progressCallback' will be called with the total number of
  // files, the current file number, the file name, and the asset path.
  static void build(DirectoryAssetSource& directorySource, String const& targetPackedFile,
      StringList const& extensionSorting = {}, BuildProgressCallback progressCallback = {});

  PackedAssetSource(String const& packedFileName);

  JsonObject metadata() const override;
  StringList assetPaths() const override;

  IODevicePtr open(String const& path) override;
  ByteArray read(String const& path) override;

private:
  FilePtr m_packedFile;
  JsonObject m_metadata;
  OrderedHashMap<String, pair<uint64_t, uint64_t>> m_index;
};

}