mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
add 'write-to-user' permission & refactor checking for writeability
This commit is contained in:
parent
e327e80228
commit
7eeac66abf
6 changed files with 48 additions and 17 deletions
|
|
@ -134,6 +134,7 @@ void Engine::initialize(CoreParameters coreParameters) {
|
|||
}
|
||||
paths = std::make_unique<EnginePaths>(params);
|
||||
loadProject();
|
||||
paths->setupProject(*project);
|
||||
|
||||
editor = std::make_unique<devtools::Editor>(*this);
|
||||
cmd = std::make_unique<cmd::CommandsInterpreter>();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "io/devices/ZipFileDevice.hpp"
|
||||
#include "maths/util.hpp"
|
||||
#include "typedefs.hpp"
|
||||
#include "devtools/Project.hpp"
|
||||
#include "util/platform.hpp"
|
||||
#include "util/random.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
|
|
@ -43,7 +44,10 @@ static std::string generate_random_base64() {
|
|||
EnginePaths::EnginePaths(CoreParameters& params)
|
||||
: resourcesFolder(params.resFolder),
|
||||
userFilesFolder(params.userFolder),
|
||||
projectFolder(params.projectFolder) {
|
||||
projectFolder(params.projectFolder),
|
||||
initiallyWriteables({
|
||||
"world", "export", "config"
|
||||
}) {
|
||||
if (!params.scriptFile.empty()) {
|
||||
scriptFolder = params.scriptFile.parent_path();
|
||||
io::set_device("script", std::make_shared<io::StdfsDevice>(*scriptFolder));
|
||||
|
|
@ -239,6 +243,22 @@ void EnginePaths::setEntryPoints(std::vector<PathsRoot> entryPoints) {
|
|||
this->entryPoints = std::move(entryPoints);
|
||||
}
|
||||
|
||||
void EnginePaths::setupProject(const Project& project) {
|
||||
if (project.permissions.has(Permissions::WRITE_TO_USER)) {
|
||||
initiallyWriteables.insert("user");
|
||||
}
|
||||
}
|
||||
|
||||
bool EnginePaths::isWriteable(const std::string& entryPoint) const {
|
||||
if (entryPoint.length() < 2) {
|
||||
return false;
|
||||
}
|
||||
if (entryPoint.substr(0, 2) == "W.") {
|
||||
return true;
|
||||
}
|
||||
return initiallyWriteables.find(entryPoint) != initiallyWriteables.end();
|
||||
}
|
||||
|
||||
std::tuple<std::string, std::string> EnginePaths::parsePath(std::string_view path) {
|
||||
size_t separator = path.find(':');
|
||||
if (separator == std::string::npos) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <set>
|
||||
|
||||
struct PathsRoot {
|
||||
std::string name;
|
||||
|
|
@ -42,6 +43,8 @@ private:
|
|||
std::vector<PathsRoot> roots;
|
||||
};
|
||||
|
||||
struct Project;
|
||||
|
||||
class EnginePaths {
|
||||
public:
|
||||
ResPaths resPaths;
|
||||
|
|
@ -65,6 +68,10 @@ public:
|
|||
|
||||
void setEntryPoints(std::vector<PathsRoot> entryPoints);
|
||||
|
||||
void setupProject(const Project& project);
|
||||
|
||||
bool isWriteable(const std::string& entryPoint) const;
|
||||
|
||||
std::vector<io::path> scanForWorlds() const;
|
||||
|
||||
static std::tuple<std::string, std::string> parsePath(std::string_view view);
|
||||
|
|
@ -81,6 +88,7 @@ private:
|
|||
std::vector<PathsRoot> entryPoints;
|
||||
std::unordered_map<std::string, std::string> writeables;
|
||||
std::vector<std::string> mounted;
|
||||
std::set<std::string> initiallyWriteables;
|
||||
|
||||
void cleanup();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue