Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Cache.h
Go to the documentation of this file.
1#pragma once
2#include <API/Base.h>
3#include "Logger/Logger.h"
4
5#include <unordered_map>
6#include <unordered_set>
7#include <filesystem>
8#include <iostream>
9#include <fstream>
10
11namespace Cache
12{
14
15 void saveToFile(const std::filesystem::path& filename, const std::string& content);
16
18
19 template <typename T>
20 void serializeMap(const std::unordered_map<std::string, T>& data, const std::filesystem::path& filename)
21 {
23 if (!file.is_open())
24 {
25 Log::GetLog()->error("Error opening file for writing: " + filename.string());
26 return;
27 }
28
29 for (const auto& entry : data)
30 {
32 file.write(reinterpret_cast<char*>(&keySize), sizeof(keySize));
34 file.write(reinterpret_cast<const char*>(&entry.second), sizeof(T));
35 }
36
37 file.close();
38 }
39
40 template <typename T>
42 {
45
47 {
48 Log::GetLog()->error("File does not exist: " + filename.string());
49 return data;
50 }
51
53 if (!file.is_open()) {
54 Log::GetLog()->error("Error opening file for writing: " + filename.string());
55 return data;
56 }
57
58 while (file) {
60 if (file.read(reinterpret_cast<char*>(&keySize), sizeof(keySize))) {
61 std::string key;
63 if (file.read(&key[0], keySize)) {
64 T value;
65 if (file.read(reinterpret_cast<char*>(&value), sizeof(T))) {
66 data[key] = value;
67 }
68 else {
69 Log::GetLog()->error("Error reading value");
70 }
71 }
72 else {
73 Log::GetLog()->error("Error reading key");
74 }
75 }
76 }
77
78 file.close();
79 return data;
80 }
81
82 void saveToFilePlain(const std::filesystem::path& filename, const std::unordered_map<std::string, intptr_t>& map);
83
85
87 "$",
88 "<",
89 "Z_",
90 "z_",
91 "zlib",
92 "xatlas",
93 "_",
94 "TSet",
95 "TSQVisitor",
96 "TReversePredicate",
97 "TResourceArray",
98 "TResizableCircularQueue",
99 "TRenderThreadStruct",
100 "TRenderResourcePool",
101 "TRenderAssetUpdate",
102 "TRemove",
103 "TRHILambdaCommand",
104 "TRDGLambdaPass",
105 "TQueue",
106 "TProperty",
107 "TPrivateObjectPtr",
108 "TPairInitializer",
109 "TObjectPtr",
110 "TMapBase",
111 "TBase",
112 "TArray",
113 "SharedPointerInternals",
114 "TSharedRef",
115 "TSizedInlineAllocator",
116 "TSparseArray",
117 "TTypedElementList",
118 "TUniquePtr",
119 "TWeakPtr",
120 "UE.",
121 "UScriptStruct",
122 "oo2::",
123 "std::",
124 "ogg",
125 "oidn",
126 "ngx",
127 "curl",
128 "dt",
129 "cpp",
130 "Vulkan",
131 "USynth",
132 "UUI",
133 "TType",
134 "UE.",
135 "UE:",
136 "TkDOP",
137 "TStatic",
138 "TSlateBaseNamedArgs",
139 "TSharedFromThis",
140 "TShaderRefBase",
141 "TMeshProcessorShaders",
142 "TMaterialCHS",
143 "TGraphTask",
144 "TDelegate",
145 "TCommon",
146 "STableRow",
147 "SNotification",
148 "Nanite",
149 "Metasound",
150 "IPCGAttributeAccessorT",
151 "ITyped",
152 "FWide",
153 "FView",
154 "FSource",
155 "FShader",
156 "FRig",
157 "FRender",
158 "FRecast",
159 "FRDG",
160 "FPixel",
161 "FOpen",
162 "FOnlineFriendsSpec",
163 "FNiagara",
164 "FNDI",
165 "FMovie",
166 "FLumen",
167 "FD3D",
168 "FComputeShaderUtils",
169 "FCombine",
170 "Eigen",
171 "D3D",
172 "Chaos",
173 "Build",
174 "BINK",
175 "Aws",
176 "Audio",
177 "Add",
178 "Algo",
179 "PCG",
180 "TInd",
181 "TSha",
182 "TSlate",
183 "TWeakBase",
184 "UWi",
185 "TIndTSha",
186 "TSlate",
187 "TWeakBase",
188 "UWin"
189 };
190}
std::string calculateSHA256(const std::filesystem::path &filename)
Definition Cache.cpp:13
void saveToFile(const std::filesystem::path &filename, const std::string &content)
Definition Cache.cpp:63
static const std::unordered_set< std::string > default_filters
Definition Cache.h:86
std::string readFromFile(const std::filesystem::path &filename)
Definition Cache.cpp:75
void serializeMap(const std::unordered_map< std::string, T > &data, const std::filesystem::path &filename)
Definition Cache.h:20
void saveToFilePlain(const std::filesystem::path &filename, const std::unordered_map< std::string, intptr_t > &map)
Definition Cache.cpp:93
std::unordered_map< std::string, T > deserializeMap(const std::filesystem::path &filename)
Definition Cache.h:41
std::unordered_set< std::string > readFileIntoSet(const std::filesystem::path &filename)
Definition Cache.cpp:113