darker
2025-02-11 9b2d1e962bf802f75c44c1f5372fc4cf029e3f4e
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 "SECSConfigManager.h"
 
// ³£Á¿
const std::string DATABASE_FILE = R"(SECSConfigManager.db)";
 
// ¾²Ì¬³ÉÔ±³õʼ»¯
std::mutex SECSConfigManager::m_mutex;
 
// »ñÈ¡µ¥ÀýʵÀý
SECSConfigManager& SECSConfigManager::getInstance() {
    static SECSConfigManager instance;
    return instance;
}
 
// ¹¹Ô캯Êý
SECSConfigManager::SECSConfigManager() {
    m_pDB = new BL::SQLiteDatabase();
}
 
// Îö¹¹º¯Êý
SECSConfigManager::~SECSConfigManager() {
    termSECSSetting();
 
    if (m_pDB != nullptr) {
        delete m_pDB;
        m_pDB = nullptr;
    }
}
 
// ÉèÖÃÊý¾Ý¿âÁ¬½Ó
void SECSConfigManager::setDatabase(BL::Database* db) {
    std::lock_guard<std::mutex> lock(m_mutex);
    m_pDB = db;
}
 
// ³õʼ»¯SECSÉèÖùÜÀí¿â
bool SECSConfigManager::initSECSSetting() {
    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 SECSConfigManager::termSECSSetting() {
    if (m_pDB != nullptr) {
        m_pDB->disconnect();
    }
}