diff --git a/.gitmodules b/.gitmodules index c03b0e1..412fbb7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e0e033..dd228c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} ) diff --git a/cpfs b/cpfs new file mode 160000 index 0000000..064da45 --- /dev/null +++ b/cpfs @@ -0,0 +1 @@ +Subproject commit 064da4585b33d8fa1e87617b8dfa3fe9899eb83e diff --git a/src/MCMap.cpp b/src/MCMap.cpp index 08bf864..32a63ed 100644 --- a/src/MCMap.cpp +++ b/src/MCMap.cpp @@ -10,8 +10,7 @@ #include #include #include -#include -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 & 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 & 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); } diff --git a/src/MTMap.cpp b/src/MTMap.cpp index b0fbfed..b2d3804 100644 --- a/src/MTMap.cpp +++ b/src/MTMap.cpp @@ -7,8 +7,8 @@ #include #include #include -#include -namespace fs = boost::filesystem; +#include +#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, diff --git a/src/util.hpp b/src/util.hpp index a0ac8bc..b8b3bc0 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -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