fix: 修复JSON导入、备份目录创建和内存安全等问题

修复JSON导入时转义字符处理不完整的问题,添加对\b、\f等控制字符的转义
改进备份目录创建逻辑,使用SHCreateDirectoryExW递归创建目录
修复内存分配失败处理,避免空指针解引用
修正选项卡标题设置位置,从Dialog改为Tabs控件
增强导入功能,支持TXT文件导入时选择目标变量类型
优化清理无效路径算法,使用标记数组减少内存移动
修复宽字符环境变量设置,使用_wputenv_s替代putenv
添加导入数据初始化,防止未初始化内存访问
改进文件属性检查,使用宽字符API支持Unicode路径
This commit is contained in:
2026-04-28 22:21:06 +08:00
parent 7908bad1f4
commit e777b26879
11 changed files with 257 additions and 157 deletions
+12 -1
View File
@@ -42,6 +42,8 @@ int btn_import_cb(Ihandle *self)
if (filepath)
{
ExportData imported;
init_string_list(&imported.system);
init_string_list(&imported.user);
ErrorCode import_result = import_paths_from_file(filepath, &imported);
if (import_result == ERR_OK)
{
@@ -51,6 +53,8 @@ int btn_import_cb(Ihandle *self)
if (!has_system && !has_user)
{
IupMessage("错误", "文件中没有找到有效的路径!");
clear_string_list(&imported.system);
clear_string_list(&imported.user);
IupDestroy(filedlg);
return IUP_DEFAULT;
}
@@ -63,7 +67,10 @@ int btn_import_cb(Ihandle *self)
}
else if (has_system)
{
choice = 3;
// TXT 文件导入时,让用户选择目标(系统变量或用户变量)
choice = IupAlarm("导入选项", "请选择导入目标:",
"导入到系统变量", "导入到用户变量", NULL);
// IupAlarm 返回 1 或 2,转换为 1(系统) 或 2(用户)
}
else
{
@@ -96,6 +103,10 @@ int btn_import_cb(Ihandle *self)
total_imported += imported.user.count;
}
// 释放导入数据
clear_string_list(&imported.system);
clear_string_list(&imported.user);
char msg[256];
snprintf(msg, sizeof(msg), "成功导入 %d 个路径!", total_imported);
IupMessage("导入成功", msg);