This commit is contained in:
yangjiaxuan 2023-05-11 21:07:46 +08:00
commit 00ae7dbda2
1 changed files with 23 additions and 1 deletions

View File

@ -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)