#include "stdafx.h"
|
#include "SECSRuntimeManager.h"
|
|
// ³£Á¿
|
const std::string DATABASE_FILE = R"(SECSRuntimeManager.db)";
|
|
// ¾²Ì¬³ÉÔ±³õʼ»¯
|
std::mutex SECSRuntimeManager::m_mutex;
|
|
// »ñÈ¡µ¥ÀýʵÀý
|
SECSRuntimeManager& SECSRuntimeManager::getInstance() {
|
static SECSRuntimeManager instance;
|
return instance;
|
}
|
|
// ¹¹Ô캯Êý
|
SECSRuntimeManager::SECSRuntimeManager() {
|
m_pDB = new BL::SQLiteDatabase();
|
}
|
|
// Îö¹¹º¯Êý
|
SECSRuntimeManager::~SECSRuntimeManager() {
|
termRuntimeSetting();
|
|
if (m_pDB != nullptr) {
|
delete m_pDB;
|
m_pDB = nullptr;
|
}
|
}
|
|
// ÉèÖÃÊý¾Ý¿âÁ¬½Ó
|
void SECSRuntimeManager::setDatabase(BL::Database* db) {
|
std::lock_guard<std::mutex> lock(m_mutex);
|
m_pDB = db;
|
}
|
|
// ³õʼ»¯SECSÉèÖùÜÀí¿â
|
bool SECSRuntimeManager::initRuntimeSetting() {
|
char path[MAX_PATH];
|
GetModuleFileName(NULL, path, MAX_PATH);
|
std::string exePath(path);
|
std::string dbFileDir = exePath.substr(0, exePath.find_last_of("\\/")) + "\\DB";
|
if (!CreateDirectory(dbFileDir.c_str(), NULL) && ERROR_ALREADY_EXISTS != GetLastError()) {
|
throw std::runtime_error("Failed to create database directory.");
|
}
|
|
std::string dbFilePath = dbFileDir + "\\" + DATABASE_FILE;
|
if (!m_pDB->connect(dbFilePath, true)) {
|
return false;
|
}
|
|
return true;
|
}
|
|
// Ïú»ÙSECSÉèÖùÜÀí¿â
|
void SECSRuntimeManager::termRuntimeSetting() {
|
if (m_pDB != nullptr) {
|
m_pDB->disconnect();
|
}
|
}
|