add pack.request_writeable(...) & update gui.confirm screen

This commit is contained in:
MihailRis
2025-03-12 17:07:57 +03:00
parent 4cdb1fbae2
commit 88b45e5098
6 changed files with 84 additions and 14 deletions
+31
View File
@@ -150,6 +150,37 @@ void EnginePaths::setCurrentWorldFolder(io::path folder) {
io::create_subdevice("world", "user", currentWorldFolder);
}
#include <chrono>
#include "maths/util.hpp"
std::string EnginePaths::createWriteablePackDevice(const std::string& name) {
const auto& found = writeablePacks.find(name);
if (found != writeablePacks.end()) {
return found->second;
}
io::path folder;
for (const auto& pack : *contentPacks) {
if (pack.id == name) {
folder = pack.folder;
break;
}
}
if (folder.emptyOrInvalid()) {
throw std::runtime_error("pack not found");
}
auto now = std::chrono::high_resolution_clock::now();
auto seed = now.time_since_epoch().count();
util::PseudoRandom random(seed); // fixme: replace with safe random
auto number = random.rand64();
auto entryPoint = std::string("W.") + util::base64_urlsafe_encode(reinterpret_cast<ubyte*>(&number), 6);
io::create_subdevice(entryPoint, folder.entryPoint(), folder.pathPart());
writeablePacks[name] = entryPoint;
return entryPoint;
}
void EnginePaths::setContentPacks(std::vector<ContentPack>* contentPacks) {
// Remove previous content entry-points
for (const auto& id : contentEntryPoints) {
+4
View File
@@ -1,5 +1,6 @@
#pragma once
#include <unordered_map>
#include <stdexcept>
#include <optional>
#include <string>
@@ -33,6 +34,8 @@ public:
io::path getControlsFile() const;
io::path getSettingsFile() const;
std::string createWriteablePackDevice(const std::string& name);
void setContentPacks(std::vector<ContentPack>* contentPacks);
std::vector<io::path> scanForWorlds() const;
@@ -47,6 +50,7 @@ private:
std::optional<std::filesystem::path> scriptFolder;
std::vector<ContentPack>* contentPacks = nullptr;
std::vector<std::string> contentEntryPoints;
std::unordered_map<std::string, std::string> writeablePacks;
};
struct PathsRoot {