/
githubmirror
/
TrafficMonitor
Обзор
Документация
Войти
/
githubmirror
/
TrafficMonitor
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
PluginDemo/DataManager.cpp
66 строк
2 KB
zhongyang219
时间日期插件的配置文件保存位置跟随主程序的设置
01 фев 2022, 16:27
01 фев 2022, 16:27
dd6c638
Код
Авторство
О чём код?
#include "pch.h" #include "DataManager.h" CDataManager CDataManager::m_instance; CDataManager::CDataManager() { } CDataManager::~CDataManager() { SaveConfig(); } CDataManager& CDataManager::Instance() { return m_instance; } void CDataManager::LoadConfig(const std::wstring& config_dir) { //获取模块的路径 HMODULE hModule = reinterpret_cast<HMODULE>(&__ImageBase); wchar_t path[MAX_PATH]; GetModuleFileNameW(hModule, path, MAX_PATH); std::wstring module_path = path; m_config_path = module_path; if (!config_dir.empty()) { size_t index = module_path.find_last_of(L"\\/"); //模块的文件名 std::wstring module_file_name = module_path.substr(index + 1); m_config_path = config_dir + module_file_name; } m_config_path += L".ini"; m_setting_data.show_second = GetPrivateProfileInt(_T("config"), _T("show_second"), 0, m_config_path.c_str()); //m_setting_data.show_label_text = GetPrivateProfileInt(_T("config"), _T("show_label_text"), 1, config_path.c_str()); } static void WritePrivateProfileInt(const wchar_t* app_name, const wchar_t* key_name, int value, const wchar_t* file_path) { wchar_t buff[16]; swprintf_s(buff, L"%d", value); WritePrivateProfileString(app_name, key_name, buff, file_path); } void CDataManager::SaveConfig() const { WritePrivateProfileInt(_T("config"), _T("show_second"), m_setting_data.show_second, m_config_path.c_str()); //WritePrivateProfileInt(_T("config"), _T("show_label_text"), m_setting_data.show_label_text, config_path.c_str()); } const CString& CDataManager::StringRes(UINT id) { auto iter = m_string_table.find(id); if (iter != m_string_table.end()) { return iter->second; } else { AFX_MANAGE_STATE(AfxGetStaticModuleState()); m_string_table[id].LoadString(id); return m_string_table[id]; } }