From 5dca9ae3a5580fb39b5d8218ef0cf1c599d36459 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 9 Oct 2020 18:23:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0GetLocalAppdataPath=E5=87=BD?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E4=BD=BF=E5=85=B6=E9=A3=8E=E6=A0=BC=E5=92=8C?= =?UTF-8?q?=E5=85=B6=E5=AE=83=E5=87=BD=E6=95=B0=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Android/ProgramPath.cpp | 5 +++-- src/Apple/ProgramPath.mm | 5 +++-- src/UNIX/ProgramPath.cpp | 5 +++-- src/Win/ProgramPath.cpp | 10 ++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Android/ProgramPath.cpp b/src/Android/ProgramPath.cpp index d87a548..9ea2217 100644 --- a/src/Android/ProgramPath.cpp +++ b/src/Android/ProgramPath.cpp @@ -17,9 +17,10 @@ namespace hgl strcpy(files_dir,HGL_MAX_PATH,fn); } - void GetLocalAppdataPath(char fn[HGL_MAX_PATH]) + bool GetLocalAppdataPath(OSString &result) { - strcpy(fn,HGL_MAX_PATH,files_dir); + result=files_dir; + return(true); } /** diff --git a/src/Apple/ProgramPath.mm b/src/Apple/ProgramPath.mm index ae6bfec..c77e82e 100644 --- a/src/Apple/ProgramPath.mm +++ b/src/Apple/ProgramPath.mm @@ -5,13 +5,14 @@ namespace hgl { namespace filesystem { - void GetLocalAppdataPath(char fn[HGL_MAX_PATH]) + bool GetLocalAppdataPath(OSString &result) { NSFileManager *dfm=[NSFileManager defaultManager]; const char *str=[[[dfm homeDirectoryForCurrentUser] path] cStringUsingEncoding:NSUTF8StringEncoding]; - hgl::strcpy(fn,HGL_MAX_PATH,str,strlen(str)); + result=str; + return(true); } /** diff --git a/src/UNIX/ProgramPath.cpp b/src/UNIX/ProgramPath.cpp index 34f0328..e84f267 100644 --- a/src/UNIX/ProgramPath.cpp +++ b/src/UNIX/ProgramPath.cpp @@ -7,7 +7,7 @@ namespace hgl { namespace filesystem { - void GetLocalAppdataPath(os_char fn[HGL_MAX_PATH]) + bool GetLocalAppdataPath(OSString &result) { struct passwd pwd; struct passwd *result; @@ -21,9 +21,10 @@ namespace hgl getpwuid_r(getuid(),&pwd,buf,bufsize,&result); - strcpy(fn,HGL_MAX_PATH,pwd.pw_dir); + result=pwd.pw_dir; free(buf); + return(true); } /** diff --git a/src/Win/ProgramPath.cpp b/src/Win/ProgramPath.cpp index f7d08b3..a73f828 100644 --- a/src/Win/ProgramPath.cpp +++ b/src/Win/ProgramPath.cpp @@ -6,9 +6,15 @@ namespace hgl { namespace filesystem { - void GetLocalAppdataPath(os_char fn[HGL_MAX_PATH]) + bool GetLocalAppdataPath(OSString &result) { - SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, fn); + os_char fn[HGL_MAX_PATH]; + + if(SHGetFolderPathW(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, fn)!=S_OK) + return(false); + + result=fn; + return(true); } /**