mirror of
https://github.com/ModOrganizer2/libbsarch.git
synced 2026-07-27 14:06:31 -07:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2398ca5df9 | ||
|
|
9444e7e108 | ||
|
|
d9c01eac14 | ||
|
|
4efa6ab6d8 | ||
|
|
736a69ccab | ||
|
|
e16bca653f | ||
|
|
d7cf9d9761 | ||
|
|
0dfbae29f0 | ||
|
|
4f32506570 | ||
|
|
bf840701de | ||
|
|
37f139a236 | ||
|
|
3a277db0fb | ||
|
|
701bc58e9a |
+3
-3
@@ -19,7 +19,7 @@ AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
@@ -55,13 +55,13 @@ DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
ForEachMacros:
|
||||
- forever
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
IncludeCategories:
|
||||
- Regex: '^<Q.*'
|
||||
Priority: 200
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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"
|
||||
@@ -49,6 +49,7 @@ compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
*-prefix/
|
||||
@@ -134,6 +135,7 @@ ui_*.h
|
||||
*.jsc
|
||||
Makefile*
|
||||
*build-*
|
||||
vsbuild
|
||||
|
||||
# Qt unit tests
|
||||
target_wrapper.*
|
||||
@@ -529,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
|
||||
|
||||
@@ -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
|
||||
+101
-81
@@ -1,73 +1,83 @@
|
||||
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)
|
||||
|
||||
# Add library to build.
|
||||
add_library(libbsarch SHARED
|
||||
src/DDS.h
|
||||
src/libbsarch.h
|
||||
src/libbsarch.cpp
|
||||
src/libbsarch.def
|
||||
)
|
||||
find_package(mo2-dds-header CONFIG REQUIRED)
|
||||
|
||||
target_compile_features(libbsarch PRIVATE cxx_std_11)
|
||||
|
||||
# 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()
|
||||
get_target_property(SRCS mo2::dds-header SOURCES)
|
||||
|
||||
# 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)
|
||||
|
||||
#We only want the lib file. The DLL will be provided by Delphi
|
||||
#Removing the generated DLL
|
||||
add_custom_command(TARGET libbsarch POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E remove
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libbsarch.dll)
|
||||
|
||||
############################################################
|
||||
# libbsarch_OOP #
|
||||
############################################################
|
||||
|
||||
find_package(Qt6 COMPONENTS Core REQUIRED)
|
||||
|
||||
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
|
||||
# preprocessor definitions
|
||||
if(MSVC)
|
||||
target_compile_options(libbsarch PRIVATE
|
||||
/W3 /EHsc /MP
|
||||
$<$<CONFIG:DEBUG>:/MDd /Od>
|
||||
$<$<CONFIG:RELEASE>:/Zi>
|
||||
)
|
||||
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)
|
||||
# 64 bits
|
||||
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")
|
||||
endif()
|
||||
|
||||
if(copy_dll_to_binary_dir)
|
||||
#Finding debug or release
|
||||
if(CMAKE_BUILD_TYPE MATCHES DEBUG)
|
||||
set(libbsarch_dll_path "${lib_delphi}/libbsarchd.dll")
|
||||
else()
|
||||
set(libbsarch_dll_path "${lib_delphi}/libbsarch.dll")
|
||||
endif()
|
||||
install(TARGETS libbsarch libbsarch_OOP EXPORT libbsarchTargets FILE_SET HEADERS)
|
||||
install(FILES $<TARGET_PDB_FILE:libbsarch> DESTINATION pdb OPTIONAL)
|
||||
install(EXPORT libbsarchTargets
|
||||
FILE mo2-libbsarch-targets.cmake
|
||||
NAMESPACE mo2::
|
||||
DESTINATION lib/cmake/mo2-libbsarch
|
||||
)
|
||||
|
||||
#Actually copying the DLL
|
||||
add_custom_command(TARGET libbsarch POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
${libbsarch_dll_path}
|
||||
${CMAKE_BINARY_DIR}/libbsarch.dll)
|
||||
message("libbsarch: Copying the DLL to ${CMAKE_BINARY_DIR}/libbsarch.dll")
|
||||
endif()
|
||||
# install the true DLLs
|
||||
install(FILES ${lib_delphi}/libbsarch.dll DESTINATION bin CONFIGURATIONS Release RelWithDebInfo MinSizeRel)
|
||||
install(FILES ${lib_delphi}/libbsarchd.dll DESTINATION bin CONFIGURATIONS Debug)
|
||||
|
||||
#Adding Qt support
|
||||
if(Qt6_FOUND)
|
||||
message("libbsarch: Qt6 found, enabling Qt support")
|
||||
target_link_libraries(libbsarch_OOP PUBLIC Qt::Core)
|
||||
target_compile_definitions(libbsarch PUBLIC "QT")
|
||||
target_compile_definitions(libbsarch_OOP PUBLIC "QT")
|
||||
endif()
|
||||
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config.cmake"
|
||||
INSTALL_DESTINATION "lib/cmake/mo2-libbsarch"
|
||||
NO_SET_AND_CHECK_MACRO
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||
)
|
||||
|
||||
target_link_libraries(libbsarch_OOP PUBLIC libbsarch)
|
||||
target_compile_features(libbsarch_OOP PRIVATE cxx_std_17)
|
||||
target_compile_definitions(libbsarch_OOP PRIVATE _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/Version.cmake)
|
||||
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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
# BSArchive DLL and C++ bindings
|
||||
|
||||
BSArchive Dynamic Link Library and C++ bindings
|
||||
|
||||
## How to build
|
||||
@@ -9,7 +10,7 @@ BSArchive Dynamic Link Library and C++ bindings
|
||||
|
||||
## How to use
|
||||
|
||||
With CMake:
|
||||
With CMake:
|
||||
Use ``add_subdirectory`` and ``target_link_library``
|
||||
Then ``#include "libbsarch.h"`` for the C wrapper, or ``#include "bs_archive_auto"`` for the C++ wrapper.
|
||||
See the example for code use.
|
||||
@@ -20,4 +21,5 @@ Use `libbsarch.dll` (provided in delphi/lib), `libbsarch.lib` and `libbsarch.h`
|
||||
## Credits
|
||||
|
||||
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.
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
set(LIBBSARCH_MAJOR_VERSION 0)
|
||||
set(LIBBSARCH_MINOR_VERSION 1)
|
||||
set(LIBBSARCH_PATCH_VERSION 2)
|
||||
@@ -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.
+5
-22
@@ -9,10 +9,6 @@ uses
|
||||
wbBSArchive;
|
||||
|
||||
type
|
||||
TwbBSResultBuffer = packed record
|
||||
size: Cardinal;
|
||||
data: PByte;
|
||||
end;
|
||||
TwbBSResultCode = (
|
||||
BSA_RESULT_NONE = 0,
|
||||
BSA_RESULT_EXCEPTION = -1
|
||||
@@ -24,7 +20,7 @@ type
|
||||
TwbBSResultMessageBuffer = packed record
|
||||
buffer: TwbBSResultBuffer;
|
||||
message: TwbBSResultMessage;
|
||||
end;
|
||||
end;
|
||||
|
||||
{Shared}
|
||||
|
||||
@@ -197,14 +193,10 @@ begin
|
||||
end;
|
||||
|
||||
function bsa_add_file_from_memory(obj: Pointer; const aFilePath: PChar; const aSize: Cardinal; const aData: PByte): TwbBSResultMessage; stdcall;
|
||||
var
|
||||
Buffer: TBytes;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
SetLength(Buffer, aSize);
|
||||
Move(aData[0], Buffer[0], aSize);
|
||||
try
|
||||
TwbBSArchive(obj).AddFileData(String(aFilePath), Buffer);
|
||||
TwbBSArchive(obj).AddFileData(String(aFilePath), aSize, aData);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
@@ -221,14 +213,10 @@ begin
|
||||
end;
|
||||
|
||||
function bsa_extract_file_data_by_record(obj: Pointer; aFileRecord: Pointer): TwbBSResultMessageBuffer; stdcall;
|
||||
var
|
||||
Buffer: TBytes;
|
||||
begin
|
||||
Result.message.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
Buffer := TwbBSArchive(obj).ExtractFileData(aFileRecord);
|
||||
Result.buffer.data := @Buffer[0];
|
||||
Result.buffer.size := Length(Buffer);
|
||||
Result.buffer := TwbBSArchive(obj).ExtractFileData(aFileRecord);
|
||||
except
|
||||
on E: Exception do
|
||||
buffer_exception_handler(E, Result);
|
||||
@@ -236,14 +224,10 @@ begin
|
||||
end;
|
||||
|
||||
function bsa_extract_file_data_by_filename(obj: Pointer; const aFilePath: PChar): TwbBSResultMessageBuffer; stdcall;
|
||||
var
|
||||
Buffer: TBytes;
|
||||
begin
|
||||
Result.message.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
Buffer := TwbBSArchive(obj).ExtractFileData(String(aFilePath));
|
||||
Result.buffer.data := @Buffer[0];
|
||||
Result.buffer.size := Length(Buffer);
|
||||
Result.buffer := TwbBSArchive(obj).ExtractFileData(String(aFilePath));
|
||||
except
|
||||
on E: Exception do
|
||||
buffer_exception_handler(E, Result);
|
||||
@@ -254,8 +238,7 @@ function bsa_file_data_free(obj: Pointer; fileDataResult: TwbBSResultMessageBuff
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
FreeMem(fileDataResult.buffer.data);
|
||||
fileDataResult.buffer.size := 0;
|
||||
TwbBSArchive(obj).ReleaseFileData(fileDataResult.buffer);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
|
||||
+73
-45
@@ -232,11 +232,11 @@ type
|
||||
TBSArchiveType = (baNone, baTES3, baTES4, baFO3, baSSE, baFO4, baFO4dds, baSF, baSFdds);
|
||||
TBSArchiveState = (stReading, stWriting);
|
||||
TBSArchiveStates = set of TBSArchiveState;
|
||||
TBSFileIterationProc = function(aArchive: TwbBSArchive; const aFileName: string;
|
||||
TBSFileIterationProc = function(aArchive: Pointer; const aFileName: string;
|
||||
aFileRecord: Pointer; aFolderRecord: Pointer; aData: Pointer): Boolean; stdcall;
|
||||
|
||||
TDDSInfo = record Width, Height, MipMaps: Integer; end;
|
||||
TBSFileDDSInfoProc = procedure(aArchive: TwbBSArchive; const aFileName: string;
|
||||
TBSFileDDSInfoProc = procedure(aArchive: Pointer; const aFileName: string;
|
||||
var aInfo: TDDSInfo; aContext: Pointer); stdcall;
|
||||
|
||||
TwbBSHeaderTES3 = packed record
|
||||
@@ -346,6 +346,11 @@ type
|
||||
end;
|
||||
PPackedDataInfo = ^TPackedDataInfo;
|
||||
|
||||
TwbBSResultBuffer = packed record
|
||||
size: Cardinal;
|
||||
data: PByte;
|
||||
end;
|
||||
|
||||
TwbBSArchive = class
|
||||
private
|
||||
fStream: TwbBaseCachedFileStream;
|
||||
@@ -413,11 +418,11 @@ type
|
||||
procedure Save;
|
||||
procedure AddFileDisk(const aFilePath, aSourcePath: string);
|
||||
procedure AddFileDiskRoot(const aRootDir, aSourcePath: string);
|
||||
procedure AddFileData(const aFileName: string; const aData: TBytes); overload;
|
||||
procedure AddFileData(const aFileName: string; const aSize: Cardinal; const aData: PByte); overload;
|
||||
function FindFileRecord(const aFileName: string): Pointer;
|
||||
function ExtractFileData(aFileRecord: Pointer): TBytes; overload;
|
||||
function ExtractFileData(const aFileName: string): TBytes; overload;
|
||||
procedure ExtractFileToStream(const aFileName: string; aStream: TStream);
|
||||
function ExtractFileData(aFileRecord: Pointer): TwbBSResultBuffer; overload;
|
||||
function ExtractFileData(const aFileName: string): TwbBSResultBuffer; overload;
|
||||
procedure ReleaseFileData(fileDataResult: TwbBSResultBuffer);
|
||||
procedure ExtractFile(const aFileName, aSaveAs: string);
|
||||
procedure IterateFiles(aProc: TBSFileIterationProc; aData: Pointer = nil;
|
||||
aSingleThreaded: Boolean = False);
|
||||
@@ -1757,19 +1762,26 @@ procedure TwbBSArchive.AddFileDisk(const aFilePath, aSourcePath: string);
|
||||
var
|
||||
fname: string;
|
||||
i: integer;
|
||||
Buffer: TBytes;
|
||||
buffer: PByte;
|
||||
stream: TFileStream;
|
||||
begin
|
||||
if not (stWriting in fStates) then
|
||||
raise Exception.Create('Archive is not in writing mode');
|
||||
|
||||
with TFileStream.Create(aSourcePath, fmOpenRead + fmShareDenyNone) do try
|
||||
SetLength(Buffer, Size);
|
||||
Read(Buffer[0], Length(Buffer));
|
||||
stream := TFileStream.Create(aSourcePath, fmOpenRead + fmShareDenyNone);
|
||||
try
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
buffer := AllocMem(stream.Size);
|
||||
try
|
||||
stream.Read(buffer^, stream.Size);
|
||||
AddFileData(aFilePath, stream.Size, buffer);
|
||||
finally
|
||||
if Assigned(buffer) then
|
||||
FreeMem(buffer);
|
||||
end;
|
||||
finally
|
||||
Free;
|
||||
stream.Free;
|
||||
end;
|
||||
|
||||
AddFileData(aFilePath, Buffer);
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.AddFileDiskRoot(const aRootDir, aSourcePath: string);
|
||||
@@ -1919,7 +1931,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.AddFileData(const aFileName: string; const aData: TBytes);
|
||||
procedure TwbBSArchive.AddFileData(const aFileName: string; const aSize: Cardinal; const aData: PByte);
|
||||
var
|
||||
i, j, Off, MipSize, BitsPerPixel: integer;
|
||||
DataHash: TPackedDataHash;
|
||||
@@ -1932,7 +1944,7 @@ begin
|
||||
|
||||
// dds mipmaps have their own partial hash calculation down below
|
||||
if fShareData and not (fType in [baFO4dds, baSFdds]) then
|
||||
DataHash := CalcDataHash(@aData[0], Length(aData));
|
||||
DataHash := CalcDataHash(@aData[0], aSize);
|
||||
|
||||
SyncBeginWrite;
|
||||
try
|
||||
@@ -1941,7 +1953,7 @@ begin
|
||||
if not FindFileRecordTES3(aFileName, i) then
|
||||
raise Exception.Create('File not found in files table: ' + aFileName);
|
||||
|
||||
PackData(@fFilesTES3[i], aFileName, DataHash, @aData[0], Length(aData), False);
|
||||
PackData(@fFilesTES3[i], aFileName, DataHash, @aData[0], aSize, False);
|
||||
end;
|
||||
|
||||
baTES4, baFO3, baSSE: begin
|
||||
@@ -1950,7 +1962,7 @@ begin
|
||||
|
||||
PackData(
|
||||
@fFoldersTES4[i].Files[j], fFoldersTES4[i].Name + '\' + fFoldersTES4[i].Files[j].Name,
|
||||
DataHash, @aData[0], Length(aData), fFoldersTES4[i].Files[j].Compress(Self)
|
||||
DataHash, @aData[0], aSize, fFoldersTES4[i].Files[j].Compress(Self)
|
||||
);
|
||||
end;
|
||||
|
||||
@@ -1959,11 +1971,11 @@ begin
|
||||
raise Exception.Create('File not found in files table: ' + aFileName);
|
||||
|
||||
fFilesFO4[i].Offset := fStream.Position;
|
||||
fFilesFO4[i].Size := Length(aData);
|
||||
fFilesFO4[i].Size := aSize;
|
||||
|
||||
PackData(
|
||||
@fFilesFO4[i], fFilesFO4[i].Name,
|
||||
DataHash, @aData[0], Length(aData), fFilesFO4[i].Compress(Self)
|
||||
DataHash, @aData[0], aSize, fFilesFO4[i].Compress(Self)
|
||||
);
|
||||
end;
|
||||
|
||||
@@ -2081,7 +2093,7 @@ begin
|
||||
else begin
|
||||
// last chunk stores all remaining mipmaps
|
||||
fFilesFO4[i].TexChunks[j].EndMip := Pred(fFilesFO4[i].NumMips);
|
||||
MipSize := Length(aData) - Off;
|
||||
MipSize := Integer(aSize) - Off;
|
||||
end;
|
||||
|
||||
DataHash := CalcDataHash(@aData[Off], MipSize);
|
||||
@@ -2102,7 +2114,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TwbBSArchive.ExtractFileData(aFileRecord: Pointer): TBytes;
|
||||
function TwbBSArchive.ExtractFileData(aFileRecord: Pointer): TwbBSResultBuffer;
|
||||
var
|
||||
FileTES3: PwbBSFileTES3;
|
||||
FileTES4: PwbBSFileTES4;
|
||||
@@ -2125,8 +2137,9 @@ begin
|
||||
baTES3: begin
|
||||
FileTES3 := aFileRecord;
|
||||
fStream.Position := fDataOffset + FileTES3.Offset;
|
||||
SetLength(Result, FileTES3.Size);
|
||||
fStream.ReadBuffer(Result[0], Length(Result));
|
||||
Result.size := FileTES3.Size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(FileTES3.Size);
|
||||
end;
|
||||
|
||||
baTES4, baFO3, baSSE: begin
|
||||
@@ -2145,23 +2158,27 @@ begin
|
||||
|
||||
if bCompressed then begin
|
||||
// reading uncompressed size
|
||||
SetLength(Result, fStream.ReadCardinal);
|
||||
Result.size := fStream.ReadCardinal;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
dec(size, SizeOf(Cardinal));
|
||||
if (Length(Result) > 0) and (size > 0) then begin
|
||||
if (Result.size > 0) and (size > 0) then begin
|
||||
SetLength(Buffer, size);
|
||||
fStream.ReadBuffer(Buffer[0], Length(Buffer));
|
||||
SyncEndWrite;
|
||||
try
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result[0], Length(Result));
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result.data[0], Result.size);
|
||||
finally
|
||||
SyncBeginWrite;
|
||||
end;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
SetLength(Result, size);
|
||||
Result.size := size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
if size > 0 then
|
||||
fStream.ReadBuffer(Result[0], size);
|
||||
fStream.ReadBuffer(Result.data[0], Result.size);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -2171,17 +2188,21 @@ begin
|
||||
if FileFO4.PackedSize <> 0 then begin
|
||||
SetLength(Buffer, FileFO4.PackedSize);
|
||||
fStream.ReadBuffer(Buffer[0], Length(Buffer));
|
||||
SetLength(Result, FileFO4.Size);
|
||||
Result.size := FileFO4.Size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
SyncEndWrite;
|
||||
try
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result[0], Length(Result));
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result.data[0], Result.size);
|
||||
finally
|
||||
SyncBeginWrite;
|
||||
end;
|
||||
end
|
||||
else begin
|
||||
SetLength(Result, FileFO4.Size);
|
||||
fStream.ReadBuffer(Result[0], Length(Result));
|
||||
Result.size := FileFO4.Size;
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
fStream.ReadBuffer(Result.data[0], Result.size);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -2191,9 +2212,12 @@ begin
|
||||
TexSize := SizeOf(TDDSHeader);
|
||||
for i := Low(FileFO4.TexChunks) to High(FileFO4.TexChunks) do
|
||||
Inc(TexSize, FileFO4.TexChunks[i].Size);
|
||||
SetLength(Result, TexSize);
|
||||
Result.size := Texsize;
|
||||
|
||||
DDSHeader := @Result[0];
|
||||
// Modified: Make sure memory is zeroed when allocated
|
||||
Result.data := AllocMem(Result.size);
|
||||
|
||||
DDSHeader := @Result.data[0];
|
||||
DDSHeader.Magic := MAGIC_DDS;
|
||||
DDSHeader.dwSize := SizeOf(TDDSHeader) - SizeOf(TMagic4);
|
||||
DDSHeader.dwWidth := FileFO4.Width;
|
||||
@@ -2206,7 +2230,7 @@ begin
|
||||
DDSHeader.dwCaps := DDSHeader.dwCaps or DDSCAPS_MIPMAP or DDSCAPS_COMPLEX;
|
||||
DDSHeader.dwDepth := 1;
|
||||
|
||||
DDSHeaderDX10 := @Result[SizeOf(TDDSHeader)];
|
||||
DDSHeaderDX10 := @Result.data[SizeOf(TDDSHeader)];
|
||||
DDSHeaderDX10.resourceDimension := DDS_DIMENSION_TEXTURE2D;
|
||||
DDSHeaderDX10.arraySize := 1;
|
||||
|
||||
@@ -2381,8 +2405,9 @@ begin
|
||||
|
||||
TexSize := SizeOf(TDDSHeader);
|
||||
if DDSHeader.ddspf.dwFourCC = MAGIC_DX10 then begin
|
||||
SetLength(Result, Length(Result) + SizeOf(TDDSHeaderDX10));
|
||||
ReallocMem(Result.data, Result.size + SizeOf(TDDSHeaderDX10));
|
||||
Inc(TexSize, SizeOf(TDDSHeaderDX10));
|
||||
Result.size := TexSize;
|
||||
end;
|
||||
|
||||
// append chunks
|
||||
@@ -2394,16 +2419,17 @@ begin
|
||||
fStream.ReadBuffer(Buffer[0], Length(Buffer));
|
||||
SyncEndWrite;
|
||||
try
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result[TexSize], Size);
|
||||
DecompressBuf(@Buffer[0], Length(Buffer), @Result.data[TexSize], Size);
|
||||
finally
|
||||
SyncBeginWrite;
|
||||
end;
|
||||
end
|
||||
// uncompressed chunk
|
||||
else
|
||||
fStream.ReadBuffer(Result[TexSize], Size);
|
||||
fStream.ReadBuffer(Result.data[TexSize], Size);
|
||||
|
||||
Inc(TexSize, Size);
|
||||
Result.size := TexSize;
|
||||
end;
|
||||
end
|
||||
|
||||
@@ -2415,7 +2441,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TwbBSArchive.ExtractFileData(const aFileName: string): TBytes;
|
||||
function TwbBSArchive.ExtractFileData(const aFileName: string): TwbBSResultBuffer;
|
||||
var
|
||||
FileRecord: Pointer;
|
||||
begin
|
||||
@@ -2430,25 +2456,27 @@ begin
|
||||
Result := ExtractFileData(FileRecord);
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.ExtractFileToStream(const aFileName: string; aStream: TStream);
|
||||
var
|
||||
FileData: TBytes;
|
||||
// Addded: For use in non-Borland C/C++
|
||||
procedure TwbBSArchive.ReleaseFileData(fileDataResult: TwbBSResultBuffer);
|
||||
begin
|
||||
FileData := ExtractFileData(aFileName);
|
||||
aStream.Write(FileData[0], Length(FileData));
|
||||
FreeMem(fileDataResult.data);
|
||||
fileDataResult.size := 0;
|
||||
end;
|
||||
|
||||
procedure TwbBSArchive.ExtractFile(const aFileName, aSaveAs: string);
|
||||
var
|
||||
fs: TFileStream;
|
||||
fileData: TwbBSResultBuffer;
|
||||
begin
|
||||
if not (stReading in fStates) then
|
||||
raise Exception.Create('Archive is not loaded');
|
||||
|
||||
fs := TFileStream.Create(aSaveAs, fmCreate);
|
||||
try
|
||||
ExtractFileToStream(aFileName, fs);
|
||||
fileData := ExtractFileData(aFileName);
|
||||
fs.Write(fileData.data[0], fileData.size);
|
||||
finally
|
||||
ReleaseFileData(fileData);
|
||||
fs.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -1,146 +1,162 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
#include "libbsarch.h"
|
||||
#include <libbsarch/libbsarch.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -62,17 +62,17 @@ public:
|
||||
void *context)
|
||||
{
|
||||
const auto &path = *static_cast<convertible_string *>(context) + '/' + convertible_string(file_path);
|
||||
|
||||
|
||||
auto image = std::make_unique<DirectX::ScratchImage>();
|
||||
DirectX::TexMetadata info;
|
||||
|
||||
|
||||
const auto hr = LoadFromDDSFile(PREPARE_PATH_LIBBSARCH(path), DirectX::DDS_FLAGS_BAD_DXTN_TAILS, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
//Do not throw here. Exceptions will be ignored
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dds_info->width = info.width;
|
||||
dds_info->height = info.height;
|
||||
dds_info->mipmaps = info.mipLevels;
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace libbsarch {
|
||||
/*!
|
||||
* \brief The bs_archive_auto class is a convenience class. It manages both bs_archive and bs_archive_entries.
|
||||
* \brief The bs_archive_auto class is a convenience class. It manages both bs_archive and bs_archive_entries.
|
||||
* It is recommended when packing from disk/extracting to disk
|
||||
* Otherwise, if using memory, the use of these two separate classes is recommended
|
||||
*/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user