Switch from Boost filesystem to CPFS

The Boost libraries are huge and make Windows compilation very difficult.
master
ShadowNinja 2017-04-22 12:13:43 -04:00
parent 550abde86b
commit ac0d18f310
6 changed files with 34 additions and 16 deletions

3
.gitmodules vendored
View File

@ -1,3 +1,6 @@
[submodule "nbt"]
path = nbt
url = https://github.com/ShadowNinja/NBT-CPP.git
[submodule "cpfs"]
path = cpfs
url = https://github.com/ShadowNinja/CPFS.git

View File

@ -13,22 +13,22 @@ add_executable(${PROJECT_NAME}
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
add_subdirectory(nbt)
add_subdirectory(cpfs)
find_package(Threads REQUIRED)
find_package(Boost REQUIRED COMPONENTS "filesystem" "system")
find_package(SQLite3 REQUIRED)
target_link_libraries(${PROJECT_NAME}
Threads::Threads
"nbt"
"CPFS"
${ZLIB_LIBRARY}
${SQLite3_LIBRARY}
${Boost_LIBRARIES}
)
include_directories(
"${NBT_SOURCE_DIR}/src"
"${CPFS_SOURCE_DIR}/src"
${ZLIB_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${SQLite3_INCLUDE_DIRS}
)

1
cpfs Submodule

@ -0,0 +1 @@
Subproject commit 064da4585b33d8fa1e87617b8dfa3fe9899eb83e

View File

@ -10,8 +10,7 @@
#include <fstream>
#include <iostream>
#include <csignal>
#include <boost/filesystem/operations.hpp>
namespace fs = boost::filesystem;
#include "cpfs.h"
#define CHUNK_OFS_POS(x, z) ((x & 0x1F) + (z & 0x1F) * 32) * 4
@ -42,11 +41,23 @@ MCMap::MCMap(const std::string & path) :
void MCMap::listGroups(std::vector<MCGroup*> & v)
{
MCFormat format = MCFormat::Regions;
using dir_iter = fs::directory_iterator;
for (dir_iter it(path + DIR_DELIM "region"); it != dir_iter(); ++it) {
std::string filename = it->path().filename().string();
CpfsPath cp_path;
cpfs_path_create(&cp_path, (path + DIR_DELIM "region").c_str());
CpfsDirIter it;
if (!cpfs_dir_create(&it, &cp_path)) {
cpfs_path_destroy(&cp_path);
}
cpfs_path_destroy(&cp_path);
while (cpfs_dir_next(&it)) {
CpfsPath filename;
cpfs_dir_name(&it, &filename);
char *filename_utf8 = cpfs_path_utf8(&filename);
std::string filename_str(filename_utf8);
cpfs_path_utf8_destroy(filename_utf8);
Tokenizer tok(filename_str);
Tokenizer tok(filename);
std::string x_s, z_s, ext;
if (!tok.next(&ext, '.') || ext != "r") continue;
if (!tok.next(&x_s, '.')) continue;
@ -78,8 +89,9 @@ void MCMap::listGroups(std::vector<MCGroup*> & v)
continue;
}
v.push_back(new MCGroup(filename, x, z, format));
v.push_back(new MCGroup(filename_str, x, z, format));
}
cpfs_dir_destroy(&it);
}

View File

@ -7,8 +7,8 @@
#include <iostream>
#include <memory>
#include <cassert>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#include <cstring>
#include "cpfs.h"
#define SER_FMT_VER_HIGHEST_WRITE 25
@ -55,10 +55,15 @@ MTMap::MTMap(const std::string & path) :
{
init_conversions();
if (!fs::is_directory(path) && !fs::create_directories(path))
CpfsPath cp_path;
cpfs_path_create(&cp_path, path.c_str());
if (!cpfs_is_directory(&cp_path) && !cpfs_create_directory(&cp_path))
throw std::runtime_error("Failed to create database save "
"directory: " + path);
cpfs_path_destroy(&cp_path);
sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
SQLOK(sqlite3_open_v2((path + DIR_DELIM "map.sqlite").c_str(), &db,

View File

@ -8,15 +8,12 @@
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a))
#ifdef _WIN32
# define DIR_DELIM "\\"
# define fileno(x) _fileno(x)
inline bool isatty(int fd)
{
DWORD mode;
return GetConsoleMode((HANDLE)_get_osfhandle(fd), &mode);
}
#else
# define DIR_DELIM "/"
#endif