Skip to content

Commit

Permalink
Added dep loading
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoDv committed Mar 29, 2024
1 parent 4b08b2b commit a04eab7
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions src/Companion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,22 @@ void Companion::PrepareCache(const std::string& path) {
fs::create_directories(tdir);
} else {
for(auto& entry : fs::directory_iterator("tcache/" + cache)) {
std::ifstream file(entry.path(), std::ios::binary);
std::vector<uint8_t> buffer = std::vector<uint8_t>(std::istreambuf_iterator(file), {});
file.close();
std::string cpath = entry.path().filename().string();
std::replace(cpath.begin(), cpath.end(), '+', '/');
this->gCacheData[cache][cpath] = buffer;
const auto ext = entry.path().extension().string();

if(ext == ".data") {
std::ifstream file(entry.path(), std::ios::binary);
std::vector<uint8_t> buffer = std::vector<uint8_t>(std::istreambuf_iterator(file), {});
file.close();
std::string cpath = entry.path().filename().string();
std::replace(cpath.begin(), cpath.end(), '+', '/');
this->gCacheData[cache][cpath] = buffer;
} else if(ext == ".yaml") {
std::ifstream file(entry.path(), std::ios::binary);
YAML::Node dependencies = YAML::LoadFile(entry.path().string());
for(auto dep = dependencies.begin(); dep != dependencies.end(); ++dep) {
this->gAssetDependencies[this->gCurrentFile][dep->first.as<std::string>()] = std::make_pair(dep->second.as<YAML::Node>(), false);
}
}
}
}
} else {
Expand All @@ -457,7 +467,20 @@ void Companion::PrepareCache(const std::string& path) {
void Companion::StoreCache(const std::string path, const std::vector<uint8_t>& value) {
std::string outpath = path;
std::replace(outpath.begin(), outpath.end(), '/', '+');
std::ofstream file("tcache/" + this->gCurrentCacheHash + "/" + outpath, std::ios::binary);


YAML::Node dependencies = YAML::Node();

// Dump asset dependencies
for (auto [fst, snd] : this->gAssetDependencies[this->gCurrentFile]) {
dependencies[fst] = snd.first;
}

std::ofstream deps("tcache/" + this->gCurrentCacheHash + "/" + outpath + "-deps.yaml", std::ios::binary);
deps << dependencies;
deps.close();

std::ofstream file("tcache/" + this->gCurrentCacheHash + "/" + outpath + ".data", std::ios::binary);
file.write(reinterpret_cast<const char*>(value.data()), value.size());
file.close();
}
Expand Down Expand Up @@ -1007,6 +1030,8 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::RegisterAsset(cons
auto entry = std::make_tuple(output, node);
this->gAddrMap[this->gCurrentFile][node["offset"].as<uint32_t>()] = entry;



return entry;
}

Expand Down

0 comments on commit a04eab7

Please sign in to comment.