From 31ad79217c1292d9859df80883a71a4b8d67cf8d Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 27 Sep 2024 19:59:43 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BA=E6=96=87?= =?utf8?q?=E4=BB=B6=E5=A4=B9=E7=9A=84=E7=BB=9F=E4=B8=80=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../uicomponents/UIComponents.cpp | 23 ++++++++++++++++++- .../uicomponents/UIComponents.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 5c5d51daf..db029afaf 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -1,11 +1,14 @@ #include "uicomponents/UIComponents.h" #include #include -#include #include #include "common/text.h" #include "common/typed_text.h" #include "font/ui_font.h" +#include +#include +#include +#include namespace OHOS { @@ -890,5 +893,23 @@ namespace OHOS } printf("%s\r\n",str_); } + + /*创建文件夹*/ + void CreateDirectoryIfNotExists(const std::string &path) { + struct stat info; + if (stat(path.c_str(), &info) != 0) { + if (mkdir(path.c_str(), 0755) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Error: Could not create directory %s. Errno: %d", + path.c_str(), errno); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Created directory: %s", + path.c_str()); + } + } else if (info.st_mode & S_IFDIR) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", + path.c_str()); + } + } } diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index ca024b07d..41dccf9c3 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -304,6 +304,8 @@ namespace OHOS void updata_char(char *str_,char *str,uint32_t max_len); + void CreateDirectoryIfNotExists(const std::string &path); + #endif } // namespace OHOS -- 2.17.1