mirror of
https://github.com/huiyiruciduojiao/FuckScreenCap.git
synced 2026-01-28 03:54:37 +08:00
107 lines
3.0 KiB
C++
107 lines
3.0 KiB
C++
#pragma once
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
/**
|
|
* 配置管理库 - 用于管理进程过滤和其他配置选项
|
|
*/
|
|
namespace ConfigManager {
|
|
|
|
// 进程过滤配置结构
|
|
struct ProcessFilterConfig {
|
|
enum FilterMode {
|
|
WHITELIST, // 白名单模式:只处理列表中的进程
|
|
BLACKLIST // 黑名单模式:处理除列表中以外的进程
|
|
};
|
|
|
|
FilterMode mode = WHITELIST;
|
|
std::unordered_set<std::string> processList;
|
|
bool caseSensitive = false;
|
|
|
|
void clear();
|
|
};
|
|
|
|
// 配置管理器类
|
|
class Config {
|
|
private:
|
|
ProcessFilterConfig m_filterConfig;
|
|
std::string m_configFilePath;
|
|
|
|
// 工具函数
|
|
std::string toLowerCase(const std::string& str) const;
|
|
std::string trim(const std::string& str) const;
|
|
bool fileExists(const std::string& filePath) const;
|
|
|
|
public:
|
|
Config();
|
|
explicit Config(const std::string& configPath);
|
|
~Config() = default;
|
|
|
|
// 配置文件路径管理
|
|
void setConfigPath(const std::string& configPath);
|
|
std::string getConfigPath() const;
|
|
std::string getDefaultConfigPath() const;
|
|
|
|
// 配置加载和保存
|
|
bool loadConfig();
|
|
bool loadConfig(const std::string& configPath);
|
|
bool saveDefaultConfig() const;
|
|
bool saveDefaultConfig(const std::string& configPath) const;
|
|
bool reloadConfig();
|
|
|
|
// 进程过滤配置访问
|
|
const ProcessFilterConfig& getProcessFilterConfig() const;
|
|
ProcessFilterConfig& getProcessFilterConfig();
|
|
|
|
// 进程过滤相关方法
|
|
bool shouldProcessBeHooked(const std::string& processName) const;
|
|
void setFilterMode(ProcessFilterConfig::FilterMode mode);
|
|
ProcessFilterConfig::FilterMode getFilterMode() const;
|
|
void setCaseSensitive(bool sensitive);
|
|
bool isCaseSensitive() const;
|
|
|
|
// 进程列表管理
|
|
void addProcess(const std::string& processName);
|
|
void removeProcess(const std::string& processName);
|
|
void clearProcessList();
|
|
std::vector<std::string> getProcessList() const;
|
|
size_t getProcessCount() const;
|
|
|
|
// 配置验证
|
|
bool isConfigValid() const;
|
|
|
|
// 调试信息
|
|
void printConfig() const;
|
|
};
|
|
|
|
// 全局配置实例管理
|
|
class GlobalConfig {
|
|
private:
|
|
static Config* s_instance;
|
|
static bool s_initialized;
|
|
|
|
public:
|
|
static bool initialize();
|
|
static bool initialize(const std::string& configPath);
|
|
static void cleanup();
|
|
static Config* getInstance();
|
|
static bool isInitialized();
|
|
};
|
|
|
|
// 便捷函数
|
|
bool initializeGlobalConfig();
|
|
bool initializeGlobalConfig(const std::string& configPath);
|
|
Config* getGlobalConfig();
|
|
void cleanupGlobalConfig();
|
|
|
|
// 直接操作全局配置的便捷函数
|
|
bool shouldProcessBeHooked(const std::string& processName);
|
|
bool reloadGlobalConfig();
|
|
}
|
|
|
|
// 兼容性宏定义
|
|
#define PROCESS_FILTER_WHITELIST ConfigManager::ProcessFilterConfig::WHITELIST
|
|
#define PROCESS_FILTER_BLACKLIST ConfigManager::ProcessFilterConfig::BLACKLIST |