From e1c0edff89726cc0130e3c46a8a90cf428b5a660 Mon Sep 17 00:00:00 2001 From: Caisking Date: Tue, 20 May 2025 20:44:21 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=88=A4=E6=96=AD=E6=96=87?= =?utf8?q?=E4=BB=B6=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E7=9A=84=E9=80=9A?= =?utf8?q?=E7=94=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- code/sdk/zhihui/utils/custom_utils.c | 38 ++++++++++++++++++++++++++++ code/sdk/zhihui/utils/custom_utils.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/code/sdk/zhihui/utils/custom_utils.c b/code/sdk/zhihui/utils/custom_utils.c index f4cee04a4..abf6b47d3 100644 --- a/code/sdk/zhihui/utils/custom_utils.c +++ b/code/sdk/zhihui/utils/custom_utils.c @@ -114,6 +114,8 @@ #include "mag_hal.h" #endif +#include + errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg) { if (task_cfg==NULL) @@ -1319,6 +1321,42 @@ void ScreenAlwaysOnCtr(uint8_t turnOnFlag) } } + +bool uapi_create_dir(const char *path) +{ + if (path == NULL || strlen(path) == 0) { + PRINT("[DirCreate] ERROR: Invalid path (NULL or empty)\n"); + return false; + } + + PRINT("[DirCreate] Checking directory: %s\n", path); + + struct stat info; + // 检查目录是否存在 + if (stat(path, &info) != 0) { + PRINT("[DirCreate] Directory does not exist, creating...\n"); + + // 目录不存在,尝试创建 + if (mkdir(path, 0755) != 0) { + // 创建失败,打印错误信息 + PRINT("[DirCreate] ERROR: Failed to create directory %s (errno=%d)\n", path, errno); + return false; + } + + PRINT("[DirCreate] SUCCESS: Directory created: %s\n", path); + return true; + } + + // 检查是否为目录 + if (info.st_mode & S_IFDIR) { + PRINT("[DirCreate] Directory already exists: %s\n", path); + return true; + } + + return false; +} + + // Is the screen always on bool mmi_screen_always_on_flag_get(void) { diff --git a/code/sdk/zhihui/utils/custom_utils.h b/code/sdk/zhihui/utils/custom_utils.h index f1bf6ef42..f355bec5c 100644 --- a/code/sdk/zhihui/utils/custom_utils.h +++ b/code/sdk/zhihui/utils/custom_utils.h @@ -163,6 +163,9 @@ errcode_t uapi_get_fw_version(uint8_t *_major, uint8_t *_mid,uint8_t *_minor); * @} */ + //判断文件夹是否存在 + bool uapi_create_dir(const char *path); + // 使能翻腕亮灭屏功能接口 // cmd: 1-active;other-deactive void uapi_take_to_wake(int cmd); -- 2.17.1