Repository navigation
Expand file tree
/
Copy pathGPUCacheLoader.cpp
More file actions
48 lines (42 loc) · 1.49 KB
/
Copy pathGPUCacheLoader.cpp
File metadata and controls
48 lines (42 loc) · 1.49 KB
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
43
44
45
46
47
48
// GPUCacheLoader.cpp
#include "GPUCacheLoader.h"
GPUCacheLoader::GPUCacheLoader(const std::string& cacheDirectory)
: cacheDirectory(cacheDirectory) {
}
GPUCacheLoader::~GPUCacheLoader() {}
bool GPUCacheLoader::LoadCache() {
try {
for (const auto& entry : fs::directory_iterator(cacheDirectory)) {
if (entry.is_regular_file()) {
if (!LoadFile(entry.path().string())) {
std::cerr << "Failed to load file: " << entry.path() << std::endl;
return false;
}
}
}
return true;
}
catch (const std::exception& e) {
std::cerr << "Error accessing cache directory: " << e.what() << std::endl;
return false;
}
}
const std::vector<std::vector<char>>& GPUCacheLoader::GetCacheData() const {
return cacheData;
}
bool GPUCacheLoader::LoadFile(const std::string& filePath) {
try {
std::ifstream file(filePath, std::ios::binary);
if (!file.is_open()) {
std::cerr << "Unable to open file: " << filePath << std::endl;
return false;
}
std::vector<char> fileData((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
cacheData.push_back(std::move(fileData));
return true;
}
catch (const std::exception& e) {
std::cerr << "Error reading file: " << filePath << " - " << e.what() << std::endl;
return false;
}
}