From c09f7936a58d0b7cacedc4c4c0890cfe80f5b3a3 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Thu, 11 May 2023 15:09:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3linux=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=B8=8A=E9=9D=A2=E8=8E=B7=E5=8F=96=E7=9A=84=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/base/HGUtility.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/base/HGUtility.cpp b/modules/base/HGUtility.cpp index 29aa6e32..0b7f7eb6 100644 --- a/modules/base/HGUtility.cpp +++ b/modules/base/HGUtility.cpp @@ -414,7 +414,29 @@ HGResult HGAPI HGBase_GetDocumentsPath(HGChar* documentsPath, HGUInt maxLen) strcpy(docPath, pw->pw_dir); if (docPath[strlen(docPath) - 1] != '/') strcat(docPath, "/"); - strcat(docPath, "Documents/"); + std::string docName; + FILE* file = popen("cat $HOME/.config/user-dirs.dirs | grep DOCUMENTS | tail -1 | cut -d '=' -f 2 | sed 's/\"//g'", "r"); + if (NULL != file) + { + char data[1024] = { 0 }; + if (NULL != fgets(data, 1024, file)) + { + char* start = strchr(data, '/'); + if (NULL != start && 0 != *(start + 1)) + { + char* end = strchr(start + 1, '\n'); + if (NULL != end) + *end = 0; + docName = start + 1; + } + } + + pclose(file); + } + if (docName.empty()) + docName = "Documents"; + strcat(docPath, docName.c_str()); + strcat(docPath, "/"); #endif if (maxLen < strlen(docPath) + 1)