Skip to content

Commit

Permalink
feat: make hkx32to64 Linux compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Guekka committed Aug 19, 2023
1 parent e2dd6ba commit 801acca
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 34 deletions.
6 changes: 1 addition & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
},
{
"cacheVariables": {
"BETHUTIL_HKX": {
"type": "BOOL",
"value": "ON"
},
"CMAKE_EXE_LINKER_FLAGS_RELEASE": {
"type": "STRING",
"value": "/DEBUG:FASTLINK"
Expand All @@ -61,7 +57,7 @@
},
"VCPKG_MANIFEST_FEATURES": {
"type": "STRING",
"value": "hkx;tests"
"value": "tests"
},
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
Expand Down
4 changes: 1 addition & 3 deletions cmake/config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ find_dependency("directxtex")
find_dependency("bc7enc")
find_dependency("mpsc_channel")
find_dependency("nlohmann_json")
if(@BETHUTIL_HKX@)
find_dependency("reproc++")
endif()
find_dependency("reproc++")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
Binary file modified data/exe.7z
Binary file not shown.
2 changes: 2 additions & 0 deletions include/btu/hkx/anim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class AnimExeInfo
[[nodiscard]] virtual auto get_required_files(const Path &exe_dir) const noexcept
-> std::vector<Path> = 0;
[[nodiscard]] virtual auto get_full_args(const Path &exe_dir) const -> std::vector<std::string> = 0;

[[nodiscard]] virtual auto is_os_supported() const noexcept -> bool = 0;
};

using AnimExeRef = std::reference_wrapper<const AnimExeInfo>;
Expand Down
2 changes: 2 additions & 0 deletions include/btu/hkx/error_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class AnimErr
NoAppropriateExe,
ExeFailed,
NoExeFound,
OsNotSupported,
};
} // namespace btu::hkx

