解决linux系统上面获取的文档目录不准确的问题
This commit is contained in:
parent
b89e7a1e86
commit
c09f7936a5
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue