mirror of
https://github.com/ModOrganizer2/libbsarch.git
synced 2026-07-27 14:06:31 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8331290047 | ||
|
|
4f7aeaf4f1 | ||
|
|
4f32506570 | ||
|
|
bf840701de | ||
|
|
37f139a236 | ||
|
|
3a277db0fb | ||
|
|
701bc58e9a | ||
|
|
c535689ef4 | ||
|
|
3219ade30e | ||
|
|
4a88aab247 | ||
|
|
f8327f3112 | ||
|
|
9e984fd268 | ||
|
|
f7e1090612 | ||
|
|
77a6be7bcb | ||
|
|
7acca3d47d | ||
|
|
0f114677b1 | ||
|
|
f276cd1825 | ||
|
|
c68e39d2a1 | ||
|
|
d3d36d2694 | ||
|
|
3855899330 | ||
|
|
6c3a9234e4 | ||
|
|
322b6c0302 | ||
|
|
6fe376e887 | ||
|
|
bd0ab57f6d | ||
|
|
08536255ff | ||
|
|
30b4a2eb8d | ||
|
|
f92b4cdb28 |
+117
@@ -0,0 +1,117 @@
|
||||
---
|
||||
Language: Cpp
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: DontAlign
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: true
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: true
|
||||
BeforeElse: true
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 120
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- forever
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^<Q.*'
|
||||
Priority: 200
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 4
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 150
|
||||
PenaltyBreakBeforeFirstCallParameter: 300
|
||||
PenaltyBreakComment: 500
|
||||
PenaltyBreakFirstLessLess: 400
|
||||
PenaltyBreakString: 600
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 50
|
||||
PenaltyReturnTypeOnItsOwnLine: 300
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: true
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
...
|
||||
@@ -1,7 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = crlf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
+133
-45
@@ -1,5 +1,57 @@
|
||||
# Created by https://www.gitignore.io/api/vim,delphi,visualstudio,visualstudiocode
|
||||
# Edit at https://www.gitignore.io/?templates=vim,delphi,visualstudio,visualstudiocode
|
||||
|
||||
# Created by https://www.gitignore.io/api/qt,c++,cmake,delphi,qtcreator,visualstudio
|
||||
# Edit at https://www.gitignore.io/?templates=qt,c++,cmake,delphi,qtcreator,visualstudio
|
||||
|
||||
### C++ ###
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
### CMake ###
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
*-prefix/
|
||||
|
||||
### Delphi ###
|
||||
# Uncomment these types if you want even more clean repository. But be careful.
|
||||
@@ -7,30 +59,27 @@
|
||||
#
|
||||
# Resource files are binaries containing manifest, project icon and version info.
|
||||
# They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
|
||||
*.res
|
||||
#*.res
|
||||
# Type library file (binary). In old Delphi versions it should be stored.
|
||||
# Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
|
||||
*.tlb
|
||||
#*.tlb
|
||||
# Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
|
||||
# Uncomment this if you are not using diagrams or use newer Delphi version.
|
||||
*.ddp
|
||||
#*.ddp
|
||||
# Visual LiveBindings file. Added in Delphi XE2.
|
||||
# Uncomment this if you are not using LiveBindings Designer.
|
||||
*.vlb
|
||||
#*.vlb
|
||||
# Deployment Manager configuration file for your project. Added in Delphi XE2.
|
||||
# Uncomment this if it is not mobile development and you do not use remote debug feature.
|
||||
*.deployproj
|
||||
#*.deployproj
|
||||
# C++ object files produced when C/C++ Output file generation is configured.
|
||||
# Uncomment this if you are not using external objects (zlib library for example).
|
||||
*.obj
|
||||
#*.obj
|
||||
|
||||
# Delphi compiler-generated binaries (safe to delete)
|
||||
*.exe
|
||||
*.dll
|
||||
*.bpl
|
||||
*.bpi
|
||||
*.dcp
|
||||
*.so
|
||||
*.apk
|
||||
*.drc
|
||||
*.map
|
||||
@@ -38,14 +87,11 @@
|
||||
*.rsm
|
||||
*.tds
|
||||
*.dcu
|
||||
*.lib
|
||||
*.a
|
||||
*.o
|
||||
*.ocx
|
||||
|
||||
# Delphi autogenerated files (duplicated info)
|
||||
*.cfg
|
||||
*.hpp
|
||||
# *.hpp
|
||||
*Resource.rc
|
||||
|
||||
# Delphi local files (user-specific info)
|
||||
@@ -66,35 +112,73 @@ __recovery/
|
||||
# Boss dependency manager vendor folder https://github.com/HashLoad/boss
|
||||
modules/
|
||||
|
||||
### Vim ###
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
### Qt ###
|
||||
# C++ objects and libs
|
||||
|
||||
# Session
|
||||
Session.vim
|
||||
# Qt-es
|
||||
object_script.*.Release
|
||||
object_script.*.Debug
|
||||
*_plugin_import.cpp
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
*.pro.user
|
||||
*.pro.user.*
|
||||
*.qbs.user
|
||||
*.qbs.user.*
|
||||
*.moc
|
||||
moc_*.cpp
|
||||
moc_*.h
|
||||
qrc_*.cpp
|
||||
ui_*.h
|
||||
*.qmlc
|
||||
*.jsc
|
||||
Makefile*
|
||||
*build-*
|
||||
vsbuild
|
||||
|
||||
# Temporary
|
||||
.netrwhist
|
||||
*~
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
# Qt unit tests
|
||||
target_wrapper.*
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
# QtCreator
|
||||
*.autosave
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
# QtCreator Qml
|
||||
*.qmlproject.user
|
||||
*.qmlproject.user.*
|
||||
|
||||
# QtCreator CMake
|
||||
CMakeLists.txt.user*
|
||||
|
||||
# QtCreator 4.8< compilation database
|
||||
|
||||
# QtCreator local machine specific files for imported projects
|
||||
*creator.user*
|
||||
|
||||
### QtCreator ###
|
||||
# gitignore for Qt Creator like IDE for pure C/C++ project without Qt
|
||||
# Reference: http://doc.qt.io/qtcreator/creator-project-generic.html
|
||||
|
||||
|
||||
|
||||
# Qt Creator autogenerated files
|
||||
|
||||
|
||||
# A listing of all the files included in the project
|
||||
*.files
|
||||
|
||||
# Include directories
|
||||
*.includes
|
||||
|
||||
# Project configuration settings like predefined Macros
|
||||
*.config
|
||||
|
||||
# Qt Creator settings
|
||||
*.creator
|
||||
|
||||
# User project settings
|
||||
*.creator.user*
|
||||
|
||||
# Qt Creator backups
|
||||
|
||||
### VisualStudio ###
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
@@ -141,9 +225,10 @@ Generated\ Files/
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
# NUnit
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
nunit-*.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
@@ -167,9 +252,7 @@ StyleCopReport.xml
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
@@ -284,6 +367,8 @@ PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# NuGet Symbol Packages
|
||||
*.snupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/[Pp]ackages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
@@ -320,6 +405,7 @@ _pkginfo.txt
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
@@ -358,7 +444,9 @@ ServiceFabricBackup/
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
*.rptproj.rsuser
|
||||
*- Backup*.rdl
|
||||
*- [Bb]ackup.rdl
|
||||
*- [Bb]ackup ([0-9]).rdl
|
||||
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
@@ -441,4 +529,4 @@ healthchecksdb
|
||||
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||
MigrationBackup/
|
||||
|
||||
# End of https://www.gitignore.io/api/vim,delphi,visualstudio,visualstudiocode
|
||||
# End of https://www.gitignore.io/api/qt,c++,cmake,delphi,qtcreator,visualstudio
|
||||
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
project(libbsarch CXX)
|
||||
|
||||
find_package(mo2-dds-header CONFIG REQUIRED)
|
||||
find_package(Qt6 COMPONENTS Core REQUIRED)
|
||||
|
||||
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)
|
||||
|
||||
# preprocessor definitions
|
||||
if(MSVC)
|
||||
target_compile_options(libbsarch PRIVATE
|
||||
/W3 /EHsc /MP
|
||||
$<$<CONFIG:DEBUG>:/MDd /Od>
|
||||
$<$<CONFIG:RELEASE>:/Zi>
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
# libbsarch_OOP
|
||||
add_library(libbsarch_OOP STATIC)
|
||||
|
||||
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()
|
||||
|
||||
# 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 "LIBBSARCH_QT_SUPPORT")
|
||||
target_compile_definitions(libbsarch_OOP PUBLIC "LIBBSARCH_QT_SUPPORT")
|
||||
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")
|
||||
message("libbsarch: using 64bits DLL")
|
||||
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
# 32 bits
|
||||
set(lib_delphi "${CMAKE_CURRENT_SOURCE_DIR}/delphi/lib")
|
||||
message("libbsarch: using 32bits 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
|
||||
)
|
||||
|
||||
# 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)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config-version.cmake"
|
||||
VERSION "0.0.13"
|
||||
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,241 +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
|
||||
|
||||
|
||||
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
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Deorder
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,4 +1,5 @@
|
||||
# BSArchive DLL and C++ bindings
|
||||
|
||||
BSArchive Dynamic Link Library and C++ bindings
|
||||
|
||||
## How to build
|
||||
@@ -9,4 +10,16 @@ BSArchive Dynamic Link Library and C++ bindings
|
||||
|
||||
## How to use
|
||||
|
||||
Use the `libbsarch.dll` (The one created by Delphi, not Visual Studio), `libbsarch.lib` and `libbsarch.h` in your project.
|
||||
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.
|
||||
|
||||
Without CMake:
|
||||
Use `libbsarch.dll` (provided in delphi/lib), `libbsarch.lib` and `libbsarch.h` in your project.
|
||||
|
||||
## 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.
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include ( "${CMAKE_CURRENT_LIST_DIR}/mo2-libbsarch-targets.cmake" )
|
||||
|
||||
target_link_libraries(mo2::libbsarch PUBLIC 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
|
||||
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)
|
||||
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)
|
||||
endif()
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,412 @@
|
||||
library libbsarch;
|
||||
|
||||
uses
|
||||
Math,
|
||||
Classes,
|
||||
Types,
|
||||
SysUtils,
|
||||
wbStreams,
|
||||
wbBSArchive;
|
||||
|
||||
type
|
||||
TwbBSResultCode = (
|
||||
BSA_RESULT_NONE = 0,
|
||||
BSA_RESULT_EXCEPTION = -1
|
||||
);
|
||||
TwbBSResultMessage = packed record
|
||||
code: ShortInt;
|
||||
text: array[0..1023] of WideChar;
|
||||
end;
|
||||
TwbBSResultMessageBuffer = packed record
|
||||
buffer: TwbBSResultBuffer;
|
||||
message: TwbBSResultMessage;
|
||||
end;
|
||||
|
||||
{Shared}
|
||||
|
||||
function string_to_cstring(
|
||||
aString: String;
|
||||
const aStringBufferSize: Cardinal;
|
||||
const aStringBuffer: PChar
|
||||
): Integer; stdcall;
|
||||
begin
|
||||
Result := Min(aStringBufferSize, Length(AString));
|
||||
if (aStringBuffer <> nil) and (Result > 0) then
|
||||
Move(AString[1], aStringBuffer^, Result * SizeOf(WideChar));
|
||||
end;
|
||||
|
||||
function string_to_cstring_end(
|
||||
aString: String;
|
||||
const aStringBufferSize: Cardinal;
|
||||
const aStringBuffer: PChar
|
||||
): Integer; stdcall;
|
||||
begin
|
||||
Result := Min(aStringBufferSize - 1, Length(AString));
|
||||
if (aStringBuffer <> nil) and (Result > 0) then
|
||||
begin
|
||||
Move(AString[1], aStringBuffer^, Result * SizeOf(WideChar));
|
||||
aStringBuffer[Result] := #0;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure exception_handler(E: Exception; var Result: TwbBSResultMessage); stdcall;
|
||||
begin
|
||||
Result.code := ShortInt(BSA_RESULT_EXCEPTION);
|
||||
string_to_cstring_end(E.Message, Length(Result.text), Result.text);
|
||||
end;
|
||||
|
||||
procedure buffer_exception_handler(E: Exception; var Result: TwbBSResultMessageBuffer); stdcall;
|
||||
begin
|
||||
Result.buffer.size := 0;
|
||||
Result.buffer.data := nil;
|
||||
Result.message.code := ShortInt(BSA_RESULT_EXCEPTION);
|
||||
string_to_cstring_end(E.Message, Length(Result.message.text), Result.message.text);
|
||||
end;
|
||||
|
||||
{BSA File List}
|
||||
|
||||
function bsa_entry_list_create:Pointer; stdcall;
|
||||
begin
|
||||
try
|
||||
Result := TStringList.Create;
|
||||
except
|
||||
Result := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_entry_list_free(obj: Pointer): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TStringList(obj).Clear();
|
||||
TStringList(obj).free;
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_entry_list_count(obj: Pointer): Integer; stdcall;
|
||||
begin
|
||||
try
|
||||
Result := TStringList(obj).Count;
|
||||
except
|
||||
Result := Ord(BSA_RESULT_EXCEPTION);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_entry_list_add(obj: Pointer; const aEntryString: PChar): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TStringList(obj).Add(String(aEntryString));
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_entry_list_get(obj: Pointer; const aIndex: Cardinal; const aStringBufferSize: Cardinal; const aStringBuffer: PChar): Integer; stdcall;
|
||||
begin
|
||||
try
|
||||
Result := string_to_cstring_end(TStringList(obj).Strings[aIndex], aStringBufferSize, aStringBuffer);
|
||||
except
|
||||
Result := Integer(BSA_RESULT_EXCEPTION);
|
||||
end;
|
||||
end;
|
||||
|
||||
{BSArchive}
|
||||
|
||||
function bsa_create:Pointer; stdcall;
|
||||
begin
|
||||
try
|
||||
Result := TwbBSArchive.Create;
|
||||
except
|
||||
Result := nil;
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_free(obj: Pointer): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).free;
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_load_from_file(obj: Pointer; const aFilePath: PChar): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).LoadFromFile(String(aFilePath));
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_create_archive(obj: Pointer; const aFilePath: PChar; aType: TBSArchiveType; aFileList: TStringList): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).CreateArchive(String(aFilePath), aType, aFileList);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_save(obj: Pointer): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).Save;
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_add_file_from_disk_root(obj: Pointer; const aRootDir, aSourcePath: PChar): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).AddFileDiskRoot(String(aRootDir), String(aSourcePath));
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_add_file_from_disk(obj: Pointer; const aFilePath, aSourcePath: PChar): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).AddFileDisk(String(aFilePath), String(aSourcePath));
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_add_file_from_memory(obj: Pointer; const aFilePath: PChar; const aSize: Cardinal; const aData: PByte): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).AddFileData(String(aFilePath), aSize, aData);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_find_file_record(obj: Pointer; const aFilePath: PChar): Pointer; stdcall;
|
||||
begin
|
||||
try
|
||||
Result := TwbBSArchive(obj).FindFileRecord(String(aFilePath));
|
||||
except
|
||||
Result := nil
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_extract_file_data_by_record(obj: Pointer; aFileRecord: Pointer): TwbBSResultMessageBuffer; stdcall;
|
||||
begin
|
||||
Result.message.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
Result.buffer := TwbBSArchive(obj).ExtractFileData(aFileRecord);
|
||||
except
|
||||
on E: Exception do
|
||||
buffer_exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_extract_file_data_by_filename(obj: Pointer; const aFilePath: PChar): TwbBSResultMessageBuffer; stdcall;
|
||||
begin
|
||||
Result.message.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
Result.buffer := TwbBSArchive(obj).ExtractFileData(String(aFilePath));
|
||||
except
|
||||
on E: Exception do
|
||||
buffer_exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_file_data_free(obj: Pointer; fileDataResult: TwbBSResultMessageBuffer): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).ReleaseFileData(fileDataResult.buffer);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_extract_file(obj: Pointer; const aFilePath, aSaveAs: PChar): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).ExtractFile(String(aFilePath), String(aSaveAs));
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_iterate_files(obj: Pointer; aProc: TBSFileIterationProc; aContext: Pointer): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).IterateFiles(aProc, aContext);
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_file_exists(obj: Pointer; const aFilePath: string): Boolean; stdcall;
|
||||
begin
|
||||
try
|
||||
Result := TwbBSArchive(obj).FileExists(aFilePath);
|
||||
except
|
||||
Result := False;
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_get_resource_list(obj: Pointer; const aEntryResultList: TStringList; aFolder: PChar): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).ResourceList(aEntryResultList, String(aFolder));
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_close(obj: Pointer): TwbBSResultMessage; stdcall;
|
||||
begin
|
||||
Result.code := Ord(BSA_RESULT_NONE);
|
||||
try
|
||||
TwbBSArchive(obj).Close;
|
||||
except
|
||||
on E: Exception do
|
||||
exception_handler(E, Result);
|
||||
end;
|
||||
end;
|
||||
|
||||
function bsa_filename_get(obj: Pointer; const aStringBufferSize: Cardinal; const aStringBuffer: PChar): Cardinal; stdcall;
|
||||
begin
|
||||
Result := string_to_cstring_end(TwbBSArchive(obj).FileName, aStringBufferSize, aStringBuffer);
|
||||
end;
|
||||
|
||||
function bsa_archive_type_get(obj: Pointer): TBSArchiveType; stdcall;
|
||||
begin
|
||||
Result := TwbBSArchive(obj).ArchiveType;
|
||||
end;
|
||||
|
||||
function bsa_version_get(obj: Pointer): Cardinal; stdcall;
|
||||
begin
|
||||
Result := TwbBSArchive(obj).Version;
|
||||
end;
|
||||
|
||||
function bsa_format_name_get(obj: Pointer; const aStringBufferSize: Cardinal; const aStringBuffer: PChar): Cardinal; stdcall;
|
||||
begin
|
||||
Result := string_to_cstring_end(TwbBSArchive(obj).FormatName, aStringBufferSize, aStringBuffer);
|
||||
end;
|
||||
|
||||
function bsa_file_count_get(obj: Pointer): Cardinal; stdcall;
|
||||
begin
|
||||
Result := TwbBSArchive(obj).FileCount;
|
||||
end;
|
||||
|
||||
function bsa_archive_flags_get(obj: Pointer): Cardinal; stdcall;
|
||||
begin
|
||||
Result := TwbBSArchive(obj).ArchiveFlags;
|
||||
end;
|
||||
|
||||
procedure bsa_archive_flags_set(obj: Pointer; flags: Cardinal); stdcall;
|
||||
begin
|
||||
TwbBSArchive(obj).ArchiveFlags := flags;
|
||||
end;
|
||||
|
||||
function bsa_file_flags_get(obj: Pointer): Cardinal; stdcall;
|
||||
begin
|
||||
Result := TwbBSArchive(obj).FileFlags;
|
||||
end;
|
||||
|
||||
procedure bsa_file_flags_set(obj: Pointer; flags: Cardinal); stdcall;
|
||||
begin
|
||||
TwbBSArchive(obj).FileFlags := flags;
|
||||
end;
|
||||
|
||||
function bsa_compress_get(obj: Pointer): Boolean; stdcall;
|
||||
begin
|
||||
Result := TwbBSArchive(obj).Compress;
|
||||
end;
|
||||
|
||||
procedure bsa_compress_set(obj: Pointer; compress: Boolean); stdcall;
|
||||
begin
|
||||
TwbBSArchive(obj).Compress := compress;
|
||||
end;
|
||||
|
||||
function bsa_share_data_get(obj: Pointer): Boolean; stdcall;
|
||||
begin
|
||||
Result := TwbBSArchive(obj).ShareData;
|
||||
end;
|
||||
|
||||
procedure bsa_share_data_set(obj: Pointer; shareData: Boolean); stdcall;
|
||||
begin
|
||||
TwbBSArchive(obj).ShareData := shareData;
|
||||
end;
|
||||
|
||||
procedure bsa_file_dds_info_callback_set(obj: Pointer; aProc: TBSFileDDSInfoProc; aContext: Pointer); stdcall;
|
||||
begin
|
||||
TwbBSArchive(obj).DDSInfoProc := aProc;
|
||||
TwbBSArchive(obj).DDSInfoProcContext := aContext;
|
||||
end;
|
||||
|
||||
exports
|
||||
bsa_entry_list_create,
|
||||
bsa_entry_list_free,
|
||||
bsa_entry_list_count,
|
||||
bsa_entry_list_add,
|
||||
bsa_entry_list_get,
|
||||
|
||||
bsa_filename_get,
|
||||
bsa_archive_type_get,
|
||||
bsa_version_get,
|
||||
bsa_format_name_get,
|
||||
bsa_file_count_get,
|
||||
bsa_archive_flags_get,
|
||||
bsa_archive_flags_set,
|
||||
bsa_file_flags_get,
|
||||
bsa_file_flags_set,
|
||||
bsa_compress_get,
|
||||
bsa_compress_set,
|
||||
bsa_share_data_get,
|
||||
bsa_share_data_set,
|
||||
bsa_file_dds_info_callback_set,
|
||||
|
||||
bsa_close,
|
||||
bsa_get_resource_list,
|
||||
bsa_file_exists,
|
||||
bsa_iterate_files,
|
||||
bsa_extract_file,
|
||||
bsa_file_data_free,
|
||||
bsa_extract_file_data_by_filename,
|
||||
bsa_extract_file_data_by_record,
|
||||
bsa_find_file_record,
|
||||
bsa_add_file_from_memory,
|
||||
bsa_add_file_from_disk_root,
|
||||
bsa_add_file_from_disk,
|
||||
bsa_save,
|
||||
bsa_create_archive,
|
||||
bsa_load_from_file,
|
||||
bsa_create,
|
||||
bsa_free
|
||||
;
|
||||
end.
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,174 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
#include "libbsarch.h"
|
||||
|
||||
#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 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));
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
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.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);
|
||||
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)
|
||||
printf("ba2 large %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_large\\";
|
||||
|
||||
bsa_entry_list_get(entries, index, 2048, filename);
|
||||
wcscat_s(dest_filename, 2048, filename);
|
||||
|
||||
printf("ba2 file large: %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 large %ls\n", result.text);
|
||||
}
|
||||
else {
|
||||
printf("ba2 large could not create: %ls\n", dirname(dest_filename).c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bsa_free(archive);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28803.156
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbsarch-visualstudio-test", "libbsarch-visualstudio-test.vcxproj", "{8F73F848-939D-4862-B58B-26572CF20A5F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Debug|x64.Build.0 = Debug|x64
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Debug|x86.Build.0 = Debug|Win32
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Release|x64.ActiveCfg = Release|x64
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Release|x64.Build.0 = Release|x64
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Release|x86.ActiveCfg = Release|Win32
|
||||
{8F73F848-939D-4862-B58B-26572CF20A5F}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F05F0FBF-790B-4443-B2EC-E7033074D9E0}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,66 @@
|
||||
/* Copyright (C) 2019 G'k
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
#pragma once
|
||||
|
||||
#include "libbsarch.h"
|
||||
#include "utils/convertible_string.hpp"
|
||||
#include <variant>
|
||||
|
||||
namespace libbsarch {
|
||||
struct memory_blob : public bsa_result_buffer_t
|
||||
{
|
||||
memory_blob(uint32_t buffer_size, bsa_buffer_t buffer_data, bsa_archive_t parent)
|
||||
: bsa_result_buffer_t{buffer_size, buffer_data}
|
||||
, parent_(parent)
|
||||
{}
|
||||
|
||||
memory_blob(bsa_result_buffer_t buffer, bsa_archive_t parent)
|
||||
: bsa_result_buffer_t(buffer)
|
||||
, parent_(parent)
|
||||
{}
|
||||
|
||||
bsa_archive_t parent_;
|
||||
|
||||
memory_blob(memory_blob const &) = default;
|
||||
~memory_blob() { bsa_file_data_free(parent_, *this); }
|
||||
};
|
||||
|
||||
struct disk_blob
|
||||
{
|
||||
disk_blob(const convertible_string &root_dir, const convertible_string &absolute_path)
|
||||
: path_in_archive(absolute_path)
|
||||
, path_on_disk(absolute_path)
|
||||
{
|
||||
path_in_archive.remove_substring(root_dir);
|
||||
}
|
||||
|
||||
disk_blob(const convertible_string &path_in_archive,
|
||||
const convertible_string &absolute_path,
|
||||
[[maybe_unused]] bool decoy_parameter)
|
||||
: path_in_archive(path_in_archive)
|
||||
, path_on_disk(absolute_path)
|
||||
{}
|
||||
|
||||
convertible_string path_in_archive;
|
||||
convertible_string path_on_disk;
|
||||
};
|
||||
|
||||
struct bs_packed_file
|
||||
{
|
||||
bs_packed_file(const disk_blob &blob)
|
||||
: path_in_archive(blob.path_in_archive)
|
||||
, data(blob.path_on_disk)
|
||||
{}
|
||||
|
||||
bs_packed_file(convertible_string path_in_archive, memory_blob blob)
|
||||
: path_in_archive(std::move(path_in_archive))
|
||||
, data(blob)
|
||||
{}
|
||||
|
||||
convertible_string path_in_archive;
|
||||
std::variant<memory_blob, convertible_string> data;
|
||||
};
|
||||
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include "bs_archive_entries.h"
|
||||
#include "libbsarch.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
class bs_archive
|
||||
{
|
||||
public:
|
||||
bs_archive();
|
||||
bs_archive(const bsa_archive_type_t &type);
|
||||
virtual ~bs_archive();
|
||||
|
||||
/* Properties */
|
||||
convertible_string get_filename();
|
||||
bsa_archive_type_t get_type();
|
||||
uint32_t get_version();
|
||||
convertible_string get_format_name();
|
||||
uint32_t get_file_count();
|
||||
|
||||
uint32_t get_archive_flags();
|
||||
void set_archive_flags(uint32_t flags);
|
||||
|
||||
uint32_t get_file_flags();
|
||||
void set_file_flags(uint32_t flags);
|
||||
|
||||
void set_compressed(bool value);
|
||||
bool get_compressed();
|
||||
|
||||
void set_share_data(bool value);
|
||||
bool get_share_data();
|
||||
|
||||
/* Input-Output */
|
||||
virtual void load_from_disk(const convertible_string &archive_path);
|
||||
virtual void create(const convertible_string &archiveName, const bs_archive_entries &entries);
|
||||
virtual void create(const convertible_string &archiveName,
|
||||
const bs_archive_entries &entries,
|
||||
const bsa_archive_type_t type);
|
||||
void save() const;
|
||||
|
||||
/* Add to archive */
|
||||
virtual void add_file_from_disk(const disk_blob &blob);
|
||||
virtual void add_file_from_memory(const convertible_string &path_in_archive, const memory_blob &memory_data);
|
||||
|
||||
/* Extract */
|
||||
memory_blob extract_to_memory(bsa_file_record_t record);
|
||||
memory_blob extract_to_memory(const convertible_string &filename);
|
||||
void extract_to_disk(const convertible_string &filename, const convertible_string &save_as) const;
|
||||
|
||||
/* Selectors */
|
||||
bsa_file_record_t find_file_record(const convertible_string &filename);
|
||||
std::vector<convertible_string> list_files() const;
|
||||
|
||||
/* Other */
|
||||
|
||||
/*! \brief Sets the DDS callback. It is required to use Fallout 4 DDS archives. You do not have
|
||||
* to manage the lifetime of the provided context
|
||||
* \example
|
||||
void dds_callback([[maybe_unused]] bsa_archive_t archive,
|
||||
const wchar_t *file_path,
|
||||
bsa_dds_info_t *dds_info,
|
||||
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;
|
||||
}
|
||||
*/
|
||||
template<typename context_type>
|
||||
void set_dds_callback(bsa_file_dds_info_proc_t dds_function, const context_type &context)
|
||||
{
|
||||
debug_log() << "Setting DDS callback for archive: " << archive_ << "\nCallback adress: " << &dds_function;
|
||||
|
||||
auto heap_context = new context_type(context);
|
||||
callback_contexts_.emplace_back(heap_context);
|
||||
bsa_file_dds_info_callback_set(archive_, dds_function, callback_contexts_.back());
|
||||
}
|
||||
|
||||
bsa_archive_t get_archive() const;
|
||||
|
||||
protected:
|
||||
bsa_archive_t archive_;
|
||||
bsa_archive_type_t type_;
|
||||
|
||||
private:
|
||||
std::vector<void *> callback_contexts_;
|
||||
};
|
||||
} // namespace libbsarch
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user