Expand All @@ -37,6 +38,7 @@ struct AnimErrCategory : std::error_category
case AnimErr::NoAppropriateExe: return "no appropriate exe found";
case AnimErr::ExeFailed: return "exe failed";
case AnimErr::NoExeFound: return "no exe found at all";
case AnimErr::OsNotSupported: return "os not supported by exe";
}
return "(unrecognized error)";
};
Expand Down
17 changes: 5 additions & 12 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(HEADER_FILES
"${INCLUDE_DIR}/btu/bsa/detail/archive_type.hpp"
"${INCLUDE_DIR}/btu/esp/error_code.hpp"
"${INCLUDE_DIR}/btu/esp/functions.hpp"
"${INCLUDE_DIR}/btu/hkx/anim.hpp"
"${INCLUDE_DIR}/btu/hkx/error_code.hpp"
"${INCLUDE_DIR}/btu/modmanager/mod_folder.hpp"
"${INCLUDE_DIR}/btu/modmanager/mod_manager.hpp"
"${INCLUDE_DIR}/btu/nif/detail/common.hpp"
Expand Down Expand Up @@ -45,6 +47,7 @@ set(SOURCE_FILES
"${SOURCE_DIR}/bsa/unpack.cpp"
"${SOURCE_DIR}/bsa/detail/archive_type.cpp"
"${SOURCE_DIR}/esp/functions.cpp"
"${SOURCE_DIR}/hkx/anim.cpp"
"${SOURCE_DIR}/modmanager/mod_folder.cpp"
"${SOURCE_DIR}/modmanager/mod_manager.cpp"
"${SOURCE_DIR}/nif/functions.cpp"
Expand All @@ -58,14 +61,6 @@ set(SOURCE_FILES
"${SOURCE_DIR}/tex/texture.cpp"
"${SOURCE_DIR}/tex/error_code.cpp")

option(BETHUTIL_HKX "Build hkx part" OFF)
if(${BETHUTIL_HKX})
list(APPEND HEADER_FILES "${INCLUDE_DIR}/btu/hkx/anim.hpp"
"${INCLUDE_DIR}/btu/hkx/error_code.hpp")

list(APPEND SOURCE_FILES "${SOURCE_DIR}/hkx/anim.cpp")
endif()

source_group(TREE "${ROOT_DIR}" FILES ${HEADER_FILES} ${SOURCE_FILES})

add_library(
Expand Down Expand Up @@ -104,10 +99,8 @@ target_link_libraries("${PROJECT_NAME}" PRIVATE mpsc::mpsc_channel)
find_package(nlohmann_json CONFIG REQUIRED)
target_link_libraries("${PROJECT_NAME}" PRIVATE nlohmann_json::nlohmann_json)

if(${BETHUTIL_HKX})
find_package(reproc++ CONFIG REQUIRED)
target_link_libraries("${PROJECT_NAME}" PRIVATE reproc++)
endif()
find_package(reproc++ CONFIG REQUIRED)
target_link_libraries("${PROJECT_NAME}" PRIVATE reproc++)

set_target_properties("${PROJECT_NAME}" PROPERTIES DEBUG_POSTFIX "d")
set_target_properties("${PROJECT_NAME}" PROPERTIES LINKER_LANGUAGE CXX)
Expand Down
35 changes: 32 additions & 3 deletions src/hkx/anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class Info32to64 : public detail::AnimExeInfo
public:
[[nodiscard]] constexpr auto name() const noexcept -> std::string_view override
{
return "hkx32to64.exe";
return "hkx32to64"
#ifndef __unix__
".exe"
#endif
;
}
[[nodiscard]] constexpr auto input_file_name() const noexcept -> std::string_view override
{
Expand All @@ -33,18 +37,30 @@ class Info32to64 : public detail::AnimExeInfo
{
return "OUTFILE64.hkx";
}
[[nodiscard]] constexpr auto target_game() const noexcept -> btu::Game override { return btu::Game::SSE; }
[[nodiscard]] constexpr auto target_game() const noexcept -> btu::Game override
{
return btu::Game::SSE;
}

[[nodiscard]] auto get_required_files([[maybe_unused]] const Path &exe_dir) const noexcept
-> std::vector<Path> override
{
#ifdef __unix__
return {exe_dir / "hkx32to64.exe"};
#else
return {};
#endif
}

[[nodiscard]] auto get_full_args(const Path &exe_dir) const -> std::vector<std::string> override
{
return {(exe_dir / name()).string(), std::string(input_file_name())};
}

[[nodiscard]] auto is_os_supported() const noexcept -> bool override
{
return true;
}
};
static inline const auto k_exe_32to64 = Info32to64{};

Expand Down Expand Up @@ -74,6 +90,15 @@ class Info64to32 : public detail::AnimExeInfo
{
return {(exe_dir / name()).string(), std::string(input_file_name()), "-s", "32ref.hko"s};
}

[[nodiscard]] auto is_os_supported() const noexcept -> bool override
{
#ifdef __unix__
return false;
#else
return true;
#endif
}
};
static inline const auto k_exe_64to32 = Info64to32{};

Expand Down Expand Up @@ -131,6 +156,9 @@ auto AnimExe::make(Path exe_dir) noexcept -> tl::expected<AnimExe, Error>
if (it == detected.end())
return tl::make_unexpected(Error(AnimErr::NoAppropriateExe));

if (!it->get().is_os_supported())
return tl::make_unexpected(Error(AnimErr::OsNotSupported));

return *it;
}

Expand Down Expand Up @@ -196,9 +224,10 @@ struct ReprocOptions : public reproc::options
if (ec)
return tl::make_unexpected(Error(ec));

fs::rename(output_path, output, ec);
fs::copy(output_path, output, ec);
if (ec)
return tl::make_unexpected(Error(ec));
fs::remove(output_path);

return {};
}
Expand Down
5 changes: 1 addition & 4 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(SOURCE_FILES
"${SOURCE_DIR}/bsa/plugin.cpp"
"${SOURCE_DIR}/bsa/unpack.cpp"
"${SOURCE_DIR}/esp/functions.cpp"
"${SOURCE_DIR}/hkx/anim.cpp"
"${SOURCE_DIR}/modmanager/mod_folder.cpp"
"${SOURCE_DIR}/modmanager/mod_manager.cpp"
"${SOURCE_DIR}/nif/functions.cpp"
Expand All @@ -25,10 +26,6 @@ set(SOURCE_FILES
"${SOURCE_DIR}/tex/functions.cpp"
"${SOURCE_DIR}/tex/optimize.cpp")

if(${BETHUTIL_HKX})
list(APPEND SOURCE_FILES "${SOURCE_DIR}/hkx/anim.cpp")
endif()

if("${BETHUTIL_BUILD_EXAMPLES}")
list(APPEND SOURCE_FILES)
endif()
Expand Down
2 changes: 1 addition & 1 deletion tests/hkx/anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST_CASE("Converting from LE to SE", "[src]")
CHECK(btu::common::compare_files(dir / "LE_EXPECTED.hkx", dir / "LE_OUTPUT.hkx"));
}

TEST_CASE("Converting from SE to LE", "[src]")
TEST_CASE("Converting from SE to LE", "[src]" FAIL_ON_LINUX_TAG)
{
convert(btu::Game::SLE, dir / "SE_INPUT.hkx", dir / "SE_OUTPUT.hkx");
CHECK(btu::common::compare_files(dir / "SE_EXPECTED.hkx", dir / "SE_OUTPUT.hkx"));
Expand Down
6 changes: 6 additions & 0 deletions tests/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

#include <fstream>

#ifdef __unix__
#define FAIL_ON_LINUX_TAG "[!nonportable] [!shouldfail]"
#else
#define FAIL_ON_LINUX_TAG "[!nonportable]"
#endif

using btu::Path;
using namespace std::literals;

Expand Down
7 changes: 1 addition & 6 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
"mpsc-channel",
"nifly",
"nlohmann-json",
"reproc",
"utf8h",
"rsm-bsa",
"tl-expected"
],
"features": {
"hkx": {
"description": "Build hkx part. Windows only",
"dependencies": [
"reproc"
]
},
"tests": {
"description": "Build tests",
"dependencies": [
Expand Down

0 comments on commit 801acca

Please sign in to comment.