mirror of
https://github.com/ModOrganizer2/libbsarch.git
synced 2026-07-27 14:06:31 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a544ac3de | ||
|
|
4f32506570 |
@@ -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
|
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
|
||||||
|
|||||||
@@ -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
|
||||||
+99
-77
@@ -1,71 +1,83 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
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/libbsarch.h
|
get_target_property(SRCS mo2::dds-header SOURCES)
|
||||||
src/libbsarch.cpp
|
|
||||||
src/libbsarch.def
|
# 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}/dds)
|
target_include_directories(libbsarch PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch)
|
||||||
target_compile_features(libbsarch PRIVATE cxx_std_11)
|
set_target_properties(libbsarch PROPERTIES DEBUG_POSTFIX "d" CXX_STANDARD 11)
|
||||||
|
target_link_libraries(libbsarch PUBLIC mo2::dds-header)
|
||||||
# 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()
|
|
||||||
|
|
||||||
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>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
############################################################
|
|
||||||
# libbsarch_OOP #
|
|
||||||
############################################################
|
|
||||||
|
|
||||||
find_package(Qt6 COMPONENTS Core REQUIRED)
|
# libbsarch_OOP
|
||||||
|
add_library(libbsarch_OOP STATIC)
|
||||||
|
|
||||||
add_library(libbsarch_OOP STATIC
|
target_sources(libbsarch_OOP
|
||||||
src/base_types.hpp
|
PRIVATE
|
||||||
src/bs_archive_auto.cpp
|
src/bs_archive_entries.cpp
|
||||||
src/bs_archive_auto.hpp
|
src/utils/string_convert.cpp
|
||||||
src/bs_archive.cpp
|
src/utils/convertible_ostream.cpp
|
||||||
src/bs_archive.h
|
src/utils/convertible_string.cpp
|
||||||
src/bs_archive_entries.cpp
|
src/bs_archive_auto.cpp
|
||||||
src/bs_archive_entries.h
|
src/bs_archive.cpp
|
||||||
|
PUBLIC
|
||||||
src/libbsarch.hpp
|
FILE_SET HEADERS
|
||||||
src/libbsarch.h
|
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||||
|
FILES
|
||||||
src/utils/convertible_string.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/base_types.hpp
|
||||||
src/utils/convertible_string.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive_auto.hpp
|
||||||
src/utils/convertible_ostream.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive.h
|
||||||
src/utils/convertible_ostream.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/bs_archive_entries.h
|
||||||
src/utils/string_convert.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/include/libbsarch/libbsarch.hpp
|
||||||
src/utils/string_convert.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}/dds)
|
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
|
||||||
|
)
|
||||||
|
|
||||||
## Copying the corresponding DLL ##
|
if (MSVC)
|
||||||
|
target_compile_options(libbsarch_OOP PRIVATE /MP)
|
||||||
|
endif()
|
||||||
|
|
||||||
#Finding 32 or 64bits
|
# 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")
|
||||||
@@ -76,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(Qt6_FOUND)
|
"${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config.cmake"
|
||||||
message("libbsarch: Qt6 found, enabling Qt support")
|
INSTALL_DESTINATION "lib/cmake/mo2-libbsarch"
|
||||||
target_link_libraries(libbsarch_OOP PUBLIC Qt::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
|
||||||
|
)
|
||||||
|
|||||||
@@ -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 DLL and C++ bindings
|
||||||
|
|
||||||
BSArchive Dynamic Link Library and C++ bindings
|
BSArchive Dynamic Link Library and C++ bindings
|
||||||
|
|
||||||
## How to build
|
## How to build
|
||||||
@@ -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.
|
||||||
|
|||||||
@@ -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()
|
||||||
@@ -1,240 +0,0 @@
|
|||||||
//--------------------------------------------------------------------------------------
|
|
||||||
// dds.h
|
|
||||||
//
|
|
||||||
// This header defines constants and structures that are useful when parsing
|
|
||||||
// DDS files. DDS files were originally designed to use several structures
|
|
||||||
// and constants that are native to DirectDraw and are defined in ddraw.h,
|
|
||||||
// such as DDSURFACEDESC2 and DDSCAPS2. This file defines similar
|
|
||||||
// (compatible) constants and structures so that one can use DDS files
|
|
||||||
// without needing to include ddraw.h.
|
|
||||||
//
|
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// Licensed under the MIT License.
|
|
||||||
//
|
|
||||||
// http://go.microsoft.com/fwlink/?LinkId=248926
|
|
||||||
// http://go.microsoft.com/fwlink/?LinkId=248929
|
|
||||||
// http://go.microsoft.com/fwlink/?LinkID=615561
|
|
||||||
//--------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <dxgiformat.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
namespace DirectX {
|
|
||||||
#pragma pack(push, 1)
|
|
||||||
|
|
||||||
const uint32_t DDS_MAGIC = 0x20534444; // "DDS "
|
|
||||||
|
|
||||||
struct DDS_PIXELFORMAT
|
|
||||||
{
|
|
||||||
uint32_t size;
|
|
||||||
uint32_t flags;
|
|
||||||
uint32_t fourCC;
|
|
||||||
uint32_t RGBBitCount;
|
|
||||||
uint32_t RBitMask;
|
|
||||||
uint32_t GBitMask;
|
|
||||||
uint32_t BBitMask;
|
|
||||||
uint32_t ABitMask;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
|
|
||||||
#define DDS_RGB 0x00000040 // DDPF_RGB
|
|
||||||
#define DDS_RGBA 0x00000041 // DDPF_RGB | DDPF_ALPHAPIXELS
|
|
||||||
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
|
|
||||||
#define DDS_LUMINANCEA 0x00020001 // DDPF_LUMINANCE | DDPF_ALPHAPIXELS
|
|
||||||
#define DDS_ALPHAPIXELS 0x00000001 // DDPF_ALPHAPIXELS
|
|
||||||
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
|
|
||||||
#define DDS_PAL8 0x00000020 // DDPF_PALETTEINDEXED8
|
|
||||||
#define DDS_PAL8A 0x00000021 // DDPF_PALETTEINDEXED8 | DDPF_ALPHAPIXELS
|
|
||||||
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
|
|
||||||
|
|
||||||
#ifndef MAKEFOURCC
|
|
||||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
|
||||||
(static_cast<uint32_t>(static_cast<uint8_t>(ch0)) | (static_cast<uint32_t>(static_cast<uint8_t>(ch1)) << 8) \
|
|
||||||
| (static_cast<uint32_t>(static_cast<uint8_t>(ch2)) << 16) \
|
|
||||||
| (static_cast<uint32_t>(static_cast<uint8_t>(ch3)) << 24))
|
|
||||||
#endif /* defined(MAKEFOURCC) */
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_DXT1 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '1'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_DXT2 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '2'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_DXT3 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '3'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_DXT4 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '4'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_DXT5 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', 'T', '5'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_BC4_UNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '4', 'U'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_BC4_SNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '4', 'S'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_BC5_UNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '5', 'U'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_BC5_SNORM = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('B', 'C', '5', 'S'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_R8G8_B8G8 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('R', 'G', 'B', 'G'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_G8R8_G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('G', 'R', 'G', 'B'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_YUY2 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('Y', 'U', 'Y', '2'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_A8R8G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_X8R8G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_A8B8G8R8 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_X8B8G8R8 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_G16R16 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_R5G6B5 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_A1R5G5B5 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00007c00, 0x000003e0, 0x0000001f, 0x00008000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_A4R4G4B4 = {sizeof(DDS_PIXELFORMAT), DDS_RGBA, 0, 16, 0x00000f00, 0x000000f0, 0x0000000f, 0x0000f000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_R8G8B8 = {sizeof(DDS_PIXELFORMAT), DDS_RGB, 0, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const
|
|
||||||
DDS_PIXELFORMAT DDSPF_L8 = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 8, 0xff, 0x00, 0x00, 0x00};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const
|
|
||||||
DDS_PIXELFORMAT DDSPF_L16 = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCE, 0, 16, 0xffff, 0x0000, 0x0000, 0x0000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_A8L8 = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 16, 0x00ff, 0x0000, 0x0000, 0xff00};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_A8L8_ALT = {sizeof(DDS_PIXELFORMAT), DDS_LUMINANCEA, 0, 8, 0x00ff, 0x0000, 0x0000, 0xff00};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const
|
|
||||||
DDS_PIXELFORMAT DDSPF_A8 = {sizeof(DDS_PIXELFORMAT), DDS_ALPHA, 0, 8, 0x00, 0x00, 0x00, 0xff};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_V8U8 = {sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 16, 0x00ff, 0xff00, 0x0000, 0x0000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_Q8W8V8U8 = {sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000};
|
|
||||||
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_V16U16 = {sizeof(DDS_PIXELFORMAT), DDS_BUMPDUDV, 0, 32, 0x0000ffff, 0xffff0000, 0x00000000, 0x00000000};
|
|
||||||
|
|
||||||
// D3DFMT_A2R10G10B10/D3DFMT_A2B10G10R10 should be written using DX10 extension to avoid D3DX 10:10:10:2 reversal issue
|
|
||||||
|
|
||||||
// This indicates the DDS_HEADER_DXT10 extension is present (the format is in dxgiFormat)
|
|
||||||
extern __declspec(selectany) const DDS_PIXELFORMAT
|
|
||||||
DDSPF_DX10 = {sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D', 'X', '1', '0'), 0, 0, 0, 0, 0};
|
|
||||||
|
|
||||||
#define DDS_HEADER_FLAGS_TEXTURE 0x00001007 // DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT
|
|
||||||
#define DDS_HEADER_FLAGS_MIPMAP 0x00020000 // DDSD_MIPMAPCOUNT
|
|
||||||
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
|
|
||||||
#define DDS_HEADER_FLAGS_PITCH 0x00000008 // DDSD_PITCH
|
|
||||||
#define DDS_HEADER_FLAGS_LINEARSIZE 0x00080000 // DDSD_LINEARSIZE
|
|
||||||
|
|
||||||
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
|
|
||||||
#define DDS_WIDTH 0x00000004 // DDSD_WIDTH
|
|
||||||
|
|
||||||
#define DDS_SURFACE_FLAGS_TEXTURE 0x00001000 // DDSCAPS_TEXTURE
|
|
||||||
#define DDS_SURFACE_FLAGS_MIPMAP 0x00400008 // DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
|
|
||||||
#define DDS_SURFACE_FLAGS_CUBEMAP 0x00000008 // DDSCAPS_COMPLEX
|
|
||||||
|
|
||||||
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
|
|
||||||
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
|
|
||||||
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
|
|
||||||
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
|
|
||||||
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
|
|
||||||
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
|
|
||||||
|
|
||||||
#define DDS_CUBEMAP_ALLFACES \
|
|
||||||
(DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX | DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY \
|
|
||||||
| DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ)
|
|
||||||
|
|
||||||
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
|
|
||||||
|
|
||||||
#define DDS_FLAGS_VOLUME 0x00200000 // DDSCAPS2_VOLUME
|
|
||||||
|
|
||||||
// Subset here matches D3D10_RESOURCE_DIMENSION and D3D11_RESOURCE_DIMENSION
|
|
||||||
enum DDS_RESOURCE_DIMENSION
|
|
||||||
{
|
|
||||||
DDS_DIMENSION_TEXTURE1D = 2,
|
|
||||||
DDS_DIMENSION_TEXTURE2D = 3,
|
|
||||||
DDS_DIMENSION_TEXTURE3D = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Subset here matches D3D10_RESOURCE_MISC_FLAG and D3D11_RESOURCE_MISC_FLAG
|
|
||||||
enum DDS_RESOURCE_MISC_FLAG
|
|
||||||
{
|
|
||||||
DDS_RESOURCE_MISC_TEXTURECUBE = 0x4L,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DDS_MISC_FLAGS2
|
|
||||||
{
|
|
||||||
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum DDS_ALPHA_MODE
|
|
||||||
{
|
|
||||||
DDS_ALPHA_MODE_UNKNOWN = 0,
|
|
||||||
DDS_ALPHA_MODE_STRAIGHT = 1,
|
|
||||||
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
|
|
||||||
DDS_ALPHA_MODE_OPAQUE = 3,
|
|
||||||
DDS_ALPHA_MODE_CUSTOM = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DDS_HEADER
|
|
||||||
{
|
|
||||||
uint32_t size;
|
|
||||||
uint32_t flags;
|
|
||||||
uint32_t height;
|
|
||||||
uint32_t width;
|
|
||||||
uint32_t pitchOrLinearSize;
|
|
||||||
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
|
|
||||||
uint32_t mipMapCount;
|
|
||||||
uint32_t reserved1[11];
|
|
||||||
DDS_PIXELFORMAT ddspf;
|
|
||||||
uint32_t caps;
|
|
||||||
uint32_t caps2;
|
|
||||||
uint32_t caps3;
|
|
||||||
uint32_t caps4;
|
|
||||||
uint32_t reserved2;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DDS_HEADER_DXT10
|
|
||||||
{
|
|
||||||
DXGI_FORMAT dxgiFormat;
|
|
||||||
uint32_t resourceDimension;
|
|
||||||
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
|
|
||||||
uint32_t arraySize;
|
|
||||||
uint32_t miscFlags2; // see DDS_MISC_FLAGS2
|
|
||||||
};
|
|
||||||
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
|
|
||||||
static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
|
|
||||||
|
|
||||||
} // namespace DirectX
|
|
||||||
Binary file not shown.
Binary file not shown.
@@ -2429,6 +2429,7 @@ begin
|
|||||||
fStream.ReadBuffer(Result.data[TexSize], Size);
|
fStream.ReadBuffer(Result.data[TexSize], Size);
|
||||||
|
|
||||||
Inc(TexSize, Size);
|
Inc(TexSize, Size);
|
||||||
|
Result.size := TexSize;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <dxgiformat.h>
|
#include <dxgiformat.h>
|
||||||
#include <dds.h>
|
|
||||||
|
#include <DDS.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef BSARCH_DLL_EXPORT
|
#ifdef BSARCH_DLL_EXPORT
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user