From 736a69ccab34818935d2bbf3a209488f4367b9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Tue, 27 May 2025 21:03:01 +0200 Subject: [PATCH] Fix issue with DLL name in Debug configuration. --- .gitignore | 7 + CMakeLists.txt | 2 +- cmake/config.cmake.in | 1 + examples/libbsarch-visualstudio-test.cpp | 254 ++++++++++++----------- src/libbsarch.def | 1 - vcpkg.json | 2 +- 6 files changed, 145 insertions(+), 122 deletions(-) diff --git a/.gitignore b/.gitignore index 980d79d..4c54425 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ compile_commands.json CTestTestfile.cmake _deps + ### CMake Patch ### # External projects *-prefix/ @@ -530,3 +531,9 @@ healthchecksdb MigrationBackup/ # End of https://www.gitignore.io/api/qt,c++,cmake,delphi,qtcreator,visualstudio + +install +examples/build +examples/vsbuild +examples/test_ba1 +examples/test_ba2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 920c881..235ee53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(CMakePackageConfigHelpers) project(libbsarch CXX) find_package(mo2-dds-header CONFIG REQUIRED) -find_package(Qt6 COMPONENTS Core REQUIRED) +find_package(Qt6 COMPONENTS Core) get_target_property(SRCS mo2::dds-header SOURCES) diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in index 05a5ce0..8bb228f 100644 --- a/cmake/config.cmake.in +++ b/cmake/config.cmake.in @@ -6,6 +6,7 @@ target_link_libraries(mo2::libbsarch INTERFACE mo2::libbsarch_OOP) # libbsarch is usually be build in Debug or Release/RelWithDebInfo, so we need to map # missing configurations to avoid issue with CMP0111 +get_target_property(_LIBBSARCH_CONFIGURATIONS mo2::libbsarch IMPORTED_CONFIGURATIONS) list(FIND _LIBBSARCH_CONFIGURATIONS "RELEASE" _LIBBSARCH_HAS_RELEASE) if (_LIBBSARCH_HAS_RELEASE EQUAL -1) set_target_properties(mo2::libbsarch PROPERTIES diff --git a/examples/libbsarch-visualstudio-test.cpp b/examples/libbsarch-visualstudio-test.cpp index 443e817..1183ee9 100644 --- a/examples/libbsarch-visualstudio-test.cpp +++ b/examples/libbsarch-visualstudio-test.cpp @@ -1,146 +1,162 @@ #include #include -#include "libbsarch.h" +#include -#pragma comment(lib, "libbsarch") +// #pragma comment(lib, "libbsarch") static const std::wstring separators(L"\\/"); -std::wstring dirname(const std::wstring& path) { - size_t slash_pos = path.find_last_of(separators); - return path.substr(0, slash_pos); +std::wstring dirname(const std::wstring &path) +{ + size_t slash_pos = path.find_last_of(separators); + return path.substr(0, slash_pos); } -std::wstring basename(const std::wstring& path) { - size_t slash_pos = path.find_last_of(separators); - return path.substr(slash_pos + 1); +std::wstring basename(const std::wstring &path) +{ + size_t slash_pos = path.find_last_of(separators); + return path.substr(slash_pos + 1); } -bool mkdirp(const std::wstring& directory, bool basedir = true) { - DWORD attributes = ::GetFileAttributesW(directory.c_str()); - if(attributes == INVALID_FILE_ATTRIBUTES) { - std::size_t slash_pos = directory.find_last_of(separators); - if(slash_pos != std::wstring::npos) { - mkdirp(directory.substr(0, slash_pos)); +bool mkdirp(const std::wstring &directory, bool basedir = true) +{ + DWORD attributes = ::GetFileAttributesW(directory.c_str()); + if (attributes == INVALID_FILE_ATTRIBUTES) + { + std::size_t slash_pos = directory.find_last_of(separators); + if (slash_pos != std::wstring::npos) + { + mkdirp(directory.substr(0, slash_pos)); + } + return ::CreateDirectoryW(directory.c_str(), nullptr); } - return ::CreateDirectoryW(directory.c_str(), nullptr); - } else { - return true; - } -} - -void dds_info(bsa_archive_t archive, const wchar_t* file_path, bsa_dds_info_t* dds_info, void* context) { - // Mock result - dds_info->width = 2048; - dds_info->height = 2048; - dds_info->mipmaps = 12; - - printf("ba2 dds_info callback file: %ls, context: %s\n", file_path, (char*)context); -} - -int main() { - bsa_result_message_t result = { 0 }; - bsa_archive_t archive = bsa_create(); - - { - result = bsa_load_from_file(archive, L"test_read.bsa"); - if(result.code < 0) - printf("ba1 %ls\n", result.text); - - bsa_entry_list_t entries = bsa_entry_list_create(); - bsa_get_resource_list(archive, entries, L""); - - for(size_t index = 0; index < bsa_entry_list_count(entries); index++) { - wchar_t filename[2048]; - wchar_t dest_filename[2048] = L"test_ba1\\"; - - bsa_entry_list_get(entries, index, 2048, filename); - wcscat_s(dest_filename, 2048, filename); - - printf("ba1 file: %ls %ls\n", filename, dest_filename); - - if(mkdirp(dirname(dest_filename))) { - result = bsa_extract_file(archive, filename, dest_filename); - if(result.code < 0) - printf("ba1 %ls\n", result.text); - } else { - printf("ba1 could not create: %ls\n", dirname(dest_filename).c_str()); - } + else + { + return true; } +} - bsa_entry_list_free(entries); +void dds_info(bsa_archive_t archive, const wchar_t *file_path, bsa_dds_info_t *dds_info, void *context) +{ + // Mock result + dds_info->width = 2048; + dds_info->height = 2048; + dds_info->mipmaps = 12; - bsa_close(archive); - } + printf("ba2 dds_info callback file: %ls, context: %s\n", file_path, (char *) context); +} - { - bsa_entry_list_t entries = bsa_entry_list_create(); - bsa_entry_list_add(entries, L"textures\\grass\\test.dds"); - bsa_entry_list_add(entries, L"textures\\grass\\test2.dds"); +int main() +{ + bsa_result_message_t result = {0}; + bsa_archive_t archive = bsa_create(); - bsa_create_archive(archive, L"test_write.bsa", baSSE, entries); - bsa_add_file_from_disk_root(archive, L"test_ba1\\", L"test_ba1\\textures\\grass\\test.dds"); - result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba1\\textures\\grass\\test.dds"); - if (result.code < 0) - printf("ba1 %ls\n", result.text); - bsa_save(archive); - bsa_close(archive); - - bsa_entry_list_free(entries); - } - - bsa_file_dds_info_callback_set(archive, dds_info, (void*)"I was shared"); - - { - result = bsa_load_from_file(archive, L"test_read.ba2"); - if (result.code < 0) - printf("ba2 %ls\n", result.text); - - bsa_entry_list_t entries = bsa_entry_list_create(); - bsa_get_resource_list(archive, entries, L""); - - for (size_t index = 0; index < bsa_entry_list_count(entries); index++) { - wchar_t filename[2048]; - wchar_t dest_filename[2048] = L"test_ba2\\"; - - bsa_entry_list_get(entries, index, 2048, filename); - wcscat_s(dest_filename, 2048, filename); - - printf("ba2 file: %ls %ls\n", filename, dest_filename); - - if (mkdirp(dirname(dest_filename))) { - result = bsa_extract_file(archive, filename, dest_filename); + { + result = bsa_load_from_file(archive, L"test_read.bsa"); if (result.code < 0) - printf("ba2 %ls\n", result.text); - } - else { - printf("ba2 could not create: %ls\n", dirname(dest_filename).c_str()); - } + printf("ba1 %ls\n", result.text); + + bsa_entry_list_t entries = bsa_entry_list_create(); + bsa_get_resource_list(archive, entries, L""); + + for (size_t index = 0; index < bsa_entry_list_count(entries); index++) + { + wchar_t filename[2048]; + wchar_t dest_filename[2048] = L"test_ba1\\"; + + bsa_entry_list_get(entries, index, 2048, filename); + wcscat_s(dest_filename, 2048, filename); + + printf("ba1 file: %ls %ls\n", filename, dest_filename); + + if (mkdirp(dirname(dest_filename))) + { + result = bsa_extract_file(archive, filename, dest_filename); + if (result.code < 0) + printf("ba1 %ls\n", result.text); + } + else + { + printf("ba1 could not create: %ls\n", dirname(dest_filename).c_str()); + } + } + + bsa_entry_list_free(entries); + + bsa_close(archive); } - bsa_entry_list_free(entries); + { + bsa_entry_list_t entries = bsa_entry_list_create(); + bsa_entry_list_add(entries, L"textures\\grass\\test.dds"); + bsa_entry_list_add(entries, L"textures\\grass\\test2.dds"); - bsa_close(archive); - } + bsa_create_archive(archive, L"test_write.bsa", baSSE, entries); + bsa_add_file_from_disk_root(archive, L"test_ba1\\", L"test_ba1\\textures\\grass\\test.dds"); + result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba1\\textures\\grass\\test.dds"); + if (result.code < 0) + printf("ba1 %ls\n", result.text); + bsa_save(archive); + bsa_close(archive); - { - bsa_entry_list_t entries = bsa_entry_list_create(); - bsa_entry_list_add(entries, L"textures\\grass\\test.dds"); - bsa_entry_list_add(entries, L"textures\\grass\\test2.dds"); + bsa_entry_list_free(entries); + } - bsa_create_archive(archive, L"test_write.ba2", baFO4dds, entries); - bsa_add_file_from_disk_root(archive, L"test_ba2\\", L"test_ba2\\textures\\grass\\test.dds"); - result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba2\\textures\\grass\\test.dds"); - if (result.code < 0) - printf("ba2 %ls\n", result.text); - bsa_save(archive); - bsa_close(archive); + bsa_file_dds_info_callback_set(archive, dds_info, (void *) "I was shared"); - bsa_entry_list_free(entries); - } + { + result = bsa_load_from_file(archive, L"test_read.ba2"); + if (result.code < 0) + printf("ba2 %ls\n", result.text); - /* + bsa_entry_list_t entries = bsa_entry_list_create(); + bsa_get_resource_list(archive, entries, L""); + + for (size_t index = 0; index < bsa_entry_list_count(entries); index++) + { + wchar_t filename[2048]; + wchar_t dest_filename[2048] = L"test_ba2\\"; + + bsa_entry_list_get(entries, index, 2048, filename); + wcscat_s(dest_filename, 2048, filename); + + printf("ba2 file: %ls %ls\n", filename, dest_filename); + + if (mkdirp(dirname(dest_filename))) + { + result = bsa_extract_file(archive, filename, dest_filename); + if (result.code < 0) + printf("ba2 %ls\n", result.text); + } + else + { + printf("ba2 could not create: %ls\n", dirname(dest_filename).c_str()); + } + } + + bsa_entry_list_free(entries); + + bsa_close(archive); + } + + { + bsa_entry_list_t entries = bsa_entry_list_create(); + bsa_entry_list_add(entries, L"textures\\grass\\test.dds"); + bsa_entry_list_add(entries, L"textures\\grass\\test2.dds"); + + bsa_create_archive(archive, L"test_write.ba2", baFO4dds, entries); + bsa_add_file_from_disk_root(archive, L"test_ba2\\", L"test_ba2\\textures\\grass\\test.dds"); + result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba2\\textures\\grass\\test.dds"); + if (result.code < 0) + printf("ba2 %ls\n", result.text); + bsa_save(archive); + bsa_close(archive); + + bsa_entry_list_free(entries); + } + + /* { result = bsa_load_from_file(archive, L"test_large.ba2"); if (result.code < 0) @@ -170,5 +186,5 @@ int main() { } */ - bsa_free(archive); + bsa_free(archive); } diff --git a/src/libbsarch.def b/src/libbsarch.def index 9a34ed8..d6386b0 100644 --- a/src/libbsarch.def +++ b/src/libbsarch.def @@ -1,4 +1,3 @@ -LIBRARY LIBBSARCH ;DESCRIPTION "BSArch DLL" EXPORTS bsa_entry_list_create diff --git a/vcpkg.json b/vcpkg.json index 03fbd46..3cfe0a0 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -10,7 +10,7 @@ { "kind": "git", "repository": "https://github.com/ModOrganizer2/vcpkg-registry", - "baseline": "27d8adbfe9e4ce88a875be3a45fadab69869eb60", + "baseline": "69db61b22147b14ad66fd05cf798d855f6d68c12", "packages": ["mo2-*"] } ]