9 Commits
Author SHA1 Message Date
Mikaël Capelle 2a544ac3de Move to VCPKG (#5)
* Drop support for Qt.
* Reorganize repository to build proper CMake targets.
* Add pre-commit hook.
* Add GH actions for linting, build and publish (on tag).
2025-05-28 14:50:53 +02:00
Jeremy Rimpo 4f32506570 Restore mistakenly removed size increment
- Should fix missing texture data
2024-07-11 01:55:00 -05:00
Jeremy Rimpo bf840701de Merge pull request #3 from ModOrganizer2/dev/archive_preview
WIP: Archive preview support
2024-07-05 16:23:38 -05:00
Mikaël Capelle 37f139a236 Modification to use external DDS.h header in MO2. (#4) 2024-07-01 17:13:21 +02:00
Jeremy Rimpo 3a277db0fb Restore changes for PByte pointers 2024-06-25 20:19:39 -05:00
Jeremy Rimpo 701bc58e9a Merge pull request #2 from ModOrganizer2/starfield_support
Update to latest BSArch / xEdit
2024-06-24 01:03:08 -05:00
Jeremy Rimpo c535689ef4 Migrate to newer data types 2024-06-22 15:39:13 -05:00
Jeremy Rimpo 3219ade30e Update to latest BSArch / xEdit
- Supports Starfield and FO4 NG archives
- Other code improvements
- Removed some old functions
2024-06-22 05:32:40 -05:00
Jeremy Rimpo 4a88aab247 Update for Qt6 2021-12-04 04:38:23 -06:00
37 changed files with 2019 additions and 1081 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false BinPackArguments: false
BinPackParameters: false BinPackParameters: false
BraceWrapping: BraceWrapping:
AfterClass: true AfterClass: true
AfterControlStatement: true AfterControlStatement: true
AfterEnum: true AfterEnum: true
@@ -55,13 +55,13 @@ DerivePointerAlignment: false
DisableFormat: false DisableFormat: false
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true FixNamespaceComments: true
ForEachMacros: ForEachMacros:
- forever - forever
- foreach - foreach
- Q_FOREACH - Q_FOREACH
- BOOST_FOREACH - BOOST_FOREACH
IncludeBlocks: Preserve IncludeBlocks: Preserve
IncludeCategories: IncludeCategories:
- Regex: '^<Q.*' - Regex: '^<Q.*'
Priority: 200 Priority: 200
- Regex: '^(<|"(gtest|gmock|isl|json)/)' - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+7
View File
@@ -0,0 +1,7 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
# Explicitly declare text files you want to always be normalized and converted
# to native line endings on checkout.
*.cpp text eol=crlf
*.h text eol=crlf
+64
View File
@@ -0,0 +1,64 @@
name: Build libbsarch
on:
push:
branches: [master]
tags:
- "*"
pull_request:
types: [opened, synchronize, reopened]
env:
VCPKG_BINARY_SOURCES: clear;x-azblob,${{ vars.AZ_BLOB_VCPKG_URL }},${{ secrets.AZ_BLOB_SAS }},readwrite
jobs:
build:
runs-on: windows-2022
steps:
- name: "Set environmental variables"
shell: bash
run: |
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV
- uses: actions/checkout@v4
- run: cmake --preset vs2022-windows "-DCMAKE_INSTALL_PREFIX=install"
# build both Debug and Release for package
- name: Build libbsarch
run: |
cmake --build vsbuild --config Debug --verbose
cmake --build vsbuild --config Release --verbose
- name: Install libbsarch
run: |
cmake --install vsbuild --config Debug
cmake --install vsbuild --config Release
- name: Upload libbsarch artifact
uses: actions/upload-artifact@master
with:
name: libbsarch
path: ./install
publish:
if: github.ref_type == 'tag'
needs: build
runs-on: windows-2022
permissions:
contents: write
steps:
- name: Download Artifact
uses: actions/download-artifact@master
with:
name: libbsarch
path: ./install
- name: Create libbsarch archive
run: 7z a libbsarch_${{ github.ref_name }}.7z ./install/*
- name: Publish Release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: gh release create --draft=false --notes="${{ github.ref_name }}" "${{ github.ref_name }}" ./libbsarch_${{ github.ref_name }}.7z
+17
View File
@@ -0,0 +1,17 @@
name: Lint libbsarch
on:
push:
pull_request:
types: [opened, synchronize, reopened]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check format
uses: ModOrganizer2/check-formatting-action@master
with:
check-path: "."
exclude-regex: "third-party"
+8
View File
@@ -49,6 +49,7 @@ compile_commands.json
CTestTestfile.cmake CTestTestfile.cmake
_deps _deps
### CMake Patch ### ### CMake Patch ###
# External projects # External projects
*-prefix/ *-prefix/
@@ -134,6 +135,7 @@ ui_*.h
*.jsc *.jsc
Makefile* Makefile*
*build-* *build-*
vsbuild
# Qt unit tests # Qt unit tests
target_wrapper.* target_wrapper.*
@@ -529,3 +531,9 @@ healthchecksdb
MigrationBackup/ MigrationBackup/
# End of https://www.gitignore.io/api/qt,c++,cmake,delphi,qtcreator,visualstudio # End of https://www.gitignore.io/api/qt,c++,cmake,delphi,qtcreator,visualstudio
install
examples/build
examples/vsbuild
examples/test_ba1
examples/test_ba2
+20
View File
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-merge-conflict
- id: check-case-conflict
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.5
hooks:
- id: clang-format
'types_or': [c++, c]
ci:
autofix_commit_msg: "[pre-commit.ci] Auto fixes from pre-commit.com hooks."
autofix_prs: true
autoupdate_commit_msg: "[pre-commit.ci] Pre-commit autoupdate."
autoupdate_schedule: quarterly
submodules: false
+102 -82
View File
@@ -1,73 +1,83 @@
cmake_minimum_required(VERSION 3.5..3.15) cmake_minimum_required(VERSION 3.16)
option(copy_dll_to_binary_dir "Will copy libbsarch DLL to the binary directory. May not work if libbsarch is used as a subproject" ON) include(CMakePackageConfigHelpers)
# Project
project(libbsarch CXX) project(libbsarch CXX)
# Add library to build. find_package(mo2-dds-header CONFIG REQUIRED)
add_library(libbsarch SHARED
src/DDS.h
src/libbsarch.h
src/libbsarch.cpp
src/libbsarch.def
)
target_compile_features(libbsarch PRIVATE cxx_std_11) get_target_property(SRCS mo2::dds-header SOURCES)
# Preprocessor definitions
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(MSVC)
target_compile_options(libbsarch PRIVATE /W3 /MDd /Od /EHsc)
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(MSVC)
target_compile_options(libbsarch PRIVATE /W3 /Zi /EHsc)
endif()
endif()
# libbsarch
add_library(libbsarch SHARED)
target_sources(libbsarch
PRIVATE
src/libbsarch.cpp
src/libbsarch.def
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/libbsarch.h
)
target_include_directories(libbsarch PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch)
set_target_properties(libbsarch PROPERTIES DEBUG_POSTFIX "d" CXX_STANDARD 11)
target_link_libraries(libbsarch PUBLIC mo2::dds-header)
target_compile_definitions(libbsarch PRIVATE BSARCH_DLL_EXPORT) target_compile_definitions(libbsarch PRIVATE BSARCH_DLL_EXPORT)
#We only want the lib file. The DLL will be provided by Delphi # preprocessor definitions
#Removing the generated DLL if(MSVC)
add_custom_command(TARGET libbsarch POST_BUILD target_compile_options(libbsarch PRIVATE
COMMAND ${CMAKE_COMMAND} -E remove /W3 /EHsc /MP
${CMAKE_CURRENT_BINARY_DIR}/libbsarch.dll) $<$<CONFIG:DEBUG>:/MDd /Od>
$<$<CONFIG:RELEASE>:/Zi>
############################################################
# libbsarch_OOP #
############################################################
find_package(Qt5 OPTIONAL_COMPONENTS Core)
add_library(libbsarch_OOP STATIC
src/base_types.hpp
src/bs_archive_auto.cpp
src/bs_archive_auto.hpp
src/bs_archive.cpp
src/bs_archive.h
src/bs_archive_entries.cpp
src/bs_archive_entries.h
src/dds.h
src/libbsarch.hpp
src/libbsarch.h
src/dds.h
src/utils/convertible_string.cpp
src/utils/convertible_string.hpp
src/utils/convertible_ostream.cpp
src/utils/convertible_ostream.hpp
src/utils/string_convert.cpp
src/utils/string_convert.hpp
) )
endif()
## Copying the corresponding DLL ## # libbsarch_OOP
add_library(libbsarch_OOP STATIC)
#Finding 32 or 64bits target_sources(libbsarch_OOP
PRIVATE
src/bs_archive_entries.cpp
src/utils/string_convert.cpp
src/utils/convertible_ostream.cpp
src/utils/convertible_string.cpp
src/bs_archive_auto.cpp
src/bs_archive.cpp
PUBLIC
FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
FILES
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/base_types.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive_auto.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive.h
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive_entries.h
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/libbsarch.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/libbsarch.h
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils/convertible_string.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils/convertible_ostream.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils/string_convert.hpp
)
target_include_directories(libbsarch_OOP PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/utils)
target_link_libraries(libbsarch_OOP PUBLIC mo2::dds-header)
set_target_properties(libbsarch_OOP PROPERTIES
DEBUG_POSTFIX "d"
CXX_STANDARD 17
)
if (MSVC)
target_compile_options(libbsarch_OOP PRIVATE /MP)
endif()
# target_link_libraries(libbsarch_OOP PUBLIC libbsarch)
# install
# finding 32 or 64bits
if(CMAKE_SIZEOF_VOID_P EQUAL 8) if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# 64 bits # 64 bits
set(lib_delphi "${CMAKE_CURRENT_SOURCE_DIR}/delphi/lib64") set(lib_delphi "${CMAKE_CURRENT_SOURCE_DIR}/delphi/lib64")
@@ -78,30 +88,40 @@ elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
message("libbsarch: using 32bits DLL") message("libbsarch: using 32bits DLL")
endif() endif()
if(copy_dll_to_binary_dir) install(TARGETS libbsarch libbsarch_OOP EXPORT libbsarchTargets FILE_SET HEADERS)
#Finding debug or release install(FILES $<TARGET_PDB_FILE:libbsarch> DESTINATION pdb OPTIONAL)
if(CMAKE_BUILD_TYPE MATCHES DEBUG) install(EXPORT libbsarchTargets
set(libbsarch_dll_path "${lib_delphi}/libbsarchd.dll") FILE mo2-libbsarch-targets.cmake
else() NAMESPACE mo2::
set(libbsarch_dll_path "${lib_delphi}/libbsarch.dll") DESTINATION lib/cmake/mo2-libbsarch
endif() )
#Actually copying the DLL # install the true DLLs
add_custom_command(TARGET libbsarch POST_BUILD install(FILES ${lib_delphi}/libbsarch.dll DESTINATION bin CONFIGURATIONS Release RelWithDebInfo MinSizeRel)
COMMAND ${CMAKE_COMMAND} -E copy_if_different install(FILES ${lib_delphi}/libbsarchd.dll DESTINATION bin CONFIGURATIONS Debug)
${libbsarch_dll_path}
${CMAKE_BINARY_DIR}/libbsarch.dll)
message("libbsarch: Copying the DLL to ${CMAKE_BINARY_DIR}/libbsarch.dll")
endif()
#Adding Qt support configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
if(Qt5_FOUND) "${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config.cmake"
message("libbsarch: Qt5 found, enabling Qt support") INSTALL_DESTINATION "lib/cmake/mo2-libbsarch"
target_link_libraries(libbsarch_OOP PUBLIC Qt5::Core) NO_SET_AND_CHECK_MACRO
target_compile_definitions(libbsarch PUBLIC "QT") NO_CHECK_REQUIRED_COMPONENTS_MACRO
target_compile_definitions(libbsarch_OOP PUBLIC "QT") )
endif()
target_link_libraries(libbsarch_OOP PUBLIC libbsarch)
target_compile_features(libbsarch_OOP PRIVATE cxx_std_17) include(${CMAKE_CURRENT_SOURCE_DIR}/Version.cmake)
target_compile_definitions(libbsarch_OOP PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING) set(LIBBSARCH_VERSION
${LIBBSARCH_MAJOR_VERSION}.${LIBBSARCH_MINOR_VERSION}.${LIBBSARCH_PATCH_VERSION})
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config-version.cmake"
VERSION "${LIBBSARCH_VERSION}"
COMPATIBILITY AnyNewerVersion
ARCH_INDEPENDENT
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config-version.cmake
DESTINATION lib/cmake/mo2-libbsarch
)
+17
View File
@@ -0,0 +1,17 @@
{
"configurePresets": [
{
"binaryDir": "${sourceDir}/vsbuild",
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"generator": "Visual Studio 17 2022",
"name": "vs2022-windows"
}
],
"buildPresets": [
{
"name": "vs2022-windows",
"configurePreset": "vs2022-windows"
}
],
"version": 4
}
+4 -2
View File
@@ -1,4 +1,5 @@
# BSArchive DLL and C++ bindings # BSArchive DLL and C++ bindings
BSArchive Dynamic Link Library and C++ bindings BSArchive Dynamic Link Library and C++ bindings
## How to build ## How to build
@@ -9,7 +10,7 @@ BSArchive Dynamic Link Library and C++ bindings
## How to use ## How to use
With CMake: With CMake:
Use ``add_subdirectory`` and ``target_link_library`` Use ``add_subdirectory`` and ``target_link_library``
Then ``#include "libbsarch.h"`` for the C wrapper, or ``#include "bs_archive_auto"`` for the C++ wrapper. Then ``#include "libbsarch.h"`` for the C wrapper, or ``#include "bs_archive_auto"`` for the C++ wrapper.
See the example for code use. See the example for code use.
@@ -20,4 +21,5 @@ Use `libbsarch.dll` (provided in delphi/lib), `libbsarch.lib` and `libbsarch.h`
## Credits ## Credits
The original BSArchive can be found at: https://github.com/TES5Edit/TES5Edit/tree/dev/Tools/BSArchive The original BSArchive can be found at: https://github.com/TES5Edit/TES5Edit/tree/dev/Tools/BSArchive
The version in this project had been modified for better compatibility with C/C++ and allow the users to allocate their own memory in some cases. The version in this project had been modified for better compatibility with C/C++ and
allow the users to allocate their own memory in some cases.
+3
View File
@@ -0,0 +1,3 @@
set(LIBBSARCH_MAJOR_VERSION 0)
set(LIBBSARCH_MINOR_VERSION 1)
set(LIBBSARCH_PATCH_VERSION 2)
+37
View File
@@ -0,0 +1,37 @@
@PACKAGE_INIT@
include ( "${CMAKE_CURRENT_LIST_DIR}/mo2-libbsarch-targets.cmake" )
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
MAP_IMPORTED_CONFIG_MINSIZEREL RelWithDebInfo
MAP_IMPORTED_CONFIG_RELEASE RelWithDebInfo
)
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS MINSIZEREL)
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(mo2::libbsarch_OOP PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL RelWithDebInfo
MAP_IMPORTED_CONFIG_RELEASE RelWithDebInfo
)
set_property(TARGET mo2::libbsarch_OOP APPEND PROPERTY IMPORTED_CONFIGURATIONS MINSIZEREL)
set_property(TARGET mo2::libbsarch_OOP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
else()
set_target_properties(mo2::libbsarch PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
)
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS MINSIZEREL)
set_property(TARGET mo2::libbsarch APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
set_target_properties(mo2::libbsarch_OOP PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL Release
MAP_IMPORTED_CONFIG_RELWITHDEBINFO Release
)
set_property(TARGET mo2::libbsarch_OOP APPEND PROPERTY IMPORTED_CONFIGURATIONS MINSIZEREL)
set_property(TARGET mo2::libbsarch_OOP APPEND PROPERTY IMPORTED_CONFIGURATIONS RELWITHDEBINFO)
endif()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+18 -30
View File
@@ -20,7 +20,7 @@ type
TwbBSResultMessageBuffer = packed record TwbBSResultMessageBuffer = packed record
buffer: TwbBSResultBuffer; buffer: TwbBSResultBuffer;
message: TwbBSResultMessage; message: TwbBSResultMessage;
end; end;
{Shared} {Shared}
@@ -68,7 +68,7 @@ end;
function bsa_entry_list_create:Pointer; stdcall; function bsa_entry_list_create:Pointer; stdcall;
begin begin
try try
Result := TwbBSEntryList.Create; Result := TStringList.Create;
except except
Result := nil; Result := nil;
end; end;
@@ -78,8 +78,8 @@ function bsa_entry_list_free(obj: Pointer): TwbBSResultMessage; stdcall;
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
try try
TwbBSEntryList(obj).Clear(); TStringList(obj).Clear();
TwbBSEntryList(obj).free; TStringList(obj).free;
except except
on E: Exception do on E: Exception do
exception_handler(E, Result); exception_handler(E, Result);
@@ -89,7 +89,7 @@ end;
function bsa_entry_list_count(obj: Pointer): Integer; stdcall; function bsa_entry_list_count(obj: Pointer): Integer; stdcall;
begin begin
try try
Result := TwbBSEntryList(obj).Count; Result := TStringList(obj).Count;
except except
Result := Ord(BSA_RESULT_EXCEPTION); Result := Ord(BSA_RESULT_EXCEPTION);
end; end;
@@ -99,7 +99,7 @@ function bsa_entry_list_add(obj: Pointer; const aEntryString: PChar): TwbBSResul
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
try try
TwbBSEntryList(obj).Add(String(aEntryString)); TStringList(obj).Add(String(aEntryString));
except except
on E: Exception do on E: Exception do
exception_handler(E, Result); exception_handler(E, Result);
@@ -109,7 +109,7 @@ end;
function bsa_entry_list_get(obj: Pointer; const aIndex: Cardinal; const aStringBufferSize: Cardinal; const aStringBuffer: PChar): Integer; stdcall; function bsa_entry_list_get(obj: Pointer; const aIndex: Cardinal; const aStringBufferSize: Cardinal; const aStringBuffer: PChar): Integer; stdcall;
begin begin
try try
Result := string_to_cstring_end(TwbBSEntryList(obj).Strings[aIndex], aStringBufferSize, aStringBuffer); Result := string_to_cstring_end(TStringList(obj).Strings[aIndex], aStringBufferSize, aStringBuffer);
except except
Result := Integer(BSA_RESULT_EXCEPTION); Result := Integer(BSA_RESULT_EXCEPTION);
end; end;
@@ -148,11 +148,11 @@ begin
end; end;
end; end;
function bsa_create_archive(obj: Pointer; const aFilePath: PChar; aType: TBSArchiveType; aFileList: TwbBSEntryList): TwbBSResultMessage; stdcall; function bsa_create_archive(obj: Pointer; const aFilePath: PChar; aType: TBSArchiveType; aFileList: TStringList): TwbBSResultMessage; stdcall;
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
try try
TwbBSArchive(obj).CreateArchiveCompat(String(aFilePath), aType, aFileList); TwbBSArchive(obj).CreateArchive(String(aFilePath), aType, aFileList);
except except
on E: Exception do on E: Exception do
exception_handler(E, Result); exception_handler(E, Result);
@@ -196,7 +196,7 @@ function bsa_add_file_from_memory(obj: Pointer; const aFilePath: PChar; const aS
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
try try
TwbBSArchive(obj).AddFileDataCompat(String(aFilePath), aSize, aData); TwbBSArchive(obj).AddFileData(String(aFilePath), aSize, aData);
except except
on E: Exception do on E: Exception do
exception_handler(E, Result); exception_handler(E, Result);
@@ -216,7 +216,7 @@ function bsa_extract_file_data_by_record(obj: Pointer; aFileRecord: Pointer): Tw
begin begin
Result.message.code := Ord(BSA_RESULT_NONE); Result.message.code := Ord(BSA_RESULT_NONE);
try try
Result.buffer := TwbBSArchive(obj).ExtractFileDataCompat(aFileRecord); Result.buffer := TwbBSArchive(obj).ExtractFileData(aFileRecord);
except except
on E: Exception do on E: Exception do
buffer_exception_handler(E, Result); buffer_exception_handler(E, Result);
@@ -227,7 +227,7 @@ function bsa_extract_file_data_by_filename(obj: Pointer; const aFilePath: PChar)
begin begin
Result.message.code := Ord(BSA_RESULT_NONE); Result.message.code := Ord(BSA_RESULT_NONE);
try try
Result.buffer := TwbBSArchive(obj).ExtractFileDataCompat(String(aFilePath)); Result.buffer := TwbBSArchive(obj).ExtractFileData(String(aFilePath));
except except
on E: Exception do on E: Exception do
buffer_exception_handler(E, Result); buffer_exception_handler(E, Result);
@@ -238,7 +238,7 @@ function bsa_file_data_free(obj: Pointer; fileDataResult: TwbBSResultMessageBuff
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
try try
TwbBSArchive(obj).ReleaseFileDataCompat(fileDataResult.buffer); TwbBSArchive(obj).ReleaseFileData(fileDataResult.buffer);
except except
on E: Exception do on E: Exception do
exception_handler(E, Result); exception_handler(E, Result);
@@ -256,11 +256,11 @@ begin
end; end;
end; end;
function bsa_iterate_files(obj: Pointer; aProc: TBSFileIterationProcCompat; aContext: Pointer): TwbBSResultMessage; stdcall; function bsa_iterate_files(obj: Pointer; aProc: TBSFileIterationProc; aContext: Pointer): TwbBSResultMessage; stdcall;
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
try try
TwbBSArchive(obj).IterateFilesCompat(aProc, aContext); TwbBSArchive(obj).IterateFiles(aProc, aContext);
except except
on E: Exception do on E: Exception do
exception_handler(E, Result); exception_handler(E, Result);
@@ -276,28 +276,17 @@ begin
end; end;
end; end;
function bsa_get_resource_list(obj: Pointer; const aEntryResultList: TwbBSEntryList; aFolder: PChar): TwbBSResultMessage; stdcall; function bsa_get_resource_list(obj: Pointer; const aEntryResultList: TStringList; aFolder: PChar): TwbBSResultMessage; stdcall;
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
try try
TwbBSArchive(obj).ResourceListCompat(aEntryResultList, String(aFolder)); TwbBSArchive(obj).ResourceList(aEntryResultList, String(aFolder));
except except
on E: Exception do on E: Exception do
exception_handler(E, Result); exception_handler(E, Result);
end; end;
end; end;
function bsa_resolve_hash(obj: Pointer; const aHash: UInt64; const aEntryResultList: TwbBSEntryList): TwbBSResultMessage; stdcall;
begin
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).ResolveHashCompat(aHash, aEntryResultList);
except
on E: Exception do
exception_handler(E, Result);
end;
end;
function bsa_close(obj: Pointer): TwbBSResultMessage; stdcall; function bsa_close(obj: Pointer): TwbBSResultMessage; stdcall;
begin begin
Result.code := Ord(BSA_RESULT_NONE); Result.code := Ord(BSA_RESULT_NONE);
@@ -374,7 +363,7 @@ begin
TwbBSArchive(obj).ShareData := shareData; TwbBSArchive(obj).ShareData := shareData;
end; end;
procedure bsa_file_dds_info_callback_set(obj: Pointer; aProc: TBSFileDDSInfoProcCompat; aContext: Pointer); stdcall; procedure bsa_file_dds_info_callback_set(obj: Pointer; aProc: TBSFileDDSInfoProc; aContext: Pointer); stdcall;
begin begin
TwbBSArchive(obj).DDSInfoProc := aProc; TwbBSArchive(obj).DDSInfoProc := aProc;
TwbBSArchive(obj).DDSInfoProcContext := aContext; TwbBSArchive(obj).DDSInfoProcContext := aContext;
@@ -403,7 +392,6 @@ exports
bsa_file_dds_info_callback_set, bsa_file_dds_info_callback_set,
bsa_close, bsa_close,
bsa_resolve_hash,
bsa_get_resource_list, bsa_get_resource_list,
bsa_file_exists, bsa_file_exists,
bsa_iterate_files, bsa_iterate_files,
+758 -8
View File
File diff suppressed because it is too large Load Diff
+655 -428
View File
File diff suppressed because it is too large Load Diff
+135 -119
View File
@@ -1,146 +1,162 @@
#include <iostream> #include <iostream>
#include <windows.h> #include <windows.h>
#include "libbsarch.h" #include <libbsarch/libbsarch.h>
#pragma comment(lib, "libbsarch") // #pragma comment(lib, "libbsarch")
static const std::wstring separators(L"\\/"); static const std::wstring separators(L"\\/");
std::wstring dirname(const std::wstring& path) { std::wstring dirname(const std::wstring &path)
size_t slash_pos = path.find_last_of(separators); {
return path.substr(0, slash_pos); size_t slash_pos = path.find_last_of(separators);
return path.substr(0, slash_pos);
} }
std::wstring basename(const std::wstring& path) { std::wstring basename(const std::wstring &path)
size_t slash_pos = path.find_last_of(separators); {
return path.substr(slash_pos + 1); size_t slash_pos = path.find_last_of(separators);
return path.substr(slash_pos + 1);
} }
bool mkdirp(const std::wstring& directory, bool basedir = true) { bool mkdirp(const std::wstring &directory, bool basedir = true)
DWORD attributes = ::GetFileAttributesW(directory.c_str()); {
if(attributes == INVALID_FILE_ATTRIBUTES) { DWORD attributes = ::GetFileAttributesW(directory.c_str());
std::size_t slash_pos = directory.find_last_of(separators); if (attributes == INVALID_FILE_ATTRIBUTES)
if(slash_pos != std::wstring::npos) { {
mkdirp(directory.substr(0, slash_pos)); 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
} else { {
return true; 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());
}
} }
}
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);
} }
{ int main()
bsa_entry_list_t entries = bsa_entry_list_create(); {
bsa_entry_list_add(entries, L"textures\\grass\\test.dds"); bsa_result_message_t result = {0};
bsa_entry_list_add(entries, L"textures\\grass\\test2.dds"); 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_load_from_file(archive, L"test_read.bsa");
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);
if (result.code < 0) if (result.code < 0)
printf("ba2 %ls\n", result.text); printf("ba1 %ls\n", result.text);
}
else { bsa_entry_list_t entries = bsa_entry_list_create();
printf("ba2 could not create: %ls\n", dirname(dest_filename).c_str()); 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_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_create_archive(archive, L"test_write.ba2", baFO4dds, entries); bsa_file_dds_info_callback_set(archive, dds_info, (void *) "I was shared");
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_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"); result = bsa_load_from_file(archive, L"test_large.ba2");
if (result.code < 0) if (result.code < 0)
@@ -170,5 +186,5 @@ int main() {
} }
*/ */
bsa_free(archive); bsa_free(archive);
} }

Some files were not shown because too many files have changed in this diff Show More