darker
2025-02-11 23a50ec03beb2a4d99cc89766256a053d1d19727
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#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();
    }
}