-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.c
More file actions
263 lines (208 loc) · 11.7 KB
/
config.c
File metadata and controls
263 lines (208 loc) · 11.7 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include "mouse_stabilizer.h"
// Global log level configuration (default: INFO)
LogLevel g_log_level = LOG_INFO;
void Settings_WriteLog(const char* format, ...) {
static FILE* log_file = NULL;
static bool first_call = true;
if (first_call) {
char log_path[MAX_PATH];
GetModuleFileName(NULL, log_path, MAX_PATH);
char* last_slash = strrchr(log_path, '\\');
if (last_slash) {
strcpy_s(last_slash + 1, MAX_PATH - (last_slash + 1 - log_path), "mouse_stabilizer.log");
}
if (fopen_s(&log_file, log_path, "a") != 0) {
log_file = NULL;
// Cannot log here since logging system is not yet initialized
}
first_call = false;
if (log_file) {
time_t now = time(NULL);
struct tm timeinfo;
localtime_s(&timeinfo, &now);
fprintf(log_file, "\n=== Mouse Stabilizer Started: %04d-%02d-%02d %02d:%02d:%02d ===\n",
timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday,
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
fflush(log_file);
}
}
if (!log_file) return;
time_t now = time(NULL);
struct tm timeinfo;
localtime_s(&timeinfo, &now);
fprintf(log_file, "[%02d:%02d:%02d] ",
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
va_list args;
va_start(args, format);
vfprintf(log_file, format, args);
va_end(args);
fprintf(log_file, "\n");
fflush(log_file);
}
void Settings_Load(void) {
char config_path[MAX_PATH];
GetModuleFileName(NULL, config_path, MAX_PATH);
char* last_slash = strrchr(config_path, '\\');
if (last_slash) {
strcpy_s(last_slash + 1, MAX_PATH - (last_slash + 1 - config_path), "mouse_stabilizer.ini");
}
g_stabilizer.follow_strength = (float)GetPrivateProfileInt("Settings", "FollowStrength",
(int)(DEFAULT_FOLLOW_STRENGTH * 100),
config_path) / 100.0f;
g_stabilizer.min_distance = (float)GetPrivateProfileInt("Settings", "MinDistance",
(int)(DEFAULT_MIN_DISTANCE * 10),
config_path) / 10.0f;
g_stabilizer.ease_type = (EaseType)GetPrivateProfileInt("Settings", "EaseType",
EASE_OUT, config_path);
g_stabilizer.dual_mode = GetPrivateProfileInt("Settings", "DualMode", 1, config_path) != 0;
g_stabilizer.enabled = GetPrivateProfileInt("Settings", "Enabled", 1, config_path) != 0;
g_stabilizer.delay_start_ms = GetPrivateProfileInt("Settings", "DelayStartMs",
DEFAULT_DELAY_START_MS, config_path);
g_stabilizer.target_show_distance = (float)GetPrivateProfileInt("Settings", "TargetShowDistance",
(int)(DEFAULT_TARGET_SHOW_DISTANCE * 10),
config_path) / 10.0f;
g_stabilizer.pointer_type = (PointerType)GetPrivateProfileInt("Settings", "PointerType",
DEFAULT_POINTER_TYPE, config_path);
g_stabilizer.target_size = GetPrivateProfileInt("Settings", "TargetSize",
DEFAULT_TARGET_SIZE, config_path);
g_stabilizer.target_alpha = GetPrivateProfileInt("Settings", "TargetAlpha",
DEFAULT_TARGET_ALPHA, config_path);
g_stabilizer.target_color = GetPrivateProfileInt("Settings", "TargetColor",
RGB(255, 100, 100), config_path);
// Load log level setting
g_log_level = (LogLevel)GetPrivateProfileInt("Settings", "LogLevel",
LOG_DEBUG, config_path); // Default to DEBUG for now
// Load capture exclusion settings
g_stabilizer.exclude_from_capture = GetPrivateProfileInt("Settings", "ExcludeFromCapture",
DEFAULT_EXCLUDE_FROM_CAPTURE ? 1 : 0, config_path) != 0;
g_stabilizer.capture_compatibility_mode = GetPrivateProfileInt("Settings", "CaptureCompatibilityMode",
DEFAULT_CAPTURE_COMPATIBILITY_MODE ? 1 : 0, config_path) != 0;
// Load target visibility setting
g_stabilizer.target_always_visible = GetPrivateProfileInt("Settings", "TargetAlwaysVisible",
DEFAULT_TARGET_ALWAYS_VISIBLE ? 1 : 0, config_path) != 0;
if (g_stabilizer.follow_strength < 0.05f) g_stabilizer.follow_strength = 0.05f;
if (g_stabilizer.follow_strength > 1.0f) g_stabilizer.follow_strength = 1.0f;
if (g_stabilizer.min_distance < 0.1f) g_stabilizer.min_distance = 0.1f;
if (g_stabilizer.min_distance > 5.0f) g_stabilizer.min_distance = 5.0f;
if (g_stabilizer.ease_type < 0 || g_stabilizer.ease_type > 3) {
g_stabilizer.ease_type = EASE_OUT;
}
if (g_stabilizer.delay_start_ms > 1000) g_stabilizer.delay_start_ms = 1000;
if (g_stabilizer.target_show_distance < 1.0f) g_stabilizer.target_show_distance = 1.0f;
if (g_stabilizer.target_show_distance > 50.0f) g_stabilizer.target_show_distance = 50.0f;
if (g_stabilizer.pointer_type < POINTER_CIRCLE || g_stabilizer.pointer_type > POINTER_CROSS) {
g_stabilizer.pointer_type = DEFAULT_POINTER_TYPE;
}
if (g_stabilizer.target_size < 3) g_stabilizer.target_size = 3;
if (g_stabilizer.target_size > 20) g_stabilizer.target_size = 20;
if (g_stabilizer.target_alpha < 50) g_stabilizer.target_alpha = 50;
if (g_stabilizer.target_alpha > 255) g_stabilizer.target_alpha = 255;
if (g_log_level < LOG_ERROR || g_log_level > LOG_TRACE) g_log_level = LOG_INFO;
Settings_WriteLog("Settings loaded - Follow: %.2f, Ease: %d, Dual: %s, Delay: %dms, TargetDist: %.1f, Enabled: %s",
g_stabilizer.follow_strength, g_stabilizer.ease_type,
g_stabilizer.dual_mode ? "true" : "false", g_stabilizer.delay_start_ms,
g_stabilizer.target_show_distance, g_stabilizer.enabled ? "true" : "false");
}
void Settings_Save(void) {
char config_path[MAX_PATH];
GetModuleFileName(NULL, config_path, MAX_PATH);
char* last_slash = strrchr(config_path, '\\');
if (last_slash) {
strcpy_s(last_slash + 1, MAX_PATH - (last_slash + 1 - config_path), "mouse_stabilizer.ini");
}
char buffer[32];
sprintf_s(buffer, sizeof(buffer), "%d", (int)(g_stabilizer.follow_strength * 100));
WritePrivateProfileString("Settings", "FollowStrength", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", (int)(g_stabilizer.min_distance * 10));
WritePrivateProfileString("Settings", "MinDistance", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", (int)g_stabilizer.ease_type);
WritePrivateProfileString("Settings", "EaseType", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", g_stabilizer.dual_mode ? 1 : 0);
WritePrivateProfileString("Settings", "DualMode", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", g_stabilizer.enabled ? 1 : 0);
WritePrivateProfileString("Settings", "Enabled", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%lu", (unsigned long)g_stabilizer.delay_start_ms);
WritePrivateProfileString("Settings", "DelayStartMs", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", (int)(g_stabilizer.target_show_distance * 10));
WritePrivateProfileString("Settings", "TargetShowDistance", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", (int)g_stabilizer.pointer_type);
WritePrivateProfileString("Settings", "PointerType", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", g_stabilizer.target_size);
WritePrivateProfileString("Settings", "TargetSize", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", g_stabilizer.target_alpha);
WritePrivateProfileString("Settings", "TargetAlpha", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", (int)g_stabilizer.target_color);
WritePrivateProfileString("Settings", "TargetColor", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", (int)g_log_level);
WritePrivateProfileString("Settings", "LogLevel", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", g_stabilizer.exclude_from_capture ? 1 : 0);
WritePrivateProfileString("Settings", "ExcludeFromCapture", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", g_stabilizer.capture_compatibility_mode ? 1 : 0);
WritePrivateProfileString("Settings", "CaptureCompatibilityMode", buffer, config_path);
sprintf_s(buffer, sizeof(buffer), "%d", g_stabilizer.target_always_visible ? 1 : 0);
WritePrivateProfileString("Settings", "TargetAlwaysVisible", buffer, config_path);
Settings_WriteLog("Settings saved");
}
/**
* Enhanced logging system with level control
*/
void Settings_WriteLogLevel(LogLevel level, const char* format, ...) {
// Skip logging if current level is below the message level
if (level > g_log_level) {
return;
}
static FILE* log_file = NULL;
static bool first_call = true;
if (first_call) {
char log_path[MAX_PATH];
GetModuleFileName(NULL, log_path, MAX_PATH);
char* last_slash = strrchr(log_path, '\\');
if (last_slash) {
strcpy_s(last_slash + 1, MAX_PATH - (last_slash + 1 - log_path), "mouse_stabilizer.log");
}
if (fopen_s(&log_file, log_path, "a") != 0) {
log_file = NULL;
}
first_call = false;
if (log_file) {
time_t now = time(NULL);
struct tm timeinfo;
localtime_s(&timeinfo, &now);
fprintf(log_file, "\n=== Mouse Stabilizer Started: %04d-%02d-%02d %02d:%02d:%02d ===\n",
timeinfo.tm_year + 1900, timeinfo.tm_mon + 1, timeinfo.tm_mday,
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec);
fflush(log_file);
}
}
if (!log_file) return;
time_t now = time(NULL);
struct tm timeinfo;
localtime_s(&timeinfo, &now);
// Add log level prefix to timestamp
const char* level_str = Settings_GetLogLevelName(level);
fprintf(log_file, "[%02d:%02d:%02d %s] ",
timeinfo.tm_hour, timeinfo.tm_min, timeinfo.tm_sec, level_str);
va_list args;
va_start(args, format);
vfprintf(log_file, format, args);
va_end(args);
fprintf(log_file, "\n");
fflush(log_file);
}
void Settings_SetLogLevel(LogLevel level) {
g_log_level = level;
LOG_INFO("Log level changed to: %s", Settings_GetLogLevelName(level));
}
LogLevel Settings_GetLogLevel(void) {
return g_log_level;
}
const char* Settings_GetLogLevelName(LogLevel level) {
switch (level) {
case LOG_ERROR: return "ERROR";
case LOG_WARN: return "WARN ";
case LOG_INFO: return "INFO ";
case LOG_DEBUG: return "DEBUG";
case LOG_TRACE: return "TRACE";
default: return "UNKN ";
}
}