mirror of
https://github.com/ModOrganizer2/libbsarch.git
synced 2026-07-27 14:06:31 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2398ca5df9 | ||
|
|
9444e7e108 | ||
|
|
d9c01eac14 | ||
|
|
4efa6ab6d8 | ||
|
|
736a69ccab | ||
|
|
e16bca653f | ||
|
|
d7cf9d9761 | ||
|
|
0dfbae29f0 |
+3
-3
@@ -19,7 +19,7 @@ AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BraceWrapping:
|
||||
BraceWrapping:
|
||||
AfterClass: true
|
||||
AfterControlStatement: true
|
||||
AfterEnum: true
|
||||
@@ -55,13 +55,13 @@ DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
ForEachMacros:
|
||||
- forever
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
IncludeCategories:
|
||||
- Regex: '^<Q.*'
|
||||
Priority: 200
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Explicitly declare text files you want to always be normalized and converted
|
||||
# to native line endings on checkout.
|
||||
*.cpp text eol=crlf
|
||||
*.h text eol=crlf
|
||||
@@ -0,0 +1,64 @@
|
||||
name: Build libbsarch
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
tags:
|
||||
- "*"
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
env:
|
||||
VCPKG_BINARY_SOURCES: clear;x-azblob,${{ vars.AZ_BLOB_VCPKG_URL }},${{ secrets.AZ_BLOB_SAS }},readwrite
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: "Set environmental variables"
|
||||
shell: bash
|
||||
run: |
|
||||
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- run: cmake --preset vs2022-windows "-DCMAKE_INSTALL_PREFIX=install"
|
||||
|
||||
# build both Debug and Release for package
|
||||
- name: Build libbsarch
|
||||
run: |
|
||||
cmake --build vsbuild --config Debug --verbose
|
||||
cmake --build vsbuild --config Release --verbose
|
||||
|
||||
- name: Install libbsarch
|
||||
run: |
|
||||
cmake --install vsbuild --config Debug
|
||||
cmake --install vsbuild --config Release
|
||||
|
||||
- name: Upload libbsarch artifact
|
||||
uses: actions/upload-artifact@master
|
||||
with:
|
||||
name: libbsarch
|
||||
path: ./install
|
||||
|
||||
publish:
|
||||
if: github.ref_type == 'tag'
|
||||
needs: build
|
||||
runs-on: windows-2022
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Download Artifact
|
||||
uses: actions/download-artifact@master
|
||||
with:
|
||||
name: libbsarch
|
||||
path: ./install
|
||||
|
||||
- name: Create libbsarch archive
|
||||
run: 7z a libbsarch_${{ github.ref_name }}.7z ./install/*
|
||||
|
||||
- name: Publish Release
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
GH_REPO: ${{ github.repository }}
|
||||
run: gh release create --draft=false --notes="${{ github.ref_name }}" "${{ github.ref_name }}" ./libbsarch_${{ github.ref_name }}.7z
|
||||
@@ -0,0 +1,17 @@
|
||||
name: Lint libbsarch
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Check format
|
||||
uses: ModOrganizer2/check-formatting-action@master
|
||||
with:
|
||||
check-path: "."
|
||||
exclude-regex: "third-party"
|
||||
@@ -49,6 +49,7 @@ compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
*-prefix/
|
||||
@@ -530,3 +531,9 @@ healthchecksdb
|
||||
MigrationBackup/
|
||||
|
||||
# End of https://www.gitignore.io/api/qt,c++,cmake,delphi,qtcreator,visualstudio
|
||||
|
||||
install
|
||||
examples/build
|
||||
examples/vsbuild
|
||||
examples/test_ba1
|
||||
examples/test_ba2
|
||||
|
||||
@@ -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
|
||||
+7
-10
@@ -5,7 +5,6 @@ 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)
|
||||
|
||||
@@ -74,14 +73,6 @@ 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
|
||||
@@ -116,9 +107,15 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.cmake.in
|
||||
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||
)
|
||||
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/Version.cmake)
|
||||
set(LIBBSARCH_VERSION
|
||||
${LIBBSARCH_MAJOR_VERSION}.${LIBBSARCH_MINOR_VERSION}.${LIBBSARCH_PATCH_VERSION})
|
||||
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/mo2-libbsarch-config-version.cmake"
|
||||
VERSION "0.0.13"
|
||||
VERSION "${LIBBSARCH_VERSION}"
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
ARCH_INDEPENDENT
|
||||
)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
set(LIBBSARCH_MAJOR_VERSION 0)
|
||||
set(LIBBSARCH_MINOR_VERSION 1)
|
||||
set(LIBBSARCH_PATCH_VERSION 2)
|
||||
+14
-1
@@ -2,10 +2,11 @@
|
||||
|
||||
include ( "${CMAKE_CURRENT_LIST_DIR}/mo2-libbsarch-targets.cmake" )
|
||||
|
||||
target_link_libraries(mo2::libbsarch PUBLIC mo2::libbsarch_OOP)
|
||||
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
|
||||
@@ -14,6 +15,12 @@ if (_LIBBSARCH_HAS_RELEASE EQUAL -1)
|
||||
)
|
||||
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
|
||||
@@ -21,4 +28,10 @@ else()
|
||||
)
|
||||
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()
|
||||
|
||||
@@ -20,7 +20,7 @@ type
|
||||
TwbBSResultMessageBuffer = packed record
|
||||
buffer: TwbBSResultBuffer;
|
||||
message: TwbBSResultMessage;
|
||||
end;
|
||||
end;
|
||||
|
||||
{Shared}
|
||||
|
||||
|
||||
@@ -1,146 +1,162 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
#include "libbsarch.h"
|
||||
#include <libbsarch/libbsarch.h>
|
||||
|
||||
#pragma comment(lib, "libbsarch")
|
||||
// #pragma comment(lib, "libbsarch")
|
||||
|
||||
static const std::wstring separators(L"\\/");
|
||||
|
||||
std::wstring dirname(const std::wstring& path) {
|
||||
size_t slash_pos = path.find_last_of(separators);
|
||||
return path.substr(0, slash_pos);
|
||||
std::wstring dirname(const std::wstring &path)
|
||||
{
|
||||
size_t slash_pos = path.find_last_of(separators);
|
||||
return path.substr(0, slash_pos);
|
||||
}
|
||||
|
||||
std::wstring basename(const std::wstring& path) {
|
||||
size_t slash_pos = path.find_last_of(separators);
|
||||
return path.substr(slash_pos + 1);
|
||||
std::wstring basename(const std::wstring &path)
|
||||
{
|
||||
size_t slash_pos = path.find_last_of(separators);
|
||||
return path.substr(slash_pos + 1);
|
||||
}
|
||||
|
||||
bool mkdirp(const std::wstring& directory, bool basedir = true) {
|
||||
DWORD attributes = ::GetFileAttributesW(directory.c_str());
|
||||
if(attributes == INVALID_FILE_ATTRIBUTES) {
|
||||
std::size_t slash_pos = directory.find_last_of(separators);
|
||||
if(slash_pos != std::wstring::npos) {
|
||||
mkdirp(directory.substr(0, slash_pos));
|
||||
bool mkdirp(const std::wstring &directory, bool basedir = true)
|
||||
{
|
||||
DWORD attributes = ::GetFileAttributesW(directory.c_str());
|
||||
if (attributes == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
std::size_t slash_pos = directory.find_last_of(separators);
|
||||
if (slash_pos != std::wstring::npos)
|
||||
{
|
||||
mkdirp(directory.substr(0, slash_pos));
|
||||
}
|
||||
return ::CreateDirectoryW(directory.c_str(), nullptr);
|
||||
}
|
||||
return ::CreateDirectoryW(directory.c_str(), nullptr);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void dds_info(bsa_archive_t archive, const wchar_t* file_path, bsa_dds_info_t* dds_info, void* context) {
|
||||
// Mock result
|
||||
dds_info->width = 2048;
|
||||
dds_info->height = 2048;
|
||||
dds_info->mipmaps = 12;
|
||||
|
||||
printf("ba2 dds_info callback file: %ls, context: %s\n", file_path, (char*)context);
|
||||
}
|
||||
|
||||
int main() {
|
||||
bsa_result_message_t result = { 0 };
|
||||
bsa_archive_t archive = bsa_create();
|
||||
|
||||
{
|
||||
result = bsa_load_from_file(archive, L"test_read.bsa");
|
||||
if(result.code < 0)
|
||||
printf("ba1 %ls\n", result.text);
|
||||
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_get_resource_list(archive, entries, L"");
|
||||
|
||||
for(size_t index = 0; index < bsa_entry_list_count(entries); index++) {
|
||||
wchar_t filename[2048];
|
||||
wchar_t dest_filename[2048] = L"test_ba1\\";
|
||||
|
||||
bsa_entry_list_get(entries, index, 2048, filename);
|
||||
wcscat_s(dest_filename, 2048, filename);
|
||||
|
||||
printf("ba1 file: %ls %ls\n", filename, dest_filename);
|
||||
|
||||
if(mkdirp(dirname(dest_filename))) {
|
||||
result = bsa_extract_file(archive, filename, dest_filename);
|
||||
if(result.code < 0)
|
||||
printf("ba1 %ls\n", result.text);
|
||||
} else {
|
||||
printf("ba1 could not create: %ls\n", dirname(dest_filename).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bsa_entry_list_free(entries);
|
||||
void dds_info(bsa_archive_t archive, const wchar_t *file_path, bsa_dds_info_t *dds_info, void *context)
|
||||
{
|
||||
// Mock result
|
||||
dds_info->width = 2048;
|
||||
dds_info->height = 2048;
|
||||
dds_info->mipmaps = 12;
|
||||
|
||||
bsa_close(archive);
|
||||
}
|
||||
printf("ba2 dds_info callback file: %ls, context: %s\n", file_path, (char *) context);
|
||||
}
|
||||
|
||||
{
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test.dds");
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test2.dds");
|
||||
int main()
|
||||
{
|
||||
bsa_result_message_t result = {0};
|
||||
bsa_archive_t archive = bsa_create();
|
||||
|
||||
bsa_create_archive(archive, L"test_write.bsa", baSSE, entries);
|
||||
bsa_add_file_from_disk_root(archive, L"test_ba1\\", L"test_ba1\\textures\\grass\\test.dds");
|
||||
result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba1\\textures\\grass\\test.dds");
|
||||
if (result.code < 0)
|
||||
printf("ba1 %ls\n", result.text);
|
||||
bsa_save(archive);
|
||||
bsa_close(archive);
|
||||
|
||||
bsa_entry_list_free(entries);
|
||||
}
|
||||
|
||||
bsa_file_dds_info_callback_set(archive, dds_info, (void*)"I was shared");
|
||||
|
||||
{
|
||||
result = bsa_load_from_file(archive, L"test_read.ba2");
|
||||
if (result.code < 0)
|
||||
printf("ba2 %ls\n", result.text);
|
||||
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_get_resource_list(archive, entries, L"");
|
||||
|
||||
for (size_t index = 0; index < bsa_entry_list_count(entries); index++) {
|
||||
wchar_t filename[2048];
|
||||
wchar_t dest_filename[2048] = L"test_ba2\\";
|
||||
|
||||
bsa_entry_list_get(entries, index, 2048, filename);
|
||||
wcscat_s(dest_filename, 2048, filename);
|
||||
|
||||
printf("ba2 file: %ls %ls\n", filename, dest_filename);
|
||||
|
||||
if (mkdirp(dirname(dest_filename))) {
|
||||
result = bsa_extract_file(archive, filename, dest_filename);
|
||||
{
|
||||
result = bsa_load_from_file(archive, L"test_read.bsa");
|
||||
if (result.code < 0)
|
||||
printf("ba2 %ls\n", result.text);
|
||||
}
|
||||
else {
|
||||
printf("ba2 could not create: %ls\n", dirname(dest_filename).c_str());
|
||||
}
|
||||
printf("ba1 %ls\n", result.text);
|
||||
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_get_resource_list(archive, entries, L"");
|
||||
|
||||
for (size_t index = 0; index < bsa_entry_list_count(entries); index++)
|
||||
{
|
||||
wchar_t filename[2048];
|
||||
wchar_t dest_filename[2048] = L"test_ba1\\";
|
||||
|
||||
bsa_entry_list_get(entries, index, 2048, filename);
|
||||
wcscat_s(dest_filename, 2048, filename);
|
||||
|
||||
printf("ba1 file: %ls %ls\n", filename, dest_filename);
|
||||
|
||||
if (mkdirp(dirname(dest_filename)))
|
||||
{
|
||||
result = bsa_extract_file(archive, filename, dest_filename);
|
||||
if (result.code < 0)
|
||||
printf("ba1 %ls\n", result.text);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ba1 could not create: %ls\n", dirname(dest_filename).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bsa_entry_list_free(entries);
|
||||
|
||||
bsa_close(archive);
|
||||
}
|
||||
|
||||
bsa_entry_list_free(entries);
|
||||
{
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test.dds");
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test2.dds");
|
||||
|
||||
bsa_close(archive);
|
||||
}
|
||||
bsa_create_archive(archive, L"test_write.bsa", baSSE, entries);
|
||||
bsa_add_file_from_disk_root(archive, L"test_ba1\\", L"test_ba1\\textures\\grass\\test.dds");
|
||||
result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba1\\textures\\grass\\test.dds");
|
||||
if (result.code < 0)
|
||||
printf("ba1 %ls\n", result.text);
|
||||
bsa_save(archive);
|
||||
bsa_close(archive);
|
||||
|
||||
{
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test.dds");
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test2.dds");
|
||||
bsa_entry_list_free(entries);
|
||||
}
|
||||
|
||||
bsa_create_archive(archive, L"test_write.ba2", baFO4dds, entries);
|
||||
bsa_add_file_from_disk_root(archive, L"test_ba2\\", L"test_ba2\\textures\\grass\\test.dds");
|
||||
result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba2\\textures\\grass\\test.dds");
|
||||
if (result.code < 0)
|
||||
printf("ba2 %ls\n", result.text);
|
||||
bsa_save(archive);
|
||||
bsa_close(archive);
|
||||
bsa_file_dds_info_callback_set(archive, dds_info, (void *) "I was shared");
|
||||
|
||||
bsa_entry_list_free(entries);
|
||||
}
|
||||
{
|
||||
result = bsa_load_from_file(archive, L"test_read.ba2");
|
||||
if (result.code < 0)
|
||||
printf("ba2 %ls\n", result.text);
|
||||
|
||||
/*
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_get_resource_list(archive, entries, L"");
|
||||
|
||||
for (size_t index = 0; index < bsa_entry_list_count(entries); index++)
|
||||
{
|
||||
wchar_t filename[2048];
|
||||
wchar_t dest_filename[2048] = L"test_ba2\\";
|
||||
|
||||
bsa_entry_list_get(entries, index, 2048, filename);
|
||||
wcscat_s(dest_filename, 2048, filename);
|
||||
|
||||
printf("ba2 file: %ls %ls\n", filename, dest_filename);
|
||||
|
||||
if (mkdirp(dirname(dest_filename)))
|
||||
{
|
||||
result = bsa_extract_file(archive, filename, dest_filename);
|
||||
if (result.code < 0)
|
||||
printf("ba2 %ls\n", result.text);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ba2 could not create: %ls\n", dirname(dest_filename).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bsa_entry_list_free(entries);
|
||||
|
||||
bsa_close(archive);
|
||||
}
|
||||
|
||||
{
|
||||
bsa_entry_list_t entries = bsa_entry_list_create();
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test.dds");
|
||||
bsa_entry_list_add(entries, L"textures\\grass\\test2.dds");
|
||||
|
||||
bsa_create_archive(archive, L"test_write.ba2", baFO4dds, entries);
|
||||
bsa_add_file_from_disk_root(archive, L"test_ba2\\", L"test_ba2\\textures\\grass\\test.dds");
|
||||
result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"test_ba2\\textures\\grass\\test.dds");
|
||||
if (result.code < 0)
|
||||
printf("ba2 %ls\n", result.text);
|
||||
bsa_save(archive);
|
||||
bsa_close(archive);
|
||||
|
||||
bsa_entry_list_free(entries);
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
result = bsa_load_from_file(archive, L"test_large.ba2");
|
||||
if (result.code < 0)
|
||||
@@ -170,5 +186,5 @@ int main() {
|
||||
}
|
||||
*/
|
||||
|
||||
bsa_free(archive);
|
||||
bsa_free(archive);
|
||||
}
|
||||
|
||||
@@ -62,17 +62,17 @@ public:
|
||||
void *context)
|
||||
{
|
||||
const auto &path = *static_cast<convertible_string *>(context) + '/' + convertible_string(file_path);
|
||||
|
||||
|
||||
auto image = std::make_unique<DirectX::ScratchImage>();
|
||||
DirectX::TexMetadata info;
|
||||
|
||||
|
||||
const auto hr = LoadFromDDSFile(PREPARE_PATH_LIBBSARCH(path), DirectX::DDS_FLAGS_BAD_DXTN_TAILS, &info, *image);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
//Do not throw here. Exceptions will be ignored
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
dds_info->width = info.width;
|
||||
dds_info->height = info.height;
|
||||
dds_info->mipmaps = info.mipLevels;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace libbsarch {
|
||||
/*!
|
||||
* \brief The bs_archive_auto class is a convenience class. It manages both bs_archive and bs_archive_entries.
|
||||
* \brief The bs_archive_auto class is a convenience class. It manages both bs_archive and bs_archive_entries.
|
||||
* It is recommended when packing from disk/extracting to disk
|
||||
* Otherwise, if using memory, the use of these two separate classes is recommended
|
||||
*/
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
#include "string_convert.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
|
||||
template<typename String>
|
||||
class convertible_string_converter;
|
||||
|
||||
class convertible_string
|
||||
{
|
||||
public:
|
||||
@@ -35,12 +39,6 @@ public:
|
||||
operator std::wstring() const;
|
||||
operator const wchar_t *() const;
|
||||
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
convertible_string(const QString &qsvalue, bool to_native_path = true);
|
||||
convertible_string &operator=(const QString &qsvalue);
|
||||
operator QString() const;
|
||||
#endif
|
||||
|
||||
/* Util */
|
||||
bool remove_substring(const convertible_string &sub_str);
|
||||
convertible_string &to_native_path();
|
||||
|
||||
@@ -13,13 +13,6 @@
|
||||
#include <string>
|
||||
|
||||
namespace libbsarch {
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
std::wstring to_wstring(const QString &str);
|
||||
std::string to_string(const QString &str);
|
||||
QString to_qstring(const std::string &str);
|
||||
QString to_qstring(const std::wstring &str);
|
||||
#endif
|
||||
|
||||
std::string to_string(const std::wstring &str);
|
||||
std::wstring to_wstring(const std::string &str);
|
||||
} // namespace libbsarch
|
||||
|
||||
@@ -69,14 +69,12 @@ void bs_archive_auto::save_to_disk(const convertible_string &archive_path)
|
||||
{
|
||||
switch (file.data.index())
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
case 0: {
|
||||
const auto &blob = std::get<memory_blob>(file.data);
|
||||
bs_archive::add_file_from_memory(file.path_in_archive, blob);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
case 1: {
|
||||
const auto &file_path = std::get<convertible_string>(file.data);
|
||||
const auto &blob = disk_blob(file.path_in_archive, file_path, bool());
|
||||
bs_archive::add_file_from_disk(blob);
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
namespace libbsarch {
|
||||
bs_archive_entries::bs_archive_entries()
|
||||
: _entries(bsa_entry_list_create())
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bs_archive_entries::bs_archive_entries(const std::vector<convertible_string> &entries)
|
||||
: _entries(bsa_entry_list_create())
|
||||
@@ -15,8 +14,7 @@ bs_archive_entries::bs_archive_entries(const std::vector<convertible_string> &en
|
||||
|
||||
bs_archive_entries::bs_archive_entries(const bsa_entry_list_t &entries)
|
||||
: _entries(entries)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
bs_archive_entries::~bs_archive_entries()
|
||||
{
|
||||
|
||||
+127
-75
@@ -3,152 +3,204 @@
|
||||
|
||||
namespace libbsarch {
|
||||
|
||||
BSARCH_DLL_API(bsa_entry_list_t) bsa_entry_list_create() {
|
||||
return NULL;
|
||||
BSARCH_DLL_API(bsa_entry_list_t) bsa_entry_list_create()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_entry_list_free(bsa_entry_list_t entry_list) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_entry_list_free(bsa_entry_list_t entry_list)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_entry_list_count(bsa_entry_list_t entry_list) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t) bsa_entry_list_count(bsa_entry_list_t entry_list)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_entry_list_add(bsa_entry_list_t entry_list, const wchar_t *entry_string) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_entry_list_add(bsa_entry_list_t entry_list, const wchar_t *entry_string)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_entry_list_get(bsa_entry_list_t entry_list, uint32_t index, uint32_t string_buffer_size, wchar_t *string_buffer) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t)
|
||||
bsa_entry_list_get(bsa_entry_list_t entry_list, uint32_t index, uint32_t string_buffer_size, wchar_t *string_buffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_archive_t) bsa_create() {
|
||||
return NULL;
|
||||
BSARCH_DLL_API(bsa_archive_t) bsa_create()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_free(bsa_archive_t archive) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_free(bsa_archive_t archive)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_load_from_file(bsa_archive_t archive, const wchar_t *file_path) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_load_from_file(bsa_archive_t archive, const wchar_t *file_path)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_create_archive(bsa_archive_t archive, const wchar_t *file_path, bsa_archive_type_t archive_type, bsa_entry_list_t entry_list) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_create_archive(bsa_archive_t archive,
|
||||
const wchar_t *file_path,
|
||||
bsa_archive_type_t archive_type,
|
||||
bsa_entry_list_t entry_list)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_save(bsa_archive_t archive) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_save(bsa_archive_t archive)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_add_file_from_disk(bsa_archive_t archive, const wchar_t *file_path, const wchar_t *source_path) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_add_file_from_disk(bsa_archive_t archive, const wchar_t *file_path, const wchar_t *source_path)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_add_file_from_disk_root(bsa_archive_t archive, const wchar_t* root_dir, const wchar_t* source_path) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_add_file_from_disk_root(bsa_archive_t archive, const wchar_t *root_dir, const wchar_t *source_path)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_add_file_from_memory(bsa_archive_t archive, const wchar_t *file_path, uint32_t size, bsa_buffer_t data) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_add_file_from_memory(bsa_archive_t archive, const wchar_t *file_path, uint32_t size, bsa_buffer_t data)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_file_record_t) bsa_find_file_record(bsa_archive_t archive, const wchar_t *file_path) {
|
||||
return NULL;
|
||||
BSARCH_DLL_API(bsa_file_record_t) bsa_find_file_record(bsa_archive_t archive, const wchar_t *file_path)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_buffer_t) bsa_extract_file_data_by_record(bsa_archive_t archive, bsa_file_record_t file_record) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_buffer_t)
|
||||
bsa_extract_file_data_by_record(bsa_archive_t archive, bsa_file_record_t file_record)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_buffer_t) bsa_extract_file_data_by_filename(bsa_archive_t archive, const wchar_t *file_path) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_buffer_t)
|
||||
bsa_extract_file_data_by_filename(bsa_archive_t archive, const wchar_t *file_path)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_file_data_free(bsa_archive_t archive, bsa_result_buffer_t file_data_result) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_file_data_free(bsa_archive_t archive, bsa_result_buffer_t file_data_result)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_extract_file(bsa_archive_t archive, const wchar_t *file_path, const wchar_t *save_as) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_extract_file(bsa_archive_t archive, const wchar_t *file_path, const wchar_t *save_as)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_iterate_files(bsa_archive_t archive, bsa_file_iteration_proc_t file_iteration_proc, void *context) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_iterate_files(bsa_archive_t archive, bsa_file_iteration_proc_t file_iteration_proc, void *context)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bool) bsa_file_exists(bsa_archive_t archive, const wchar_t *file_path) {
|
||||
return false;
|
||||
BSARCH_DLL_API(bool) bsa_file_exists(bsa_archive_t archive, const wchar_t *file_path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_get_resource_list(bsa_archive_t archive, bsa_entry_list_t entry_result_list, const wchar_t *folder) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_get_resource_list(bsa_archive_t archive, bsa_entry_list_t entry_result_list, const wchar_t *folder)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_resolve_hash(bsa_archive_t archive, uint64_t hash, bsa_entry_list_t entry_result_list) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t)
|
||||
bsa_resolve_hash(bsa_archive_t archive, uint64_t hash, bsa_entry_list_t entry_result_list)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_close(bsa_archive_t archive) {
|
||||
return { 0 };
|
||||
BSARCH_DLL_API(bsa_result_message_t) bsa_close(bsa_archive_t archive)
|
||||
{
|
||||
return {0};
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_filename_get(bsa_archive_t archive, uint32_t string_buffer_size, wchar_t *string_buffer) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t) bsa_filename_get(bsa_archive_t archive, uint32_t string_buffer_size, wchar_t *string_buffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bsa_archive_type_t) bsa_archive_type_get(bsa_archive_t archive) {
|
||||
return bsa_archive_type_t::baNone;
|
||||
BSARCH_DLL_API(bsa_archive_type_t) bsa_archive_type_get(bsa_archive_t archive)
|
||||
{
|
||||
return bsa_archive_type_t::baNone;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_version_get(bsa_archive_t archive) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t) bsa_version_get(bsa_archive_t archive)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_format_name_get(bsa_archive_t archive, uint32_t string_buffer_size, wchar_t *string_buffer) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t) bsa_format_name_get(bsa_archive_t archive, uint32_t string_buffer_size, wchar_t *string_buffer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_file_count_get(bsa_archive_t archive) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t) bsa_file_count_get(bsa_archive_t archive)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_archive_flags_get(bsa_archive_t archive) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t) bsa_archive_flags_get(bsa_archive_t archive)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(void) bsa_archive_flags_set(bsa_archive_t archive, uint32_t flags) {
|
||||
return;
|
||||
BSARCH_DLL_API(void) bsa_archive_flags_set(bsa_archive_t archive, uint32_t flags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(uint32_t) bsa_file_flags_get(bsa_archive_t archive) {
|
||||
return 0;
|
||||
BSARCH_DLL_API(uint32_t) bsa_file_flags_get(bsa_archive_t archive)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(void) bsa_file_flags_set(bsa_archive_t archive, uint32_t flags) {
|
||||
return;
|
||||
BSARCH_DLL_API(void) bsa_file_flags_set(bsa_archive_t archive, uint32_t flags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bool) bsa_compress_get(bsa_archive_t archive) {
|
||||
return false;
|
||||
BSARCH_DLL_API(bool) bsa_compress_get(bsa_archive_t archive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(void) bsa_compress_set(bsa_archive_t archive, bool flags) {
|
||||
return;
|
||||
BSARCH_DLL_API(void) bsa_compress_set(bsa_archive_t archive, bool flags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(bool) bsa_share_data_get(bsa_archive_t archive) {
|
||||
return false;
|
||||
BSARCH_DLL_API(bool) bsa_share_data_get(bsa_archive_t archive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(void) bsa_share_data_set(bsa_archive_t archive, bool flags) {
|
||||
return;
|
||||
BSARCH_DLL_API(void) bsa_share_data_set(bsa_archive_t archive, bool flags)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BSARCH_DLL_API(void) bsa_file_dds_info_callback_set(bsa_archive_t archive, bsa_file_dds_info_proc_t file_dds_info_proc, void *context) {
|
||||
return;
|
||||
}
|
||||
BSARCH_DLL_API(void)
|
||||
bsa_file_dds_info_callback_set(bsa_archive_t archive, bsa_file_dds_info_proc_t file_dds_info_proc, void *context)
|
||||
{
|
||||
return;
|
||||
}
|
||||
} // namespace libbsarch
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
LIBRARY LIBBSARCH
|
||||
;DESCRIPTION "BSArch DLL"
|
||||
EXPORTS
|
||||
bsa_entry_list_create
|
||||
|
||||
@@ -100,27 +100,4 @@ convertible_string &convertible_string::to_native_path()
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef LIBBSARCH_QT_SUPPORT
|
||||
convertible_string::convertible_string(const QString &qsvalue, bool to_native_path)
|
||||
: str_(to_string(qsvalue))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
|
||||
convertible_string &convertible_string::operator=(const QString &qsvalue)
|
||||
{
|
||||
str_ = to_string(qsvalue);
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
|
||||
convertible_string::operator QString() const
|
||||
{
|
||||
return to_qstring(str_);
|
||||
}
|
||||
#endif
|
||||
|
||||
} // 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