mirror of
https://github.com/LHY0125/PathEditor.git
synced 2026-05-09 18:02:52 +08:00
feat: 新增导入导出功能,支持备份和恢复 PATH 配置
- 添加 import_export 模块,实现 JSON 格式的导入导出 - 在界面中添加导入和导出按钮,并配置回调函数 - 更新配置文件,增加相关文本和状态提示 - 在非管理员权限下禁用导入按钮
This commit is contained in:
@@ -21,6 +21,7 @@ set(SOURCES
|
|||||||
src/core/path_manager.c
|
src/core/path_manager.c
|
||||||
src/core/app_context.c
|
src/core/app_context.c
|
||||||
src/core/lua_config.c
|
src/core/lua_config.c
|
||||||
|
src/core/import_export.c
|
||||||
src/controller/callbacks.c
|
src/controller/callbacks.c
|
||||||
ico/resources.rc
|
ico/resources.rc
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ int btn_del_cb(Ihandle *self);
|
|||||||
int btn_up_cb(Ihandle *self);
|
int btn_up_cb(Ihandle *self);
|
||||||
int btn_down_cb(Ihandle *self);
|
int btn_down_cb(Ihandle *self);
|
||||||
int btn_clean_cb(Ihandle *self);
|
int btn_clean_cb(Ihandle *self);
|
||||||
|
int btn_import_cb(Ihandle *self);
|
||||||
|
int btn_export_cb(Ihandle *self);
|
||||||
int btn_ok_cb(Ihandle *self);
|
int btn_ok_cb(Ihandle *self);
|
||||||
int btn_cancel_cb(Ihandle *self);
|
int btn_cancel_cb(Ihandle *self);
|
||||||
int btn_help_cb(Ihandle *self);
|
int btn_help_cb(Ihandle *self);
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef IMPORT_EXPORT_H
|
||||||
|
#define IMPORT_EXPORT_H
|
||||||
|
|
||||||
|
#include "utils/string_ext.h"
|
||||||
|
|
||||||
|
#define EXPORT_VERSION "1.0"
|
||||||
|
|
||||||
|
// 导出 PATH 到文件
|
||||||
|
int export_paths_to_file(const StringList *list, const char *filepath, int is_system);
|
||||||
|
|
||||||
|
// 从文件导入 PATH
|
||||||
|
int import_paths_from_file(const char *filepath, StringList *list);
|
||||||
|
|
||||||
|
#endif // IMPORT_EXPORT_H
|
||||||
+7
-2
@@ -31,6 +31,8 @@ local config = {
|
|||||||
up = "上移(U)",
|
up = "上移(U)",
|
||||||
down = "下移(O)",
|
down = "下移(O)",
|
||||||
clean = "一键清理",
|
clean = "一键清理",
|
||||||
|
import = "导入(I)",
|
||||||
|
export = "导出(E)",
|
||||||
ok = "确定",
|
ok = "确定",
|
||||||
cancel = "取消",
|
cancel = "取消",
|
||||||
help = "帮助(?)"
|
help = "帮助(?)"
|
||||||
@@ -41,7 +43,9 @@ local config = {
|
|||||||
title = "环境变量编辑器:",
|
title = "环境变量编辑器:",
|
||||||
search_placeholder = "输入关键词搜索...",
|
search_placeholder = "输入关键词搜索...",
|
||||||
tab_sys = "系统变量 (System)",
|
tab_sys = "系统变量 (System)",
|
||||||
tab_user = "用户变量 (User)"
|
tab_user = "用户变量 (User)",
|
||||||
|
export_title = "导出 PATH",
|
||||||
|
import_title = "导入 PATH"
|
||||||
},
|
},
|
||||||
|
|
||||||
-- 布局设置
|
-- 布局设置
|
||||||
@@ -64,7 +68,8 @@ local config = {
|
|||||||
error = "状态: ✗ 保存失败",
|
error = "状态: ✗ 保存失败",
|
||||||
deleted = "状态: 已删除选中项",
|
deleted = "状态: 已删除选中项",
|
||||||
loaded = "状态: 已加载系统和用户变量",
|
loaded = "状态: 已加载系统和用户变量",
|
||||||
drag_folder_only = "提示: 只能拖拽文件夹添加到 PATH"
|
drag_folder_only = "提示: 只能拖拽文件夹添加到 PATH",
|
||||||
|
admin_warning = "未检测到管理员权限,只能查看和导出 PATH,无法保存更改。"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+123
-18
@@ -3,6 +3,7 @@
|
|||||||
#include "core/registry_service.h"
|
#include "core/registry_service.h"
|
||||||
#include "core/path_manager.h"
|
#include "core/path_manager.h"
|
||||||
#include "core/lua_config.h"
|
#include "core/lua_config.h"
|
||||||
|
#include "core/import_export.h"
|
||||||
#include "utils/string_ext.h"
|
#include "utils/string_ext.h"
|
||||||
#include "utils/os_env.h"
|
#include "utils/os_env.h"
|
||||||
#include "ui/ui_utils.h"
|
#include "ui/ui_utils.h"
|
||||||
@@ -358,25 +359,106 @@ int btn_cancel_cb(Ihandle *self)
|
|||||||
return IUP_DEFAULT;
|
return IUP_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按钮回调:帮助
|
// 按钮回调:导入
|
||||||
int btn_help_cb(Ihandle *self)
|
int btn_import_cb(Ihandle *self)
|
||||||
{
|
{
|
||||||
IupMessage("使用说明",
|
Ihandle *dlg = IupGetDialog(self);
|
||||||
"1. 本程序用于编辑系统环境变量 PATH。\n"
|
AppContext *ctx = get_app_context(dlg);
|
||||||
"2. 必须以【管理员身份】运行才能保存更改。\n"
|
if (!ctx)
|
||||||
"3. 操作说明:\n"
|
return IUP_DEFAULT;
|
||||||
" - 新建:添加新路径到列表末尾。\n"
|
|
||||||
" - 编辑:修改选中的路径。\n"
|
if (!check_admin())
|
||||||
" - 浏览:从文件系统选择目录添加。\n"
|
{
|
||||||
" - 删除:移除选中的路径。\n"
|
IupMessage("错误", "需要管理员权限才能导入 PATH!");
|
||||||
" - 上移/下移:调整路径优先级。\n"
|
return IUP_DEFAULT;
|
||||||
"4. 点击【确定】保存更改并生效。\n"
|
}
|
||||||
"5. 注意:某些正在运行的程序可能需要重启才能识别新的环境变量。\n\n"
|
|
||||||
"--------------------------------------------------\n"
|
Ihandle *filedlg = IupFileDlg();
|
||||||
"作者:LHY\n"
|
IupSetAttribute(filedlg, "DIALOGTYPE", "OPEN");
|
||||||
"邮箱:3364451258@qq.com\n"
|
IupSetAttribute(filedlg, "TITLE", lua_config_get_string("label", "import_title"));
|
||||||
"GitHub:https://github.com/LHY0125/PathEditor\n"
|
IupSetAttribute(filedlg, "FILTER", "json");
|
||||||
"记得给我的项目点个star!");
|
IupSetAttribute(filedlg, "EXTFILTER", "JSON 文件 (*.json)|*.json|文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*");
|
||||||
|
|
||||||
|
IupPopup(filedlg, IUP_CENTER, IUP_CENTER);
|
||||||
|
|
||||||
|
if (IupGetInt(filedlg, "STATUS") != -1)
|
||||||
|
{
|
||||||
|
char *filepath = IupGetAttribute(filedlg, "VALUE");
|
||||||
|
if (filepath)
|
||||||
|
{
|
||||||
|
Ihandle *tabs_main = IupGetDialogChild(dlg, "TABS_MAIN");
|
||||||
|
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||||
|
|
||||||
|
StringList *target_list = (pos == 0) ? &ctx->sys_paths : &ctx->user_paths;
|
||||||
|
|
||||||
|
if (import_paths_from_file(filepath, target_list) == 0)
|
||||||
|
{
|
||||||
|
Ihandle *current_list = get_current_list(dlg);
|
||||||
|
sync_string_list_to_ui(current_list, target_list);
|
||||||
|
|
||||||
|
char msg[256];
|
||||||
|
snprintf(msg, sizeof(msg), "成功导入 %d 个路径!", target_list->count);
|
||||||
|
IupMessage("导入成功", msg);
|
||||||
|
|
||||||
|
Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS");
|
||||||
|
if (lbl_status)
|
||||||
|
IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "loaded"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IupMessage("错误", "导入失败,请检查文件格式是否正确!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IupDestroy(filedlg);
|
||||||
|
return IUP_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按钮回调:导出
|
||||||
|
int btn_export_cb(Ihandle *self)
|
||||||
|
{
|
||||||
|
Ihandle *dlg = IupGetDialog(self);
|
||||||
|
AppContext *ctx = get_app_context(dlg);
|
||||||
|
if (!ctx)
|
||||||
|
return IUP_DEFAULT;
|
||||||
|
|
||||||
|
Ihandle *tabs_main = IupGetDialogChild(dlg, "TABS_MAIN");
|
||||||
|
int pos = IupGetInt(tabs_main, "VALUEPOS");
|
||||||
|
|
||||||
|
StringList *source_list = (pos == 0) ? &ctx->sys_paths : &ctx->user_paths;
|
||||||
|
int is_system = (pos == 0);
|
||||||
|
|
||||||
|
Ihandle *filedlg = IupFileDlg();
|
||||||
|
IupSetAttribute(filedlg, "DIALOGTYPE", "SAVE");
|
||||||
|
IupSetAttribute(filedlg, "TITLE", lua_config_get_string("label", "export_title"));
|
||||||
|
IupSetAttribute(filedlg, "FILTER", "json");
|
||||||
|
IupSetAttribute(filedlg, "EXTFILTER", "JSON 文件 (*.json)|*.json");
|
||||||
|
IupSetAttribute(filedlg, "DEFAULTEXT", "json");
|
||||||
|
|
||||||
|
char default_name[64];
|
||||||
|
snprintf(default_name, sizeof(default_name), "path_%s.json", is_system ? "system" : "user");
|
||||||
|
IupSetAttribute(filedlg, "VALUE", default_name);
|
||||||
|
|
||||||
|
IupPopup(filedlg, IUP_CENTER, IUP_CENTER);
|
||||||
|
|
||||||
|
if (IupGetInt(filedlg, "STATUS") != -1)
|
||||||
|
{
|
||||||
|
char *filepath = IupGetAttribute(filedlg, "VALUE");
|
||||||
|
if (filepath)
|
||||||
|
{
|
||||||
|
if (export_paths_to_file(source_list, filepath, is_system) == 0)
|
||||||
|
{
|
||||||
|
char msg[256];
|
||||||
|
snprintf(msg, sizeof(msg), "成功导出 %d 个路径到:\n%s", source_list->count, filepath);
|
||||||
|
IupMessage("导出成功", msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IupMessage("错误", "导出失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IupDestroy(filedlg);
|
||||||
return IUP_DEFAULT;
|
return IUP_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,4 +487,27 @@ void load_all_paths(void)
|
|||||||
Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS");
|
Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS");
|
||||||
if (lbl_status)
|
if (lbl_status)
|
||||||
IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "loaded"));
|
IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "loaded"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按钮回调:帮助
|
||||||
|
int btn_help_cb(Ihandle *self)
|
||||||
|
{
|
||||||
|
IupMessage("使用说明",
|
||||||
|
"1. 本程序用于编辑系统环境变量 PATH。\n"
|
||||||
|
"2. 必须以【管理员身份】运行才能保存更改。\n"
|
||||||
|
"3. 操作说明:\n"
|
||||||
|
" - 新建:添加新路径到列表末尾。\n"
|
||||||
|
" - 编辑:修改选中的路径。\n"
|
||||||
|
" - 浏览:从文件系统选择目录添加。\n"
|
||||||
|
" - 删除:移除选中的路径。\n"
|
||||||
|
" - 上移/下移:调整路径优先级。\n"
|
||||||
|
" - 导入/导出:备份和恢复 PATH 配置。\n"
|
||||||
|
"4. 点击【确定】保存更改并生效。\n"
|
||||||
|
"5. 注意:某些正在运行的程序可能需要重启才能识别新的环境变量。\n\n"
|
||||||
|
"--------------------------------------------------\n"
|
||||||
|
"作者:LHY\n"
|
||||||
|
"邮箱:3364451258@qq.com\n"
|
||||||
|
"GitHub:https://github.com/LHY0125/PathEditor\n"
|
||||||
|
"记得给我的项目点个star!");
|
||||||
|
return IUP_DEFAULT;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,241 @@
|
|||||||
|
#include "core/import_export.h"
|
||||||
|
#include "utils/os_env.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
// 获取当前日期时间
|
||||||
|
static void get_current_datetime(char *buffer, int size)
|
||||||
|
{
|
||||||
|
time_t now = time(NULL);
|
||||||
|
struct tm *tm_info = localtime(&now);
|
||||||
|
strftime(buffer, size, "%Y-%m-%d %H:%M:%S", tm_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 转义 JSON 字符串中的特殊字符
|
||||||
|
static char *escape_json_string(const char *str)
|
||||||
|
{
|
||||||
|
if (!str)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
int len = strlen(str);
|
||||||
|
char *result = (char *)malloc(len * 2 + 1);
|
||||||
|
if (!result)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
char *p = result;
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
switch (str[i])
|
||||||
|
{
|
||||||
|
case '\\':
|
||||||
|
*p++ = '\\';
|
||||||
|
*p++ = '\\';
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
*p++ = '\\';
|
||||||
|
*p++ = '"';
|
||||||
|
break;
|
||||||
|
case '\n':
|
||||||
|
*p++ = '\\';
|
||||||
|
*p++ = 'n';
|
||||||
|
break;
|
||||||
|
case '\r':
|
||||||
|
*p++ = '\\';
|
||||||
|
*p++ = 'r';
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
*p++ = '\\';
|
||||||
|
*p++ = 't';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*p++ = str[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*p = '\0';
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出 PATH 到 JSON 文件
|
||||||
|
int export_paths_to_file(const StringList *list, const char *filepath, int is_system)
|
||||||
|
{
|
||||||
|
if (!list || !filepath)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
FILE *fp = fopen(filepath, "w, ccs=UTF-8");
|
||||||
|
if (!fp)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
char datetime[64];
|
||||||
|
get_current_datetime(datetime, sizeof(datetime));
|
||||||
|
|
||||||
|
fprintf(fp, "{\n");
|
||||||
|
fprintf(fp, " \"version\": \"%s\",\n", EXPORT_VERSION);
|
||||||
|
fprintf(fp, " \"type\": \"%s\",\n", is_system ? "SYSTEM" : "USER");
|
||||||
|
fprintf(fp, " \"exported\": \"%s\",\n", datetime);
|
||||||
|
fprintf(fp, " \"paths\": [\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < list->count; i++)
|
||||||
|
{
|
||||||
|
if (list->items[i])
|
||||||
|
{
|
||||||
|
char *escaped = escape_json_string(list->items[i]);
|
||||||
|
if (escaped)
|
||||||
|
{
|
||||||
|
fprintf(fp, " \"%s\"%s\n", escaped, (i < list->count - 1) ? "," : "");
|
||||||
|
free(escaped);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(fp, " ]\n");
|
||||||
|
fprintf(fp, "}\n");
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除字符串首尾的空格、制表符、换行符和回车符
|
||||||
|
static void trim_whitespace(char *str)
|
||||||
|
{
|
||||||
|
char *start = str;
|
||||||
|
while (*start == ' ' || *start == '\t')
|
||||||
|
start++;
|
||||||
|
|
||||||
|
char *end = str + strlen(str) - 1;
|
||||||
|
while (end > start && (*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r'))
|
||||||
|
*end-- = '\0';
|
||||||
|
|
||||||
|
if (start != str)
|
||||||
|
memmove(str, start, strlen(start) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否为注释行或空行
|
||||||
|
static int is_comment_or_empty(const char *line)
|
||||||
|
{
|
||||||
|
while (*line == ' ' || *line == '\t')
|
||||||
|
line++;
|
||||||
|
|
||||||
|
if (*line == '#' || *line == '\0')
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查是否为 JSON 文件
|
||||||
|
static int is_json_file(const char *filepath)
|
||||||
|
{
|
||||||
|
const char *ext = strrchr(filepath, '.');
|
||||||
|
return ext && strcasecmp(ext, ".json") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 从文件导入 PATH
|
||||||
|
int import_paths_from_file(const char *filepath, StringList *list)
|
||||||
|
{
|
||||||
|
if (!filepath || !list)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (is_json_file(filepath))
|
||||||
|
{
|
||||||
|
FILE *fp = fopen(filepath, "r, ccs=UTF-8");
|
||||||
|
if (!fp)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
clear_string_list(list);
|
||||||
|
|
||||||
|
char buffer[8192];
|
||||||
|
int in_paths = 0;
|
||||||
|
int depth = 0;
|
||||||
|
int in_string = 0;
|
||||||
|
char path_buffer[4096];
|
||||||
|
int path_len = 0;
|
||||||
|
|
||||||
|
while (fgets(buffer, sizeof(buffer), fp))
|
||||||
|
{
|
||||||
|
char *p = buffer;
|
||||||
|
while (*p)
|
||||||
|
{
|
||||||
|
if (*p == '"' && (p == buffer || *(p - 1) != '\\'))
|
||||||
|
{
|
||||||
|
in_string = !in_string;
|
||||||
|
}
|
||||||
|
else if (in_string && *p == '\\')
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
if (*p)
|
||||||
|
{
|
||||||
|
if (*p == 'n')
|
||||||
|
*p = '\n';
|
||||||
|
else if (*p == 'r')
|
||||||
|
*p = '\r';
|
||||||
|
else if (*p == 't')
|
||||||
|
*p = '\t';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!in_string)
|
||||||
|
{
|
||||||
|
if (*p == '{' || *p == '[')
|
||||||
|
depth++;
|
||||||
|
else if (*p == '}' || *p == ']')
|
||||||
|
depth--;
|
||||||
|
else if (*p == ':')
|
||||||
|
in_paths = (depth == 1);
|
||||||
|
else if (in_paths && depth == 2 && *p == '"')
|
||||||
|
{
|
||||||
|
path_len = 0;
|
||||||
|
p++;
|
||||||
|
while (*p && path_len < (int)sizeof(path_buffer) - 1)
|
||||||
|
{
|
||||||
|
if (*p == '"' && *(p - 1) != '\\')
|
||||||
|
break;
|
||||||
|
if (*p == '\\' && *(p + 1))
|
||||||
|
{
|
||||||
|
p++;
|
||||||
|
if (*p == 'n')
|
||||||
|
*p = '\n';
|
||||||
|
else if (*p == 'r')
|
||||||
|
*p = '\r';
|
||||||
|
else if (*p == 't')
|
||||||
|
*p = '\t';
|
||||||
|
}
|
||||||
|
path_buffer[path_len++] = *p++;
|
||||||
|
}
|
||||||
|
if (path_len > 0)
|
||||||
|
{
|
||||||
|
path_buffer[path_len] = '\0';
|
||||||
|
add_string_list(list, path_buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FILE *fp = fopen(filepath, "r, ccs=UTF-8");
|
||||||
|
if (!fp)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
clear_string_list(list);
|
||||||
|
|
||||||
|
char line[4096];
|
||||||
|
while (fgets(line, sizeof(line), fp))
|
||||||
|
{
|
||||||
|
trim_whitespace(line);
|
||||||
|
|
||||||
|
if (is_comment_or_empty(line))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
add_string_list(list, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
+91
-44
@@ -6,69 +6,116 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static lua_State* G_L = NULL;
|
static lua_State *G_L = NULL;
|
||||||
static int G_loaded = 0;
|
static int G_loaded = 0;
|
||||||
static const char* G_config_path = "lua/config.lua";
|
static const char *G_config_path = "lua/config.lua";
|
||||||
|
|
||||||
static const char* get_string_default(const char* section, const char* key)
|
static const char *get_string_default(const char *section, const char *key)
|
||||||
{
|
{
|
||||||
if (strcmp(section, "app") == 0)
|
if (strcmp(section, "app") == 0)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "name") == 0) return "PathEditor";
|
if (strcmp(key, "name") == 0)
|
||||||
if (strcmp(key, "name_readonly") == 0) return "PathEditor (只读模式)";
|
return "PathEditor";
|
||||||
|
if (strcmp(key, "name_readonly") == 0)
|
||||||
|
return "PathEditor (只读模式)";
|
||||||
}
|
}
|
||||||
else if (strcmp(section, "dialog") == 0)
|
else if (strcmp(section, "dialog") == 0)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "size") == 0) return "800x800";
|
if (strcmp(key, "size") == 0)
|
||||||
if (strcmp(key, "minsize") == 0) return "800x800";
|
return "800x800";
|
||||||
if (strcmp(key, "select_dir") == 0) return "选择目录";
|
if (strcmp(key, "minsize") == 0)
|
||||||
|
return "800x800";
|
||||||
|
if (strcmp(key, "select_dir") == 0)
|
||||||
|
return "选择目录";
|
||||||
}
|
}
|
||||||
else if (strcmp(section, "list") == 0)
|
else if (strcmp(section, "list") == 0)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "item_padding") == 0) return "5x5";
|
if (strcmp(key, "item_padding") == 0)
|
||||||
if (strcmp(key, "backcolor") == 0) return "255 255 255";
|
return "5x5";
|
||||||
|
if (strcmp(key, "backcolor") == 0)
|
||||||
|
return "255 255 255";
|
||||||
}
|
}
|
||||||
else if (strcmp(section, "button") == 0)
|
else if (strcmp(section, "button") == 0)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "rastersize") == 0) return "100x32";
|
if (strcmp(key, "rastersize") == 0)
|
||||||
if (strcmp(key, "new") == 0) return "新建(N)";
|
return "100x32";
|
||||||
if (strcmp(key, "edit") == 0) return "编辑(E)";
|
if (strcmp(key, "new") == 0)
|
||||||
if (strcmp(key, "browse") == 0) return "浏览(B)...";
|
return "新建(N)";
|
||||||
if (strcmp(key, "del") == 0) return "删除(D)";
|
if (strcmp(key, "edit") == 0)
|
||||||
if (strcmp(key, "up") == 0) return "上移(U)";
|
return "编辑(E)";
|
||||||
if (strcmp(key, "down") == 0) return "下移(O)";
|
if (strcmp(key, "browse") == 0)
|
||||||
if (strcmp(key, "clean") == 0) return "一键清理";
|
return "浏览(B)...";
|
||||||
if (strcmp(key, "ok") == 0) return "确定";
|
if (strcmp(key, "del") == 0)
|
||||||
if (strcmp(key, "cancel") == 0) return "取消";
|
return "删除(D)";
|
||||||
if (strcmp(key, "help") == 0) return "帮助(?)";
|
if (strcmp(key, "up") == 0)
|
||||||
|
return "上移(U)";
|
||||||
|
if (strcmp(key, "down") == 0)
|
||||||
|
return "下移(O)";
|
||||||
|
if (strcmp(key, "clean") == 0)
|
||||||
|
return "一键清理";
|
||||||
|
if (strcmp(key, "import") == 0)
|
||||||
|
return "导入(I)";
|
||||||
|
if (strcmp(key, "export") == 0)
|
||||||
|
return "导出(E)";
|
||||||
|
if (strcmp(key, "ok") == 0)
|
||||||
|
return "确定";
|
||||||
|
if (strcmp(key, "cancel") == 0)
|
||||||
|
return "取消";
|
||||||
|
if (strcmp(key, "help") == 0)
|
||||||
|
return "帮助(?)";
|
||||||
}
|
}
|
||||||
else if (strcmp(section, "label") == 0)
|
else if (strcmp(section, "label") == 0)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "title") == 0) return "环境变量编辑器:";
|
if (strcmp(key, "title") == 0)
|
||||||
if (strcmp(key, "search_placeholder") == 0) return "输入关键词搜索...";
|
return "环境变量编辑器:";
|
||||||
if (strcmp(key, "tab_sys") == 0) return "系统变量 (System)";
|
if (strcmp(key, "search_placeholder") == 0)
|
||||||
if (strcmp(key, "tab_user") == 0) return "用户变量 (User)";
|
return "输入关键词搜索...";
|
||||||
|
if (strcmp(key, "tab_sys") == 0)
|
||||||
|
return "系统变量 (System)";
|
||||||
|
if (strcmp(key, "tab_user") == 0)
|
||||||
|
return "用户变量 (User)";
|
||||||
|
if (strcmp(key, "export_title") == 0)
|
||||||
|
return "导出 PATH";
|
||||||
|
if (strcmp(key, "import_title") == 0)
|
||||||
|
return "导入 PATH";
|
||||||
}
|
}
|
||||||
else if (strcmp(section, "layout") == 0)
|
else if (strcmp(section, "layout") == 0)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "vbox_gap") == 0) return "5";
|
if (strcmp(key, "vbox_gap") == 0)
|
||||||
if (strcmp(key, "vbox_margin") == 0) return "0x0";
|
return "5";
|
||||||
if (strcmp(key, "vbox_all_margin") == 0) return "10x10";
|
if (strcmp(key, "vbox_margin") == 0)
|
||||||
if (strcmp(key, "vbox_all_gap") == 0) return "5";
|
return "0x0";
|
||||||
if (strcmp(key, "hbox_gap") == 0) return "10";
|
if (strcmp(key, "vbox_all_margin") == 0)
|
||||||
if (strcmp(key, "hbox_margin") == 0) return "10x10";
|
return "10x10";
|
||||||
if (strcmp(key, "hbox_alignment") == 0) return "ACENTER";
|
if (strcmp(key, "vbox_all_gap") == 0)
|
||||||
|
return "5";
|
||||||
|
if (strcmp(key, "hbox_gap") == 0)
|
||||||
|
return "10";
|
||||||
|
if (strcmp(key, "hbox_margin") == 0)
|
||||||
|
return "10x10";
|
||||||
|
if (strcmp(key, "hbox_alignment") == 0)
|
||||||
|
return "ACENTER";
|
||||||
}
|
}
|
||||||
else if (strcmp(section, "status") == 0)
|
else if (strcmp(section, "status") == 0)
|
||||||
{
|
{
|
||||||
if (strcmp(key, "normal") == 0) return "状态: 就绪";
|
if (strcmp(key, "normal") == 0)
|
||||||
if (strcmp(key, "readonly") == 0) return "状态: ⚠️ 只读模式 (无管理员权限)";
|
return "状态: 就绪";
|
||||||
if (strcmp(key, "saving") == 0) return "状态: 保存中...";
|
if (strcmp(key, "readonly") == 0)
|
||||||
if (strcmp(key, "saved") == 0) return "状态: ✓ 保存成功";
|
return "状态: ⚠️ 只读模式 (无管理员权限)";
|
||||||
if (strcmp(key, "error") == 0) return "状态: ✗ 保存失败";
|
if (strcmp(key, "saving") == 0)
|
||||||
if (strcmp(key, "deleted") == 0) return "状态: 已删除选中项";
|
return "状态: 保存中...";
|
||||||
if (strcmp(key, "loaded") == 0) return "状态: 已加载系统和用户变量";
|
if (strcmp(key, "saved") == 0)
|
||||||
if (strcmp(key, "drag_folder_only") == 0) return "提示: 只能拖拽文件夹添加到 PATH";
|
return "状态: ✓ 保存成功";
|
||||||
|
if (strcmp(key, "error") == 0)
|
||||||
|
return "状态: ✗ 保存失败";
|
||||||
|
if (strcmp(key, "deleted") == 0)
|
||||||
|
return "状态: 已删除选中项";
|
||||||
|
if (strcmp(key, "loaded") == 0)
|
||||||
|
return "状态: 已加载系统和用户变量";
|
||||||
|
if (strcmp(key, "drag_folder_only") == 0)
|
||||||
|
return "提示: 只能拖拽文件夹添加到 PATH";
|
||||||
|
if (strcmp(key, "admin_warning") == 0)
|
||||||
|
return "未检测到管理员权限,只能查看和导出 PATH,无法保存更改。";
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -90,7 +137,7 @@ int lua_config_init(void)
|
|||||||
|
|
||||||
if (luaL_dofile(G_L, G_config_path) != LUA_OK)
|
if (luaL_dofile(G_L, G_config_path) != LUA_OK)
|
||||||
{
|
{
|
||||||
const char* err = lua_tostring(G_L, -1);
|
const char *err = lua_tostring(G_L, -1);
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "[Lua Config] 加载配置文件失败: %s\n", err);
|
fprintf(stderr, "[Lua Config] 加载配置文件失败: %s\n", err);
|
||||||
@@ -115,7 +162,7 @@ void lua_config_destroy(void)
|
|||||||
G_loaded = 0;
|
G_loaded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* lua_config_get_string(const char* section, const char* key)
|
const char *lua_config_get_string(const char *section, const char *key)
|
||||||
{
|
{
|
||||||
if (G_L == NULL || section == NULL || key == NULL)
|
if (G_L == NULL || section == NULL || key == NULL)
|
||||||
{
|
{
|
||||||
@@ -143,13 +190,13 @@ const char* lua_config_get_string(const char* section, const char* key)
|
|||||||
return get_string_default(section, key);
|
return get_string_default(section, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* value = lua_tostring(G_L, -1);
|
const char *value = lua_tostring(G_L, -1);
|
||||||
lua_settop(G_L, 0);
|
lua_settop(G_L, 0);
|
||||||
|
|
||||||
return value ? value : get_string_default(section, key);
|
return value ? value : get_string_default(section, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int lua_config_get_int(const char* section, const char* key, int default_value)
|
int lua_config_get_int(const char *section, const char *key, int default_value)
|
||||||
{
|
{
|
||||||
if (G_L == NULL || section == NULL || key == NULL)
|
if (G_L == NULL || section == NULL || key == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ int main(int argc, char **argv)
|
|||||||
// 检查管理员权限
|
// 检查管理员权限
|
||||||
if (!check_admin())
|
if (!check_admin())
|
||||||
{
|
{
|
||||||
|
IupMessage("警告", lua_config_get_string("status", "admin_warning"));
|
||||||
|
|
||||||
Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS");
|
Ihandle *lbl_status = IupGetDialogChild(dlg, "LBL_STATUS");
|
||||||
if (lbl_status)
|
if (lbl_status)
|
||||||
IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "readonly"));
|
IupSetAttribute(lbl_status, "TITLE", lua_config_get_string("status", "readonly"));
|
||||||
@@ -113,6 +115,13 @@ int main(int argc, char **argv)
|
|||||||
IupSetAttribute(btn_clean, "ACTIVE", "NO");
|
IupSetAttribute(btn_clean, "ACTIVE", "NO");
|
||||||
if (btn_ok)
|
if (btn_ok)
|
||||||
IupSetAttribute(btn_ok, "ACTIVE", "NO");
|
IupSetAttribute(btn_ok, "ACTIVE", "NO");
|
||||||
|
|
||||||
|
Ihandle *btn_import = IupGetDialogChild(dlg, "BTN_IMPORT");
|
||||||
|
Ihandle *btn_export = IupGetDialogChild(dlg, "BTN_EXPORT");
|
||||||
|
if (btn_import)
|
||||||
|
IupSetAttribute(btn_import, "ACTIVE", "NO");
|
||||||
|
if (btn_export)
|
||||||
|
IupSetAttribute(btn_export, "ACTIVE", "NO");
|
||||||
}
|
}
|
||||||
|
|
||||||
IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
|
IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ Ihandle *create_main_window(void)
|
|||||||
Ihandle *btn_clean = IupButton(lua_config_get_string("button", "clean"), NULL);
|
Ihandle *btn_clean = IupButton(lua_config_get_string("button", "clean"), NULL);
|
||||||
IupSetAttribute(btn_clean, "NAME", "BTN_CLEAN");
|
IupSetAttribute(btn_clean, "NAME", "BTN_CLEAN");
|
||||||
|
|
||||||
|
Ihandle *btn_import = IupButton(lua_config_get_string("button", "import"), NULL);
|
||||||
|
IupSetAttribute(btn_import, "NAME", "BTN_IMPORT");
|
||||||
|
Ihandle *btn_export = IupButton(lua_config_get_string("button", "export"), NULL);
|
||||||
|
IupSetAttribute(btn_export, "NAME", "BTN_EXPORT");
|
||||||
|
|
||||||
// 设置按钮回调
|
// 设置按钮回调
|
||||||
IupSetCallback(btn_new, "ACTION", (Icallback)btn_new_cb);
|
IupSetCallback(btn_new, "ACTION", (Icallback)btn_new_cb);
|
||||||
IupSetCallback(btn_edit, "ACTION", (Icallback)btn_edit_cb);
|
IupSetCallback(btn_edit, "ACTION", (Icallback)btn_edit_cb);
|
||||||
@@ -69,6 +74,8 @@ Ihandle *create_main_window(void)
|
|||||||
IupSetCallback(btn_up, "ACTION", (Icallback)btn_up_cb);
|
IupSetCallback(btn_up, "ACTION", (Icallback)btn_up_cb);
|
||||||
IupSetCallback(btn_down, "ACTION", (Icallback)btn_down_cb);
|
IupSetCallback(btn_down, "ACTION", (Icallback)btn_down_cb);
|
||||||
IupSetCallback(btn_clean, "ACTION", (Icallback)btn_clean_cb);
|
IupSetCallback(btn_clean, "ACTION", (Icallback)btn_clean_cb);
|
||||||
|
IupSetCallback(btn_import, "ACTION", (Icallback)btn_import_cb);
|
||||||
|
IupSetCallback(btn_export, "ACTION", (Icallback)btn_export_cb);
|
||||||
|
|
||||||
// 设置按钮大小
|
// 设置按钮大小
|
||||||
const char *btn_size = lua_config_get_string("button", "rastersize");
|
const char *btn_size = lua_config_get_string("button", "rastersize");
|
||||||
@@ -79,6 +86,8 @@ Ihandle *create_main_window(void)
|
|||||||
IupSetAttribute(btn_up, "RASTERSIZE", btn_size);
|
IupSetAttribute(btn_up, "RASTERSIZE", btn_size);
|
||||||
IupSetAttribute(btn_down, "RASTERSIZE", btn_size);
|
IupSetAttribute(btn_down, "RASTERSIZE", btn_size);
|
||||||
IupSetAttribute(btn_clean, "RASTERSIZE", btn_size);
|
IupSetAttribute(btn_clean, "RASTERSIZE", btn_size);
|
||||||
|
IupSetAttribute(btn_import, "RASTERSIZE", btn_size);
|
||||||
|
IupSetAttribute(btn_export, "RASTERSIZE", btn_size);
|
||||||
|
|
||||||
// 创建操作按钮垂直布局
|
// 创建操作按钮垂直布局
|
||||||
Ihandle *vbox_btns = IupVbox(
|
Ihandle *vbox_btns = IupVbox(
|
||||||
@@ -86,6 +95,7 @@ Ihandle *create_main_window(void)
|
|||||||
IupFill(),
|
IupFill(),
|
||||||
btn_clean,
|
btn_clean,
|
||||||
IupFill(),
|
IupFill(),
|
||||||
|
btn_import, btn_export,
|
||||||
btn_up, btn_down,
|
btn_up, btn_down,
|
||||||
NULL);
|
NULL);
|
||||||
IupSetAttribute(vbox_btns, "GAP", lua_config_get_string("layout", "vbox_gap"));
|
IupSetAttribute(vbox_btns, "GAP", lua_config_get_string("layout", "vbox_gap"));
|
||||||
|
|||||||
Reference in New Issue
Block a user