Overte C++ Documentation
AssetUtils.h
1 //
2 // AssetUtils.h
3 // libraries/networking/src
4 //
5 // Created by Ryan Huffman on 2015/07/30
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_AssetUtils_h
13 #define hifi_AssetUtils_h
14 
15 #include <cstdint>
16 
17 #include <map>
18 
19 #include <QtCore/QByteArray>
20 #include <QtCore/QUrl>
21 
22 namespace AssetUtils {
23 
24 using DataOffset = int64_t;
25 
26 using AssetPath = QString;
27 using AssetHash = QString;
28 using AssetPathList = QStringList;
29 
30 const size_t SHA256_HASH_LENGTH = 32;
31 const size_t SHA256_HASH_HEX_LENGTH = 64;
32 const uint64_t MAX_UPLOAD_SIZE = 1000 * 1000 * 1000; // 1GB
33 
34 const QString ASSET_FILE_PATH_REGEX_STRING = "^(\\/[^\\/\\0]+)+$";
35 const QString ASSET_PATH_REGEX_STRING = "^\\/([^\\/\\0]+(\\/)?)+$";
36 const QString ASSET_HASH_REGEX_STRING = QString("^[a-fA-F0-9]{%1}$").arg(SHA256_HASH_HEX_LENGTH);
37 
38 const QString HIDDEN_BAKED_CONTENT_FOLDER = "/.baked/";
39 
40 enum AssetServerError : uint8_t {
41  NoError = 0,
42  AssetNotFound,
43  InvalidByteRange,
44  AssetTooLarge,
45  PermissionDenied,
46  MappingOperationFailed,
47  FileOperationFailed,
48  NoAssetServer,
49  LostConnection
50 };
51 
52 enum AssetMappingOperationType : uint8_t {
53  Get = 0,
54  GetAll,
55  Set,
56  Delete,
57  Rename,
58  SetBakingEnabled
59 };
60 
61 enum BakingStatus {
62  Irrelevant,
63  NotBaked,
64  Pending,
65  Baking,
66  Baked,
67  Error
68 };
69 
70 struct MappingInfo {
71  AssetHash hash;
72  BakingStatus status;
73  QString bakingErrors;
74 };
75 
76 using AssetMappings = std::map<AssetPath, MappingInfo>;
77 using Mappings = std::map<AssetPath, AssetHash>;
78 
79 QUrl getATPUrl(const QString& input);
80 AssetHash extractAssetHash(const QString& input);
81 
82 QByteArray hashData(const QByteArray& data);
83 
84 QByteArray loadFromCache(const QUrl& url);
85 bool saveToCache(const QUrl& url, const QByteArray& file);
86 
87 bool isValidFilePath(const AssetPath& path);
88 bool isValidPath(const AssetPath& path);
89 bool isValidHash(const QString& hashString);
90 
91 QString bakingStatusToString(BakingStatus status);
92 
93 } // namespace AssetUtils
94 
95 #endif // hifi_AssetUtils_h