blob: 9e37e05bb4d4c7d8c51193f568a0ab2815a5fab5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#pragma once
#include <libbsarch/libbsarch.h>
#include <string>
#include <stdexcept>
#include <cstring>
#include <QDebug>
#include <QDir>
#include <QStringList>
namespace QLibBsarch
{
constexpr bool enableDebugLog = true;
#define LOG_LIBBSARCH \
if constexpr (QLibBsarch::enableDebugLog) \
qDebug() << "[QLIBBSARCH] " << __FUNCTION__ << ' '
#define PREPARE_PATH_LIBBSARCH(qstring) reinterpret_cast<const wchar_t *>(QDir::toNativeSeparators(qstring).utf16())
inline const std::string wcharToString(const wchar_t *text) { return QString::fromWCharArray(text).toStdString(); }
inline void checkResult(const bsa_result_message_s &result)
{
if (result.code == BSA_RESULT_EXCEPTION)
{
wchar_t aligned_text[1024];
std::memcpy(aligned_text, result.text, sizeof(aligned_text));
const std::string error = QLibBsarch::wcharToString(aligned_text);
LOG_LIBBSARCH << QString::fromStdString(error);
throw std::runtime_error(error);
}
}
inline void checkResult(const bsa_result_message_buffer_s &result)
{
checkResult(result.message);
}
} // namespace QLibBsarch
|