From 9058f9a2723b41c0f6836dd00fdb2ce3422f6f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 10:39:52 +0200 Subject: [PATCH 01/13] build: use c++20 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85f8870..37e61e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.9.4) set(Wololokingdoms_INSTALLER WololoKingdoms) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) project(WololoKingdoms) From 286d4c4e802a104117df29760e82679d0f6ee7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 10:42:47 +0200 Subject: [PATCH 02/13] ci: try clang 10 --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c9b9e1..306881b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - name: Setup apt repositories run: | if [ $CC = clang ]; then - sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main" + sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main" fi - name: Update apt repositories run: sudo apt-get update @@ -27,7 +27,7 @@ jobs: - name: Install C compiler run: | if [ $CC = clang ]; then - sudo apt-get install -y --no-install-recommends clang-9 + sudo apt-get install -y --no-install-recommends clang-10 export CXX=clang++ else sudo apt-get install -y --no-install-recommends $CC From 143d0fc1e6dbff63bad5408fa23f7741373314e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 10:47:58 +0200 Subject: [PATCH 03/13] 9 --- .github/workflows/ci.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 306881b..f2aab9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ jobs: strategy: fail-fast: false matrix: - cc: [gcc, clang] + cc: [gcc-9, clang] runs-on: ubuntu-latest env: CC: ${{matrix.cc}} @@ -18,7 +18,7 @@ jobs: - name: Setup apt repositories run: | if [ $CC = clang ]; then - sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main" + sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main" fi - name: Update apt repositories run: sudo apt-get update @@ -27,10 +27,11 @@ jobs: - name: Install C compiler run: | if [ $CC = clang ]; then - sudo apt-get install -y --no-install-recommends clang-10 + sudo apt-get install -y --no-install-recommends clang-9 export CXX=clang++ else sudo apt-get install -y --no-install-recommends $CC + export CXX=g++-9 fi - name: Generate build files run: | From 18fc4520da5f6324b5c0983938128f8ee9b095ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 10:51:10 +0200 Subject: [PATCH 04/13] ci: correctly set env vars --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f2aab9a..1dd676d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,10 +28,10 @@ jobs: run: | if [ $CC = clang ]; then sudo apt-get install -y --no-install-recommends clang-9 - export CXX=clang++ + echo ::set-env name=CXX::clang++ else sudo apt-get install -y --no-install-recommends $CC - export CXX=g++-9 + echo ::set-env name=CXX::g++-9 fi - name: Generate build files run: | From 102b544df7288e3f7a930fb07766594798003b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:25:27 +0200 Subject: [PATCH 05/13] fix building genieutils as a static library --- libwololokingdoms/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libwololokingdoms/CMakeLists.txt b/libwololokingdoms/CMakeLists.txt index 057ed9c..f8573e2 100644 --- a/libwololokingdoms/CMakeLists.txt +++ b/libwololokingdoms/CMakeLists.txt @@ -21,7 +21,8 @@ endif() # dependencies: if (WK_STATIC_BUILD) - set(GENIEUTILS_STATIC_BUILD 1) + # Set `GUTILS_STATIC` option for genieutils. + set(GUTILS_STATIC ON CACHE BOOL "") endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) From d13046ca45da23347351fab3098017fd9fc95469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:28:11 +0200 Subject: [PATCH 06/13] make libwk build more library like --- libwololokingdoms/CMakeLists.txt | 141 ++++++++++++++++--------------- 1 file changed, 75 insertions(+), 66 deletions(-) diff --git a/libwololokingdoms/CMakeLists.txt b/libwololokingdoms/CMakeLists.txt index f8573e2..637c0cb 100644 --- a/libwololokingdoms/CMakeLists.txt +++ b/libwololokingdoms/CMakeLists.txt @@ -18,24 +18,37 @@ if (CMAKE_BUILD_TYPE EQUAL RELEASE) check_ipo_supported(RESULT ENABLE_LTO OUTPUT error) endif() -# dependencies: - if (WK_STATIC_BUILD) # Set `GUTILS_STATIC` option for genieutils. set(GUTILS_STATIC ON CACHE BOOL "") endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) -add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/genieutils/) +# Create library +if (WK_STATIC_BUILD) + message(STATUS "Building libwololokingdoms as static library") + add_library(${Wololokingdoms_LIBRARY} STATIC) +else() + add_library(${Wololokingdoms_LIBRARY} SHARED) +endif() + +target_include_directories(${Wololokingdoms_LIBRARY} + PRIVATE include/ +) -# include directories: +# Dependencies + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/genieutils/) -include_directories(include/) -include_directories(third_party/genieutils/include/) -include_directories(third_party/miniz) +target_include_directories(${Wololokingdoms_LIBRARY} + PRIVATE third_party/genieutils/include/ + third_party/miniz +) if (WIN32) add_definitions(-DICONV_SECOND_ARGUMENT_IS_CONST) - include_directories(third_party/genieutils/extern/win-iconv) + target_include_directories(${Wololokingdoms_LIBRARY} + PRIVATE third_party/genieutils/extern/win-iconv + ) endif() if (${ICONV_FOUND}) @@ -43,9 +56,9 @@ if (${ICONV_FOUND}) endif (${ICONV_FOUND}) if(NOT MSVC) - add_definitions(-Wall -Wsign-compare -Wextra -Wpedantic) + target_compile_options(${Wololokingdoms_LIBRARY} PRIVATE -Wall -Wsign-compare -Wextra -Wpedantic) else() - add_definitions(/wd4244 /wd4018 /wd4267 /wd4996 /wd4800) + target_compile_options(${Wololokingdoms_LIBRARY} PRIVATE /wd4244 /wd4018 /wd4267 /wd4996 /wd4800) endif() # check c++17 filesystem support @@ -55,70 +68,64 @@ set(CMAKE_REQUIRED_FLAGS) set(CMAKE_REQUIRED_LIBRARIES) if (NOT WORKING_STD_FS) message(WARNING "builtin filesystem is bad, falling back to gulrak/filesystem") - include_directories(third_party/filesystem/include/) - add_definitions(-DUSE_USERLAND_FS) + target_include_directories(${Wololokingdoms_LIBRARY} + PRIVATE third_party/filesystem/include/ + ) + target_compile_definitions(${Wololokingdoms_LIBRARY} + PRIVATE USE_USERLAND_FS + ) endif() if (WIN32) - add_definitions(-DUNICODE) - add_definitions(-D_UNICODE) + target_compile_definitions(${Wololokingdoms_LIBRARY} + PRIVATE UNICODE _UNICODE + ) endif() #------------------------------------------------------------------------------# # Source files: #------------------------------------------------------------------------------# -set(ALL_SRC - libwololokingdoms.cpp - fs.cpp - base64.cpp - md5.cpp - wk_xml.cpp - string_helpers.cpp - zr_map_creator.cpp - drs_creator.cpp - missing_strings.cpp - fixes/addunits.cpp - fixes/ai900unitidfix.cpp - fixes/aztecbonusfix.cpp - fixes/balance.cpp - fixes/berbersutfix.cpp - fixes/burmesefix.cpp - fixes/cuttingfix.cpp - fixes/demoshipfix.cpp - fixes/disablenonworkingunits.cpp - fixes/ethiopiansfreepikeupgradefix.cpp - fixes/feitoriafix.cpp - fixes/houseattackfix.cpp - fixes/hotkeysfix.cpp - fixes/khmerfix.cpp - fixes/malayfix.cpp - fixes/maliansfreeminingupgradefix.cpp - fixes/nomadsfix.cpp - fixes/portuguesefix.cpp - fixes/queuetechs.cpp - fixes/separateshipgraphics.cpp - fixes/siegetowerfix.cpp - fixes/slavteambonusfix.cpp - fixes/smallfixes.cpp - fixes/splituniquetechicons.cpp - fixes/tricklebuildingfix.cpp - fixes/uprootingfix.cpp - fixes/vietfix.cpp - wkconverter.cpp - third_party/miniz/miniz.c +target_sources(${Wololokingdoms_LIBRARY} PRIVATE + libwololokingdoms.cpp + fs.cpp + base64.cpp + md5.cpp + wk_xml.cpp + string_helpers.cpp + zr_map_creator.cpp + drs_creator.cpp + missing_strings.cpp + fixes/addunits.cpp + fixes/ai900unitidfix.cpp + fixes/aztecbonusfix.cpp + fixes/balance.cpp + fixes/berbersutfix.cpp + fixes/burmesefix.cpp + fixes/cuttingfix.cpp + fixes/demoshipfix.cpp + fixes/disablenonworkingunits.cpp + fixes/ethiopiansfreepikeupgradefix.cpp + fixes/feitoriafix.cpp + fixes/houseattackfix.cpp + fixes/hotkeysfix.cpp + fixes/khmerfix.cpp + fixes/malayfix.cpp + fixes/maliansfreeminingupgradefix.cpp + fixes/nomadsfix.cpp + fixes/portuguesefix.cpp + fixes/queuetechs.cpp + fixes/separateshipgraphics.cpp + fixes/siegetowerfix.cpp + fixes/slavteambonusfix.cpp + fixes/smallfixes.cpp + fixes/splituniquetechicons.cpp + fixes/tricklebuildingfix.cpp + fixes/uprootingfix.cpp + fixes/vietfix.cpp + wkconverter.cpp + third_party/miniz/miniz.c ) - -#------------------------------------------------------------------------------# -# Executeable: -#------------------------------------------------------------------------------# - -if (WK_STATIC_BUILD) - message(STATUS "Building libwololokingdoms as static library") - add_library(${Wololokingdoms_LIBRARY} STATIC ${ALL_SRC}) -else() - add_library(${Wololokingdoms_LIBRARY} SHARED ${ALL_SRC}) - target_link_libraries(${Wololokingdoms_LIBRARY} genieutils) -endif() +target_link_libraries(${Wololokingdoms_LIBRARY} genieutils) install(TARGETS ${Wololokingdoms_LIBRARY} LIBRARY DESTINATION lib @@ -132,5 +139,7 @@ install( if(ENABLE_LTO) message(STATUS "Building libwololokingdoms with link time optimization") - set_property(TARGET ${Wololokingdoms_LIBRARY} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) + set_target_properties(${Wololokingdoms_LIBRARY} + PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE + ) endif() From 00b0d25d21c3320b27e1acfa90f4f6c35c6bed08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:29:43 +0200 Subject: [PATCH 07/13] get rid of ghc/filesystem --- .gitmodules | 3 --- CMakeLists.txt | 9 --------- libwololokingdoms/CMakeLists.txt | 15 --------------- .../cmake/HasWorkingFilesystem.cmake | 16 ---------------- libwololokingdoms/third_party/filesystem | 1 - 5 files changed, 44 deletions(-) delete mode 100644 libwololokingdoms/cmake/HasWorkingFilesystem.cmake delete mode 160000 libwololokingdoms/third_party/filesystem diff --git a/.gitmodules b/.gitmodules index 306c94c..c363eab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "libwololokingdoms/third_party/pcrio"] path = libwololokingdoms/third_party/pcrio url = https://github.com/sandsmark/pcrio -[submodule "libwololokingdoms/third_party/filesystem"] - path = libwololokingdoms/third_party/filesystem - url = https://github.com/gulrak/filesystem diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e61e4..0994a32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,15 +71,6 @@ if (WIN32) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libwololokingdoms/third_party/genieutils/extern/win-iconv) endif() -# check c++17 filesystem support -# (mingw's windows header has a bug and msvc doesn't have it) -include(HasWorkingFilesystem) -if (NOT WORKING_STD_FS) - message(WARNING "builtin filesystem is bad, falling back to gulrak/filesystem") - include_directories(libwololokingdoms/third_party/filesystem/include/) - add_definitions(-DUSE_USERLAND_FS) -endif() - if (WIN32) add_definitions(-DNOMINMAX) add_definitions(-DWIN32_LEAN_AND_MEAN) diff --git a/libwololokingdoms/CMakeLists.txt b/libwololokingdoms/CMakeLists.txt index 637c0cb..9824118 100644 --- a/libwololokingdoms/CMakeLists.txt +++ b/libwololokingdoms/CMakeLists.txt @@ -61,21 +61,6 @@ else() target_compile_options(${Wololokingdoms_LIBRARY} PRIVATE /wd4244 /wd4018 /wd4267 /wd4996 /wd4800) endif() -# check c++17 filesystem support -# (mingw's windows header has a bug and msvc doesn't have it) -include(HasWorkingFilesystem) -set(CMAKE_REQUIRED_FLAGS) -set(CMAKE_REQUIRED_LIBRARIES) -if (NOT WORKING_STD_FS) - message(WARNING "builtin filesystem is bad, falling back to gulrak/filesystem") - target_include_directories(${Wololokingdoms_LIBRARY} - PRIVATE third_party/filesystem/include/ - ) - target_compile_definitions(${Wololokingdoms_LIBRARY} - PRIVATE USE_USERLAND_FS - ) -endif() - if (WIN32) target_compile_definitions(${Wololokingdoms_LIBRARY} PRIVATE UNICODE _UNICODE diff --git a/libwololokingdoms/cmake/HasWorkingFilesystem.cmake b/libwololokingdoms/cmake/HasWorkingFilesystem.cmake deleted file mode 100644 index 0732b2f..0000000 --- a/libwololokingdoms/cmake/HasWorkingFilesystem.cmake +++ /dev/null @@ -1,16 +0,0 @@ -include(CheckCXXSourceCompiles) - -set(CMAKE_REQUIRED_FLAGS "-std=c++17") -set(CMAKE_REQUIRED_LIBRARIES stdc++fs) - -check_cxx_source_compiles(" -#include -int main() { - std::filesystem::path aPath {\"hello\"}; - aPath /= \"world\"; - return 0; -} -" WORKING_STD_FS) - -set(CMAKE_REQUIRED_FLAGS) -set(CMAKE_REQUIRED_LIBRARIES) diff --git a/libwololokingdoms/third_party/filesystem b/libwololokingdoms/third_party/filesystem deleted file mode 160000 index 26077f2..0000000 --- a/libwololokingdoms/third_party/filesystem +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 26077f272e7c63af5747fac3aafed96ce7fb988b From a6c3b3a239ca62257b0d3733ab60ebd18225a936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:41:53 +0200 Subject: [PATCH 08/13] Use directly --- libwololokingdoms/CMakeLists.txt | 1 - libwololokingdoms/caseless.h | 27 +++++--- libwololokingdoms/drs_creator.h | 16 +++-- libwololokingdoms/fs.cpp | 6 -- libwololokingdoms/include/fs.h | 24 ------- libwololokingdoms/libwololokingdoms.cpp | 3 +- libwololokingdoms/wkconverter.cpp | 4 +- libwololokingdoms/wkconverter.h | 92 ++++++++++++++----------- libwololokingdoms/wksettings.h | 20 +++--- mainwindow.cpp | 4 +- mainwindow.h | 21 +++--- paths.cpp | 4 +- paths.h | 12 ++-- paths_linux.cpp | 4 +- wkinstaller.cpp | 3 + wkinstaller.h | 4 +- 16 files changed, 124 insertions(+), 121 deletions(-) delete mode 100644 libwololokingdoms/fs.cpp delete mode 100644 libwololokingdoms/include/fs.h diff --git a/libwololokingdoms/CMakeLists.txt b/libwololokingdoms/CMakeLists.txt index 9824118..9580a56 100644 --- a/libwololokingdoms/CMakeLists.txt +++ b/libwololokingdoms/CMakeLists.txt @@ -72,7 +72,6 @@ endif() #------------------------------------------------------------------------------# target_sources(${Wololokingdoms_LIBRARY} PRIVATE libwololokingdoms.cpp - fs.cpp base64.cpp md5.cpp wk_xml.cpp diff --git a/libwololokingdoms/caseless.h b/libwololokingdoms/caseless.h index b6b3a7d..52b32a2 100644 --- a/libwololokingdoms/caseless.h +++ b/libwololokingdoms/caseless.h @@ -1,27 +1,31 @@ #pragma once -#include +#include #ifdef _WIN32 /** * Windows is already case insensitive. */ -namespace cfs = fs; +namespace cfs = std::filesystem; #else #include "./string_helpers.h" #include // Remember the casing of previously used paths. -static std::map caseless_directories = {}; -static std::map> caseless_files = {}; +static std::map + caseless_directories = {}; +static std::map> + caseless_files = {}; /** * Case-insensitively find a file path. */ -static const fs::path& caseless(fs::path const& input) { +static const std::filesystem::path& +caseless(std::filesystem::path const& input) { std::string inputs = input.string(); - fs::path linput = tolower(inputs); + std::filesystem::path linput = tolower(inputs); if (caseless_directories.find(linput) != caseless_directories.end()) { return caseless_directories[linput]; } @@ -39,13 +43,13 @@ static const fs::path& caseless(fs::path const& input) { auto filename = linput.filename(); if (caseless_files.find(parent) == caseless_files.end()) { // Invalid path, trying to use a nonexistent directory - if (!fs::is_directory(parent)) { + if (!std::filesystem::is_directory(parent)) { return input; } caseless_directories[parent_path] = parent; auto& cached_dir = caseless_files[parent]; - for (auto& entry : fs::directory_iterator(parent)) { + for (auto& entry : std::filesystem::directory_iterator(parent)) { auto basename = entry.path().filename(); cached_dir[tolower(basename.string())] = parent / basename; } @@ -53,7 +57,7 @@ static const fs::path& caseless(fs::path const& input) { auto& directory = caseless_files[parent]; if (directory.find(filename) == directory.end()) { - // Creates a new file, use the casing used in the fs call + // Creates a new file, use the casing used in the std::filesystem call directory[filename] = parent / input.filename(); } @@ -61,10 +65,11 @@ static const fs::path& caseless(fs::path const& input) { } /** - * Case-insensitive wrappers around fs methods, for use on case sensitive file - * systems. + * Case-insensitive wrappers around std::filesystem methods, for use on case + * sensitive file systems. */ namespace cfs { +namespace fs = std::filesystem; using path = fs::path; using copy_options = fs::copy_options; static path resolve [[maybe_unused]] (const path& p) { return caseless(p); } diff --git a/libwololokingdoms/drs_creator.h b/libwololokingdoms/drs_creator.h index 2ce153a..818bfaa 100644 --- a/libwololokingdoms/drs_creator.h +++ b/libwololokingdoms/drs_creator.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include #include @@ -20,12 +20,13 @@ class DRSCreatorTableEntry { uint32_t size_ = 0; // Owned by this object std::istream* stream_ = nullptr; - fs::path filename_; + std::filesystem::path filename_; public: inline DRSCreatorTableEntry(uint32_t id, std::istream* data) : id_(id), stream_(data) {} - inline DRSCreatorTableEntry(uint32_t id, const fs::path& filename) + inline DRSCreatorTableEntry(uint32_t id, + const std::filesystem::path& filename) : id_(id), filename_(filename) {} inline DRSCreatorTableEntry(DRSCreatorTableEntry&& entry) : id_(entry.id_), stream_(entry.stream_), @@ -53,7 +54,7 @@ class DRSCreatorTable { public: inline void addFile(uint32_t id, std::istream* data); - inline void addFile(uint32_t id, const fs::path& filename); + inline void addFile(uint32_t id, const std::filesystem::path& filename); private: inline void setOffset(uint32_t offset); @@ -73,7 +74,7 @@ class DRSCreator { inline void addFile(DRSTableType table, uint32_t id, std::istream* data); inline void addFile(DRSTableType table, uint32_t id, - const fs::path& filename); + const std::filesystem::path& filename); void commit(); }; @@ -81,7 +82,8 @@ inline void DRSCreatorTable::addFile(uint32_t id, std::istream* data) { files_.push_back(DRSCreatorTableEntry(id, data)); } -inline void DRSCreatorTable::addFile(uint32_t id, const fs::path& filename) { +inline void DRSCreatorTable::addFile(uint32_t id, + const std::filesystem::path& filename) { files_.push_back(DRSCreatorTableEntry(id, filename)); } @@ -91,6 +93,6 @@ inline void DRSCreator::addFile(DRSTableType table, uint32_t id, } inline void DRSCreator::addFile(DRSTableType table, uint32_t id, - const fs::path& filename) { + const std::filesystem::path& filename) { tables_[table].addFile(id, filename); } diff --git a/libwololokingdoms/fs.cpp b/libwololokingdoms/fs.cpp deleted file mode 100644 index de7c427..0000000 --- a/libwololokingdoms/fs.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#if defined(__cplusplus) && __cplusplus >= 201703L && \ - defined(__has_include) && __has_include() && !defined(USE_USERLAND_FS) -// nothing -#else -#include -#endif diff --git a/libwololokingdoms/include/fs.h b/libwololokingdoms/include/fs.h deleted file mode 100644 index 051e71f..0000000 --- a/libwololokingdoms/include/fs.h +++ /dev/null @@ -1,24 +0,0 @@ -#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include() && !defined(USE_USERLAND_FS) - -#include -#include - -namespace fs { - using namespace std::filesystem; - using ifstream = std::ifstream; - using ofstream = std::ofstream; - using fstream = std::fstream; -} - -#else - -#include - -namespace fs { - using namespace ghc::filesystem; - using ifstream = ghc::filesystem::ifstream; - using ofstream = ghc::filesystem::ofstream; - using fstream = ghc::filesystem::fstream; -} - -#endif diff --git a/libwololokingdoms/libwololokingdoms.cpp b/libwololokingdoms/libwololokingdoms.cpp index e3c5c5c..fc71cc9 100644 --- a/libwololokingdoms/libwololokingdoms.cpp +++ b/libwololokingdoms/libwololokingdoms.cpp @@ -1,8 +1,9 @@ #include "wkconverter.h" #include "wksettings.h" -#include +#include #include +namespace fs = std::filesystem; using path_char_t = fs::path::value_type; class Listener; diff --git a/libwololokingdoms/wkconverter.cpp b/libwololokingdoms/wkconverter.cpp index 7f2483b..7740e05 100644 --- a/libwololokingdoms/wkconverter.cpp +++ b/libwololokingdoms/wkconverter.cpp @@ -37,13 +37,15 @@ #include "wololo/datPatch.h" #include "zr_map_creator.h" #include -#include +#include #include #include #include #include #include +namespace fs = std::filesystem; + // this copy is unfortunate but cfs::resolve returns a temporary :/ const fs::path resolve_path(const fs::path& input) { #ifdef _WIN32 diff --git a/libwololokingdoms/wkconverter.h b/libwololokingdoms/wkconverter.h index 9283d60..2ebc7f2 100644 --- a/libwololokingdoms/wkconverter.h +++ b/libwololokingdoms/wkconverter.h @@ -3,7 +3,7 @@ #include "genie/lang/LangFile.h" #include "platform.h" #include "wksettings.h" -#include +#include #include #include #include @@ -39,12 +39,14 @@ class WKConvertListener { /** * Report an error. */ - virtual void error([[maybe_unused]] std::exception const& err, bool showDialog = false) {} + virtual void error([[maybe_unused]] std::exception const& err, + bool showDialog = false) {} /** * Report an error (message only). */ - virtual void error([[maybe_unused]] std::string message, bool showDialog = false) { + virtual void error([[maybe_unused]] std::string message, + bool showDialog = false) { error(std::runtime_error(message), showDialog); } @@ -86,7 +88,7 @@ class WKConvertListener { * flags */ virtual void - installUserPatch([[maybe_unused]] fs::path userPatchExe, + installUserPatch([[maybe_unused]] std::filesystem::path userPatchExe, [[maybe_unused]] std::vector cliFlags) {} }; @@ -97,7 +99,7 @@ class WKConverter { public: WKConverter(WKSettings& settings, WKConvertListener* const listener) : settings(settings), listener(listener) { - if (settings.resourceDir != fs::path()) { + if (settings.resourceDir != std::filesystem::path()) { resourceDir = settings.resourceDir; } } @@ -108,18 +110,18 @@ class WKConverter { private: std::set civLetters; std::set aocSlpFiles; - std::map slpFiles; - std::map wavFiles; - std::map newTerrainFiles; + std::map slpFiles; + std::map wavFiles; + std::map newTerrainFiles; std::vector> rmsCodeStrings; bool secondAttempt = false; - fs::path nfzUpOutPath; - fs::path nfzVooblyOutPath; - fs::path vooblyDir; - fs::path upDir; - fs::path installDir; - fs::path resourceDir = "resources"; + std::filesystem::path nfzUpOutPath; + std::filesystem::path nfzVooblyOutPath; + std::filesystem::path vooblyDir; + std::filesystem::path upDir; + std::filesystem::path installDir; + std::filesystem::path resourceDir = "resources"; enum TerrainType { None, @@ -139,41 +141,50 @@ class WKConverter { TerrainType terrain_type; }; - void copyHDMaps(const fs::path& inputDir, const fs::path& outputDir, - bool replace = false); + void copyHDMaps(const std::filesystem::path& inputDir, + const std::filesystem::path& outputDir, bool replace = false); bool usesMultipleWaterTerrains(const std::string& map, std::map& terrainsUsed); bool isTerrainUsed(int terrain, std::map& terrainsUsed, const std::string& map, const std::map& patterns); void upgradeTrees(int usedTerrain, int oldTerrain, std::string& map); - void createZRmap(std::map& terrainOverrides, - fs::path outputDir, std::string mapName); + void + createZRmap(std::map& terrainOverrides, + std::filesystem::path outputDir, std::string mapName); void terrainSwap(genie::DatFile* hdDat, genie::DatFile* aocDat, int tNew, int tOld, int slpID); - void indexDrsFiles(fs::path const& src, bool expansionFiles = true, - bool terrainFiles = false); - inline void indexDrsFiles(fs::path const& src, WKSettings::IndexType flags) { + void indexDrsFiles(std::filesystem::path const& src, + bool expansionFiles = true, bool terrainFiles = false); + inline void indexDrsFiles(std::filesystem::path const& src, + WKSettings::IndexType flags) { indexDrsFiles( src, static_cast(flags & WKSettings::IndexType::Expansion) != 0, static_cast(flags & WKSettings::IndexType::Terrain) != 0); } - void copyHistoryFiles(fs::path inputDir, fs::path outputDir); + void copyHistoryFiles(std::filesystem::path inputDir, + std::filesystem::path outputDir); std::pair parseHDTextLine(std::string line); void convertLanguageFile(std::ifstream& in, std::ofstream& iniOut, std::map& langReplacement); - void createLanguageFile(fs::path languageIniPath, fs::path patchFolder); - void loadGameStrings(std::map& langReplacement, fs::path file); - void loadModdedStrings(fs::path moddedStringsFile, + void createLanguageFile(std::filesystem::path languageIniPath, + std::filesystem::path patchFolder); + void loadGameStrings(std::map& langReplacement, + std::filesystem::path file); + void loadModdedStrings(std::filesystem::path moddedStringsFile, std::map& langReplacement); - void makeRandomMapScriptsDrs(std::ofstream& out, const fs::path& drsDir); + void makeRandomMapScriptsDrs(std::ofstream& out, + const std::filesystem::path& drsDir); void makeDrs(std::ofstream& out); void editDrs(std::ifstream* in, std::ofstream* out); - void copyCivIntroSounds(const fs::path& inputDir, const fs::path& outputDir); - void copyWallFiles(const fs::path& inputDir); - void createMusicPlaylist(const fs::path& inputDir, const fs::path& outputDir); + void copyCivIntroSounds(const std::filesystem::path& inputDir, + const std::filesystem::path& outputDir); + void copyWallFiles(const std::filesystem::path& inputDir); + void createMusicPlaylist(const std::filesystem::path& inputDir, + const std::filesystem::path& outputDir); void transferHdDatElements(genie::DatFile* hdDat, genie::DatFile* aocDat); - void adjustArchitectureFlags(genie::DatFile* aocDat, fs::path flagFilename); + void adjustArchitectureFlags(genie::DatFile* aocDat, + std::filesystem::path flagFilename); void patchArchitectures(genie::DatFile* aocDat); bool checkGraphics(genie::DatFile* aocDat, short graphicID, std::vector checkedGraphics); @@ -184,15 +195,18 @@ class WKConverter { std::map& replacedGraphics, std::vector duplicatedGraphics, short graphicID, short compareID, short offset, bool civGroups = false); - bool identifyHotkeyFile(const fs::path& directory, fs::path& maxHki, - fs::path& lastEditedHki); - void copyHotkeyFile(const fs::path& maxHki, const fs::path& lastEditedHki, - fs::path dst); + bool identifyHotkeyFile(const std::filesystem::path& directory, + std::filesystem::path& maxHki, + std::filesystem::path& lastEditedHki); + void copyHotkeyFile(const std::filesystem::path& maxHki, + const std::filesystem::path& lastEditedHki, + std::filesystem::path dst); void removeWkHotkeys(); void hotkeySetup(); - void refreshSymlink(const fs::path& oldDir, const fs::path& newDir, - const LinkType type, bool copyOldContents = false); - void symlinkSetup(const fs::path& oldDir, const fs::path& newDir, - bool dataMod = false); - void setupFolders(fs::path xmlOutPathUP); + void refreshSymlink(const std::filesystem::path& oldDir, + const std::filesystem::path& newDir, const LinkType type, + bool copyOldContents = false); + void symlinkSetup(const std::filesystem::path& oldDir, + const std::filesystem::path& newDir, bool dataMod = false); + void setupFolders(std::filesystem::path xmlOutPathUP); }; diff --git a/libwololokingdoms/wksettings.h b/libwololokingdoms/wksettings.h index 3cd90a5..e83c0bf 100644 --- a/libwololokingdoms/wksettings.h +++ b/libwololokingdoms/wksettings.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include #include #include @@ -36,20 +36,20 @@ class WKSettings { int patch = -1; int hotkeyChoice = 0; int dlcLevel = 0; - fs::path resourceDir; - fs::path hdPath; - fs::path outPath; - fs::path vooblyDir; - fs::path upDir; - fs::path nfzVooblyOutPath; - fs::path nfzUpOutPath; + std::filesystem::path resourceDir; + std::filesystem::path hdPath; + std::filesystem::path outPath; + std::filesystem::path vooblyDir; + std::filesystem::path upDir; + std::filesystem::path nfzVooblyOutPath; + std::filesystem::path nfzUpOutPath; std::map dataModList; std::string modName; std::string baseModName; - std::vector> drsModDirectories; + std::vector> drsModDirectories; - inline void addDrsResources(const fs::path& directory, + inline void addDrsResources(const std::filesystem::path& directory, IndexType type = IndexType::Expansion) { drsModDirectories.push_back(std::make_pair(directory, type)); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 46162e7..e152236 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -28,6 +28,8 @@ #include #include +namespace fs = std::filesystem; + MainWindow::MainWindow(QWidget* parent, bool skipUpdater) : QMainWindow(parent), ui(new Ui::MainWindow) { fs::path exePath = getExePath(); diff --git a/mainwindow.h b/mainwindow.h index 2fe0bda..a92829c 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,7 +3,8 @@ #include #include #include -#include +#include +#include namespace Ui { class MainWindow; @@ -31,9 +32,9 @@ public slots: ~MainWindow(); private: - fs::path steamPath; - fs::path hdPath; - fs::path outPath; + std::filesystem::path steamPath; + std::filesystem::path hdPath; + std::filesystem::path outPath; std::map> dataModList; @@ -48,13 +49,13 @@ public slots: std::string modName; std::ofstream logFile; - fs::path vooblyDir; - fs::path upDir; - fs::path installDir; - fs::path nfzUpOutPath; - fs::path nfzVooblyOutPath; + std::filesystem::path vooblyDir; + std::filesystem::path upDir; + std::filesystem::path installDir; + std::filesystem::path nfzUpOutPath; + std::filesystem::path nfzVooblyOutPath; std::string baseModName = "WololoKingdoms Beta"; - fs::path resourceDir; + std::filesystem::path resourceDir; Ui::MainWindow* ui; diff --git a/paths.cpp b/paths.cpp index 53c4c98..7bd7213 100644 --- a/paths.cpp +++ b/paths.cpp @@ -1,7 +1,7 @@ #include "paths.h" #include "libwololokingdoms/platform.h" #include "libwololokingdoms/string_helpers.h" -#include +#include #include #include #include @@ -13,6 +13,8 @@ #include #endif +namespace fs = std::filesystem; + static fs::path extractHDPath(fs::path steamPath) { std::string line; fs::path hdPath; diff --git a/paths.h b/paths.h index e9ad6cc..ab7d196 100644 --- a/paths.h +++ b/paths.h @@ -1,9 +1,9 @@ #pragma once -#include +#include -static fs::path extractHDPath(fs::path steamPath); -fs::path getExePath(); +static std::filesystem::path extractHDPath(std::filesystem::path steamPath); +std::filesystem::path getExePath(); std::wstring readRegistryKey(std::wstring keyPath, std::wstring key); -fs::path getSteamPath(); -fs::path getHDPath(fs::path steamPath); -fs::path getOutPath(fs::path HDPath); +std::filesystem::path getSteamPath(); +std::filesystem::path getHDPath(std::filesystem::path steamPath); +std::filesystem::path getOutPath(std::filesystem::path HDPath); diff --git a/paths_linux.cpp b/paths_linux.cpp index e9f2fc6..14f1f96 100644 --- a/paths_linux.cpp +++ b/paths_linux.cpp @@ -4,7 +4,7 @@ #include "paths.h" #include #include -#include +#include #include #include #include @@ -12,6 +12,8 @@ #include #include +namespace fs = std::filesystem; + fs::path getExePath() { return fs::read_symlink("/proc/self/exe"); } static fs::path getHomeDirectory() { diff --git a/wkinstaller.cpp b/wkinstaller.cpp index c7e450a..4248ff2 100644 --- a/wkinstaller.cpp +++ b/wkinstaller.cpp @@ -1,6 +1,9 @@ #include "wkinstaller.h" #include #include +#include + +namespace fs = std::filesystem; WKInstaller::WKInstaller(WKSettings& settings) : settings(settings) {} diff --git a/wkinstaller.h b/wkinstaller.h index 641e237..45ede07 100644 --- a/wkinstaller.h +++ b/wkinstaller.h @@ -1,7 +1,7 @@ #include "libwololokingdoms/wkconverter.h" #include "libwololokingdoms/wksettings.h" #include -#include +#include #include #include @@ -26,6 +26,6 @@ public slots: public: WKInstaller(WKSettings& settings); void error(std::exception const& err, bool showDialog = false) override; - void installUserPatch(fs::path exePath, + void installUserPatch(std::filesystem::path exePath, std::vector cliFlags) override; }; From d9aa5f575ccbfe2611e1c7652a0bd0c5a360e520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:47:37 +0200 Subject: [PATCH 09/13] mod name should not be path_char_t --- libwololokingdoms/libwololokingdoms.cpp | 3 +-- libwololokingdoms/libwololokingdoms.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libwololokingdoms/libwololokingdoms.cpp b/libwololokingdoms/libwololokingdoms.cpp index fc71cc9..d35d50a 100644 --- a/libwololokingdoms/libwololokingdoms.cpp +++ b/libwololokingdoms/libwololokingdoms.cpp @@ -191,8 +191,7 @@ extern "C" void wksettings_up_path(wksettings_t inst, const path_char_t* path) { inst->upDir = path; } -extern "C" void wksettings_mod_name(wksettings_t inst, - const path_char_t* name) { +extern "C" void wksettings_mod_name(wksettings_t inst, const char* name) { inst->modName = name; } diff --git a/libwololokingdoms/libwololokingdoms.h b/libwololokingdoms/libwololokingdoms.h index 224d2cf..2106bd1 100644 --- a/libwololokingdoms/libwololokingdoms.h +++ b/libwololokingdoms/libwololokingdoms.h @@ -37,7 +37,7 @@ void wksettings_hd_path(wksettings_t, const path_char_t* path); void wksettings_output_path(wksettings_t, const path_char_t* path); void wksettings_voobly_path(wksettings_t, const path_char_t* path); void wksettings_up_path(wksettings_t, const path_char_t* path); -void wksettings_mod_name(wksettings_t, const path_char_t* name); +void wksettings_mod_name(wksettings_t, const char* name); // Add mods. void wksettings_data_mod(wksettings_t, const char* name, const char* exe, From 58d5c5671f80c7b2ca799a6b18daaba03262009e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:50:23 +0200 Subject: [PATCH 10/13] use stoi which works on wstrings --- libwololokingdoms/wkconverter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libwololokingdoms/wkconverter.cpp b/libwololokingdoms/wkconverter.cpp index 7740e05..2cedaf4 100644 --- a/libwololokingdoms/wkconverter.cpp +++ b/libwololokingdoms/wkconverter.cpp @@ -99,13 +99,13 @@ void WKConverter::indexDrsFiles(fs::path const& src, bool expansionFiles, } } else { if (extension == ".slp") { - int id = atoi(src.stem().string().c_str()); + int id = std::stoi(src.stem().string()); if (!expansionFiles) aocSlpFiles.insert(id); else slpFiles[id] = src; } else if (extension == ".wav") { - int id = atoi(src.stem().string().c_str()); + int id = std::stoi(src.stem().string()); wavFiles[id] = src; } } @@ -430,7 +430,7 @@ void WKConverter::makeRandomMapScriptsDrs(std::ofstream& out, const fs::path& drsDir) { DRSCreator drs(out); for (const auto& p : fs::directory_iterator(resolve_path(drsDir))) { - auto id = std::atoi(p.path().stem().c_str()); + auto id = std::stoi(p.path().stem().string()); drs.addFile(DRSTableType::Bina, id, p.path()); } drs.commit(); @@ -1915,7 +1915,7 @@ static void addMonkGraphicsToCiv(std::map& slpFiles, for (const auto& current : fs::directory_iterator(newMonkGraphicsDir)) { auto src = current.path(); std::string extension = src.extension().string(); - int id = prefix * 10000 + atoi(src.stem().string().c_str()); + int id = prefix * 10000 + std::stoi(src.stem().string()); slpFiles[id] = src; } } From 303627941704f38d135fb20d1e7265352c000f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:54:50 +0200 Subject: [PATCH 11/13] fix missed path_char_t reference --- libwololokingdoms/libwololokingdoms.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libwololokingdoms/libwololokingdoms.cpp b/libwololokingdoms/libwololokingdoms.cpp index d35d50a..8036c82 100644 --- a/libwololokingdoms/libwololokingdoms.cpp +++ b/libwololokingdoms/libwololokingdoms.cpp @@ -41,7 +41,7 @@ void wksettings_hd_path(wksettings_t, const path_char_t* path); void wksettings_output_path(wksettings_t, const path_char_t* path); void wksettings_voobly_path(wksettings_t, const path_char_t* path); void wksettings_up_path(wksettings_t, const path_char_t* path); -void wksettings_mod_name(wksettings_t, const path_char_t* name); +void wksettings_mod_name(wksettings_t, const char* name); // Add mods. void wksettings_data_mod(wksettings_t, const char* name, const char* exe, From 712962b6990238f0b72791995456838413f51c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 11:57:15 +0200 Subject: [PATCH 12/13] remove implicit allocating conversion from mklink calls --- libwololokingdoms/platform.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/libwololokingdoms/platform.h b/libwololokingdoms/platform.h index cb6b3c2..be23931 100644 --- a/libwololokingdoms/platform.h +++ b/libwololokingdoms/platform.h @@ -1,4 +1,5 @@ #pragma once +#include #include /** @@ -35,17 +36,10 @@ static void runCmd(std::wstring exe) { WaitForSingleObject(ShExecInfo.hProcess, INFINITE); } -static void mklink(LinkType type, std::string link, std::string dest) { - std::wstring wlink; - std::wstring wdest; - for (auto c : link) { - wchar_t w = c; - wlink.push_back(w); - } - for (auto c : dest) { - wchar_t w = c; - wdest.push_back(w); - } +static void mklink(LinkType type, const std::filesystem::path& link, + const std::filesystem::path& dest) { + std::wstring wlink = link.wstring(); + std::wstring wdest = dest.wstring(); if (type == LinkType::Soft) { std::wstringstream line; @@ -71,7 +65,8 @@ static void mklink(LinkType type, std::string link, std::string dest) { #include static void mklink [[maybe_unused]] ([[maybe_unused]] LinkType type, - std::string link, std::string dest) { + const std::filesystem::path& link, + const std::filesystem::path& dest) { symlink(dest.c_str(), link.c_str()); } From b0c1fe7bd25f43e7e1703ae161ddfb3e081303ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Wed, 27 May 2020 12:04:02 +0200 Subject: [PATCH 13/13] do not overload std::tolower --- libwololokingdoms/caseless.h | 4 ++-- libwololokingdoms/string_helpers.cpp | 2 +- libwololokingdoms/string_helpers.h | 2 +- libwololokingdoms/wkconverter.cpp | 8 +++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/libwololokingdoms/caseless.h b/libwololokingdoms/caseless.h index 52b32a2..08a1f53 100644 --- a/libwololokingdoms/caseless.h +++ b/libwololokingdoms/caseless.h @@ -25,7 +25,7 @@ static std::map(std::tolower)); return line; diff --git a/libwololokingdoms/string_helpers.h b/libwololokingdoms/string_helpers.h index 8f0d05f..4a93948 100644 --- a/libwololokingdoms/string_helpers.h +++ b/libwololokingdoms/string_helpers.h @@ -24,7 +24,7 @@ std::string wstrtostr(std::wstring wide); /** * Convert a std::string to lowercase. */ -std::string tolower(std::string line); +std::string string_to_lower(std::string line); /** * Completely consume a readable stream and concatenate it into a std::string. diff --git a/libwololokingdoms/wkconverter.cpp b/libwololokingdoms/wkconverter.cpp index 2cedaf4..8d1c565 100644 --- a/libwololokingdoms/wkconverter.cpp +++ b/libwololokingdoms/wkconverter.cpp @@ -2141,10 +2141,8 @@ void WKConverter::refreshSymlink(const fs::path& oldPath, void WKConverter::symlinkSetup(const fs::path& oldDir, const fs::path& newDir, bool dataMod) { - bool vooblySrc = - tolower(oldDir).find("\\voobly mods\\aoc") != std::string::npos; - bool vooblyDst = - tolower(newDir).find("\\voobly mods\\aoc") != std::string::npos; + bool vooblySrc = string_to_lower(oldDir.string()).find("\\voobly mods\\aoc") != std::string::npos; + bool vooblyDst = string_to_lower(newDir.string()).find("\\voobly mods\\aoc") != std::string::npos; cfs::create_directory(newDir); bool datalink = vooblySrc == vooblyDst && !dataMod; @@ -2196,7 +2194,7 @@ void WKConverter::symlinkSetup(const fs::path& oldDir, const fs::path& newDir, for (const auto& current : fs::directory_iterator(oldDir)) { const auto& currentPath = current.path(); if (!cfs::is_directory(currentPath) || - tolower(currentPath.filename().string()) != "savegame") { + string_to_lower(currentPath.filename().string()) != "savegame") { cfs::copy(currentPath, newDir / currentPath.filename(), fs::copy_options::recursive | fs::copy_options::skip_existing);