kgg-dec/src/infra/infra.h

50 lines
1.3 KiB
C
Raw Normal View History

2024-10-17 00:50:14 +00:00
#pragma once
#include <filesystem>
#include <unordered_map>
#include "sqlite_base.h"
2024-10-17 20:17:10 +00:00
#include "sqlite_fn.h"
2024-10-17 00:50:14 +00:00
namespace Infra {
typedef std::unordered_map<std::string, std::string> kgm_ekey_db_t;
extern bool g_init_sqlite_ok;
2024-10-17 20:17:10 +00:00
class SqliteDB {
2024-10-17 00:50:14 +00:00
public:
2024-10-17 20:17:10 +00:00
explicit SqliteDB(const std::filesystem::path& infra_dll_path);
bool Open(const std::filesystem::path& db_path, std::string_view key);
void Close();
[[nodiscard]] bool IsInfraOk() const { return ok_; }
[[nodiscard]] bool IsOpen() const { return db_ != nullptr; }
2024-10-17 00:50:14 +00:00
private:
2024-10-17 20:17:10 +00:00
bool InitInfraDll(const std::filesystem::path& infra_dll_path);
bool ok_{false};
protected:
void FreeInfraDll();
void* infra_{nullptr};
sqlite3_open_v2_t sqlite3_open_v2_{nullptr};
sqlite3_key_t sqlite3_key_{nullptr};
sqlite3_prepare_v2_t sqlite3_prepare_v2_{nullptr};
sqlite3_step_t sqlite3_step_{nullptr};
sqlite3_column_text_t sqlite3_column_text_{nullptr};
sqlite3_close_v2_t sqlite3_close_v2_{nullptr};
sqlite3_finalize_t sqlite3_finalize_{nullptr};
2024-10-17 00:50:14 +00:00
sqlite3* db_{nullptr};
};
2024-10-17 20:17:10 +00:00
class KugouDb : public SqliteDB {
public:
explicit KugouDb(const std::filesystem::path& infra_dll_path, const std::filesystem::path& db_path);
~KugouDb();
bool Open(const std::filesystem::path& db_path);
kgm_ekey_db_t dump_ekey(int& error);
};
2024-10-17 00:50:14 +00:00
} // namespace Infra