6 Commits
Author SHA1 Message Date
Deorder 0f114677b1 Added context to FO4 DDS info callback 2019-08-28 14:39:10 +02:00
Deorder f276cd1825 DDS Info callback was missing a pointer for returning the info 2019-08-17 00:30:14 +02:00
Deorder c68e39d2a1 Added way to add files from any source path (without using a shared/common root)
bsa_add_file_from_disk is now bsa_add_file_from_disk_root
Fixed issues with using libbsarch with GCC
2019-05-08 23:48:46 +02:00
Deorder d3d36d2694 Fixed issue with releasing file buffer result causing access violation while extracting 2019-05-01 00:17:42 +02:00
Deorder 3855899330 Added exception handling making the dll more reliable 2019-04-17 01:36:22 +02:00
Deorder 6c3a9234e4 Cleaned up test source 2019-04-15 04:26:29 +02:00
10 changed files with 535 additions and 239 deletions
+7
View File
@@ -0,0 +1,7 @@
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define PACKED(datastructure) datastructure __attribute__((__packed__))
#define PACKED(datastructure) __pragma(pack(push, 1)) datastructure __pragma(pack(pop))
#define BSARCH_DLL_API(ReturnType) extern "C" __declspec(dllexport) ReturnType __stdcall
#define BSARCH_DLL_API(ReturnType) extern "C" __declspec(dllimport) ReturnType __stdcall
+67 -13
View File
@@ -1,28 +1,82 @@
#include <iostream>
#include <windows.h>
#include "libbsarch.h"
using namespace std::string_literals;
#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;
}
}
int main() {
bsa_result_message_t result = { 0 };
bsa_archive_t archive = bsa_create();
bsa_load_from_file(archive, L"test_read.bsa");
bsa_close(archive);
{
result = bsa_load_from_file(archive, L"test_read.bsa");
if(result.code < 0)
printf("%ls\n", result.text);
bsa_entry_list_t entries = bsa_entry_list_create();
bsa_entry_list_add(entries, L"textures\\grass\\test.dds");
bsa_entry_list_t entries = bsa_entry_list_create();
bsa_get_resource_list(archive, entries, L"");
bsa_create_archive(archive, L"test_write.bsa", baSSE, entries);
bsa_add_file_from_disk(archive, L"files", L"files\\textures\\grass\\test.dds");
bsa_save(archive);
bsa_close(archive);
for(size_t index = 0; index < bsa_entry_list_count(entries); index++) {
wchar_t filename[2048];
bsa_entry_list_get(entries, index, 2048, filename);
bsa_entry_list_free(entries);
printf("file: %ls\n", filename);
if(mkdirp(dirname(filename))) {
result = bsa_extract_file(archive, filename, filename);
if(result.code < 0)
printf("%ls\n", result.text);
} else {
printf("could not create: %ls\n", dirname(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"", L"textures\\grass\\test.dds");
result = bsa_add_file_from_disk(archive, L"textures\\grass\\test2.dds", L"textures\\grass\\test.dds");
if (result.code < 0)
printf("%ls\n", result.text);
bsa_save(archive);
bsa_close(archive);
bsa_entry_list_free(entries);
}
bsa_free(archive);
printf("test\n");
}
+37 -33
View File
@@ -8,16 +8,16 @@ BSARCH_DLL_API(bsa_entry_list_t) bsa_entry_list_create() {
return NULL;
}
BSARCH_DLL_API(void) bsa_entry_list_free(bsa_entry_list_t entry_list) {
return;
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(void) bsa_entry_list_add(bsa_entry_list_t entry_list, const wchar_t *entry_string) {
return;
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, const wchar_t *string_buffer) {
@@ -28,68 +28,72 @@ BSARCH_DLL_API(bsa_archive_t) bsa_create() {
return NULL;
}
BSARCH_DLL_API(void) bsa_free(bsa_archive_t archive) {
return;
BSARCH_DLL_API(bsa_result_message_t) bsa_free(bsa_archive_t archive) {
return { 0 };
}
BSARCH_DLL_API(void) bsa_load_from_file(bsa_archive_t archive, const wchar_t *filename) {
return;
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(void) bsa_create_archive(bsa_archive_t archive, const wchar_t *filename, bsa_archive_type_t archive_type, bsa_entry_list_t entry_list) {
return;
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(void) bsa_save(bsa_archive_t archive) {
return;
BSARCH_DLL_API(bsa_result_message_t) bsa_save(bsa_archive_t archive) {
return { 0 };
}
BSARCH_DLL_API(void) bsa_add_file_from_disk(bsa_archive_t archive, const wchar_t *root_dir, const wchar_t *filename) {
return;
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(void) bsa_add_file_from_memory(bsa_archive_t archive, const wchar_t *filename, uint32_t size, bsa_file_data_t data) {
return;
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_file_record_t) bsa_find_file_record(bsa_archive_t archive, const wchar_t *filename) {
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_data_result_t) bsa_extract_file_data_by_record(bsa_archive_t archive, bsa_file_record_t file_record) {
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_file_data_result_t) bsa_extract_file_data_by_filename(bsa_archive_t archive, const wchar_t *filename) {
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(void) bsa_file_data_free(bsa_archive_t archive, bsa_file_data_result_t file_data_result) {
return;
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(void) bsa_extract_file(bsa_archive_t archive, const wchar_t *filename, const wchar_t *save_as) {
return;
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(void) bsa_iterate_files(bsa_archive_t archive, bsa_file_iteration_proc_t file_iteration_proc, void *context) {
return;
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 *filename) {
BSARCH_DLL_API(bool) bsa_file_exists(bsa_archive_t archive, const wchar_t *file_path) {
return false;
}
BSARCH_DLL_API(void) bsa_get_resource_list(bsa_archive_t archive, bsa_entry_list_t entry_result_list, const wchar_t *folder) {
return;
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(void) bsa_resolve_hash(bsa_archive_t archive, uint64_t hash, bsa_entry_list_t entry_result_list) {
return;
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(void) bsa_close(bsa_archive_t archive) {
return;
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, const wchar_t *string_buffer) {
@@ -144,6 +148,6 @@ 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) {
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;
}
+1
View File
@@ -12,6 +12,7 @@ EXPORTS
bsa_create_archive
bsa_save
bsa_add_file_from_disk
bsa_add_file_from_disk_root
bsa_add_file_from_memory
bsa_find_file_record
bsa_extract_file_data_by_record
+227 -49
View File
@@ -8,134 +8,310 @@ uses
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): Cardinal; stdcall;
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(Char));
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
Result := TwbBSEntryList.Create;
try
Result := TwbBSEntryList.Create;
except
Result := nil;
end;
end;
procedure bsa_entry_list_free(obj: Pointer); stdcall;
function bsa_entry_list_free(obj: Pointer): TwbBSResultMessage; stdcall;
begin
TwbBSEntryList(obj).Clear();
TwbBSEntryList(obj).free;
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSEntryList(obj).Clear();
TwbBSEntryList(obj).free;
except
on E: Exception do
exception_handler(E, Result);
end;
end;
function bsa_entry_list_count(obj: Pointer): Cardinal; stdcall;
function bsa_entry_list_count(obj: Pointer): Integer; stdcall;
begin
Result := TwbBSEntryList(obj).Count;
try
Result := TwbBSEntryList(obj).Count;
except
Result := Ord(BSA_RESULT_EXCEPTION);
end;
end;
procedure bsa_entry_list_add(obj: Pointer; const aEntryString: PChar); stdcall;
function bsa_entry_list_add(obj: Pointer; const aEntryString: PChar): TwbBSResultMessage; stdcall;
begin
TwbBSEntryList(obj).Add(String(aEntryString));
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSEntryList(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): Cardinal; stdcall;
function bsa_entry_list_get(obj: Pointer; const aIndex: Cardinal; const aStringBufferSize: Cardinal; const aStringBuffer: PChar): Integer; stdcall;
begin
Result := string_to_cstring(TwbBSEntryList(obj).Strings[aIndex], aStringBufferSize, aStringBuffer);
try
Result := string_to_cstring_end(TwbBSEntryList(obj).Strings[aIndex], aStringBufferSize, aStringBuffer);
except
Result := Integer(BSA_RESULT_EXCEPTION);
end;
end;
{BSArchive}
function bsa_create:Pointer; stdcall;
begin
Result := TwbBSArchive.Create;
try
Result := TwbBSArchive.Create;
except
Result := nil;
end;
end;
procedure bsa_free(obj: Pointer); stdcall;
function bsa_free(obj: Pointer): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).free;
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).free;
except
on E: Exception do
exception_handler(E, Result);
end;
end;
procedure bsa_load_from_file(obj: Pointer; const aFileName: PChar); stdcall;
function bsa_load_from_file(obj: Pointer; const aFilePath: PChar): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).LoadFromFile(String(aFileName));
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).LoadFromFile(String(aFilePath));
except
on E: Exception do
exception_handler(E, Result);
end;
end;
procedure bsa_create_archive(obj: Pointer; const aFileName: PChar; aType: TBSArchiveType; aFileList: TwbBSEntryList); stdcall;
function bsa_create_archive(obj: Pointer; const aFilePath: PChar; aType: TBSArchiveType; aFileList: TwbBSEntryList): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).CreateArchiveCompat(String(aFileName), aType, aFileList);
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).CreateArchiveCompat(String(aFilePath), aType, aFileList);
except
on E: Exception do
exception_handler(E, Result);
end;
end;
procedure bsa_save(obj: Pointer); stdcall;
function bsa_save(obj: Pointer): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).Save;
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).Save;
except
on E: Exception do
exception_handler(E, Result);
end;
end;
procedure bsa_add_file_from_disk(obj: Pointer; const aRootDir, aFileName: PChar); stdcall;
function bsa_add_file_from_disk_root(obj: Pointer; const aRootDir, aSourcePath: PChar): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).AddFile(String(aRootDir), String(aFileName));
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;
procedure bsa_add_file_from_memory(obj: Pointer; const aFileName: PChar; const aSize: Cardinal; const aData: PByte); stdcall;
function bsa_add_file_from_disk(obj: Pointer; const aFilePath, aSourcePath: PChar): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).AddFileCompat(String(aFileName), aSize, aData);
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_find_file_record(obj: Pointer; const aFileName: PChar): Pointer; stdcall;
function bsa_add_file_from_memory(obj: Pointer; const aFilePath: PChar; const aSize: Cardinal; const aData: PByte): TwbBSResultMessage; stdcall;
begin
Result := TwbBSArchive(obj).FindFileRecord(String(aFileName));
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).AddFileDataCompat(String(aFilePath), aSize, aData);
except
on E: Exception do
exception_handler(E, Result);
end;
end;
function bsa_extract_file_data_by_record(obj: Pointer; aFileRecord: Pointer): TwbBSFileDataResult; stdcall;
function bsa_find_file_record(obj: Pointer; const aFilePath: PChar): Pointer; stdcall;
begin
Result := TwbBSArchive(obj).ExtractFileDataCompat(aFileRecord);
try
Result := TwbBSArchive(obj).FindFileRecord(String(aFilePath));
except
Result := nil
end;
end;
function bsa_extract_file_data_by_filename(obj: Pointer; const aFileName: PChar): TwbBSFileDataResult; stdcall;
function bsa_extract_file_data_by_record(obj: Pointer; aFileRecord: Pointer): TwbBSResultMessageBuffer; stdcall;
begin
Result := TwbBSArchive(obj).ExtractFileDataCompat(String(aFileName));
Result.message.code := Ord(BSA_RESULT_NONE);
try
Result.buffer := TwbBSArchive(obj).ExtractFileDataCompat(aFileRecord);
except
on E: Exception do
buffer_exception_handler(E, Result);
end;
end;
procedure bsa_file_data_free(obj: Pointer; fileDataResult: TwbBSFileDataResult); stdcall;
function bsa_extract_file_data_by_filename(obj: Pointer; const aFilePath: PChar): TwbBSResultMessageBuffer; stdcall;
begin
TwbBSArchive(obj).ReleaseFileDataCompat(fileDataResult);
Result.message.code := Ord(BSA_RESULT_NONE);
try
Result.buffer := TwbBSArchive(obj).ExtractFileDataCompat(String(aFilePath));
except
on E: Exception do
buffer_exception_handler(E, Result);
end;
end;
procedure bsa_extract_file(obj: Pointer; const aFileName, aSaveAs: PChar); stdcall;
function bsa_file_data_free(obj: Pointer; fileDataResult: TwbBSResultMessageBuffer): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).ExtractFile(String(aFileName), String(aSaveAs));
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).ReleaseFileDataCompat(fileDataResult.buffer);
except
on E: Exception do
exception_handler(E, Result);
end;
end;
procedure bsa_iterate_files(obj: Pointer; aProc: TBSFileIterationProcCompat; aContext: Pointer); stdcall;
function bsa_extract_file(obj: Pointer; const aFilePath, aSaveAs: PChar): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).IterateFilesCompat(aProc, aContext);
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_file_exists(obj: Pointer; const aFileName: string): Boolean; stdcall;
function bsa_iterate_files(obj: Pointer; aProc: TBSFileIterationProcCompat; aContext: Pointer): TwbBSResultMessage; stdcall;
begin
Result := TwbBSArchive(obj).FileExists(aFileName);
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).IterateFilesCompat(aProc, aContext);
except
on E: Exception do
exception_handler(E, Result);
end;
end;
procedure bsa_get_resource_list(obj: Pointer; const aEntryResultList: TwbBSEntryList; aFolder: PChar); stdcall;
function bsa_file_exists(obj: Pointer; const aFilePath: string): Boolean; stdcall;
begin
TwbBSArchive(obj).ResourceListCompat(aEntryResultList, String(aFolder));
try
Result := TwbBSArchive(obj).FileExists(aFilePath);
except
Result := False;
end;
end;
procedure bsa_resolve_hash(obj: Pointer; const aHash: UInt64; const aEntryResultList: TwbBSEntryList); stdcall;
function bsa_get_resource_list(obj: Pointer; const aEntryResultList: TwbBSEntryList; aFolder: PChar): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).ResolveHashCompat(aHash, aEntryResultList);
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).ResourceListCompat(aEntryResultList, String(aFolder));
except
on E: Exception do
exception_handler(E, Result);
end;
end;
procedure bsa_close(obj: Pointer); stdcall;
function bsa_resolve_hash(obj: Pointer; const aHash: UInt64; const aEntryResultList: TwbBSEntryList): TwbBSResultMessage; stdcall;
begin
TwbBSArchive(obj).Close;
Result.code := Ord(BSA_RESULT_NONE);
try
TwbBSArchive(obj).ResolveHashCompat(aHash, aEntryResultList);
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(TwbBSArchive(obj).FileName, aStringBufferSize, aStringBuffer);
Result := string_to_cstring_end(TwbBSArchive(obj).FileName, aStringBufferSize, aStringBuffer);
end;
function bsa_archive_type_get(obj: Pointer): TBSArchiveType; stdcall;
@@ -150,7 +326,7 @@ end;
function bsa_format_name_get(obj: Pointer; const aStringBufferSize: Cardinal; const aStringBuffer: PChar): Cardinal; stdcall;
begin
Result := string_to_cstring(TwbBSArchive(obj).FormatName, aStringBufferSize, aStringBuffer);
Result := string_to_cstring_end(TwbBSArchive(obj).FormatName, aStringBufferSize, aStringBuffer);
end;
function bsa_file_count_get(obj: Pointer): Cardinal; stdcall;
@@ -198,9 +374,10 @@ begin
TwbBSArchive(obj).ShareData := shareData;
end;
procedure bsa_file_dds_info_callback_set(obj: Pointer; aProc: TBSFileDDSInfoProcCompat); stdcall;
procedure bsa_file_dds_info_callback_set(obj: Pointer; aProc: TBSFileDDSInfoProcCompat; aContext: Pointer); stdcall;
begin
TwbBSArchive(obj).DDSInfoProc := aProc;
TwbBSArchive(obj).DDSInfoProcContext := aContext;
end;
exports
@@ -236,6 +413,7 @@ exports
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,
+4 -2
View File
@@ -8,7 +8,7 @@
<AppType>Library</AppType>
<FrameworkType>None</FrameworkType>
<ProjectVersion>18.6</ProjectVersion>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<Platform Condition="'$(Platform)'==''">Win64</Platform>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
@@ -121,7 +121,8 @@
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Manifest_File>(None)</Manifest_File>
<DCC_ExeOutput>X64\Debug\</DCC_ExeOutput>
<Debugger_HostApplication>X64\Debug\libbsarch-visualstudio-test.exe</Debugger_HostApplication>
<Debugger_HostApplication>D:\Projects\libbsarch\x64\Debug\libbsarch-visualstudio-test.exe</Debugger_HostApplication>
<Debugger_CWD>D:\Projects\libbsarch\x64\Debug</Debugger_CWD>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
@@ -156,6 +157,7 @@
<Platform value="Win32">True</Platform>
<Platform value="Win64">True</Platform>
</Platforms>
<ModelSupport>False</ModelSupport>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
+61 -27
View File
@@ -12,8 +12,19 @@
#define BSARCH_DLL_API(ReturnType) extern "C" __declspec(dllimport) ReturnType __stdcall
#endif
#ifdef __GNUC__
#define PACKED(datastructure) datastructure __attribute__((__packed__))
#else
#define PACKED(datastructure) __pragma(pack(push, 1)) datastructure __pragma(pack(pop))
#endif
typedef enum bsa_result_code_e {
BSA_RESULT_NONE = 0,
BSA_RESULT_EXCEPTION = -1
} bsa_result_code_t;
typedef void* bsa_buffer_t;
typedef void* bsa_archive_t;
typedef void* bsa_file_data_t;
typedef void* bsa_entry_list_t;
typedef void* bsa_file_record_t;
typedef void* bsa_folder_record_t;
@@ -22,15 +33,37 @@ typedef struct bsa_dds_info_s {
uint32_t width, height, mipmaps;
} bsa_dds_info_t;
typedef struct bsa_dds_header_s {
PACKED (
struct bsa_dds_header_s {
uint32_t magic; // DDS_MAGIC
struct DirectX::DDS_HEADER header;
} bsa_dds_header_t;
});
typedef struct bsa_file_data_result_s {
typedef struct bsa_dds_header_s bsa_dds_header_t;
PACKED (
struct bsa_result_message_s {
int8_t code; // bsa_result_code_t
wchar_t text[1024];
});
typedef struct bsa_result_message_s bsa_result_message_t;
PACKED (
struct bsa_result_buffer_s {
uint32_t size;
bsa_file_data_t data;
} bsa_file_data_result_t;
bsa_buffer_t data;
});
typedef struct bsa_result_buffer_s bsa_result_buffer_t;
PACKED (
struct bsa_result_message_buffer_s {
bsa_result_buffer_t buffer;
bsa_result_message_t message;
});
typedef struct bsa_result_message_buffer_s bsa_result_message_buffer_t;
typedef enum bsa_archive_state_e {
stReading, stWriting
@@ -40,32 +73,33 @@ typedef enum bsa_archive_type_e {
baNone, baTES3, baTES4, baFO3, baSSE, baFO4, baFO4dds
} bsa_archive_type_t;
typedef void (*bsa_file_dds_info_proc_t)(bsa_archive_t archive, const wchar_t *filename, bsa_dds_info_t dds_info);
typedef bool (*bsa_file_iteration_proc_t)(bsa_archive_t archive, const wchar_t *filename, bsa_file_record_t file_record, bsa_folder_record_t folder_record, void *context);
typedef void (*bsa_file_dds_info_proc_t)(bsa_archive_t archive, const wchar_t *file_path, bsa_dds_info_t *dds_info, void *context);
typedef bool (*bsa_file_iteration_proc_t)(bsa_archive_t archive, const wchar_t *file_path, bsa_file_record_t file_record, bsa_folder_record_t folder_record, void *context);
BSARCH_DLL_API(bsa_entry_list_t) bsa_entry_list_create();
BSARCH_DLL_API(void) bsa_entry_list_free(bsa_entry_list_t entry_list);
BSARCH_DLL_API(bsa_result_message_t) bsa_entry_list_free(bsa_entry_list_t entry_list);
BSARCH_DLL_API(uint32_t) bsa_entry_list_count(bsa_entry_list_t entry_list);
BSARCH_DLL_API(void) bsa_entry_list_add(bsa_entry_list_t entry_list, const wchar_t *entry_string);
BSARCH_DLL_API(bsa_result_message_t) bsa_entry_list_add(bsa_entry_list_t entry_list, const wchar_t *entry_string);
BSARCH_DLL_API(uint32_t) bsa_entry_list_get(bsa_entry_list_t entry_list, uint32_t index, uint32_t string_buffer_size, const wchar_t *string_buffer);
BSARCH_DLL_API(bsa_archive_t) bsa_create();
BSARCH_DLL_API(void) bsa_free(bsa_archive_t archive);
BSARCH_DLL_API(void) bsa_load_from_file(bsa_archive_t archive, const wchar_t *filename);
BSARCH_DLL_API(void) bsa_create_archive(bsa_archive_t archive, const wchar_t *filename, bsa_archive_type_t archive_type, bsa_entry_list_t entry_list);
BSARCH_DLL_API(void) bsa_save(bsa_archive_t archive);
BSARCH_DLL_API(void) bsa_add_file_from_disk(bsa_archive_t archive, const wchar_t *root_dir, const wchar_t *filename);
BSARCH_DLL_API(void) bsa_add_file_from_memory(bsa_archive_t archive, const wchar_t *filename, uint32_t size, bsa_file_data_t data);
BSARCH_DLL_API(bsa_file_record_t) bsa_find_file_record(bsa_archive_t archive, const wchar_t *filename);
BSARCH_DLL_API(bsa_file_data_result_t) bsa_extract_file_data_by_record(bsa_archive_t archive, bsa_file_record_t file_record);
BSARCH_DLL_API(bsa_file_data_result_t) bsa_extract_file_data_by_filename(bsa_archive_t archive, const wchar_t *filename);
BSARCH_DLL_API(void) bsa_file_data_free(bsa_archive_t archive, bsa_file_data_result_t file_data_result);
BSARCH_DLL_API(void) bsa_extract_file(bsa_archive_t archive, const wchar_t *filename, const wchar_t *save_as);
BSARCH_DLL_API(void) bsa_iterate_files(bsa_archive_t archive, bsa_file_iteration_proc_t file_iteration_proc, void *context);
BSARCH_DLL_API(bool) bsa_file_exists(bsa_archive_t archive, const wchar_t *filename);
BSARCH_DLL_API(void) bsa_get_resource_list(bsa_archive_t archive, bsa_entry_list_t entry_result_list, const wchar_t *folder);
BSARCH_DLL_API(void) bsa_resolve_hash(bsa_archive_t archive, uint64_t hash, bsa_entry_list_t entry_result_list);
BSARCH_DLL_API(void) bsa_close(bsa_archive_t archive);
BSARCH_DLL_API(bsa_result_message_t) bsa_free(bsa_archive_t archive);
BSARCH_DLL_API(bsa_result_message_t) bsa_load_from_file(bsa_archive_t archive, const wchar_t *file_path);
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);
BSARCH_DLL_API(bsa_result_message_t) bsa_save(bsa_archive_t archive);
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);
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);
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);
BSARCH_DLL_API(bsa_file_record_t) bsa_find_file_record(bsa_archive_t archive, const wchar_t *file_path);
BSARCH_DLL_API(bsa_result_message_buffer_t) bsa_extract_file_data_by_record(bsa_archive_t archive, bsa_file_record_t file_record);
BSARCH_DLL_API(bsa_result_message_buffer_t) bsa_extract_file_data_by_filename(bsa_archive_t archive, const wchar_t *file_path);
BSARCH_DLL_API(bsa_result_message_t) bsa_file_data_free(bsa_archive_t archive, bsa_result_buffer_t file_data_result);
BSARCH_DLL_API(bsa_result_message_t) bsa_extract_file(bsa_archive_t archive, const wchar_t *file_path, const wchar_t *save_as);
BSARCH_DLL_API(bsa_result_message_t) bsa_iterate_files(bsa_archive_t archive, bsa_file_iteration_proc_t file_iteration_proc, void *context);
BSARCH_DLL_API(bool) bsa_file_exists(bsa_archive_t archive, const wchar_t *file_path);
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);
BSARCH_DLL_API(bsa_result_message_t) bsa_resolve_hash(bsa_archive_t archive, uint64_t hash, bsa_entry_list_t entry_result_list);
BSARCH_DLL_API(bsa_result_message_t) bsa_close(bsa_archive_t archive);
BSARCH_DLL_API(uint32_t) bsa_filename_get(bsa_archive_t archive, uint32_t string_buffer_size, const wchar_t *string_buffer);
BSARCH_DLL_API(bsa_archive_type_t) bsa_archive_type_get(bsa_archive_t archive);
@@ -81,4 +115,4 @@ BSARCH_DLL_API(void) bsa_compress_set(bsa_archive_t archive, bool flags);
BSARCH_DLL_API(bool) bsa_share_data_get(bsa_archive_t archive);
BSARCH_DLL_API(void) bsa_share_data_set(bsa_archive_t archive, bool flags);
BSARCH_DLL_API(void) bsa_file_dds_info_callback_set(bsa_archive_t archive, bsa_file_dds_info_proc_t file_dds_info_proc);
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);
+1
View File
@@ -149,6 +149,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<None Include=".vscode\ipch\c1c5ff332820ca89\mmap_address.bin" />
<None Include="cpp.hint" />
<None Include="libbsarch.def" />
<None Include="tforge\TFL.inc" />
</ItemGroup>
+1
View File
@@ -24,6 +24,7 @@
<None Include=".vscode\ipch\c1c5ff332820ca89\mmap_address.bin">
<Filter>Resource Files</Filter>
</None>
<None Include="cpp.hint" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="DDS.h">
+129 -115
View File
File diff suppressed because it is too large Load Diff