fixed worlds list scanning
This commit is contained in:
@@ -28,8 +28,6 @@
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
regfile::regfile(fs::path filename) : file(filename) {
|
||||
if (file.length() < REGION_HEADER_SIZE)
|
||||
throw std::runtime_error("incomplete region file header");
|
||||
@@ -90,6 +88,8 @@ uint WorldRegion::getChunkDataSize(uint x, uint z) {
|
||||
return sizes[z * REGION_SIZE + x];
|
||||
}
|
||||
|
||||
const char* WorldFiles::WORLD_FILE = "world.json";
|
||||
|
||||
WorldFiles::WorldFiles(fs::path directory, const DebugSettings& settings)
|
||||
: directory(directory),
|
||||
generatorTestMode(settings.generatorTestMode),
|
||||
@@ -248,7 +248,7 @@ fs::path WorldFiles::getPlayerFile() const {
|
||||
}
|
||||
|
||||
fs::path WorldFiles::getWorldFile() const {
|
||||
return directory/fs::path("world.json");
|
||||
return directory/fs::path(WORLD_FILE);
|
||||
}
|
||||
|
||||
fs::path WorldFiles::getIndicesFile() const {
|
||||
|
||||
@@ -146,6 +146,8 @@ public:
|
||||
void write(const World* world, const Content* content);
|
||||
void writePacks(const World* world);
|
||||
void writeIndices(const ContentIndices* indices);
|
||||
|
||||
static const char* WORLD_FILE;
|
||||
};
|
||||
|
||||
#endif /* FILES_WORLDFILES_H_ */
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "WorldFiles.h"
|
||||
|
||||
#define SCREENSHOTS_FOLDER "screenshots"
|
||||
|
||||
@@ -41,6 +43,27 @@ fs::path EnginePaths::getWorldsFolder() {
|
||||
return userfiles/fs::path("worlds");
|
||||
}
|
||||
|
||||
std::vector<fs::path> EnginePaths::scanForWorlds() {
|
||||
std::vector<fs::path> folders;
|
||||
|
||||
fs::path folder = getWorldsFolder();
|
||||
if (!fs::is_directory(folder))
|
||||
return folders;
|
||||
|
||||
for (auto entry : fs::directory_iterator(folder)) {
|
||||
if (!entry.is_directory()) {
|
||||
continue;
|
||||
}
|
||||
fs::path worldFolder = entry.path();
|
||||
fs::path worldFile = worldFolder/fs::path(WorldFiles::WORLD_FILE);
|
||||
if (!fs::is_regular_file(worldFile)) {
|
||||
continue;
|
||||
}
|
||||
folders.push_back(worldFolder);
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
|
||||
bool EnginePaths::isWorldNameUsed(std::string name) {
|
||||
return fs::exists(EnginePaths::getWorldsFolder()/fs::u8path(name));
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ public:
|
||||
void setResources(fs::path folder);
|
||||
void setContentPacks(std::vector<ContentPack>* contentPacks);
|
||||
|
||||
std::vector<fs::path> scanForWorlds();
|
||||
|
||||
fs::path resolve(std::string path);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user