refactor(core): 统一使用ErrorCode并添加错误日志记录

- 将path_manager和import_export模块的返回值从int/void改为ErrorCode
- 在关键操作中添加日志记录,便于调试和错误追踪
- 更新调用代码以检查错误码并记录错误
- 修改运行命令以管理员权限启动程序
This commit is contained in:
2026-03-26 18:27:38 +08:00
parent 3af0e96060
commit 9a78b88c4a
6 changed files with 80 additions and 38 deletions
+19 -12
View File
@@ -1,51 +1,57 @@
#include "core/path_manager.h"
#include "utils/os_env.h"
#include "utils/error_code.h"
#include "utils/logger.h"
#include <stdlib.h>
#include <string.h>
// 删除指定索引的路径项
void path_manager_remove_at(StringList *list, int index)
ErrorCode path_manager_remove_at(StringList *list, int index)
{
if (!list || index < 0 || index >= list->count)
return;
return ERR_NULL_PTR;
free(list->items[index]);
for (int i = index; i < list->count - 1; i++)
{
list->items[i] = list->items[i + 1];
}
list->items[list->count - 1] = NULL;
list->count--;
return ERR_OK;
}
// 向上移动路径项
void path_manager_move_up(StringList *list, int index)
ErrorCode path_manager_move_up(StringList *list, int index)
{
if (!list || index <= 0 || index >= list->count)
return;
return ERR_NULL_PTR;
char *temp = list->items[index];
list->items[index] = list->items[index - 1];
list->items[index - 1] = temp;
return ERR_OK;
}
// 向下移动路径项
void path_manager_move_down(StringList *list, int index)
ErrorCode path_manager_move_down(StringList *list, int index)
{
if (!list || index < 0 || index >= list->count - 1)
return;
return ERR_NULL_PTR;
char *temp = list->items[index];
list->items[index] = list->items[index + 1];
list->items[index + 1] = temp;
return ERR_OK;
}
// 清理无效路径项
int path_manager_clean(StringList *list)
ErrorCode path_manager_clean(StringList *list)
{
if (!list) return 0;
if (!list) return ERR_NULL_PTR;
int removed_count = 0;
// 从后往前遍历,方便删除
for (int i = list->count - 1; i >= 0; i--)
{
char *item = list->items[i];
@@ -53,14 +59,12 @@ int path_manager_clean(StringList *list)
int should_remove = 0;
// 1. 检查有效性
if (!is_path_valid(item))
{
should_remove = 1;
}
else
{
// 2. 检查重复 (检查当前项之前是否出现过)
for (int j = 0; j < i; j++)
{
char *prev_item = list->items[j];
@@ -78,5 +82,8 @@ int path_manager_clean(StringList *list)
removed_count++;
}
}
return removed_count;
log_info("Cleaned paths: removed %d invalid/duplicate paths, remaining %d",
removed_count, list->count);
return ERR_OK;
}