mirror of
https://github.com/ModOrganizer2/libbsarch.git
synced 2026-07-27 14:06:31 -07:00
Compare commits
5
Commits
0.0.7
...
reorganize
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6dbe006156 | ||
|
|
f8327f3112 | ||
|
|
9e984fd268 | ||
|
|
f7e1090612 | ||
|
|
77a6be7bcb |
+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
|
||||
...
|
||||
+133
-47
@@ -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,72 @@ __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-*
|
||||
|
||||
# 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 +224,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 +251,7 @@ StyleCopReport.xml
|
||||
*_h.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.iobj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.ipdb
|
||||
*.pgc
|
||||
@@ -284,6 +366,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 +404,7 @@ _pkginfo.txt
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
@@ -358,7 +443,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,7 +528,6 @@ 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
|
||||
|
||||
libbsarch_delphi*
|
||||
libbsarch_test.pas
|
||||
**/build
|
||||
|
||||
@@ -9,9 +9,15 @@ 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.
|
||||
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,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,185 @@
|
||||
#include "bs_archive.h"
|
||||
|
||||
namespace libbsarch {
|
||||
|
||||
bs_archive::bs_archive()
|
||||
: archive_(bsa_create())
|
||||
{}
|
||||
|
||||
bs_archive::bs_archive(const bsa_archive_type_t &type)
|
||||
: archive_(bsa_create())
|
||||
, type_(type)
|
||||
{}
|
||||
|
||||
bs_archive::~bs_archive()
|
||||
{
|
||||
bsa_close(archive_);
|
||||
bsa_free(archive_);
|
||||
}
|
||||
|
||||
/* Properties */
|
||||
convertible_string bs_archive::get_filename()
|
||||
{
|
||||
wchar_t name[max_string_buffer_size];
|
||||
bsa_filename_get(archive_, max_string_buffer_size, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
bsa_archive_type_t bs_archive::get_type()
|
||||
{
|
||||
return bsa_archive_type_get(archive_);
|
||||
}
|
||||
|
||||
uint32_t bs_archive::get_version()
|
||||
{
|
||||
return bsa_version_get(archive_);
|
||||
}
|
||||
|
||||
convertible_string bs_archive::get_format_name()
|
||||
{
|
||||
wchar_t format_name[max_string_buffer_size];
|
||||
bsa_format_name_get(archive_, max_string_buffer_size, format_name);
|
||||
return format_name;
|
||||
}
|
||||
|
||||
uint32_t bs_archive::get_file_count()
|
||||
{
|
||||
return bsa_file_count_get(archive_);
|
||||
}
|
||||
|
||||
uint32_t bs_archive::get_archive_flags()
|
||||
{
|
||||
return bsa_archive_flags_get(archive_);
|
||||
}
|
||||
|
||||
void bs_archive::set_archive_flags(uint32_t flags)
|
||||
{
|
||||
bsa_archive_flags_set(archive_, flags);
|
||||
}
|
||||
|
||||
uint32_t bs_archive::get_file_flags()
|
||||
{
|
||||
return bsa_file_flags_get(archive_);
|
||||
}
|
||||
|
||||
void bs_archive::set_file_flags(uint32_t flags)
|
||||
{
|
||||
bsa_file_flags_set(archive_, flags);
|
||||
}
|
||||
|
||||
void bs_archive::set_compressed(bool value)
|
||||
{
|
||||
bsa_compress_set(archive_, value);
|
||||
}
|
||||
|
||||
void bs_archive::set_share_data(bool value)
|
||||
{
|
||||
bsa_share_data_set(archive_, value);
|
||||
}
|
||||
|
||||
bool bs_archive::get_compressed()
|
||||
{
|
||||
return bsa_compress_get(archive_);
|
||||
}
|
||||
|
||||
bool bs_archive::get_share_data()
|
||||
{
|
||||
return bsa_share_data_get(archive_);
|
||||
}
|
||||
|
||||
void bs_archive::load_from_disk(const convertible_string &archive_path)
|
||||
{
|
||||
debug_log() << "Opening archive: " << archive_path;
|
||||
const std::wstring str = archive_path;
|
||||
const auto &result = bsa_load_from_file(archive_, str.c_str());
|
||||
libbsarch::checkResult(result);
|
||||
}
|
||||
|
||||
void bs_archive::create(const convertible_string &archiveName, const bs_archive_entries &entries)
|
||||
{
|
||||
create(archiveName, entries, type_);
|
||||
}
|
||||
|
||||
void bs_archive::create(const convertible_string &archiveName,
|
||||
const bs_archive_entries &entries,
|
||||
const bsa_archive_type_t type)
|
||||
{
|
||||
debug_log() << "Creating archive. Archive name: " << archiveName << '\n'
|
||||
<< "type: " << type_ << '\n'
|
||||
<< "entries: " << entries.getEntries();
|
||||
bsa_create_archive(archive_, archiveName, type, entries.getEntries());
|
||||
}
|
||||
|
||||
void bs_archive::save() const
|
||||
{
|
||||
debug_log() << "Saving archive: " << archive_;
|
||||
|
||||
const auto &result = bsa_save(archive_);
|
||||
|
||||
libbsarch::checkResult(result);
|
||||
}
|
||||
|
||||
void bs_archive::add_file_from_disk(const disk_blob &blob)
|
||||
{
|
||||
debug_log() << "Adding file from disk root. Path in archive: " << blob.path_in_archive << '\n'
|
||||
<< "Filepath: " << blob.path_on_disk << '\n'
|
||||
<< "Archive: " << archive_;
|
||||
|
||||
const auto &result = bsa_add_file_from_disk(archive_, blob.path_in_archive, blob.path_on_disk);
|
||||
|
||||
libbsarch::checkResult(result);
|
||||
}
|
||||
|
||||
void bs_archive::add_file_from_memory(const convertible_string &path_in_archive,
|
||||
const memory_blob &memory_data) //NOTE UNTESTED
|
||||
{
|
||||
debug_log() << "Adding file from memory. Filename: " << path_in_archive << '\n'
|
||||
<< "Data size: " << memory_data.size;
|
||||
const auto &result = bsa_add_file_from_memory(archive_, path_in_archive, memory_data.size, memory_data.data);
|
||||
libbsarch::checkResult(result);
|
||||
}
|
||||
|
||||
bsa_file_record_t bs_archive::find_file_record(const convertible_string &filename)
|
||||
{
|
||||
debug_log() << "Finding file record of: " << filename;
|
||||
const auto &result = bsa_find_file_record(archive_, filename);
|
||||
return result;
|
||||
}
|
||||
|
||||
memory_blob bs_archive::extract_to_memory(bsa_file_record_t record)
|
||||
{
|
||||
const auto &result = bsa_extract_file_data_by_record(archive_, record);
|
||||
libbsarch::checkResult(result);
|
||||
return memory_blob(result.buffer, archive_);
|
||||
}
|
||||
|
||||
memory_blob bs_archive::extract_to_memory(const convertible_string &filename)
|
||||
{
|
||||
const auto &result = bsa_extract_file_data_by_filename(archive_, filename);
|
||||
libbsarch::checkResult(result);
|
||||
return memory_blob(result.buffer, archive_);
|
||||
}
|
||||
|
||||
void bs_archive::extract_to_disk(const convertible_string &filename, const convertible_string &save_as) const
|
||||
{
|
||||
debug_log() << "Extracting: " << filename << " saved as " << save_as;
|
||||
const auto &result = bsa_extract_file(archive_, filename, save_as);
|
||||
|
||||
libbsarch::checkResult(result);
|
||||
}
|
||||
|
||||
std::vector<convertible_string> bs_archive::list_files() const
|
||||
{
|
||||
bsa_entry_list_t list = bsa_entry_list_create();
|
||||
const auto &result = bsa_get_resource_list(archive_, list, L"");
|
||||
|
||||
libbsarch::checkResult(result);
|
||||
|
||||
return bs_archive_entries(list).list();
|
||||
}
|
||||
|
||||
bsa_archive_t bs_archive::get_archive() const
|
||||
{
|
||||
return archive_;
|
||||
}
|
||||
} // 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
|
||||
@@ -0,0 +1,89 @@
|
||||
/* 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/. */
|
||||
|
||||
#include "bs_archive_auto.hpp"
|
||||
#include <filesystem>
|
||||
namespace libbsarch {
|
||||
bs_archive_auto::bs_archive_auto(const bsa_archive_type_t &type)
|
||||
: bs_archive(type)
|
||||
{}
|
||||
|
||||
void bs_archive_auto::add_file_from_disk(const disk_blob &blob)
|
||||
{
|
||||
files_.emplace_back(blob);
|
||||
}
|
||||
|
||||
void bs_archive_auto::add_file_from_disk(const std::vector<disk_blob> &blobs)
|
||||
{
|
||||
files_.reserve(blobs.size());
|
||||
files_.insert(files_.end(), blobs.cbegin(), blobs.cend());
|
||||
}
|
||||
|
||||
void bs_archive_auto::add_file_from_memory(const convertible_string &path_in_archive, const memory_blob &memory_data)
|
||||
{
|
||||
files_.emplace_back(bs_packed_file(path_in_archive, memory_data));
|
||||
}
|
||||
|
||||
void bs_archive_auto::add_file(const bs_packed_file &file)
|
||||
{
|
||||
files_.emplace_back(file);
|
||||
}
|
||||
|
||||
void bs_archive_auto::extract_all(const convertible_string &directory, bool overwrite_current_files)
|
||||
{
|
||||
namespace fs = std::filesystem;
|
||||
for (const auto &file : list_files())
|
||||
{
|
||||
convertible_string path_string = std::string(directory) + "/" + std::string(file);
|
||||
fs::path current_file(path_string);
|
||||
fs::path current_path = fs::path(current_file).remove_filename();
|
||||
|
||||
fs::create_directories(current_path);
|
||||
if (fs::exists(current_file) && overwrite_current_files)
|
||||
{
|
||||
fs::remove(current_file);
|
||||
extract_to_disk(file, current_file.string());
|
||||
}
|
||||
else if (!fs::exists(current_file))
|
||||
extract_to_disk(file, current_file.string());
|
||||
}
|
||||
}
|
||||
|
||||
void bs_archive_auto::load_from_disk(const convertible_string &archive_path)
|
||||
{
|
||||
bs_archive::load_from_disk(archive_path);
|
||||
for (const auto &file : list_files())
|
||||
entries_.add(file);
|
||||
}
|
||||
|
||||
void bs_archive_auto::save_to_disk(const convertible_string &archive_path)
|
||||
{
|
||||
for (const auto &file : files_)
|
||||
entries_.add(file.path_in_archive);
|
||||
|
||||
bs_archive::create(archive_path, entries_);
|
||||
|
||||
for (const auto &file : files_)
|
||||
{
|
||||
switch (file.data.index())
|
||||
{
|
||||
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:
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
bs_archive::save();
|
||||
}
|
||||
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,39 @@
|
||||
/* 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 "bs_archive.h"
|
||||
|
||||
namespace libbsarch {
|
||||
/*!
|
||||
* \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
|
||||
*/
|
||||
class bs_archive_auto : public bs_archive
|
||||
{
|
||||
protected:
|
||||
bs_archive_entries entries_;
|
||||
|
||||
public:
|
||||
bs_archive_auto() = default;
|
||||
bs_archive_auto(const bsa_archive_type_t &type);
|
||||
|
||||
void add_file_from_disk(const disk_blob &blob) override;
|
||||
void add_file_from_disk(const std::vector<disk_blob> &blobs);
|
||||
void add_file_from_memory(const convertible_string &path_in_archive, const memory_blob &memory_data) override;
|
||||
void add_file(const bs_packed_file &file);
|
||||
|
||||
void extract_all(const convertible_string &directory, bool overwrite_current_files);
|
||||
|
||||
void load_from_disk(const convertible_string &archive_path) override;
|
||||
void save_to_disk(const convertible_string &archive_path);
|
||||
|
||||
private:
|
||||
using bs_archive::create; //Use save_to_disk instead
|
||||
using bs_archive::save; //Use save_to_disk instead
|
||||
std::vector<bs_packed_file> files_;
|
||||
};
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "bs_archive_entries.h"
|
||||
|
||||
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())
|
||||
{
|
||||
for (const auto &entry : entries)
|
||||
add(entry);
|
||||
}
|
||||
|
||||
bs_archive_entries::bs_archive_entries(const bsa_entry_list_t &entries)
|
||||
: _entries(entries)
|
||||
{
|
||||
}
|
||||
|
||||
bs_archive_entries::~bs_archive_entries()
|
||||
{
|
||||
bsa_entry_list_free(_entries);
|
||||
}
|
||||
|
||||
void bs_archive_entries::add(const convertible_string &filepath)
|
||||
{
|
||||
debug_log() << "Adding to entries: " << filepath;
|
||||
const auto &result = bsa_entry_list_add(_entries, filepath);
|
||||
libbsarch::checkResult(result);
|
||||
}
|
||||
|
||||
uint32_t bs_archive_entries::count()
|
||||
{
|
||||
return bsa_entry_list_count(_entries);
|
||||
}
|
||||
|
||||
std::vector<convertible_string> bs_archive_entries::list()
|
||||
{
|
||||
std::vector<convertible_string> list;
|
||||
for (uint32_t i = 0; i < count(); ++i)
|
||||
{
|
||||
wchar_t buffer[max_string_buffer_size];
|
||||
bsa_entry_list_get(_entries, i, max_string_buffer_size, buffer);
|
||||
list.push_back(buffer);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
bsa_entry_list_t bs_archive_entries::getEntries() const
|
||||
{
|
||||
return _entries;
|
||||
}
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "libbsarch.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace libbsarch {
|
||||
class bs_archive_entries
|
||||
{
|
||||
public:
|
||||
bs_archive_entries();
|
||||
explicit bs_archive_entries(const std::vector<convertible_string> &entries);
|
||||
explicit bs_archive_entries(const bsa_entry_list_t &entries);
|
||||
~bs_archive_entries();
|
||||
|
||||
void add(const convertible_string &filepath);
|
||||
uint32_t count();
|
||||
std::vector<convertible_string> list();
|
||||
|
||||
bsa_entry_list_t getEntries() const;
|
||||
|
||||
protected:
|
||||
bsa_entry_list_t _entries;
|
||||
};
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "base_types.hpp"
|
||||
#include "utils/convertible_ostream.hpp"
|
||||
#include "utils/convertible_string.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
constexpr bool enable_debug_log = true;
|
||||
[[maybe_unused]] constexpr int max_string_buffer_size = 1024;
|
||||
|
||||
inline convertible_ostream &debug_log()
|
||||
{
|
||||
static convertible_ostream ostr;
|
||||
if constexpr (enable_debug_log)
|
||||
return ostr << "[libbsarch] " << __FUNCTION__ << ' ';
|
||||
}
|
||||
|
||||
inline void checkResult(const bsa_result_message_s &result)
|
||||
{
|
||||
if (result.code == BSA_RESULT_EXCEPTION)
|
||||
{
|
||||
const std::string &error = to_string(result.text);
|
||||
debug_log() << error;
|
||||
throw std::runtime_error(error);
|
||||
}
|
||||
}
|
||||
|
||||
inline void checkResult(const bsa_result_message_buffer_s &result)
|
||||
{
|
||||
checkResult(result.message);
|
||||
}
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,58 @@
|
||||
/* 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/. */
|
||||
#include "convertible_ostream.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
convertible_ostream &convertible_ostream::operator<<(const std::string &rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const char *rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const char rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const std::wstring &rh)
|
||||
{
|
||||
std::wcout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const void *rh)
|
||||
{
|
||||
std::cout << rh;
|
||||
return *this;
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const convertible_string &rh)
|
||||
{
|
||||
return *this << std::string(rh);
|
||||
}
|
||||
|
||||
convertible_ostream::operator std::ostream &()
|
||||
{
|
||||
return std::cout;
|
||||
}
|
||||
convertible_ostream::operator std::wostream &()
|
||||
{
|
||||
return std::wcout;
|
||||
}
|
||||
|
||||
#ifdef QT
|
||||
convertible_ostream::operator QDebug()
|
||||
{
|
||||
return qDebug();
|
||||
}
|
||||
convertible_ostream &convertible_ostream::operator<<(const QString &rh)
|
||||
{
|
||||
qDebug() << rh;
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,37 @@
|
||||
/* 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 "convertible_string.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace libbsarch {
|
||||
class convertible_ostream
|
||||
{
|
||||
public:
|
||||
convertible_ostream &operator<<(const std::string &rh);
|
||||
convertible_ostream &operator<<(const char *rh);
|
||||
convertible_ostream &operator<<(const char rh);
|
||||
convertible_ostream &operator<<(const std::wstring &rh);
|
||||
convertible_ostream &operator<<(const void *rh);
|
||||
convertible_ostream &operator<<(const convertible_string &rh);
|
||||
|
||||
template<typename number, //real type
|
||||
typename = typename std::enable_if<std::is_arithmetic<number>::value, number>::type>
|
||||
convertible_ostream &operator<<(const number &num)
|
||||
{
|
||||
std::cout << num;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator std::ostream &();
|
||||
operator std::wostream &();
|
||||
|
||||
#ifdef QT
|
||||
operator QDebug();
|
||||
convertible_ostream &operator<<(const QString &rh);
|
||||
#endif
|
||||
};
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,128 @@
|
||||
/* 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/. */
|
||||
|
||||
#include "convertible_string.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace libbsarch {
|
||||
/* conversion ctors */
|
||||
convertible_string::convertible_string(std::string value, bool to_native_path)
|
||||
: str_(std::move(value))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
|
||||
convertible_string::convertible_string(const char *const val_array, bool to_native_path)
|
||||
: str_(std::string(val_array))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
convertible_string::convertible_string(const std::wstring &wvalue, bool to_native_path)
|
||||
: str_(to_string(wvalue))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
convertible_string::convertible_string(wchar_t const *wval_array, bool to_native_path)
|
||||
: str_(to_string(std::wstring(wval_array)))
|
||||
, auto_convert_to_native_path(to_native_path)
|
||||
{
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
}
|
||||
|
||||
#ifdef QT
|
||||
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();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* assignment operators */
|
||||
convertible_string &convertible_string::operator=(const std::string &value)
|
||||
{
|
||||
str_ = value;
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
convertible_string &convertible_string::operator=(const std::wstring &wvalue)
|
||||
{
|
||||
str_ = to_string(wvalue);
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
|
||||
convertible_string &convertible_string::operator=(const wchar_t *wvalue)
|
||||
{
|
||||
str_ = to_string(std::wstring(wvalue));
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef QT
|
||||
convertible_string &convertible_string::operator=(const QString &qsvalue)
|
||||
{
|
||||
str_ = to_string(qsvalue);
|
||||
if (auto_convert_to_native_path)
|
||||
this->to_native_path();
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* implicit conversion operators */
|
||||
convertible_string::operator std::string() const
|
||||
{
|
||||
return str_;
|
||||
}
|
||||
convertible_string::operator std::wstring() const
|
||||
{
|
||||
return to_wstring(str_);
|
||||
}
|
||||
convertible_string::operator const wchar_t *() const
|
||||
{
|
||||
const std::wstring wstr = to_wstring(str_);
|
||||
wchar_t *wchar_array = new wchar_t[wstr.length() + 1];
|
||||
wcscpy_s(wchar_array, wstr.length() + 1, wstr.c_str());
|
||||
return wchar_array;
|
||||
}
|
||||
#ifdef QT
|
||||
convertible_string::operator QString() const
|
||||
{
|
||||
return to_qstring(str_);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Util */
|
||||
bool convertible_string::remove_substring(const convertible_string &sub_str)
|
||||
{
|
||||
size_t pos = str_.find(sub_str);
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
str_.erase(pos, std::string(sub_str).length());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
convertible_string &convertible_string::to_native_path()
|
||||
{
|
||||
std::filesystem::path path(str_);
|
||||
str_ = path.make_preferred().string();
|
||||
return *this;
|
||||
}
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,54 @@
|
||||
/* 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
|
||||
|
||||
//See https://stackoverflow.com/questions/4804298/how-to-convert-wstring-into-string
|
||||
|
||||
#include "string_convert.hpp"
|
||||
#ifdef QT
|
||||
#include <QString>
|
||||
#endif
|
||||
|
||||
namespace libbsarch {
|
||||
class convertible_string
|
||||
{
|
||||
public:
|
||||
// default ctor
|
||||
convertible_string() = default;
|
||||
|
||||
/* conversion ctors */
|
||||
convertible_string(std::string value, bool to_native_path = true);
|
||||
convertible_string(const char *const val_array, bool to_native_path = true);
|
||||
convertible_string(const std::wstring &wvalue, bool to_native_path = true);
|
||||
convertible_string(const wchar_t *const wval_array, bool to_native_path = true);
|
||||
#ifdef QT
|
||||
convertible_string(const QString &qsvalue, bool to_native_path = true);
|
||||
#endif
|
||||
|
||||
/* assignment operators */
|
||||
convertible_string &operator=(const std::string &value);
|
||||
convertible_string &operator=(const std::wstring &wvalue);
|
||||
convertible_string &operator=(const wchar_t *wvalue);
|
||||
#ifdef QT
|
||||
convertible_string &operator=(const QString &qsvalue);
|
||||
#endif
|
||||
|
||||
/* implicit conversion operators */
|
||||
operator std::string() const;
|
||||
operator std::wstring() const;
|
||||
operator const wchar_t *() const;
|
||||
#ifdef QT
|
||||
operator QString() const;
|
||||
#endif
|
||||
|
||||
/* Util */
|
||||
bool remove_substring(const convertible_string &sub_str);
|
||||
convertible_string &to_native_path();
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
bool auto_convert_to_native_path = true;
|
||||
};
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,49 @@
|
||||
/* 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/. */
|
||||
#include "string_convert.hpp"
|
||||
|
||||
namespace libbsarch {
|
||||
#ifdef QT
|
||||
std::wstring to_wstring(const QString &str)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
return std::wstring(reinterpret_cast<const wchar_t *>(str.utf16()));
|
||||
#else
|
||||
return str.toStdWString();
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string to_string(const QString &str)
|
||||
{
|
||||
return str.toStdString();
|
||||
}
|
||||
|
||||
QString to_qstring(const std::string &str)
|
||||
{
|
||||
return QString::fromStdString(str);
|
||||
}
|
||||
|
||||
QString to_qstring(const std::wstring &str)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
return QString::fromUtf16(reinterpret_cast<const ushort *>(str.c_str()));
|
||||
#else
|
||||
return QString::fromStdWString(str);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> s_converter;
|
||||
std::string to_string(const std::wstring &str)
|
||||
{
|
||||
return s_converter.to_bytes(str);
|
||||
}
|
||||
|
||||
std::wstring to_wstring(const std::string &str)
|
||||
{
|
||||
auto ws = s_converter.from_bytes(str);
|
||||
return ws;
|
||||
}
|
||||
} // namespace libbsarch
|
||||
@@ -0,0 +1,24 @@
|
||||
/* 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
|
||||
|
||||
#ifdef QT
|
||||
#include <QDebug>
|
||||
#endif
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
namespace libbsarch {
|
||||
#ifdef QT
|
||||
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
|
||||
@@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.17)
|
||||
|
||||
project("libbsarch-c99")
|
||||
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
|
||||
add_subdirectory(../delphi .)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} INTERFACE .)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} INTERFACE "libbsarch-delphi")
|
||||
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
|
||||
include(CPack)
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// 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
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user